1 | <?php |
||
15 | class Jetpack_Copy_Post { |
||
16 | |||
17 | /** |
||
18 | * Jetpack_Copy_Post_By_Param constructor. |
||
19 | * Add row actions to post/page/CPT listing screens. |
||
20 | * Process any `?copy` param if on a create new post/page/CPT screen. |
||
21 | * |
||
22 | * @return void |
||
|
|||
23 | */ |
||
24 | function __construct() { |
||
35 | |||
36 | /** |
||
37 | * Update the new (target) post data with the source post data. |
||
38 | * |
||
39 | * @param int $target_post_id Target post ID. |
||
40 | * @param WP_Post $post Target post object (not used). |
||
41 | * @param bool $update Whether this is an existing post being updated or not. |
||
42 | * @return void |
||
43 | */ |
||
44 | function update_post_data( $target_post_id, $post, $update ) { |
||
66 | |||
67 | /** |
||
68 | * Determine if the current user has access to the source post. |
||
69 | * |
||
70 | * @param WP_Post $post Source post object (the post being copied). |
||
71 | * @return bool True if current user is the post author, or has permissions for `edit_others_posts`; false otherwise. |
||
72 | */ |
||
73 | protected function user_can_edit_post( $post ) { |
||
76 | |||
77 | /** |
||
78 | * Update the target post's title, content, excerpt, categories, and tags. |
||
79 | * |
||
80 | * @param WP_Post $source_post Post object to be copied. |
||
81 | * @param int $target_post_id Target post ID. |
||
82 | * @return int 0 on failure, or the updated post ID on success. |
||
83 | */ |
||
84 | protected function update_content_and_taxonomies( $source_post, $target_post_id ) { |
||
95 | |||
96 | /** |
||
97 | * Update the target post's featured image. |
||
98 | * |
||
99 | * @param WP_Post $source_post Post object to be copied. |
||
100 | * @param int $target_post_id Target post ID. |
||
101 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
||
102 | */ |
||
103 | protected function update_featured_image( $source_post, $target_post_id ) { |
||
107 | |||
108 | /** |
||
109 | * Update the target post's post format. |
||
110 | * |
||
111 | * @param WP_Post $source_post Post object to be copied. |
||
112 | * @param int $target_post_id Target post ID. |
||
113 | * @return array|WP_Error|false WP_Error on error, array of affected term IDs on success. |
||
114 | */ |
||
115 | protected function update_post_format( $source_post, $target_post_id ) { |
||
119 | |||
120 | /** |
||
121 | * Update the target post's title. |
||
122 | * |
||
123 | * @param string $post_title Post title determined by `get_default_post_to_edit()`. |
||
124 | * @param WP_Post $post Post object of newly-inserted post. |
||
125 | * @return string Updated post title from source post. |
||
126 | */ |
||
127 | function filter_title( $post_title, $post ) { |
||
130 | |||
131 | /** |
||
132 | * Update the target post's content (`post_content`). |
||
133 | * |
||
134 | * @param string $post_content Post content determined by `get_default_post_to_edit()`. |
||
135 | * @param WP_Post $post Post object of newly-inserted post. |
||
136 | * @return string Updated post content from source post. |
||
137 | */ |
||
138 | function filter_content( $post_content, $post ) { |
||
141 | |||
142 | /** |
||
143 | * Update the target post's excerpt. |
||
144 | * |
||
145 | * @param string $post_excerpt Post excerpt determined by `get_default_post_to_edit()`. |
||
146 | * @param WP_Post $post Post object of newly-inserted post. |
||
147 | * @return string Updated post excerpt from source post. |
||
148 | */ |
||
149 | function filter_excerpt( $post_excerpt, $post ) { |
||
152 | |||
153 | /** |
||
154 | * Add a "Copy" row action to posts/pages/CPTs on list views. |
||
155 | * |
||
156 | * @param array $actions Existing actions. |
||
157 | * @param WP_Post $post Post object of current post in list. |
||
158 | * @return array Array of updated row actions. |
||
159 | */ |
||
160 | function add_row_action( $actions, $post ) { |
||
185 | } |
||
186 | |||
191 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.