PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.1
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 4.1, at class/class-mainwp-bulk-post.php

368 lines 10.1 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 bulkpost 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 (Bulkpost custom post type).
109 *
110 * @param int $post_id Post ID.
111 *
112 * @return void
113 */
114 public function save_bulkpost( $post_id ) {
115 $_post = get_post( $post_id );
116
117 if ( 'bulkpost' !== $_post->post_type ) {
118 return;
119 }
120
121 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'update-post_' . $post_id ) ) {
122 return;
123 }
124
125 if ( ! isset( $_POST['post_type'] ) || ( 'bulkpost' !== $_POST['post_type'] ) ) {
126 return;
127 }
128
129 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
130 return;
131 }
132
133 if ( isset( $_POST['mainwp_wpseo_metabox_save_values'] ) && ( ! empty( $_POST['mainwp_wpseo_metabox_save_values'] ) ) ) {
134 return;
135 }
136
137 $pid = MainWP_System::instance()->metaboxes->select_sites_handle( $post_id, 'bulkpost' );
138 MainWP_System::instance()->metaboxes->add_categories_handle( $post_id, 'bulkpost' );
139 MainWP_System::instance()->metaboxes->add_tags_handle( $post_id, 'bulkpost' );
140 MainWP_System::instance()->metaboxes->add_slug_handle( $post_id, 'bulkpost' );
141 MainWP_Post_Page_Handler::add_sticky_handle( $post_id );
142
143 /**
144 * Action: mainwp_save_bulkpost
145 *
146 * Fires when saving the bulkpost.
147 *
148 * @param int $post_id Post ID.
149 *
150 * @since Unknown
151 */
152 do_action( 'mainwp_save_bulkpost', $post_id );
153
154 if ( $pid == $post_id ) {
155 add_filter( 'redirect_post_location', array( $this, 'redirect_edit_bulkpost' ), 10, 2 );
156 } else {
157 /**
158 * Action: mainwp_before_redirect_posting_bulkpost
159 *
160 * Fires before redirection to posting 'bulkpost' page after post submission.
161 *
162 * @param object $_post Object containing post data.
163 *
164 * @since 4.0
165 */
166 do_action( 'mainwp_before_redirect_posting_bulkpost', $_post );
167 wp_safe_redirect( get_site_url() . '/wp-admin/admin.php?page=PostingBulkPost&id=' . $post_id . '&hideall=1' );
168 die();
169 }
170 }
171
172 /**
173 * Method save_bulkpage().
174 *
175 * Save page (Bulkpage custom post type).
176 *
177 * @param int $post_id Page ID.
178 *
179 * @return void
180 */
181 public function save_bulkpage( $post_id ) {
182
183 $_post = get_post( $post_id );
184
185 if ( 'bulkpage' !== $_post->post_type ) {
186 return;
187 }
188
189 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'update-post_' . $post_id ) ) {
190 return;
191 }
192
193 if ( ! isset( $_POST['post_type'] ) || ( 'bulkpage' !== $_POST['post_type'] ) ) {
194 return;
195 }
196
197 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
198 return;
199 }
200
201 if ( isset( $_POST['mainwp_wpseo_metabox_save_values'] ) && ( ! empty( $_POST['mainwp_wpseo_metabox_save_values'] ) ) ) {
202 return;
203 }
204
205 $pid = MainWP_System::instance()->metaboxes->select_sites_handle( $post_id, 'bulkpage' );
206 MainWP_System::instance()->metaboxes->add_slug_handle( $post_id, 'bulkpage' );
207 MainWP_Page::add_status_handle( $post_id );
208
209 /**
210 * Action: mainwp_save_bulkpage
211 *
212 * Fires when saving the bulkpage.
213 *
214 * @param int $post_id Post ID.
215 *
216 * @since Unknown
217 */
218 do_action( 'mainwp_save_bulkpage', $post_id );
219
220 if ( $pid == $post_id ) {
221 add_filter( 'redirect_post_location', array( $this, 'redirect_edit_bulkpage' ), 10, 2 );
222 } else {
223 /**
224 * Action: mainwp_before_redirect_posting_bulkpage
225 *
226 * Fires before redirection to posting 'bulkpage' page after post submission.
227 *
228 * @param object $_post Object containing post data.
229 *
230 * @since 4.0
231 */
232 do_action( 'mainwp_before_redirect_posting_bulkpage', $_post );
233 wp_safe_redirect( get_site_url() . '/wp-admin/admin.php?page=PostingBulkPage&id=' . $post_id . '&hideall=1' );
234 die();
235 }
236 }
237
238 /**
239 * Method create_post_type()
240 *
241 * Register "Bulkpost" and "Bulkpage" custom post types.
242 */
243 public function create_post_type() {
244
245 $queryable = true;
246 if ( function_exists( 'is_plugin_active' ) ) {
247 $queryable = is_plugin_active( 'mainwp-post-plus-extension/mainwp-post-plus-extension.php' ) ? true : false;
248 }
249
250 $labels = array(
251 'name' => _x( 'Bulkpost', 'bulkpost' ),
252 'singular_name' => _x( 'Bulkpost', 'bulkpost' ),
253 'add_new' => _x( 'Add New', 'bulkpost' ),
254 'add_new_item' => _x( 'Add New Bulkpost', 'bulkpost' ),
255 'edit_item' => _x( 'Edit Bulkpost', 'bulkpost' ),
256 'new_item' => _x( 'New Bulkpost', 'bulkpost' ),
257 'view_item' => _x( 'View Bulkpost', 'bulkpost' ),
258 'search_items' => _x( 'Search Bulkpost', 'bulkpost' ),
259 'not_found' => _x( 'No bulkpost found', 'bulkpost' ),
260 'not_found_in_trash' => _x( 'No bulkpost found in Trash', 'bulkpost' ),
261 'parent_item_colon' => _x( 'Parent Bulkpost:', 'bulkpost' ),
262 'menu_name' => _x( 'Bulkpost', 'bulkpost' ),
263 );
264
265 $args = array(
266 'labels' => $labels,
267 'hierarchical' => false,
268 'description' => 'description...',
269 'supports' => array(
270 'title',
271 'editor',
272 'excerpt',
273 'thumbnail',
274 'custom-fields',
275 'comments',
276 'revisions',
277 ),
278 'public' => true,
279 'show_ui' => true,
280 'show_in_nav_menus' => false,
281 'publicly_queryable' => $queryable,
282 'exclude_from_search' => true,
283 'has_archive' => false,
284 'query_var' => false,
285 'can_export' => false,
286 'rewrite' => false,
287 'capabilities' => array(
288 'edit_post' => 'read',
289 'edit_posts' => 'read',
290 'edit_others_posts' => 'read',
291 'publish_posts' => 'read',
292 'read_post' => 'read',
293 'read_private_posts' => 'read',
294 'delete_post' => 'read',
295 ),
296 );
297
298 register_post_type( 'bulkpost', $args );
299
300 $labels = array(
301 'name' => _x( 'Bulkpage', 'bulkpage' ),
302 'singular_name' => _x( 'Bulkpage', 'bulkpage' ),
303 'add_new' => _x( 'Add New', 'bulkpage' ),
304 'add_new_item' => _x( 'Add New Bulkpage', 'bulkpage' ),
305 'edit_item' => _x( 'Edit Bulkpage', 'bulkpage' ),
306 'new_item' => _x( 'New Bulkpage', 'bulkpage' ),
307 'view_item' => _x( 'View Bulkpage', 'bulkpage' ),
308 'search_items' => _x( 'Search Bulkpage', 'bulkpage' ),
309 'not_found' => _x( 'No bulkpage found', 'bulkpage' ),
310 'not_found_in_trash' => _x( 'No bulkpage found in Trash', 'bulkpage' ),
311 'parent_item_colon' => _x( 'Parent Bulkpage:', 'bulkpage' ),
312 'menu_name' => _x( 'Bulkpage', 'bulkpage' ),
313 );
314
315 $args = array(
316 'labels' => $labels,
317 'hierarchical' => false,
318 'description' => 'description...',
319 'supports' => array(
320 'title',
321 'editor',
322 'excerpt',
323 'thumbnail',
324 'custom-fields',
325 'comments',
326 'revisions',
327 ),
328 'public' => true,
329 'show_ui' => true,
330 'show_in_nav_menus' => false,
331 'publicly_queryable' => $queryable,
332 'exclude_from_search' => true,
333 'has_archive' => false,
334 'query_var' => false,
335 'can_export' => false,
336 'rewrite' => false,
337 'capabilities' => array(
338 'edit_post' => 'read',
339 'edit_posts' => 'read',
340 'edit_others_posts' => 'read',
341 'publish_posts' => 'read',
342 'read_post' => 'read',
343 'read_private_posts' => 'read',
344 'delete_post' => 'read',
345 ),
346 );
347
348 register_post_type( 'bulkpage', $args );
349 }
350
351 /**
352 * Method post_updated_messages()
353 *
354 * Render post updated message.
355 *
356 * @param string $messages Message to display.
357 *
358 * @return string $messages.
359 */
360 public function post_updated_messages( $messages ) {
361 $messages['post'][98] = esc_html__( 'WordPress SEO values have been saved.', 'mainwp' );
362 $messages['post'][99] = esc_html__( 'You have to select the sites you wish to publish to.', 'mainwp' );
363
364 return $messages;
365 }
366
367 }
368