1 | <?php |
||
18 | class Jetpack_Copy_Post { |
||
19 | /** |
||
20 | * Jetpack_Copy_Post_By_Param constructor. |
||
21 | * Add row actions to post/page/CPT listing screens. |
||
22 | * Process any `?copy` param if on a create new post/page/CPT screen. |
||
23 | * |
||
24 | * @return void |
||
|
|||
25 | */ |
||
26 | public function __construct() { |
||
37 | |||
38 | /** |
||
39 | * Update the new (target) post data with the source post data. |
||
40 | * |
||
41 | * @param int $target_post_id Target post ID. |
||
42 | * @param WP_Post $post Target post object (not used). |
||
43 | * @param bool $update Whether this is an existing post being updated or not. |
||
44 | * @return void |
||
45 | */ |
||
46 | public function update_post_data( $target_post_id, $post, $update ) { |
||
86 | |||
87 | /** |
||
88 | * Determine if the current user has edit access to the source post. |
||
89 | * |
||
90 | * @param int $post_id Source post ID (the post being copied). |
||
91 | * @return bool True if user has the meta cap of `edit_post` for the given post ID, false otherwise. |
||
92 | */ |
||
93 | protected function user_can_access_post( $post_id ) { |
||
96 | |||
97 | /** |
||
98 | * Update the target post's title, content, excerpt, categories, and tags. |
||
99 | * |
||
100 | * @param WP_Post $source_post Post object to be copied. |
||
101 | * @param int $target_post_id Target post ID. |
||
102 | * @return int 0 on failure, or the updated post ID on success. |
||
103 | */ |
||
104 | protected function update_content( $source_post, $target_post_id ) { |
||
132 | |||
133 | /** |
||
134 | * Update terms for post types. |
||
135 | * |
||
136 | * @param WP_Post $source_post Post object to be copied. |
||
137 | * @param int $target_post_id Target post ID. |
||
138 | * @return array Results of attempts to set each term to the target (new) post. |
||
139 | */ |
||
140 | protected function update_post_type_terms( $source_post, $target_post_id ) { |
||
156 | |||
157 | /** |
||
158 | * Update the target post's featured image. |
||
159 | * |
||
160 | * @param WP_Post $source_post Post object to be copied. |
||
161 | * @param int $target_post_id Target post ID. |
||
162 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
||
163 | */ |
||
164 | protected function update_featured_image( $source_post, $target_post_id ) { |
||
168 | |||
169 | /** |
||
170 | * Update the target post's post format. |
||
171 | * |
||
172 | * @param WP_Post $source_post Post object to be copied. |
||
173 | * @param int $target_post_id Target post ID. |
||
174 | * @return array|WP_Error|false WP_Error on error, array of affected term IDs on success. |
||
175 | */ |
||
176 | protected function update_post_format( $source_post, $target_post_id ) { |
||
180 | |||
181 | /** |
||
182 | * Update the target post's Likes and Sharing statuses. |
||
183 | * |
||
184 | * @param WP_Post $source_post Post object to be copied. |
||
185 | * @param int $target_post_id Target post ID. |
||
186 | * @return array Array with the results of each update action. |
||
187 | */ |
||
188 | protected function update_likes_sharing( $source_post, $target_post_id ) { |
||
198 | |||
199 | /** |
||
200 | * Update the target post's title. |
||
201 | * |
||
202 | * @param string $post_title Post title determined by `get_default_post_to_edit()`. |
||
203 | * @param WP_Post $post Post object of newly-inserted post. |
||
204 | * @return string Updated post title from source post. |
||
205 | */ |
||
206 | public function filter_title( $post_title, $post ) { |
||
209 | |||
210 | /** |
||
211 | * Update the target post's content (`post_content`). |
||
212 | * |
||
213 | * @param string $post_content Post content determined by `get_default_post_to_edit()`. |
||
214 | * @param WP_Post $post Post object of newly-inserted post. |
||
215 | * @return string Updated post content from source post. |
||
216 | */ |
||
217 | public function filter_content( $post_content, $post ) { |
||
220 | |||
221 | /** |
||
222 | * Update the target post's excerpt. |
||
223 | * |
||
224 | * @param string $post_excerpt Post excerpt determined by `get_default_post_to_edit()`. |
||
225 | * @param WP_Post $post Post object of newly-inserted post. |
||
226 | * @return string Updated post excerpt from source post. |
||
227 | */ |
||
228 | public function filter_excerpt( $post_excerpt, $post ) { |
||
231 | |||
232 | /** |
||
233 | * Validate the post type to be used for the target post. |
||
234 | * |
||
235 | * @param WP_Post $post Post object of current post in listing. |
||
236 | * @return bool True if the post type is in a list of supported psot types; false otherwise. |
||
237 | */ |
||
238 | protected function validate_post_type( $post ) { |
||
262 | |||
263 | /** |
||
264 | * Add a "Copy" row action to supported posts/pages/CPTs on list views. |
||
265 | * |
||
266 | * @param array $actions Existing actions. |
||
267 | * @param WP_Post $post Post object of current post in list. |
||
268 | * @return array Array of updated row actions. |
||
269 | */ |
||
270 | public function add_row_action( $actions, $post ) { |
||
315 | } |
||
316 | |||
324 |
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.