PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.3
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-bulk-post.php

class-mainwp-bulk-post.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0.3, at class/class-mainwp-bulk-post.php

378 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Bulk Post Class
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Bulk_Post
12 *
13 * @package MainWP\Dashboard
14 */
15 class MainWP_Bulk_Post {
16
17 /**
18 * MainWP_Bulk_Post constructor.
19 *
20 * Run each time the class is called.
21 */
22 public function __construct() {
23 add_action( 'admin_post_mainwp_editpost', array( &$this, 'handle_edit_bulkpost' ) );
24 add_action( 'save_post', array( &$this, 'save_bulkpost' ) );
25 add_action( 'save_post', array( &$this, 'save_bulkpage' ) );
26 add_action( 'init', array( &$this, 'create_post_type' ) );
27 add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages' ) );
28 }
29
30 /**
31 * Method handle_edit_bulkpost()
32 *
33 * Handle bulk post edit process.
34 */
35 public function handle_edit_bulkpost() {
36
37 $post_id = 0;
38 if ( isset( $_POST['post_ID'] ) ) {
39 $post_id = (int) $_POST['post_ID'];
40 }
41
42 if ( $post_id && isset( $_POST['select_sites_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['select_sites_nonce'] ), 'select_sites_' . $post_id ) ) {
43 check_admin_referer( 'update-post_' . $post_id );
44 edit_post();
45
46 $location = admin_url( 'admin.php?page=PostBulkEdit&post_id=' . $post_id . '&message=1' );
47
48 /**
49 * Filter: redirect_post_location
50 *
51 * Filters the location for the Edit process.
52 *
53 * @param int $post_id Post ID.
54 *
55 * @since Unknown
56 */
57 $location = apply_filters( 'redirect_post_location', $location, $post_id );
58 wp_safe_redirect( $location );
59 exit();
60 }
61 }
62
63 /**
64 * Method redirect_edit_bulkpost().
65 *
66 * Redirect to edit post.
67 *
68 * @param string $location Target URL.
69 * @param int $post_id Post ID number.
70 *
71 * @return string $location Target URL.
72 */
73 public function redirect_edit_bulkpost( $location, $post_id ) {
74 if ( $post_id ) {
75 $location = admin_url( 'admin.php?page=PostBulkEdit&post_id=' . intval( $post_id ) );
76 } else {
77 $location = admin_url( 'admin.php?page=PostBulkAdd' );
78 }
79
80 return $location;
81 }
82
83 /**
84 * Method redirect_edit_bulkpage().
85 *
86 * Redirect to edit page.
87 *
88 * @param string $location Target URL.
89 * @param int $post_id Page ID number.
90 *
91 * @return string $location Target URL.
92 */
93 public function redirect_edit_bulkpage( $location, $post_id ) {
94
95 if ( $post_id ) {
96 $location = admin_url( 'admin.php?page=PageBulkEdit&post_id=' . intval( $post_id ) );
97 } else {
98 $location = admin_url( 'admin.php?page=PageBulkAdd' );
99 }
100
101 return $location;
102 }
103
104
105 /**
106 * Method save_bulkpost().
107 *
108 * Save page (Bulk post custom post type).
109 *
110 * @param int $post_id Post ID.
111 *
112 * @return void
113 *
114 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::select_sites_handle()
115 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_categories_handle()
116 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_slug_handle()
117 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::add_sticky_handle()
118 */
119 public function save_bulkpost( $post_id ) {
120 $_post = get_post( $post_id );
121
122 if ( 'bulkpost' !== $_post->post_type ) {
123 return;
124 }
125
126 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'update-post_' . $post_id ) ) {
127 return;
128 }
129
130 if ( ! isset( $_POST['post_type'] ) || ( 'bulkpost' !== $_POST['post_type'] ) ) {
131 return;
132 }
133
134 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
135 return;
136 }
137
138 if ( isset( $_POST['mainwp_wpseo_metabox_save_values'] ) && ( ! empty( $_POST['mainwp_wpseo_metabox_save_values'] ) ) ) {
139 return;
140 }
141
142 $pid = (int) MainWP_System::instance()->metaboxes->select_sites_handle( $post_id, 'bulkpost' );
143 MainWP_System::instance()->metaboxes->add_categories_handle( $post_id, 'bulkpost' );
144 MainWP_System::instance()->metaboxes->add_tags_handle( $post_id, 'bulkpost' );
145 MainWP_System::instance()->metaboxes->add_slug_handle( $post_id, 'bulkpost' );
146 MainWP_Post_Page_Handler::add_sticky_handle( $post_id );
147 MainWP_Post_Page_Handler::add_status_handle( $post_id );
148
149 /**
150 * Action: mainwp_save_bulkpost
151 *
152 * Fires when saving the bulk post.
153 *
154 * @param int $post_id Post ID.
155 *
156 * @since Unknown
157 */
158 do_action( 'mainwp_save_bulkpost', $post_id );
159
160 if ( $pid === $post_id ) {
161 add_filter( 'redirect_post_location', array( $this, 'redirect_edit_bulkpost' ), 10, 2 );
162 } else {
163 /**
164 * Action: mainwp_before_redirect_posting_bulkpost
165 *
166 * Fires before redirection to posting 'bulk post' page after post submission.
167 *
168 * @param object $_post Object containing post data.
169 *
170 * @since 4.0
171 */
172 do_action( 'mainwp_before_redirect_posting_bulkpost', $_post );
173 wp_safe_redirect( get_site_url() . '/wp-admin/admin.php?page=PostingBulkPost&id=' . $post_id . '&hideall=1&posting_nonce=' . wp_create_nonce( 'posting_nonce_' . $post_id ) );
174 die();
175 }
176 }
177
178 /**
179 * Method save_bulkpage().
180 *
181 * Save page (Bulk page custom post type).
182 *
183 * @param int $post_id Page ID.
184 *
185 * @return void
186 *
187 * @uses \MainWP\Dashboard\MainWP_System::$metaboxes
188 * @uses \MainWP\Dashboard\MainWP_Page::add_status_handle()
189 */
190 public function save_bulkpage( $post_id ) {
191
192 $_post = get_post( $post_id );
193
194 if ( 'bulkpage' !== $_post->post_type ) {
195 return;
196 }
197
198 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'update-post_' . $post_id ) ) {
199 return;
200 }
201
202 if ( ! isset( $_POST['post_type'] ) || ( 'bulkpage' !== $_POST['post_type'] ) ) {
203 return;
204 }
205
206 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
207 return;
208 }
209
210 if ( isset( $_POST['mainwp_wpseo_metabox_save_values'] ) && ( ! empty( $_POST['mainwp_wpseo_metabox_save_values'] ) ) ) {
211 return;
212 }
213
214 $pid = (int) MainWP_System::instance()->metaboxes->select_sites_handle( $post_id, 'bulkpage' );
215 MainWP_System::instance()->metaboxes->add_slug_handle( $post_id, 'bulkpage' );
216 MainWP_Post_Page_Handler::add_status_handle( $post_id );
217
218 /**
219 * Action: mainwp_save_bulkpage
220 *
221 * Fires when saving the bulk page.
222 *
223 * @param int $post_id Post ID.
224 *
225 * @since Unknown
226 */
227 do_action( 'mainwp_save_bulkpage', $post_id );
228
229 if ( $pid === $post_id ) {
230 add_filter( 'redirect_post_location', array( $this, 'redirect_edit_bulkpage' ), 10, 2 );
231 } else {
232 /**
233 * Action: mainwp_before_redirect_posting_bulkpage
234 *
235 * Fires before redirection to posting 'bulk page' page after post submission.
236 *
237 * @param object $_post Object containing post data.
238 *
239 * @since 4.0
240 */
241 do_action( 'mainwp_before_redirect_posting_bulkpage', $_post );
242 wp_safe_redirect( get_site_url() . '/wp-admin/admin.php?page=PostingBulkPage&posting_nonce=' . wp_create_nonce( 'posting_nonce_' . $post_id ) . '&id=' . $post_id . '&hideall=1' );
243 die();
244 }
245 }
246
247 /**
248 * Method create_post_type()
249 *
250 * Register "Bulkpost" and "Bulkpage" custom post types.
251 */
252 public function create_post_type() {
253
254 $queryable = true;
255 if ( function_exists( 'is_plugin_active' ) ) {
256 $queryable = is_plugin_active( 'mainwp-post-plus-extension/mainwp-post-plus-extension.php' ) ? true : false;
257 }
258
259 $labels = array(
260 'name' => _x( 'Bulkpost', 'bulkpost' ),
261 'singular_name' => _x( 'Bulkpost', 'bulkpost' ),
262 'add_new' => _x( 'Add New', 'bulkpost' ),
263 'add_new_item' => _x( 'Add New Bulkpost', 'bulkpost' ),
264 'edit_item' => _x( 'Edit Bulkpost', 'bulkpost' ),
265 'new_item' => _x( 'New Bulkpost', 'bulkpost' ),
266 'view_item' => _x( 'View Bulkpost', 'bulkpost' ),
267 'search_items' => _x( 'Search Bulkpost', 'bulkpost' ),
268 'not_found' => _x( 'No bulkpost found', 'bulkpost' ),
269 'not_found_in_trash' => _x( 'No bulkpost found in Trash', 'bulkpost' ),
270 'parent_item_colon' => _x( 'Parent Bulkpost:', 'bulkpost' ),
271 'menu_name' => _x( 'Bulkpost', 'bulkpost' ),
272 );
273
274 $args = array(
275 'labels' => $labels,
276 'hierarchical' => false,
277 'description' => 'description...',
278 'supports' => array(
279 'title',
280 'editor',
281 'excerpt',
282 'thumbnail',
283 'custom-fields',
284 'comments',
285 'revisions',
286 ),
287 'public' => true,
288 'show_ui' => true,
289 'show_in_nav_menus' => false,
290 'publicly_queryable' => $queryable,
291 'exclude_from_search' => true,
292 'has_archive' => false,
293 'query_var' => false,
294 'can_export' => false,
295 'rewrite' => false,
296 'capabilities' => array(
297 'edit_post' => 'read',
298 'edit_posts' => 'read',
299 'edit_others_posts' => 'read',
300 'publish_posts' => 'read',
301 'read_post' => 'read',
302 'read_private_posts' => 'read',
303 'delete_post' => 'read',
304 ),
305 );
306
307 register_post_type( 'bulkpost', $args );
308
309 $labels = array(
310 'name' => _x( 'Bulkpage', 'bulkpage' ),
311 'singular_name' => _x( 'Bulkpage', 'bulkpage' ),
312 'add_new' => _x( 'Add New', 'bulkpage' ),
313 'add_new_item' => _x( 'Add New Bulkpage', 'bulkpage' ),
314 'edit_item' => _x( 'Edit Bulkpage', 'bulkpage' ),
315 'new_item' => _x( 'New Bulkpage', 'bulkpage' ),
316 'view_item' => _x( 'View Bulkpage', 'bulkpage' ),
317 'search_items' => _x( 'Search Bulkpage', 'bulkpage' ),
318 'not_found' => _x( 'No bulkpage found', 'bulkpage' ),
319 'not_found_in_trash' => _x( 'No bulkpage found in Trash', 'bulkpage' ),
320 'parent_item_colon' => _x( 'Parent Bulkpage:', 'bulkpage' ),
321 'menu_name' => _x( 'Bulkpage', 'bulkpage' ),
322 );
323
324 $args = array(
325 'labels' => $labels,
326 'hierarchical' => false,
327 'description' => 'description...',
328 'supports' => array(
329 'title',
330 'editor',
331 'excerpt',
332 'thumbnail',
333 'custom-fields',
334 'comments',
335 'revisions',
336 ),
337 'public' => true,
338 'show_ui' => true,
339 'show_in_nav_menus' => false,
340 'publicly_queryable' => $queryable,
341 'exclude_from_search' => true,
342 'has_archive' => false,
343 'query_var' => false,
344 'can_export' => false,
345 'rewrite' => false,
346 'capabilities' => array(
347 'edit_post' => 'read',
348 'edit_posts' => 'read',
349 'edit_others_posts' => 'read',
350 'publish_posts' => 'read',
351 'read_post' => 'read',
352 'read_private_posts' => 'read',
353 'delete_post' => 'read',
354 ),
355 );
356
357 register_post_type( 'bulkpage', $args );
358
359 do_action( 'mainwp_register_post_type' );
360 }
361
362 /**
363 * Method post_updated_messages()
364 *
365 * Render post updated message.
366 *
367 * @param string $messages Message to display.
368 *
369 * @return string $messages.
370 */
371 public function post_updated_messages( $messages ) {
372 $messages['post'][98] = esc_html__( 'WordPress SEO values have been saved.', 'mainwp' );
373 $messages['post'][99] = esc_html__( 'You have to select the sites you wish to publish to.', 'mainwp' );
374
375 return $messages;
376 }
377 }
378