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 ) { |
||
70 | |||
71 | /** |
||
72 | * Determine if the current user has access to the source post. |
||
73 | * |
||
74 | * @param WP_Post $post Source post object (the post being copied). |
||
75 | * @return bool True if current user is the post author, or has permissions for `edit_others_posts`; false otherwise. |
||
76 | */ |
||
77 | protected function user_can_edit_post( $post ) { |
||
80 | |||
81 | /** |
||
82 | * Update the target post's title, content, excerpt, categories, and tags. |
||
83 | * |
||
84 | * @param WP_Post $source_post Post object to be copied. |
||
85 | * @param int $target_post_id Target post ID. |
||
86 | * @return int 0 on failure, or the updated post ID on success. |
||
87 | */ |
||
88 | protected function update_content( $source_post, $target_post_id ) { |
||
102 | |||
103 | /** |
||
104 | * Update the target post's featured image. |
||
105 | * |
||
106 | * @param WP_Post $source_post Post object to be copied. |
||
107 | * @param int $target_post_id Target post ID. |
||
108 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
||
109 | */ |
||
110 | protected function update_featured_image( $source_post, $target_post_id ) { |
||
114 | |||
115 | /** |
||
116 | * Update the target post's post format. |
||
117 | * |
||
118 | * @param WP_Post $source_post Post object to be copied. |
||
119 | * @param int $target_post_id Target post ID. |
||
120 | * @return array|WP_Error|false WP_Error on error, array of affected term IDs on success. |
||
121 | */ |
||
122 | protected function update_post_format( $source_post, $target_post_id ) { |
||
126 | |||
127 | /** |
||
128 | * Update the target post's title. |
||
129 | * |
||
130 | * @param string $post_title Post title determined by `get_default_post_to_edit()`. |
||
131 | * @param WP_Post $post Post object of newly-inserted post. |
||
132 | * @return string Updated post title from source post. |
||
133 | */ |
||
134 | public function filter_title( $post_title, $post ) { |
||
137 | |||
138 | /** |
||
139 | * Update the target post's content (`post_content`). |
||
140 | * |
||
141 | * @param string $post_content Post content determined by `get_default_post_to_edit()`. |
||
142 | * @param WP_Post $post Post object of newly-inserted post. |
||
143 | * @return string Updated post content from source post. |
||
144 | */ |
||
145 | public function filter_content( $post_content, $post ) { |
||
148 | |||
149 | /** |
||
150 | * Update the target post's excerpt. |
||
151 | * |
||
152 | * @param string $post_excerpt Post excerpt determined by `get_default_post_to_edit()`. |
||
153 | * @param WP_Post $post Post object of newly-inserted post. |
||
154 | * @return string Updated post excerpt from source post. |
||
155 | */ |
||
156 | public function filter_excerpt( $post_excerpt, $post ) { |
||
159 | |||
160 | /** |
||
161 | * Add a "Copy" row action to posts/pages/CPTs on list views. |
||
162 | * |
||
163 | * @param array $actions Existing actions. |
||
164 | * @param WP_Post $post Post object of current post in list. |
||
165 | * @return array Array of updated row actions. |
||
166 | */ |
||
167 | public function add_row_action( $actions, $post ) { |
||
195 | } |
||
196 | |||
204 |
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.