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() { |
||
38 | |||
39 | /** |
||
40 | * Update the new (target) post data with the source post data. |
||
41 | * |
||
42 | * @param int $target_post_id Target post ID. |
||
43 | * @param WP_Post $post Target post object (not used). |
||
44 | * @param bool $update Whether this is an existing post being updated or not. |
||
45 | * @return void |
||
46 | */ |
||
47 | public function update_post_data( $target_post_id, $post, $update ) { |
||
90 | |||
91 | /** |
||
92 | * Determine if the current user has edit access to the source post. |
||
93 | * |
||
94 | * @param int $post_id Source post ID (the post being copied). |
||
95 | * @return bool True if user has the meta cap of `edit_post` for the given post ID, false otherwise. |
||
96 | */ |
||
97 | protected function user_can_access_post( $post_id ) { |
||
100 | |||
101 | /** |
||
102 | * Update the target post's title, content, excerpt, categories, and tags. |
||
103 | * |
||
104 | * @param WP_Post $source_post Post object to be copied. |
||
105 | * @param int $target_post_id Target post ID. |
||
106 | * @return int 0 on failure, or the updated post ID on success. |
||
107 | */ |
||
108 | protected function update_content( $source_post, $target_post_id ) { |
||
136 | |||
137 | /** |
||
138 | * Update terms for post types. |
||
139 | * |
||
140 | * @param WP_Post $source_post Post object to be copied. |
||
141 | * @param int $target_post_id Target post ID. |
||
142 | * @return array Results of attempts to set each term to the target (new) post. |
||
143 | */ |
||
144 | protected function update_post_type_terms( $source_post, $target_post_id ) { |
||
160 | |||
161 | /** |
||
162 | * Update the target post's featured image. |
||
163 | * |
||
164 | * @param WP_Post $source_post Post object to be copied. |
||
165 | * @param int $target_post_id Target post ID. |
||
166 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
||
167 | */ |
||
168 | protected function update_featured_image( $source_post, $target_post_id ) { |
||
172 | |||
173 | /** |
||
174 | * Update the target post's post format. |
||
175 | * |
||
176 | * @param WP_Post $source_post Post object to be copied. |
||
177 | * @param int $target_post_id Target post ID. |
||
178 | * @return array|WP_Error|false WP_Error on error, array of affected term IDs on success. |
||
179 | */ |
||
180 | protected function update_post_format( $source_post, $target_post_id ) { |
||
184 | |||
185 | /** |
||
186 | * Ensure the block editor doesn't modify the source post content for non-standard post formats. |
||
187 | * |
||
188 | * @param array $settings Settings to be passed into the block editor. |
||
189 | * @return array Settings with any `template` key removed. |
||
190 | */ |
||
191 | public function remove_post_format_template( $settings ) { |
||
195 | |||
196 | /** |
||
197 | * Update the target post's Likes and Sharing statuses. |
||
198 | * |
||
199 | * @param WP_Post $source_post Post object to be copied. |
||
200 | * @param int $target_post_id Target post ID. |
||
201 | * @return array Array with the results of each update action. |
||
202 | */ |
||
203 | protected function update_likes_sharing( $source_post, $target_post_id ) { |
||
213 | |||
214 | /** |
||
215 | * Update the target post's title. |
||
216 | * |
||
217 | * @param string $post_title Post title determined by `get_default_post_to_edit()`. |
||
218 | * @param WP_Post $post Post object of newly-inserted post. |
||
219 | * @return string Updated post title from source post. |
||
220 | */ |
||
221 | public function filter_title( $post_title, $post ) { |
||
224 | |||
225 | /** |
||
226 | * Update the target post's content (`post_content`). |
||
227 | * |
||
228 | * @param string $post_content Post content determined by `get_default_post_to_edit()`. |
||
229 | * @param WP_Post $post Post object of newly-inserted post. |
||
230 | * @return string Updated post content from source post. |
||
231 | */ |
||
232 | public function filter_content( $post_content, $post ) { |
||
235 | |||
236 | /** |
||
237 | * Update the target post's excerpt. |
||
238 | * |
||
239 | * @param string $post_excerpt Post excerpt determined by `get_default_post_to_edit()`. |
||
240 | * @param WP_Post $post Post object of newly-inserted post. |
||
241 | * @return string Updated post excerpt from source post. |
||
242 | */ |
||
243 | public function filter_excerpt( $post_excerpt, $post ) { |
||
246 | |||
247 | /** |
||
248 | * Validate the post type to be used for the target post. |
||
249 | * |
||
250 | * @param WP_Post $post Post object of current post in listing. |
||
251 | * @return bool True if the post type is in a list of supported psot types; false otherwise. |
||
252 | */ |
||
253 | protected function validate_post_type( $post ) { |
||
277 | |||
278 | /** |
||
279 | * Add a "Copy" row action to supported posts/pages/CPTs on list views. |
||
280 | * |
||
281 | * @param array $actions Existing actions. |
||
282 | * @param WP_Post $post Post object of current post in list. |
||
283 | * @return array Array of updated row actions. |
||
284 | */ |
||
285 | public function add_row_action( $actions, $post ) { |
||
330 | } |
||
331 | |||
339 |
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.