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 ) { |
||
73 | |||
74 | /** |
||
75 | * Determine if the current user has access to the source post. |
||
76 | * |
||
77 | * @param int $post_id Source post ID (the post being copied). |
||
78 | * @return bool True if user has the meta cap of `read_post` for the given post ID, false otherwise. |
||
79 | */ |
||
80 | protected function user_can_access_post( $post_id ) { |
||
81 | return current_user_can( 'read_post', $post_id ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Update the target post's title, content, excerpt, categories, and tags. |
||
86 | * |
||
87 | * @param WP_Post $source_post Post object to be copied. |
||
88 | * @param int $target_post_id Target post ID. |
||
89 | * @return int 0 on failure, or the updated post ID on success. |
||
90 | */ |
||
91 | protected function update_content( $source_post, $target_post_id ) { |
||
105 | |||
106 | /** |
||
107 | * Update the target post's featured image. |
||
108 | * |
||
109 | * @param WP_Post $source_post Post object to be copied. |
||
110 | * @param int $target_post_id Target post ID. |
||
111 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
||
112 | */ |
||
113 | protected function update_featured_image( $source_post, $target_post_id ) { |
||
117 | |||
118 | /** |
||
119 | * Update the target post's post format. |
||
120 | * |
||
121 | * @param WP_Post $source_post Post object to be copied. |
||
122 | * @param int $target_post_id Target post ID. |
||
123 | * @return array|WP_Error|false WP_Error on error, array of affected term IDs on success. |
||
124 | */ |
||
125 | protected function update_post_format( $source_post, $target_post_id ) { |
||
129 | |||
130 | /** |
||
131 | * Update the target post's Likes and Sharing statuses. |
||
132 | * |
||
133 | * @param WP_Post $source_post Post object to be copied. |
||
134 | * @param int $target_post_id Target post ID. |
||
135 | * @return array Array with the results of each update action. |
||
136 | */ |
||
137 | protected function update_likes_sharing( $source_post, $target_post_id ) { |
||
147 | |||
148 | /** |
||
149 | * Update the target post's title. |
||
150 | * |
||
151 | * @param string $post_title Post title determined by `get_default_post_to_edit()`. |
||
152 | * @param WP_Post $post Post object of newly-inserted post. |
||
153 | * @return string Updated post title from source post. |
||
154 | */ |
||
155 | public function filter_title( $post_title, $post ) { |
||
158 | |||
159 | /** |
||
160 | * Update the target post's content (`post_content`). |
||
161 | * |
||
162 | * @param string $post_content Post content determined by `get_default_post_to_edit()`. |
||
163 | * @param WP_Post $post Post object of newly-inserted post. |
||
164 | * @return string Updated post content from source post. |
||
165 | */ |
||
166 | public function filter_content( $post_content, $post ) { |
||
169 | |||
170 | /** |
||
171 | * Update the target post's excerpt. |
||
172 | * |
||
173 | * @param string $post_excerpt Post excerpt determined by `get_default_post_to_edit()`. |
||
174 | * @param WP_Post $post Post object of newly-inserted post. |
||
175 | * @return string Updated post excerpt from source post. |
||
176 | */ |
||
177 | public function filter_excerpt( $post_excerpt, $post ) { |
||
180 | |||
181 | /** |
||
182 | * Add a "Copy" row action to posts/pages/CPTs on list views. |
||
183 | * |
||
184 | * @param array $actions Existing actions. |
||
185 | * @param WP_Post $post Post object of current post in list. |
||
186 | * @return array Array of updated row actions. |
||
187 | */ |
||
188 | public function add_row_action( $actions, $post ) { |
||
220 | } |
||
221 | |||
229 |
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.