PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Framework / PostTrait.php

PostTrait.php in Packeta trunk, at src/Packetery/Module/Framework/PostTrait.php

53 lines 929 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Trait PostTrait.
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Framework;
11
12 use WP_Post;
13
14 /**
15 * Trait PostTrait.
16 *
17 * @package Packetery
18 */
19 trait PostTrait {
20 /**
21 * Retrieves data from a post field based on Post ID.
22 *
23 * @param string $field Post field name.
24 * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
25 *
26 * @return string
27 */
28 public function getPostField( string $field, $post ): string {
29 return get_post_field( $field, $post );
30 }
31
32 /**
33 * @return int|false
34 */
35 public function getTheId() {
36 return get_the_ID();
37 }
38
39 /**
40 * @param int|WP_Post $post
41 * @param string $context
42 *
43 * @return string|null
44 */
45 public function getEditPostLink( $post, string $context ): ?string {
46 return get_edit_post_link( $post, $context );
47 }
48
49 public function resetPostdata(): void {
50 wp_reset_postdata();
51 }
52 }
53