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() { |
||
39 | |||
40 | /** |
||
41 | * Update the new (target) post data with the source post data. |
||
42 | * |
||
43 | * @param int $target_post_id Target post ID. |
||
44 | * @param WP_Post $post Target post object (not used). |
||
45 | * @param bool $update Whether this is an existing post being updated or not. |
||
46 | * @return void |
||
47 | */ |
||
48 | public function update_post_data( $target_post_id, $post, $update ) { |
||
87 | |||
88 | /** |
||
89 | * Determine if the current user has access to the source post. |
||
90 | * |
||
91 | * @param int $post_id Source post ID (the post being copied). |
||
92 | * @return bool True if user has the meta cap of `read_post` for the given post ID, false otherwise. |
||
93 | */ |
||
94 | protected function user_can_access_post( $post_id ) { |
||
97 | |||
98 | /** |
||
99 | * Update the target post's title, content, excerpt, categories, and tags. |
||
100 | * |
||
101 | * @param WP_Post $source_post Post object to be copied. |
||
102 | * @param int $target_post_id Target post ID. |
||
103 | * @return int 0 on failure, or the updated post ID on success. |
||
104 | */ |
||
105 | protected function update_content( $source_post, $target_post_id ) { |
||
132 | |||
133 | /** |
||
134 | * Update the target post's featured image. |
||
135 | * |
||
136 | * @param WP_Post $source_post Post object to be copied. |
||
137 | * @param int $target_post_id Target post ID. |
||
138 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
||
139 | */ |
||
140 | protected function update_featured_image( $source_post, $target_post_id ) { |
||
144 | |||
145 | /** |
||
146 | * Update the target post's post format. |
||
147 | * |
||
148 | * @param WP_Post $source_post Post object to be copied. |
||
149 | * @param int $target_post_id Target post ID. |
||
150 | * @return array|WP_Error|false WP_Error on error, array of affected term IDs on success. |
||
151 | */ |
||
152 | protected function update_post_format( $source_post, $target_post_id ) { |
||
156 | |||
157 | /** |
||
158 | * Update the target post's Likes and Sharing statuses. |
||
159 | * |
||
160 | * @param WP_Post $source_post Post object to be copied. |
||
161 | * @param int $target_post_id Target post ID. |
||
162 | * @return array Array with the results of each update action. |
||
163 | */ |
||
164 | protected function update_likes_sharing( $source_post, $target_post_id ) { |
||
174 | |||
175 | /** |
||
176 | * Update the target post's title. |
||
177 | * |
||
178 | * @param string $post_title Post title determined by `get_default_post_to_edit()`. |
||
179 | * @param WP_Post $post Post object of newly-inserted post. |
||
180 | * @return string Updated post title from source post. |
||
181 | */ |
||
182 | public function filter_title( $post_title, $post ) { |
||
185 | |||
186 | /** |
||
187 | * Update the target post's content (`post_content`). |
||
188 | * |
||
189 | * @param string $post_content Post content determined by `get_default_post_to_edit()`. |
||
190 | * @param WP_Post $post Post object of newly-inserted post. |
||
191 | * @return string Updated post content from source post. |
||
192 | */ |
||
193 | public function filter_content( $post_content, $post ) { |
||
196 | |||
197 | /** |
||
198 | * Update the target post's excerpt. |
||
199 | * |
||
200 | * @param string $post_excerpt Post excerpt determined by `get_default_post_to_edit()`. |
||
201 | * @param WP_Post $post Post object of newly-inserted post. |
||
202 | * @return string Updated post excerpt from source post. |
||
203 | */ |
||
204 | public function filter_excerpt( $post_excerpt, $post ) { |
||
207 | |||
208 | /** |
||
209 | * Validate the post type to be used for the target post. |
||
210 | * |
||
211 | * @param WP_Post $post Post object of current post in listing. |
||
212 | * @return bool True if the post type is in a list of supported psot types; false otherwise. |
||
213 | */ |
||
214 | protected function validate_post_type( $post ) { |
||
237 | |||
238 | /** |
||
239 | * Add a "Copy" row action to supported posts/pages/CPTs on list views. |
||
240 | * |
||
241 | * @param array $actions Existing actions. |
||
242 | * @param WP_Post $post Post object of current post in list. |
||
243 | * @return array Array of updated row actions. |
||
244 | */ |
||
245 | public function add_row_action( $actions, $post ) { |
||
279 | } |
||
280 | |||
288 |
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.