PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.6.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.6.0.1
6.2.2 6.2.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 All 155 releases
mainwp / pages / page-mainwp-post.php

page-mainwp-post.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.6.0.1, at pages/page-mainwp-post.php

2,604 lines 98.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Post Page.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Posts
12 *
13 * @uses MainWP_Bulk_Add
14 */
15 class MainWP_Post {
16
17 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- Current complexity required to achieve desired results. Pull request solutions appreciated.
18
19 /**
20 * Method get_class_name()
21 *
22 * Get Class Name.
23 *
24 * @return object __CLASS__
25 */
26 public static function get_class_name() {
27 return __CLASS__;
28 }
29
30 /**
31 * Public static variable to hold Sub-pages data.
32 *
33 * @static
34 *
35 * @var array Sub-pages.
36 */
37 public static $subPages;
38
39 /**
40 * Method init()
41 *
42 * Initiate Page.
43 *
44 * @return void
45 */
46 public static function init() {
47 /**
48 * This hook allows you to render the Post page header via the 'mainwp-pageheader-post' action.
49 *
50 * @link http://codex.mainwp.com/#mainwp-pageheader-post
51 *
52 * This hook is normally used in the same context of 'mainwp-getsubpages-post'
53 * @link http://codex.mainwp.com/#mainwp-getsubpages-post
54 *
55 * @see \MainWP_Post::render_header
56 */
57 add_action( 'mainwp-pageheader-post', array( self::get_class_name(), 'render_header' ) ); // @deprecated Use 'mainwp_pageheader_post' instead.
58 add_action( 'mainwp_pageheader_post', array( self::get_class_name(), 'render_header' ) );
59
60 /**
61 * This hook allows you to render the Post page footer via the 'mainwp-pagefooter-post' action.
62 *
63 * @link http://codex.mainwp.com/#mainwp-pagefooter-post
64 *
65 * This hook is normally used in the same context of 'mainwp-getsubpages-post'
66 * @link http://codex.mainwp.com/#mainwp-getsubpages-post
67 *
68 * @see \MainWP_Post::render_footer
69 */
70 add_action( 'mainwp-pagefooter-post', array( self::get_class_name(), 'render_footer' ) );
71 add_action( 'mainwp_pagefooter_post', array( self::get_class_name(), 'render_footer' ) );
72
73 add_filter( 'admin_post_thumbnail_html', array( self::get_class_name(), 'admin_post_thumbnail_html' ), 10, 3 );
74
75 add_action( 'mainwp_help_sidebar_content', array( self::get_class_name(), 'mainwp_help_content' ) );
76 }
77
78 /**
79 * Method ini_menu()
80 *
81 * Initiate Page menu.
82 *
83 * @return void
84 *
85 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
86 * @uses \MainWP\Dashboard\MainWP_Post_Page_Handler::get_class_name()
87 */
88 public static function init_menu() {
89 $_page = add_submenu_page( 'mainwp_tab', esc_html__( 'Posts', 'mainwp' ), '<span id="mainwp-Posts">' . esc_html__( 'Posts', 'mainwp' ) . '</span>', 'read', 'PostBulkManage', array( self::get_class_name(), 'render' ) );
90 add_action( 'load-' . $_page, array( self::get_class_name(), 'on_load_page' ) );
91 add_filter( 'manage_' . $_page . '_columns', array( self::get_class_name(), 'get_manage_columns' ) );
92
93 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PostBulkAdd' ) ) {
94 $_page = add_submenu_page( 'mainwp_tab', esc_html__( 'Posts', 'mainwp' ), '<div class="mainwp-hidden">' . esc_html__( 'Add New', 'mainwp' ) . '</div>', 'read', 'PostBulkAdd', array( self::get_class_name(), 'render_bulk_add' ) );
95 add_action( 'load-' . $_page, array( self::get_class_name(), 'on_load_add_edit' ) );
96 }
97
98 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PostBulkEdit' ) ) {
99 $_page = add_submenu_page( 'mainwp_tab', esc_html__( 'Posts', 'mainwp' ), '<div class="mainwp-hidden">' . esc_html__( 'Edit Post', 'mainwp' ) . '</div>', 'read', 'PostBulkEdit', array( self::get_class_name(), 'render_bulk_edit' ) );
100 add_action( 'load-' . $_page, array( self::get_class_name(), 'on_load_add_edit' ) );
101 }
102
103 add_submenu_page(
104 'mainwp_tab',
105 'Posting new bulkpost',
106 '<div class="mainwp-hidden">' . esc_html__( 'Posts', 'mainwp' ) . '</div>',
107 'read',
108 'PostingBulkPost',
109 array(
110 MainWP_Post_Page_Handler::get_class_name(),
111 'posting_bulk',
112 )
113 );
114
115 /**
116 * Posts Subpages
117 *
118 * Filters subpages for the Posts page.
119 *
120 * @since Unknown
121 */
122 $sub_pages = array();
123 $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-post', array( $sub_pages ), '4.0.7.2', 'mainwp_getsubpages_post' ); // @deprecated Use 'mainwp_getsubpages_post' instead.
124 self::$subPages = apply_filters( 'mainwp_getsubpages_post', $sub_pages );
125
126 if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
127 foreach ( self::$subPages as $subPage ) {
128 if ( MainWP_Menu::is_disable_menu_item( 3, 'Post' . $subPage['slug'] ) ) {
129 continue;
130 }
131 add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Post' . $subPage['slug'], $subPage['callback'] );
132 }
133 }
134 self::init_left_menu( self::$subPages );
135 }
136
137 /**
138 * Method on_load_page()
139 *
140 * Used during init_menu() to get the class names of,
141 * admin_head and get_hidden_columns.
142 *
143 * @return void
144 */
145 public static function on_load_page() {
146 add_action( 'admin_head', array( self::get_class_name(), 'admin_head' ) );
147 add_filter( 'hidden_columns', array( self::get_class_name(), 'get_hidden_columns' ), 10, 3 );
148 add_action( 'mainwp_screen_options_modal_bottom', array( self::get_class_name(), 'hook_screen_options_modal_bottom' ), 10, 2 );
149 }
150
151 /**
152 * Method on_load_add_edit()
153 *
154 * Get the post ID,
155 * pass it to method on_load_bulkpost().
156 *
157 * @return void self::on_load_bulkpost( $post_id ).
158 */
159 public static function on_load_add_edit() {
160 global $_mainwp_menu_active_slugs;
161 if ( isset( $_GET['page'] ) && 'PostBulkAdd' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
162
163 /**
164 * MainWP default post to edit.
165 *
166 * @global string
167 */
168 global $_mainwp_default_post_to_edit;
169
170 $post_type = 'bulkpost';
171 $_mainwp_default_post_to_edit = get_default_post_to_edit( $post_type, true );
172 $post_id = $_mainwp_default_post_to_edit ? $_mainwp_default_post_to_edit->ID : 0;
173 } else {
174 $post_id = isset( $_GET['post_id'] ) ? intval( $_GET['post_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
175 $_mainwp_menu_active_slugs['PostBulkEdit'] = 'PostBulkManage'; // to fix hidden second menu level.
176 }
177
178 if ( ! $post_id ) {
179 wp_die( esc_html__( 'Invalid post.', 'mainwp' ) );
180 }
181
182 self::on_load_bulkpost( $post_id );
183 }
184
185 /**
186 * Method on_load_bulkpost()
187 *
188 * For the given post ID, this method Enqueues all scripts, styles, settings,
189 * and templates necessary to use all media JS APIs, then retrieves post data.
190 *
191 * @param mixed $post_id Given post ID.
192 *
193 * @return void (WP_Post|array|null) Sets the Global variable $GLOBALS['post'],
194 * Type corresponding to $output on success or null on failure. When $output is OBJECT, a WP_Post instance is returned.
195 */
196 public static function on_load_bulkpost( $post_id ) {
197
198 wp_enqueue_media( array( 'post' => $post_id ) );
199
200 wp_enqueue_script(
201 'mainwp-post',
202 MAINWP_PLUGIN_URL . 'assets/js/mainwp-post-edit.js',
203 array(
204 'jquery',
205 'postbox',
206 'word-count',
207 'media-views',
208 'mainwp',
209 ),
210 MAINWP_VERSION,
211 true
212 );
213
214 $_post = get_post( $post_id );
215 // phpcs:ignore -- required for custom bulk posts/pages and support hooks.
216 $GLOBALS['post'] = $_post;
217 }
218
219 /**
220 * Method get_manage_columns()
221 *
222 * Get columns to display.
223 *
224 * @return array $colums Array of columns to display on the page.
225 *
226 * @uses \MainWP\Dashboard\MainWP_Utility::enabled_wp_seo()
227 */
228 public static function get_manage_columns() {
229 $colums = array(
230 'title' => esc_html__( 'Title', 'mainwp' ),
231 'author' => esc_html__( 'Author', 'mainwp' ),
232 'date' => esc_html__( 'Last Modified', 'mainwp' ),
233 'categories' => esc_html__( 'Categories', 'mainwp' ),
234 'tags' => esc_html__( 'Tags', 'mainwp' ),
235 'post-type' => esc_html__( 'Post type', 'mainwp' ),
236 'comments' => esc_html__( 'Comments', 'mainwp' ),
237 'status' => esc_html__( 'Status', 'mainwp' ),
238 'seo-links' => esc_html__( 'Links', 'mainwp' ),
239 'seo-linked' => esc_html__( 'Linked', 'mainwp' ),
240 'seo-score' => esc_html__( 'SEO Score', 'mainwp' ),
241 'seo-readability' => esc_html__( 'Readability score', 'mainwp' ),
242 'website' => esc_html__( 'Website', 'mainwp' ),
243 );
244
245 if ( ! MainWP_Utility::enabled_wp_seo() ) {
246 unset( $colums['seo-links'] );
247 unset( $colums['seo-linked'] );
248 unset( $colums['seo-score'] );
249 unset( $colums['seo-readability'] );
250 }
251
252 return $colums;
253 }
254
255 /**
256 * Method admin_head()
257 *
258 * Grab the current_screen ID, set the pagenow JS variable,
259 * and render the JS HTML Meta tag.
260 *
261 * @return void Render the Post pagenow header tag.
262 */
263 public static function admin_head() {
264
265 /**
266 * Current screen.
267 *
268 * @global string
269 */
270 global $current_screen;
271
272 ?>
273 <script type="text/javascript"> pagenow = '<?php echo esc_html( strtolower( $current_screen->id ) ); ?>';</script>
274 <?php
275 }
276
277 /**
278 * Method get_hidden_columns()
279 *
280 * Get the currently hidden page columns.
281 *
282 * @param mixed $hidden User option value.
283 * @param mixed $screen Current screen ID.
284 *
285 * @return (mixed) $hidden User option value on success, false on failure.
286 */
287 public static function get_hidden_columns( $hidden, $screen ) {
288 if ( $screen && 'mainwp_page_PostBulkManage' === $screen->id ) {
289 $hidden = get_user_option( 'manage' . strtolower( $screen->id ) . 'columnshidden' );
290 }
291 if ( ! is_array( $hidden ) ) {
292 $hidden = array();
293 }
294 return $hidden;
295 }
296
297 /**
298 * Method hook_screen_options_modal_bottom()
299 *
300 * Render screen options modal bottom.
301 */
302 public static function hook_screen_options_modal_bottom() {
303 $page = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
304 if ( 'PostBulkManage' === $page ) {
305
306 $show_columns = get_user_option( 'mainwp_manageposts_show_columns' );
307
308 if ( ! is_array( $show_columns ) ) {
309 $show_columns = array();
310 }
311
312 $cols = self::get_manage_columns();
313 MainWP_UI::render_showhide_columns_settings( $cols, $show_columns, 'post' );
314 }
315 }
316
317 /**
318 * Method init_subpages_menu()
319 *
320 * Initiate subpages menu.
321 *
322 * @return void Render subpages menu.
323 *
324 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
325 */
326 public static function init_subpages_menu() {
327 ?>
328 <div id="menu-mainwp-Posts" class="mainwp-submenu-wrapper">
329 <div class="wp-submenu sub-open">
330 <div class="mainwp_boxout">
331 <div class="mainwp_boxoutin"></div>
332 <?php if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) { ?>
333 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PostBulkManage' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Manage Posts', 'mainwp' ); ?></a>
334 <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PostBulkAdd' ) ) { ?>
335 <a href="<?php echo esc_url( admin_url( 'admin.php?page=PostBulkAdd' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Add New', 'mainwp' ); ?></a>
336 <?php } ?>
337 <?php } ?>
338 <?php
339 if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
340 foreach ( self::$subPages as $subPage ) {
341 if ( ! isset( $subPage['menu_hidden'] ) || ( isset( $subPage['menu_hidden'] ) && true !== $subPage['menu_hidden'] ) ) {
342 if ( MainWP_Menu::is_disable_menu_item( 3, 'Post' . $subPage['slug'] ) ) {
343 continue;
344 }
345 ?>
346 <a href="<?php echo esc_url( admin_url( 'admin.php?page=Post' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo esc_html( $subPage['title'] ); ?></a>
347 <?php
348 }
349 }
350 }
351 ?>
352 </div>
353 </div>
354 </div>
355 <?php
356 }
357
358 /**
359 * Method init_left_menu()
360 *
361 * Initiate left menu.
362 *
363 * @param array $subPages Array of subPages to add to the Post left menu.
364 *
365 * @return void Menu arrays are assed on to MainWP_Menu::init_subpages_left_menu() & MainWP_Menu::init_left_menu().
366 *
367 * @uses \MainWP\Dashboard\MainWP_Menu::add_left_menu()
368 * @uses \MainWP\Dashboard\MainWP_Menu::init_subpages_left_menu()
369 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
370 */
371 public static function init_left_menu( $subPages = array() ) {
372
373 MainWP_Menu::add_left_menu(
374 array(
375 'title' => esc_html__( 'Posts', 'mainwp' ),
376 'parent_key' => 'managesites',
377 'slug' => 'PostBulkManage',
378 'href' => 'admin.php?page=PostBulkManage',
379 'icon' => '<i class="file alternate icon"></i>',
380 ),
381 1
382 );
383
384 $init_sub_subleftmenu = array(
385 array(
386 'title' => esc_html__( 'Manage Posts', 'mainwp' ),
387 'parent_key' => 'PostBulkManage',
388 'href' => 'admin.php?page=PostBulkManage',
389 'slug' => 'PostBulkManage',
390 'right' => 'manage_posts',
391 ),
392 array(
393 'title' => esc_html__( 'Add New', 'mainwp' ),
394 'parent_key' => 'PostBulkManage',
395 'href' => 'admin.php?page=PostBulkAdd',
396 'slug' => 'PostBulkAdd',
397 'right' => 'manage_posts',
398 ),
399 );
400 MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'PostBulkManage', 'Post' );
401
402 foreach ( $init_sub_subleftmenu as $item ) {
403 if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) {
404 continue;
405 }
406 MainWP_Menu::add_left_menu( $item, 2 );
407 }
408 }
409
410 /**
411 * Method admin_post_thumbnail_html()
412 *
413 * Grab the post thumbnail html.
414 *
415 * @param mixed $content Admin post thumbnail HTML markup.
416 * @param mixed $post_id Post ID.
417 * @param mixed $thumbnail_id Thumbnail ID.
418 *
419 * @return string html
420 */
421 public static function admin_post_thumbnail_html( $content, $post_id, $thumbnail_id ) {
422 $_post = get_post( $post_id );
423
424 if ( empty( $_post ) ) {
425 return $content;
426 }
427
428 if ( 'bulkpost' !== $_post->post_type && 'bulkpage' !== $_post->post_type ) {
429 return $content;
430 }
431
432 return self::wp_post_thumbnail_html( $thumbnail_id, $post_id );
433 }
434
435 /**
436 * Method render_header()
437 *
438 * @param string $shownPage Current page slug.
439 * @param null $post_id BulkEdit Post ID.
440 *
441 * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item()
442 * @uses \MainWP\Dashboard\MainWP_UI::render_top_header()
443 * @uses \MainWP\Dashboard\MainWP_UI::render_page_navigation()
444 */
445 public static function render_header( $shownPage = '', $post_id = null ) {
446 $params = array(
447 'title' => esc_html__( 'Posts', 'mainwp' ),
448 );
449 MainWP_UI::render_top_header( $params );
450
451 $renderItems = array();
452
453 if ( mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
454 $renderItems[] = array(
455 'title' => esc_html__( 'Manage Posts', 'mainwp' ),
456 'href' => 'admin.php?page=PostBulkManage',
457 'active' => ( 'BulkManage' === $shownPage ) ? true : false,
458 );
459 if ( 'BulkEdit' === $shownPage ) {
460 $renderItems[] = array(
461 'title' => esc_html__( 'Edit Post', 'mainwp' ),
462 'href' => 'admin.php?page=PostBulkEdit&post_id=' . esc_attr( $post_id ),
463 'active' => true,
464 );
465 }
466 if ( ! MainWP_Menu::is_disable_menu_item( 3, 'PostBulkAdd' ) ) {
467 $renderItems[] = array(
468 'title' => esc_html__( 'Add New', 'mainwp' ),
469 'href' => 'admin.php?page=PostBulkAdd',
470 'active' => ( 'BulkAdd' === $shownPage ) ? true : false,
471 );
472 }
473 }
474
475 if ( isset( self::$subPages ) && is_array( self::$subPages ) ) {
476 foreach ( self::$subPages as $subPage ) {
477 if ( MainWP_Menu::is_disable_menu_item( 3, 'Post' . $subPage['slug'] ) ) {
478 continue;
479 }
480
481 if ( isset( $subPage['tab_link_hidden'] ) && true === $subPage['tab_link_hidden'] ) {
482 $tab_link = '#';
483 } else {
484 $tab_link = 'admin.php?page=Post' . $subPage['slug'];
485 }
486
487 $item = array();
488 $item['title'] = $subPage['title'];
489 $item['href'] = $tab_link;
490 $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false;
491 $renderItems[] = $item;
492
493 }
494 }
495 MainWP_UI::render_page_navigation( $renderItems, __CLASS__ );
496 }
497
498 /**
499 * Method render_footer()
500 *
501 * Render page footer.
502 */
503 public static function render_footer() {
504 echo '</div>';
505 }
506
507 /**
508 * Method render()
509 *
510 * Render the page content.
511 *
512 * @return string Post page html content.
513 *
514 * @uses \MainWP\Dashboard\MainWP_Cache::get_cached_context()
515 */
516 public static function render() {
517 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
518 mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
519 return;
520 }
521
522 $cachedSearch = MainWP_Cache::get_cached_context( 'Post' );
523
524 $selected_sites = array();
525 $selected_groups = array();
526 $selected_clients = array();
527
528 if ( null !== $cachedSearch ) {
529 if ( is_array( $cachedSearch['sites'] ) ) {
530 $selected_sites = $cachedSearch['sites'];
531 } elseif ( is_array( $cachedSearch['groups'] ) ) {
532 $selected_groups = $cachedSearch['groups'];
533 } elseif ( is_array( $cachedSearch['clients'] ) ) {
534 $selected_clients = $cachedSearch['clients'];
535 }
536 }
537
538 self::render_header( 'BulkManage' );
539
540 ?>
541 <div class="ui alt mainwp-posts segment" id="mainwp-manage-posts">
542 <div class="mainwp-main-content">
543 <div class="mainwp-actions-bar ui mini form">
544 <div class="ui grid">
545 <div class="ui two column row">
546 <div class="column">
547 <select class="ui dropdown" id="mainwp-bulk-actions">
548 <option value="none"><?php esc_html_e( 'Bulk Actions', 'mainwp' ); ?></option>
549 <option value="publish"><?php esc_html_e( 'Publish', 'mainwp' ); ?></option>
550 <option value="unpublish"><?php esc_html_e( 'Unpublish', 'mainwp' ); ?></option>
551 <?php do_action( 'mainwp_manage_posts_bulk_action' ); ?>
552 <option value="trash"><?php esc_html_e( 'Trash', 'mainwp' ); ?></option>
553 <option value="restore"><?php esc_html_e( 'Restore', 'mainwp' ); ?></option>
554 <option value="delete"><?php esc_html_e( 'Delete', 'mainwp' ); ?></option>
555 <?php
556 /**
557 * Action: mainwp_posts_bulk_action
558 *
559 * Adds new action to the Bulk Actions menu on Manage Posts.
560 *
561 * Suggested HTML Markup:
562 * <option value="Your custom value">Your custom text</option>
563 *
564 * @since 4.1
565 */
566 do_action( 'mainwp_posts_bulk_action' );
567 ?>
568 </select>
569 <button class="ui mini button" id="mainwp-do-posts-bulk-actions"><?php esc_html_e( 'Apply', 'mainwp' ); ?></button>
570 <?php
571 /**
572 * Action: mainwp_posts_actions_bar_left
573 *
574 * Fires at the left side of the actions bar on the Posts screen, after the Bulk Actions menu.
575 *
576 * @since 4.0
577 */
578 do_action( 'mainwp_posts_actions_bar_left' );
579 ?>
580 </div>
581 <div class="right aligned column">
582 <?php
583 /**
584 * Action: mainwp_posts_actions_bar_right
585 *
586 * Fires at the right side of the actions bar on the Posts screen.
587 *
588 * @since 4.0
589 */
590 do_action( 'mainwp_posts_actions_bar_right' );
591 ?>
592 </div>
593 </div>
594 </div>
595 </div>
596 <div class="ui segment" id="mainwp-posts-table-wrapper">
597 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-manage-posts-info-message' ) ) : ?>
598 <div class="ui info message">
599 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-manage-posts-info-message"></i>
600 <?php printf( esc_html__( 'Manage existing posts on your child sites. Here you can edit, view and delete pages. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/manage-posts/" target="_blank">', '</a>' ); ?>
601 </div>
602 <?php endif; ?>
603 <?php self::render_table( true ); ?>
604 </div>
605 </div>
606 <div class="mainwp-side-content mainwp-no-padding">
607 <?php
608 /**
609 * Action: mainwp_manage_posts_sidebar_top
610 *
611 * Fires at the top of the sidebar on Manage posts.
612 *
613 * @since 4.1
614 */
615 do_action( 'mainwp_manage_posts_sidebar_top' );
616 ?>
617 <div class="mainwp-select-sites ui fluid accordion mainwp-sidebar-accordion">
618 <?php
619 /**
620 * Action: mainwp_manage_posts_before_select_sites
621 *
622 * Fires before the Select Sites section on Manage posts.
623 *
624 * @since 4.1
625 */
626 do_action( 'mainwp_manage_posts_before_select_sites' );
627 ?>
628 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
629 <div class="content active">
630 <?php
631 $sel_params = array(
632 'class' => 'mainwp_select_sites_box_left',
633 'selected_sites' => $selected_sites,
634 'selected_groups' => $selected_groups,
635 'selected_clients' => $selected_clients,
636 'show_client' => true,
637 );
638 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
639 ?>
640 </div>
641 <?php
642 /**
643 * Action: mainwp_manage_posts_after_select_sites
644 *
645 * Fires after the Select Sites section on Manage posts.
646 *
647 * @since 4.1
648 */
649 do_action( 'mainwp_manage_posts_after_select_sites' );
650 ?>
651 </div>
652 <div class="ui fitted divider"></div>
653 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
654 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Status', 'mainwp' ); ?></div>
655 <div class="content active">
656 <?php
657 /**
658 * Action: mainwp_manage_posts_before_search_options
659 *
660 * Fires before the Search Options on Manage Posts.
661 *
662 * @since 4.1
663 */
664 do_action( 'mainwp_manage_posts_before_search_options' );
665 ?>
666 <div class="ui mini form">
667 <div class="field">
668 <select multiple="" class="ui fluid dropdown" id="mainwp_post_search_type">
669 <option value=""><?php esc_html_e( 'Select status', 'mainwp' ); ?></option>
670 <option value="publish" selected><?php esc_html_e( 'Published', 'mainwp' ); ?></option>
671 <option value="pending"><?php esc_html_e( 'Pending', 'mainwp' ); ?></option>
672 <option value="private"><?php esc_html_e( 'Private', 'mainwp' ); ?></option>
673 <option value="future"><?php esc_html_e( 'Scheduled', 'mainwp' ); ?></option>
674 <option value="draft"><?php esc_html_e( 'Draft', 'mainwp' ); ?></option>
675 <option value="trash"><?php esc_html_e( 'Trash', 'mainwp' ); ?></option>
676 </select>
677 </div>
678 </div>
679 </div>
680 </div>
681 <div class="ui fitted divider"></div>
682 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
683 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Search Options', 'mainwp' ); ?></div>
684 <div class="content active">
685 <?php self::render_search_options(); ?>
686 <?php
687 /**
688 * Action: mainwp_manage_posts_after_search_options
689 *
690 * Fires after the Search Options on Manage Posts.
691 *
692 * @since 4.1
693 */
694 do_action( 'mainwp_manage_posts_after_search_options' );
695 ?>
696 </div>
697 </div>
698 <div class="ui fitted divider"></div>
699 <?php
700 $num_sites = apply_filters( 'mainwp_posts_search_bulk_sites', 0 );
701 ?>
702
703 <span id="search-bulk-sites" number-sites="<?php echo intval( $num_sites ); ?>"></span>
704 <div class="mainwp-search-submit">
705 <?php
706 /**
707 * Action: mainwp_manage_posts_before_submit_button
708 *
709 * Fires before the Submit Button on Manage Posts.
710 *
711 * @since 4.1
712 */
713 do_action( 'mainwp_manage_posts_before_submit_button' );
714 $is_demo = MainWP_Demo_Handle::is_demo_mode();
715 if ( $is_demo ) {
716 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<input type="button" disabled="disabled" class="ui green big fluid button disabled" value="' . esc_attr__( 'Show Posts', 'mainwp' ) . '" />' );
717 } else {
718 ?>
719 <input type="button" name="mainwp_show_posts" id="mainwp_show_posts" class="ui green big fluid button" value="<?php esc_attr_e( 'Show Posts', 'mainwp' ); ?>"/>
720 <?php
721 }
722 /**
723 * Action: mainwp_manage_posts_after_submit_button
724 *
725 * Fires after the Submit Button on Manage Posts.
726 *
727 * @since 4.1
728 */
729 do_action( 'mainwp_manage_posts_after_submit_button' );
730 ?>
731 </div>
732 <?php
733 /**
734 * Action: mainwp_manage_posts_sidebar_bottom
735 *
736 * Fires at the bottom of the sidebar on Manage posts.
737 *
738 * @since 4.1
739 */
740 do_action( 'mainwp_manage_posts_sidebar_bottom' );
741 ?>
742 </div>
743 <div class="ui hidden clearing divider"></div>
744 </div>
745
746 <?php
747
748 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
749 if ( isset( $_REQUEST['siteid'] ) && isset( $_REQUEST['postid'] ) ) {
750 echo '<script>jQuery(document).ready(function() { mainwp_show_post( ' . intval( $_REQUEST['siteid'] ) . ', ' . intval( $_REQUEST['postid'] ) . ', undefined ) } );</script>';
751 } elseif ( isset( $_REQUEST['siteid'] ) && isset( $_REQUEST['userid'] ) ) {
752 echo '<script>jQuery(document).ready(function() { mainwp_show_post( ' . intval( $_REQUEST['siteid'] ) . ', undefined, ' . intval( $_REQUEST['userid'] ) . ' ) } );</script>';
753 }
754 // phpcs:enable
755
756 // to fix issue js code display.
757 $cachedSearch = MainWP_Cache::get_cached_context( 'Post' );
758 $statuses = isset( $cachedSearch['status'] ) ? $cachedSearch['status'] : array();
759 if ( is_array( $statuses ) && 0 < count( $statuses ) ) {
760 $status = '';
761 foreach ( $statuses as $st ) {
762 $status .= "'" . esc_html( $st ) . "',";
763 }
764 $status = rtrim( $status, ',' );
765 ?>
766 <script type="text/javascript">
767 jQuery( document ).ready( function () {
768 jQuery( '#mainwp_post_search_type' ).dropdown( 'set selected', [<?php echo $status; // phpcs:ignore -- safe output. ?>] );
769 } )
770 </script>
771 <?php
772 }
773
774 self::render_footer( 'BulkManage' );
775 }
776
777 /**
778 * Method render_search_options()
779 *
780 * Search form for Post page.
781 *
782 * @uses \MainWP\Dashboard\MainWP_Cache::get_cached_context()
783 */
784 public static function render_search_options() {
785 $cachedSearch = MainWP_Cache::get_cached_context( 'Post' );
786 if ( $cachedSearch && isset( $cachedSearch['keyword'] ) ) {
787 $cachedSearch['keyword'] = trim( $cachedSearch['keyword'] );
788 }
789
790 ?>
791 <div class="ui mini form">
792 <div class="field">
793 <div class="ui input fluid">
794 <input type="text" placeholder="<?php esc_attr_e( 'Containing keyword', 'mainwp' ); ?>" id="mainwp_post_search_by_keyword" class="text" value="<?php echo ( null !== $cachedSearch ) ? esc_attr( $cachedSearch['keyword'] ) : ''; ?>"/>
795 </div>
796 </div>
797 <div class="field">
798 <?php
799 $searchon = 'title';
800 if ( null !== $cachedSearch ) {
801 $searchon = $cachedSearch['search_on'];
802 }
803 ?>
804 <select class="ui dropdown fluid" id="mainwp_post_search_on">
805 <option value=""><?php esc_html_e( 'Search in...', 'mainwp' ); ?></option>
806 <option value="title" <?php echo 'title' === $searchon ? 'selected' : ''; ?>><?php esc_html_e( 'Title', 'mainwp' ); ?></option>
807 <option value="content" <?php echo 'content' === $searchon ? 'selected' : ''; ?>><?php esc_html_e( 'Body', 'mainwp' ); ?></option>
808 <option value="all" <?php echo 'all' === $searchon ? 'selected' : ''; ?>><?php esc_html_e( 'Title and Body', 'mainwp' ); ?></option>
809 </select>
810 </div>
811 <div class="field">
812 <label><?php esc_html_e( 'Date range', 'mainwp' ); ?></label>
813 <div class="two fields">
814 <div class="field">
815 <div class="ui calendar mainwp_datepicker" >
816 <div class="ui input left icon">
817 <i class="calendar icon"></i>
818 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Date', 'mainwp' ); ?>" id="mainwp_post_search_by_dtsstart" value="<?php echo null !== $cachedSearch ? esc_attr( $cachedSearch['dtsstart'] ) : ''; ?>"/>
819 </div>
820 </div>
821 </div>
822 <div class="field">
823 <div class="ui calendar mainwp_datepicker" >
824 <div class="ui input left icon">
825 <i class="calendar icon"></i>
826 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Date', 'mainwp' ); ?>" id="mainwp_post_search_by_dtsstop" value="<?php echo null !== $cachedSearch ? esc_attr( $cachedSearch['dtsstop'] ) : ''; ?>"/>
827 </div>
828 </div>
829 </div>
830 </div>
831 </div>
832 <?php if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) : ?>
833 <div class="field">
834 <label><?php esc_html_e( 'Select post type', 'mainwp' ); ?></label><br/>
835 <select class="ui dropdown fluid" id="mainwp_get_custom_post_types_select">
836 <option value="any"><?php esc_html_e( 'All post types', 'mainwp' ); ?></option>
837 <option value="post"><?php esc_html_e( 'Post', 'mainwp' ); ?></option>
838 <?php
839 /**
840 * Default post types
841 *
842 * Set default custom post types to exclude from the CPT extension options.
843 *
844 * @since 4.0
845 */
846 $default_post_types = apply_filters( 'mainwp_custom_post_types_default', array() );
847 foreach ( get_post_types( array( '_builtin' => false ) ) as $key ) {
848 if ( ! in_array( $key, $default_post_types ) ) {
849 echo '<option value="' . esc_attr( $key ) . '">' . esc_html( $key ) . '</option>';
850 }
851 }
852 ?>
853 </select>
854 </div>
855 <?php endif; ?>
856 <div class="field">
857 <label><?php esc_html_e( 'Max posts to return', 'mainwp' ); ?></label>
858 <input type="text" name="mainwp_maximumPosts" id="mainwp_maximumPosts" value="<?php echo( ( false === get_option( 'mainwp_maximumPosts' ) ) ? 50 : esc_attr( get_option( 'mainwp_maximumPosts' ) ) ); ?>"/>
859 </div>
860 </div>
861 <?php
862 }
863
864 /**
865 * Renders Posts table.
866 *
867 * @param bool $cached Show cached data or not. Default: true.
868 * @param mixed $keyword Search keywords.
869 * @param mixed $dtsstart Date & time of Session start.
870 * @param mixed $dtsstop Date & time of Session stop.
871 * @param mixed $status Page statuses.
872 * @param mixed $groups Groups to display.
873 * @param mixed $sites Site URLS.
874 * @param int $postId Post ID.
875 * @param int $userId Current user ID.
876 * @param string $post_type Post type.
877 * @param string $search_on Site on all sites. Default = all.
878 * @param mixed $clients Clients.
879 *
880 * @uses \MainWP\Dashboard\MainWP_Cache::echo_body()
881 * @uses \MainWP\Dashboard\MainWP_Utility::enabled_wp_seo()
882 */
883 public static function render_table( $cached = true, $keyword = '', $dtsstart = '', $dtsstop = '', $status = '', $groups = '', $sites = '', $postId = 0, $userId = 0, $post_type = '', $search_on = 'all', $clients = '' ) {
884 ?>
885
886 <div id="mainwp-message-zone"></div>
887
888 <div id="mainwp-loading-posts-row" style="display: none;">
889 <div class="ui active inverted dimmer">
890 <div class="ui indeterminate large text loader"><?php esc_html_e( 'Loading Posts...', 'mainwp' ); ?></div>
891 </div>
892 </div>
893
894 <?php
895 /**
896 * Action: mainwp_before_posts_table
897 *
898 * Fires before the Manage Posts table.
899 *
900 * @since 4.1
901 */
902 do_action( 'mainwp_before_posts_table' );
903 ?>
904 <table id="mainwp-posts-table" class="ui unstackable single line table" style="width:100%">
905 <thead class="full-width">
906 <tr>
907 <th class="no-sort collapsing check-column"><span class="ui checkbox"><input id="cb-select-all-top" type="checkbox" /></span></th>
908 <?php
909 /**
910 * Action: mainwp_posts_table_header
911 *
912 * Adds new column header to the Manage posts table.
913 *
914 * @since 4.1
915 */
916 do_action( 'mainwp_posts_table_header' );
917 ?>
918 <th id="title"><?php esc_html_e( 'Title', 'mainwp' ); ?></th>
919 <th id="author" class="min-tablet"><?php esc_html_e( 'Author', 'mainwp' ); ?></th>
920 <th id="categories" class="min-tablet"><?php esc_html_e( 'Categories', 'mainwp' ); ?></th>
921 <th id="tags" class="min-tablet"><?php esc_html_e( 'Tags', 'mainwp' ); ?></th>
922 <?php if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) : ?>
923 <th id="post-type"><?php esc_html_e( 'Post Type', 'mainwp' ); ?></th>
924 <?php endif; ?>
925 <?php if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) : ?>
926 <th id="comments"><i class="comment icon"></i></th>
927 <?php endif; ?>
928 <th id="date" class="min-tablet"><?php esc_html_e( 'Last Modified', 'mainwp' ); ?></th>
929 <th id="status" class=""><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
930 <?php if ( MainWP_Utility::enabled_wp_seo() ) : ?>
931 <th id="seo-links"><?php esc_html_e( 'Links', 'mainwp' ); ?></th>
932 <th id="seo-linked"><?php esc_html_e( 'Linked', 'mainwp' ); ?></th>
933 <th id="seo-score"><?php esc_html_e( 'SEO Score', 'mainwp' ); ?></th>
934 <th id="seo-readability"><?php esc_html_e( 'Readability score', 'mainwp' ); ?></th>
935 <?php endif; ?>
936 <th id="website" class="min-tablet"><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
937 <th id="posts-actions" class="no-sort min-tablet"></th>
938 </tr>
939 </thead>
940
941 <tbody id="mainwp-posts-list">
942 <?php
943 if ( $cached ) {
944 MainWP_Cache::echo_body( 'Post' );
945 } else {
946 MainWP_Cache::init_cache( 'Post' );
947 self::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, false, $clients );
948 }
949 ?>
950 </tbody>
951 </table>
952 <?php
953 /**
954 * Action: mainwp_after_posts_table
955 *
956 * Fires after the Manage Posts table.
957 *
958 * @since 4.1
959 */
960 do_action( 'mainwp_after_posts_table' );
961
962 $table_features = array(
963 'searching' => 'true',
964 'paging' => 'true',
965 'info' => 'true',
966 'stateSave' => 'true',
967 'scrollX' => 'true',
968 'colReorder' => '{ fixedColumnsLeft: 1, fixedColumnsRight: 1 }',
969 'order' => '[]',
970 'responsive' => 'true',
971 );
972
973 /**
974 * Filter: mainwp_posts_table_fatures
975 *
976 * Filters the Manage Posts table features.
977 *
978 * @since 4.1
979 */
980 $table_features = apply_filters( 'mainwp_posts_table_fatures', $table_features );
981 if ( $cached ) {
982 ?>
983 <script type="text/javascript">
984 var responsive = <?php echo esc_html( $table_features['responsive'] ); ?>;
985 if( jQuery( window ).width() > 1140 ) {
986 responsive = false;
987 }
988 jQuery( document ).ready( function () {
989 try {
990 jQuery("#mainwp-posts-table").DataTable().destroy(); // to fix re-init database issue.
991 $manage_posts_table = jQuery('#mainwp-posts-table').DataTable( {
992 "responsive" : responsive,
993 "searching" : <?php echo esc_html( $table_features['searching'] ); ?>,
994 "colReorder" : <?php echo esc_html( $table_features['colReorder'] ); ?>,
995 "stateSave": <?php echo esc_html( $table_features['stateSave'] ); ?>,
996 "paging": <?php echo esc_html( $table_features['paging'] ); ?>,
997 "info": <?php echo esc_html( $table_features['info'] ); ?>,
998 "order": <?php echo esc_html( $table_features['order'] ); ?>,
999 "scrollX" : <?php echo esc_html( $table_features['scrollX'] ); ?>,
1000 "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ],
1001 "columnDefs": [ {
1002 "targets": 'no-sort',
1003 "orderable": false
1004 } ],
1005 "language" : { "emptyTable": "<?php esc_html_e( 'Use the search options to find the post you want to manage.', 'mainwp' ); ?>" },
1006 "preDrawCallback": function( settings ) {
1007 jQuery( '#mainwp-posts-table-wrapper table .ui.dropdown' ).dropdown();
1008 jQuery( '#mainwp-posts-table-wrapper table .ui.checkbox' ).checkbox();
1009 mainwp_datatable_fix_menu_overflow();
1010 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
1011 }
1012 } );
1013 } catch ( err ) {
1014 // to fix js error.
1015 }
1016
1017 _init_manage_sites_screen = function() {
1018 jQuery( '#mainwp-overview-screen-options-modal input[type=checkbox][id^="mainwp_show_column_"]' ).each( function() {
1019 var col_id = jQuery( this ).attr( 'id' );
1020 col_id = col_id.replace( "mainwp_show_column_", "" );
1021 try {
1022 $manage_posts_table.column( '#' + col_id ).visible( jQuery(this).is( ':checked' ) );
1023 } catch(err) {
1024 // to fix js error.
1025 }
1026 } );
1027 };
1028 _init_manage_sites_screen();
1029
1030 } );
1031 </script>
1032 <?php
1033 }
1034 }
1035
1036 /**
1037 * Method render_table_body()
1038 *
1039 * Render Posts table body.
1040 *
1041 * @param mixed $keyword Search keywords.
1042 * @param mixed $dtsstart Date & time of Session start.
1043 * @param mixed $dtsstop Date & time of Session stop.
1044 * @param mixed $status Page statuses.
1045 * @param mixed $groups Groups to display.
1046 * @param mixed $sites Site URLS.
1047 * @param integer $postId Post ID.
1048 * @param integer $userId Current user ID.
1049 * @param string $post_type Post type.
1050 * @param string $search_on Site on all sites. Default = all.
1051 * @param bool $table_content Generate table content only. Default = false.
1052 * @param mixed $clients Clients.
1053 *
1054 * @return string Post table body html.
1055 *
1056 * @uses \MainWP\Dashboard\MainWP_Cache::init_cache()
1057 * @uses \MainWP\Dashboard\MainWP_Cache::add_context()
1058 * @uses \MainWP\Dashboard\MainWP_Cache::add_body()
1059 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1060 * @uses \MainWP\Dashboard\MainWP_DB::query()
1061 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1062 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_by_group_id()
1063 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1064 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
1065 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
1066 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
1067 * @uses \MainWP\Dashboard\MainWP_Utility::enabled_wp_seo()
1068 */
1069 public static function render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type = '', $search_on = 'all', $table_content = false, $clients = '' ) { // phpcs:ignore -- complex function.
1070
1071 $data_fields = MainWP_System_Utility::get_default_map_site_fields();
1072
1073 $dbwebsites = array();
1074 if ( '' !== $sites ) {
1075 foreach ( $sites as $k => $v ) {
1076 if ( MainWP_Utility::ctype_digit( $v ) ) {
1077 $website = MainWP_DB::instance()->get_website_by_id( $v );
1078 if ( empty( $website->sync_errors ) && ! MainWP_System_Utility::is_suspended_site( $website ) ) {
1079 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
1080 $website,
1081 $data_fields
1082 );
1083 }
1084 }
1085 }
1086 }
1087 if ( '' !== $groups ) {
1088 foreach ( $groups as $k => $v ) {
1089 if ( MainWP_Utility::ctype_digit( $v ) ) {
1090 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $v ) );
1091 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1092 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
1093 continue;
1094 }
1095 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
1096 $website,
1097 $data_fields
1098 );
1099 }
1100 MainWP_DB::free_result( $websites );
1101 }
1102 }
1103 }
1104 if ( '' !== $clients && is_array( $clients ) ) {
1105 $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids(
1106 $clients,
1107 array(
1108 'select_data' => $data_fields,
1109 )
1110 );
1111
1112 foreach ( $websites as $website ) {
1113 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
1114 continue;
1115 }
1116 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
1117 $website,
1118 $data_fields
1119 );
1120 }
1121 }
1122
1123 $output = new \stdClass();
1124 $output->errors = array();
1125 $output->posts = 0;
1126 $output->table_rows = '';
1127
1128 if ( 0 < count( $dbwebsites ) ) {
1129 $post_data = array(
1130 'keyword' => $keyword,
1131 'dtsstart' => $dtsstart,
1132 'dtsstop' => $dtsstop,
1133 'status' => $status,
1134 'search_on' => $search_on,
1135 'maxRecords' => ( ( false === get_option( 'mainwp_maximumPosts' ) ) ? 50 : get_option( 'mainwp_maximumPosts' ) ),
1136 );
1137
1138 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) {
1139 $post_data['post_type'] = $post_type;
1140 if ( 'any' === $post_type ) {
1141 $post_data['exclude_page_type'] = 1;
1142 }
1143 }
1144
1145 if ( MainWP_Utility::enabled_wp_seo() ) {
1146 $post_data['WPSEOEnabled'] = 1;
1147 }
1148
1149 if ( isset( $postId ) && ( '' !== $postId ) ) {
1150 $post_data['postId'] = $postId;
1151 } elseif ( isset( $userId ) && ( '' !== $userId ) ) {
1152 $post_data['userId'] = $userId;
1153 }
1154
1155 /**
1156 * Get all posts data
1157 *
1158 * Set search parameters for the fetch process.
1159 *
1160 * @since 3.4
1161 */
1162 $post_data = apply_filters( 'mainwp_get_all_posts_data', $post_data );
1163 MainWP_Connect::fetch_urls_authed(
1164 $dbwebsites,
1165 'get_all_posts',
1166 $post_data,
1167 array(
1168 self::get_class_name(),
1169 'posts_search_handler',
1170 ),
1171 $output
1172 );
1173 echo $output->table_rows; // phpcs:ignore WordPress.Security.EscapeOutput
1174 }
1175
1176 if ( ! $table_content ) {
1177 MainWP_Cache::add_body( 'Post', $output->table_rows );
1178 MainWP_Cache::add_context(
1179 'Post',
1180 array(
1181 'count' => $output->posts,
1182 'keyword' => $keyword,
1183 'dtsstart' => $dtsstart,
1184 'dtsstop' => $dtsstop,
1185 'status' => $status,
1186 'sites' => ( '' !== $sites ) ? $sites : '',
1187 'groups' => ( '' !== $groups ) ? $groups : '',
1188 'clients' => ( '' !== $clients ) ? $clients : '',
1189 'search_on' => $search_on,
1190 )
1191 );
1192
1193 if ( 0 === $output->posts ) {
1194 MainWP_Cache::add_body( 'Post', '' );
1195 return;
1196 }
1197 }
1198 }
1199
1200 /**
1201 * Method get_status()
1202 *
1203 * Get Post status.
1204 *
1205 * @param mixed $status Post status.
1206 *
1207 * @return string $status Post status.
1208 */
1209 private static function get_status( $status ) {
1210 if ( 'publish' === $status ) {
1211 return 'Published';
1212 }
1213
1214 return esc_html( ucfirst( $status ) );
1215 }
1216
1217 /**
1218 * Method posts_search_handler()
1219 *
1220 * Post page search handler.
1221 *
1222 * @param mixed $data Search data.
1223 * @param mixed $website Child Sites ID.
1224 * @param mixed $output Html to output.
1225 *
1226 * @return string Returned search results html.
1227 *
1228 * @uses \MainWP\Dashboard\MainWP_Cache::add_body()
1229 * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
1230 * @uses \MainWP\Dashboard\MainWP_Exception
1231 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
1232 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
1233 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
1234 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
1235 */
1236 public static function posts_search_handler( $data, $website, &$output ) { // phpcs:ignore -- complex method.
1237 if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $website ) ) {
1238 return;
1239 }
1240 if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
1241 $result = $results[1];
1242 $posts = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
1243
1244 if ( is_array( $posts ) && isset( $posts['error'] ) ) {
1245 $output->errors[ $website->id ] = esc_html( $posts['error'] );
1246 return;
1247 }
1248
1249 unset( $results );
1250
1251 $child_to_dash_array = array();
1252
1253 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) {
1254 $child_post_ids = array();
1255 foreach ( $posts as $post ) {
1256 $child_post_ids[] = $post['id'];
1257 }
1258 reset( $posts );
1259
1260 $connections_ids = apply_filters( 'mainwp_custom_post_types_get_post_connections', false, $website->id, $child_post_ids );
1261 if ( ! empty( $connections_ids ) ) {
1262 foreach ( $connections_ids as $key ) {
1263 $child_to_dash_array[ $key->child_post_id ] = $key->dash_post_id;
1264 }
1265 }
1266 }
1267
1268 $table_rows = '';
1269 foreach ( $posts as $post ) {
1270 $raw_dts = '';
1271 if ( isset( $post['dts'] ) ) {
1272 $raw_dts = $post['dts'];
1273 if ( ! stristr( $post['dts'], '-' ) ) {
1274 $post['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $post['dts'] ) );
1275 }
1276 }
1277
1278 if ( ! isset( $post['title'] ) || ( '' === $post['title'] ) ) {
1279 $post['title'] = '(No Title)';
1280 }
1281
1282 ob_start();
1283 ?>
1284
1285 <tr>
1286 <td class="check-column"><span class="ui checkbox"><input type="checkbox" name="post[]" value="1"></span></td>
1287 <?php
1288 /**
1289 * Action: mainwp_posts_table_column
1290 *
1291 * Adds a new column item in the Manage posts table.
1292 *
1293 * @param array $post Array containing the post data.
1294 * @param array $website Object containing the website data.
1295 *
1296 * @since 4.1
1297 */
1298 do_action( 'mainwp_posts_table_column', $post, $website );
1299 ?>
1300 <td class="title column-title">
1301 <strong>
1302 <abbr title="<?php echo esc_attr( $post['title'] ); ?>">
1303 <?php if ( 'trash' !== $post['status'] ) { ?>
1304 <a class="row-title" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo intval( $website->id ); ?>&location=<?php echo esc_attr( base64_encode( 'post.php?post=' . $post['id'] . '&action=edit' ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>" target="_blank">
1305 <?php echo esc_html( $post['title'] ); ?>
1306 </a>
1307 <?php
1308 } else {
1309 echo esc_html( $post['title'] );
1310 }
1311 ?>
1312 </abbr>
1313 </strong>
1314 </td>
1315
1316 <td class="author column-author"><?php echo esc_html( $post['author'] ); ?></td>
1317
1318 <td class="categories column-categories"><?php echo esc_html( $post['categories'] ); ?></td>
1319
1320 <td class="tags"><?php echo esc_html( '' === $post['tags'] ? 'No Tags' : $post['tags'] ); ?></td>
1321
1322 <?php if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) : ?>
1323 <td class="post-type column-post-type"><?php echo esc_html( $post['post_type'] ); ?></td>
1324 <?php endif; ?>
1325
1326 <?php if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) : ?>
1327 <td class="comments column-comments">
1328 <div class="post-com-count-wrapper">
1329 <a href="<?php echo esc_url( admin_url( 'admin.php?page=CommentBulkManage&siteid=' . intval( $website->id ) ) . '&postid=' . $post['id'] ); ?>" title="0 pending" class="post-com-count"><span class="comment-count"><abbr title="<?php echo esc_attr( $post['comment_count'] ); ?>"><?php echo esc_html( $post['comment_count'] ); ?></abbr></span></a>
1330 </div>
1331 </td>
1332 <?php endif; ?>
1333
1334 <td class="date column-date" data-order="<?php echo esc_attr( $raw_dts ); ?>"><abbr raw_value="<?php echo esc_attr( $raw_dts ); ?>" title="<?php echo esc_attr( $post['dts'] ); ?>"><?php echo esc_html( $post['dts'] ); ?></abbr></td>
1335
1336 <td class="status column-status <?php echo 'trash' === $post['status'] ? 'post-trash' : ''; ?>"><?php echo esc_html( self::get_status( $post['status'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput ?></td>
1337
1338 <?php
1339 if ( MainWP_Utility::enabled_wp_seo() ) :
1340 $count_seo_links = null;
1341 $count_seo_linked = null;
1342 $seo_score = '';
1343 $readability_score = '';
1344 if ( isset( $post['seo_data'] ) ) {
1345 $seo_data = $post['seo_data'];
1346 $count_seo_links = esc_html( $seo_data['count_seo_links'] );
1347 $count_seo_linked = esc_html( $seo_data['count_seo_linked'] );
1348 $seo_score = MainWP_Utility::esc_content( $seo_data['seo_score'], 'mixed' );
1349 $readability_score = MainWP_Utility::esc_content( $seo_data['readability_score'], 'mixed' );
1350 }
1351 ?>
1352 <td class="column-seo-links" ><abbr raw_value="<?php echo null !== $count_seo_links ? $count_seo_links : -1; ?>" title=""><?php echo null !== $count_seo_links ? $count_seo_links : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?></abbr></td>
1353 <td class="column-seo-linked"><abbr raw_value="<?php echo null !== $count_seo_linked ? $count_seo_linked : -1; ?>" title=""><?php echo null !== $count_seo_linked ? $count_seo_linked : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?></abbr></td>
1354 <td class="column-seo-score"><abbr raw_value="<?php echo $seo_score ? 1 : 0; ?>" title=""><?php echo $seo_score; // phpcs:ignore WordPress.Security.EscapeOutput ?></abbr></td>
1355 <td class="column-seo-readability"><abbr raw_value="<?php echo $readability_score ? 1 : 0; ?>" title=""><?php echo $readability_score; // phpcs:ignore WordPress.Security.EscapeOutput ?></abbr></td>
1356 <?php endif; ?>
1357
1358 <td class="website column-website"><a href="<?php echo esc_url( $website->url ); ?>" target="_blank"><?php echo esc_html( $website->url ); ?></a></td>
1359 <td class="right aligned">
1360 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $post['id'] ); ?>"/>
1361 <input class="allowedBulkActions" type="hidden" name="allowedBulkActions" value="|get_edit|trash|delete|<?php echo ( 'publish' === $post['status'] ) ? 'unpublish|' : ''; ?><?php echo ( 'pending' === $post['status'] ) ? 'approve|' : ''; ?><?php echo ( 'trash' === $post['status'] ) ? 'restore|' : ''; ?><?php echo ( 'future' === $post['status'] || 'draft' === $post['status'] ) ? 'publish|' : ''; ?>" />
1362 <input class="websiteId" type="hidden" name="id" value="<?php echo intval( $website->id ); ?>"/>
1363 <div class="ui left pointing dropdown icon mini basic green button" style="z-index: 999">
1364 <a href="javascript:void(0)"><i class="ellipsis horizontal icon"></i></a>
1365 <div class="menu">
1366 <?php if ( 'future' === $post['status'] || 'draft' === $post['status'] ) : ?>
1367 <a class="item post_submitpublish" href="#"><?php esc_html_e( 'Publish', 'mainwp' ); ?></a>
1368 <?php endif; ?>
1369
1370 <?php if ( 'pending' === $post['status'] ) : ?>
1371 <a class="item post_submitapprove" href="#"><?php esc_html_e( 'Approve', 'mainwp' ); ?></a>
1372 <?php endif; ?>
1373
1374 <?php if ( 'publish' === $post['status'] ) : ?>
1375 <a class="item post_submitunpublish" href="#"><?php esc_html_e( 'Unpublish', 'mainwp' ); ?></a>
1376 <a class="item mainwp-may-hide-referrer" href="<?php echo esc_html( $website->url ) . ( substr( $website->url, - 1 ) !== '/' ? '/' : '' ) . '?p=' . esc_attr( $post['id'] ); ?>" target="_blank" ><?php esc_html_e( 'View', 'mainwp' ); ?></a>
1377 <?php endif; ?>
1378
1379 <?php if ( 'trash' === $post['status'] ) : ?>
1380 <a class="item post_submitrestore" href="#"><?php esc_html_e( 'Restore', 'mainwp' ); ?></a>
1381 <a class="item post_submitdelete_perm" href="#"><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
1382 <?php endif; ?>
1383
1384 <?php if ( 'trash' !== $post['status'] ) : ?>
1385 <?php if ( isset( $child_to_dash_array[ $post['id'] ] ) ) { ?>
1386 <a class="item" href="post.php?post=<?php echo (int) $child_to_dash_array[ $post['id'] ]; ?>&action=edit&select=<?php echo (int) $website->id; ?>"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
1387 <?php } else { ?>
1388 <a class="item post_getedit" href="#"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
1389 <?php } ?>
1390 <?php do_action( 'mainwp_manage_posts_action_item', $post, $child_to_dash_array ); ?>
1391 <a class="item post_submitdelete" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
1392 <?php endif; ?>
1393 <a class="item" href="<?php echo 'admin.php?page=SiteOpen&newWindow=yes&websiteid=' . intval( $website->id ); ?>&_opennonce=<?php echo esc_html( wp_create_nonce( 'mainwp-admin-nonce' ) ); ?>" data-tooltip="<?php esc_attr_e( 'Jump to the site WP Admin', 'mainwp' ); ?>" data-position="bottom right" data-inverted="" class="open_newwindow_wpadmin ui green basic icon button" target="_blank"><?php esc_html_e( 'Go to WP Admin', 'mainwp' ); ?></a>
1394 <?php
1395 /**
1396 * Action: mainwp_posts_table_action
1397 *
1398 * Adds a new item in the Actions menu in Manage Posts table.
1399 *
1400 * Suggested HTML markup:
1401 * <a class="item" href="Your custom URL">Your custom label</a>
1402 *
1403 * @param array $post Array containing the post data.
1404 * @param array $website Object containing the website data.
1405 *
1406 * @since 4.1
1407 */
1408 do_action( 'mainwp_posts_table_action', $post, $website );
1409 ?>
1410 </div>
1411 </div>
1412 </td>
1413 </tr>
1414 <?php
1415 $newOutput = ob_get_clean();
1416 $table_rows .= $newOutput;
1417 ++$output->posts;
1418 }
1419 $output->table_rows .= $table_rows;
1420 unset( $posts );
1421 } else {
1422 $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) );
1423 }
1424 }
1425
1426 /**
1427 * Method list_meta_row()
1428 *
1429 * Outputs a single row of public meta data in the Custom Fields meta box.
1430 *
1431 * @since 2.5.0
1432 *
1433 * @param array $entry Post array.
1434 * @param int $count Counter variable.
1435 *
1436 * @return string $r Custom Fields meta box HTML.
1437 *
1438 * @uses \MainWP\Dashboard\MainWP_System_Utility::maybe_unserialyze()
1439 */
1440 public static function list_meta_row( $entry, &$count ) {
1441
1442 /**
1443 * Static variable to hold update nonce.
1444 *
1445 * @static
1446 *
1447 * @var string Update nonce.
1448 */
1449 static $update_nonce = '';
1450
1451 if ( is_protected_meta( $entry['meta_key'], 'post' ) ) {
1452 return '';
1453 }
1454
1455 if ( ! $update_nonce ) {
1456 $update_nonce = wp_create_nonce( 'add-meta' );
1457 }
1458
1459 $r = '';
1460 ++$count;
1461
1462 if ( is_serialized( $entry['meta_value'] ) ) {
1463 if ( is_serialized_string( $entry['meta_value'] ) ) {
1464 $entry['meta_value'] = MainWP_System_Utility::maybe_unserialyze( $entry['meta_value'] ); //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- ok.
1465 } else {
1466 --$count;
1467 return '';
1468 }
1469 }
1470
1471 $entry['meta_key'] = esc_attr( $entry['meta_key'] ); //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- ok.
1472 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- ok.
1473 $entry['meta_id'] = (int) $entry['meta_id'];
1474
1475 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
1476
1477 $r .= "\n\t<div class=\"two column row\" meta-id=\"" . $entry['meta_id'] . '" >';
1478 $r .= "\n\t\t<div class=\"column\"><label for='meta-{$entry['meta_id']}-key'>" . esc_html__( 'Key', 'mainwp' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta-{$entry['meta_id']}-key' type='text' size='20' value='{$entry['meta_key']}' />";
1479 $r .= "\n\t\t";
1480 $r .= "<input type=\"button\" onclick=\"mainwp_post_newmeta_submit( 'delete', this )\" class=\"ui mini button\" _ajax_nonce=\"$delete_nonce\" value=\"" . esc_attr__( 'Delete', 'mainwp' ) . '">';
1481 $r .= "\n\t\t";
1482 $r .= "<input type=\"button\" onclick=\"mainwp_post_newmeta_submit( 'update', this )\" class=\"ui mini button\" value=\"" . esc_attr__( 'Update', 'mainwp' ) . '">';
1483 $r .= '</div>';
1484 $r .= "\n\t\t<div class=\"column\"><label for='meta-{$entry['meta_id']}-value'>" . esc_html__( 'Value', 'mainwp' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></div>\n\t</div>";
1485 return $r;
1486 }
1487
1488 /**
1489 * Method meta_form()
1490 *
1491 * Prints the form in the Custom Fields meta box.
1492 *
1493 * @since 1.2.0
1494 *
1495 * @global wpdb $wpdb WordPress database abstraction object.
1496 *
1497 * @param WP_Post $pos Optional. The post being edited.
1498 */
1499 public static function meta_form( $pos = null ) {
1500 global $wpdb;
1501 $_post = get_post( $pos );
1502
1503 /**
1504 * Filters values for the meta key dropdown in the Custom Fields meta box.
1505 *
1506 * Returning a non-null value will effectively short-circuit and avoid a
1507 * potentially expensive query against postmeta.
1508 *
1509 * @since 4.4.0
1510 *
1511 * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null.
1512 * @param WP_Post $_post The current post object.
1513 */
1514 $keys = apply_filters( 'postmeta_form_keys', null, $_post );
1515
1516 if ( null === $keys ) {
1517 /**
1518 * Filters the number of custom fields to retrieve for the drop-down
1519 * in the Custom Fields meta box.
1520 *
1521 * @since 2.1.0
1522 *
1523 * @param int $limit Number of custom fields to retrieve. Default 30.
1524 */
1525 $limit = apply_filters( 'postmeta_form_limit', 30 );
1526 $sql = "SELECT DISTINCT meta_key
1527 FROM $wpdb->postmeta
1528 WHERE meta_key NOT BETWEEN '_' AND '_z'
1529 HAVING meta_key NOT LIKE %s
1530 ORDER BY meta_key
1531 LIMIT %d";
1532 $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); // phpcs:ignore -- unprepared SQL ok.
1533 }
1534
1535 if ( $keys ) {
1536 natcasesort( $keys );
1537 $meta_key_input_id = 'metakeyselect';
1538 } else {
1539 $meta_key_input_id = 'metakeyinput';
1540 }
1541 ?>
1542
1543 <div class="two column row" id="mainwp-metaform-row">
1544 <div class="column">
1545 <label for="<?php echo esc_attr( $meta_key_input_id ); ?>"><?php esc_html_e( 'Name', 'mainwp' ); ?></label>
1546 <?php if ( $keys ) { ?>
1547 <select id="metakeyselect" name="metakeyselect">
1548 <option value="#NONE#"><?php esc_html_e( '&mdash; Select &mdash;', 'mainwp' ); ?></option>
1549 <?php
1550 foreach ( $keys as $key ) {
1551 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $_post->ID, $key ) ) {
1552 continue;
1553 }
1554 echo "\n<option value='" . esc_attr( $key ) . "'>" . esc_html( $key ) . '</option>';
1555 }
1556 ?>
1557 </select>
1558 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
1559 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery( '#metakeyinput, #metakeyselect, #enternew, #cancelnew' ).toggle();return false;">
1560 <span id="enternew"><?php esc_html_e( 'Enter new', 'mainwp' ); ?></span>
1561 <span id="cancelnew" class="hidden"><?php esc_html_e( 'Cancel', 'mainwp' ); ?></span>
1562 </a>
1563 <?php } else { ?>
1564 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
1565 <?php } ?>
1566 </div>
1567 <div class="column">
1568 <label for="metavalue"><?php esc_html_e( 'Value', 'mainwp' ); ?></label>
1569 <textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea>
1570 </div>
1571 </div>
1572 <div class="two column row">
1573 <div class="column">
1574 <input type="button" onclick="mainwp_post_newmeta_submit( 'add' )" class="ui mini button" value="<?php esc_attr_e( 'Add Custom Field', 'mainwp' ); ?>">
1575 </div>
1576 <div class="column"></div>
1577 </div>
1578 <?php
1579 }
1580
1581 /**
1582 * Method post_custom_meta_box()
1583 *
1584 * Display custom fields form fields.
1585 *
1586 * @since 2.6.0
1587 *
1588 * @param object $post Current post object.
1589 */
1590 public static function post_custom_meta_box( $post ) {
1591 ?>
1592 <div class="ui secondary segment">
1593 <div class="ui header"><?php esc_html_e( 'Custom Fields', 'mainwp' ); ?></div>
1594 <div class="ui grid">
1595 <?php
1596 $metadata = has_meta( $post->ID );
1597 foreach ( $metadata as $key => $value ) {
1598 if ( is_protected_meta( $metadata[ $key ]['meta_key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post->ID, $metadata[ $key ]['meta_key'] ) ) {
1599 unset( $metadata[ $key ] );
1600 }
1601 }
1602
1603 $count = 0;
1604 if ( $metadata ) {
1605 foreach ( $metadata as $entry ) {
1606 echo self::list_meta_row( $entry, $count ); // phpcs:ignore WordPress.Security.EscapeOutput
1607 }
1608 }
1609
1610 self::meta_form( $post );
1611 ?>
1612 </div>
1613 </div>
1614 <?php
1615 }
1616
1617 /**
1618 * Output HTML for the post thumbnail meta-box.
1619 *
1620 * @since 2.9.0
1621 *
1622 * @param int $thumbnail_id ID of the attachment used for thumbnail.
1623 * @param mixed $pos The post ID or object associated with the thumbnail, defaults to global $post.
1624 * @return string html
1625 */
1626 public static function wp_post_thumbnail_html( $thumbnail_id = null, $pos = null ) {
1627
1628 $_wp_additional_image_sizes = wp_get_additional_image_sizes();
1629
1630 $_post = get_post( $pos );
1631 $post_type_object = get_post_type_object( $_post->post_type );
1632
1633 $thumb_ok = false;
1634 $upload_iframe_src = get_upload_iframe_src( 'image', $_post->ID );
1635
1636 if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
1637 $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
1638
1639 /**
1640 * Filters the size used to display the post thumbnail image in the 'Featured Image' meta box.
1641 *
1642 * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
1643 * image size is registered, which differs from the 'thumbnail' image size
1644 * managed via the Settings > Media screen. See the `$size` parameter description
1645 * for more information on default values.
1646 *
1647 * @since 4.4.0
1648 *
1649 * @param string|array $size Post thumbnail image size to display in the meta box. Accepts any valid
1650 * image size, or an array of width and height values in pixels (in that order).
1651 * If the 'post-thumbnail' size is set, default is 'post-thumbnail'. Otherwise,
1652 * default is an array with 266 as both the height and width values.
1653 * @param int $thumbnail_id Post thumbnail attachment ID.
1654 * @param WP_Post $_post The post object associated with the thumbnail.
1655 */
1656 $size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $_post );
1657
1658 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size );
1659
1660 if ( ! empty( $thumbnail_html ) ) {
1661 $thumb_ok = true;
1662
1663 $set_thumbnail_link = '<p class="hide-if-no-js"><div class="field"><a href="%s" id="set-post-thumbnail"%s class="thickbox">%s</a></div></p>';
1664 $content = '<div class="ui setment">';
1665 $content .= sprintf(
1666 $set_thumbnail_link,
1667 esc_url( $upload_iframe_src ),
1668 ' aria-describedby="set-post-thumbnail-desc"',
1669 $thumbnail_html
1670 );
1671 $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . esc_html__( 'Click the image to edit or update', 'mainwp' ) . '</p>';
1672 $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
1673 $content .= '</div>';
1674 }
1675 }
1676
1677 if ( ! $thumb_ok ) {
1678 $set_thumbnail_link = '<p class="hide-if-no-js"><div class="field"><a href="%s" class="ui button fluid mini" id="set-post-thumbnail"%s class="thickbox">%s</a></div></p>';
1679 $content = sprintf(
1680 $set_thumbnail_link,
1681 esc_url( $upload_iframe_src ),
1682 '',
1683 esc_html( $post_type_object->labels->set_featured_image )
1684 );
1685 }
1686
1687 $content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />';
1688
1689 $html = '<div class="ui fluid accordion mainwp-sidebar-accordion">';
1690 $html .= '<div class="title active"><i class="dropdown icon"></i> ' . esc_html__( 'Featured Image', 'mainwp' ) . '</div>';
1691 $html .= '<div class="content active"';
1692 $html .= $content;
1693 $html .= '</div>';
1694 $html .= '</div>';
1695
1696 /**
1697 * Filters the admin post thumbnail HTML markup to return.
1698 *
1699 * @since 2.9.0
1700 * @since 3.5.0 Added the `$post_id` parameter.
1701 * @since 4.6.0 Added the `$thumbnail_id` parameter.
1702 *
1703 * @param string $content Admin post thumbnail HTML markup.
1704 * @param int $post_id Post ID.
1705 * @param int $thumbnail_id Thumbnail ID.
1706 */
1707 return apply_filters( 'mainwp_admin_post_thumbnail_html', $html, $_post->ID, $thumbnail_id );
1708 }
1709
1710 /**
1711 * Method post_thumbnail_meta_box()
1712 *
1713 * Renders the post thumbnail meta box.
1714 *
1715 * @param mixed $pos Post ID.
1716 */
1717 public static function post_thumbnail_meta_box( $pos ) {
1718 $thumbnail_id = get_post_meta( $pos->ID, '_thumbnail_id', true );
1719 echo self::wp_post_thumbnail_html( $thumbnail_id, $pos->ID ); // phpcs:ignore WordPress.Security.EscapeOutput
1720 }
1721
1722 /**
1723 * Method touch_time()
1724 *
1725 * Add time stamps to Post for screen readers.
1726 *
1727 * @param object $post Current Post object.
1728 * @param integer $edit Whether or not this is an edit or new post.
1729 * @param integer $for_post For post.
1730 * @param integer $tab_index Tabindex position.
1731 * @param integer $multi Multi.
1732 *
1733 * @return string Hidden time stamps html.
1734 */
1735 public static function touch_time( $post, $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { //phpcs:ignore -- complex method.
1736
1737 /**
1738 * WordPress Locale.
1739 *
1740 * @global string
1741 */
1742 global $wp_locale;
1743
1744 $_post = get_post( $post );
1745
1746 if ( $for_post ) {
1747 $edit = ! ( in_array( $_post->post_status, array( 'draft', 'pending' ) ) && ( ! $_post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) );
1748 }
1749
1750 $tab_index_attribute = '';
1751
1752 if ( 0 < (int) $tab_index ) {
1753 $tab_index_attribute = " tabindex=\"$tab_index\"";
1754 }
1755
1756 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
1757 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
1758 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
1759 $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
1760 $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
1761 $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
1762 $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
1763
1764 $cur_jj = current_time( 'd' );
1765 $cur_mm = current_time( 'm' );
1766 $cur_aa = current_time( 'Y' );
1767 $cur_hh = current_time( 'H' );
1768 $cur_mn = current_time( 'i' );
1769
1770 $month = '<label><span class="screen-reader-text">' . esc_html__( 'Month', 'mainwp' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
1771
1772 for ( $i = 1; $i < 13; ++$i ) {
1773 $monthnum = zeroise( $i, 2 );
1774 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
1775 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
1776 $month .= sprintf( esc_html__( '%1$s-%2$s', 'mainwp' ), $monthnum, $monthtext ) . "</option>\n";
1777 }
1778
1779 $month .= '</select></label>';
1780
1781 $day = '<label><span class="screen-reader-text">' . esc_html__( 'Day', 'mainwp' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
1782 $year = '<label><span class="screen-reader-text">' . esc_html__( 'Year', 'mainwp' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>';
1783 $hour = '<label><span class="screen-reader-text">' . esc_html__( 'Hour', 'mainwp' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
1784 $minute = '<label><span class="screen-reader-text">' . esc_html__( 'Minute', 'mainwp' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
1785
1786 echo '<div class="timestamp-wrap">';
1787 printf( esc_html__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'mainwp' ), $month, $day, $year, $hour, $minute ); // phpcs:ignore WordPress.Security.EscapeOutput
1788
1789 echo '</div><input type="hidden" id="ss" name="ss" value="' . esc_attr( $ss ) . '" />';
1790
1791 if ( $multi ) {
1792 return;
1793 }
1794
1795 echo "\n\n";
1796 $map = array(
1797 'mm' => array( $mm, $cur_mm ),
1798 'jj' => array( $jj, $cur_jj ),
1799 'aa' => array( $aa, $cur_aa ),
1800 'hh' => array( $hh, $cur_hh ),
1801 'mn' => array( $mn, $cur_mn ),
1802 );
1803
1804 foreach ( $map as $timeunit => $value ) {
1805 list( $unit, $curr ) = $value;
1806
1807 echo '<input type="hidden" id="hidden_' . esc_attr( $timeunit ) . '" name="hidden_' . esc_attr( $timeunit ) . '" value="' . esc_attr( $unit ) . '" />' . "\n";
1808 $cur_timeunit = 'cur_' . $timeunit;
1809 echo '<input type="hidden" id="' . esc_attr( $cur_timeunit ) . '" name="' . esc_attr( $cur_timeunit ) . '" value="' . esc_attr( $curr ) . '" />' . "\n";
1810 }
1811 }
1812
1813 /**
1814 * Method do_meta_boxes()
1815 *
1816 * Render meta boxes.
1817 *
1818 * @param mixed $screen Current page tab.
1819 * @param mixed $context Context.
1820 * @param mixed $input_obj Object.
1821 *
1822 * @return string Metabox html
1823 */
1824 public static function do_meta_boxes( $screen, $context, $input_obj ) { // phpcs:ignore -- current complexity required to achieve desired results. Purll Request solutions appreciated.
1825
1826 /**
1827 * WordPress Meta Boxes array.
1828 *
1829 * @global object
1830 */
1831 global $wp_meta_boxes;
1832 static $already_sorted = false;
1833
1834 if ( empty( $screen ) ) {
1835 $screen = get_current_screen();
1836 } elseif ( is_string( $screen ) ) {
1837 $screen = convert_to_screen( $screen );
1838 }
1839
1840 $page = $screen->id;
1841
1842 if ( 'mainwp_page_PostBulkAdd' === $page || 'mainwp_page_PostBulkEdit' === $page ) {
1843 $page = 'bulkpost';
1844 } elseif ( 'mainwp_page_PageBulkAdd' === $page || 'mainwp_page_PageBulkEdit' === $page ) {
1845 $page = 'bulkpage';
1846 }
1847
1848 $hidden = get_hidden_meta_boxes( $screen );
1849
1850 printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
1851
1852 $sorted = get_user_option( "meta-box-order_$page" );
1853 if ( ! $already_sorted && $sorted ) {
1854 foreach ( $sorted as $widget_context => $ids ) {
1855 foreach ( explode( ',', $ids ) as $id ) {
1856 if ( $id && 'dashboard_browser_nag' !== $id ) {
1857 add_meta_box( $id, null, null, $screen, $widget_context, 'sorted' );
1858 }
1859 }
1860 }
1861 }
1862
1863 $already_sorted = true;
1864
1865 $i = 0;
1866
1867 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1868 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
1869 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1870 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1871 if ( false === $box || ! $box['title'] ) {
1872 continue;
1873 }
1874
1875 $block_compatible = true;
1876 if ( is_array( $box['args'] ) ) {
1877 if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
1878 continue;
1879 }
1880
1881 if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
1882 $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
1883 unset( $box['args']['__block_editor_compatible_meta_box'] );
1884 }
1885
1886 if ( ! $block_compatible && $screen->is_block_editor() ) {
1887 $box['old_callback'] = $box['callback'];
1888 $box['callback'] = 'do_block_editor_incompatible_meta_box';
1889 }
1890
1891 if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
1892 $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
1893 unset( $box['args']['__back_compat_meta_box'] );
1894 }
1895 }
1896
1897 ++$i;
1898 echo '<div id="' . esc_attr( $box['id'] ) . '" class="postbox" >' . "\n";
1899 if ( 'dashboard_browser_nag' !== $box['id'] ) {
1900 $widget_title = $box['title'];
1901
1902 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
1903 $widget_title = $box['args']['__widget_basename'];
1904 unset( $box['args']['__widget_basename'] );
1905 }
1906
1907 echo '<button type="button" class="handlediv" aria-expanded="true">';
1908 echo '<span class="screen-reader-text">' . sprintf( esc_html__( 'Toggle panel: %s', 'mainwp' ), esc_html( $widget_title ) ) . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput
1909 echo '<span class="toggle-indicator" aria-hidden="true"></span>';
1910 echo '</button>';
1911 }
1912 echo "<h2 class='hndle'><span>{" . esc_html( $box['title'] ) . "}</span></h2>\n";
1913 echo '<div class="inside">' . "\n";
1914
1915 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1916 if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
1917 $plugin = _get_plugin_from_callback( $box['callback'] );
1918 if ( $plugin ) {
1919 ?>
1920 <div class="error inline">
1921 <p>
1922 <?php
1923 printf( esc_html__( 'This meta box, from the %s plugin, is not compatible with the block editor.', 'mainwp' ), '<strong>{' . esc_html( $plugin['Name'] ) . '}</strong>' ); // phpcs:ignore WordPress.Security.EscapeOutput
1924 ?>
1925 </p>
1926 </div>
1927 <?php
1928 }
1929 }
1930 // phpcs:enable
1931 call_user_func( $box['callback'], $object, $box );
1932 echo "</div>\n";
1933 echo "</div>\n";
1934 }
1935 }
1936 }
1937 }
1938
1939 echo '</div>';
1940
1941 return $i;
1942 }
1943
1944 /**
1945 * Renders bulkpost to edit.
1946 *
1947 * @param mixed $post_id Post ID.
1948 * @param mixed $input_type Post type.
1949 *
1950 * @return string Edit bulk post html.
1951 *
1952 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_slug()
1953 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_tags()
1954 * @uses \MainWP\Dashboard\MainWP_UI
1955 */
1956 public static function render_bulkpost( $post_id, $input_type ) { //phpcs:ignore -- complex method.
1957 $post = get_post( $post_id );
1958
1959 if ( $post ) {
1960 $post_type = $post->post_type;
1961 $post_type_object = get_post_type_object( $post_type );
1962 }
1963
1964 if ( ! $post_type_object || $input_type !== $post_type || ( 'bulkpost' !== $post_type && 'bulkpage' !== $post_type ) ) {
1965 esc_html_e( 'Invalid post type.', 'mainwp' );
1966 return;
1967 }
1968
1969 $post_ID = $post->ID;
1970
1971 /**
1972 * Current user global.
1973 *
1974 * @global string
1975 */
1976 global $current_user;
1977
1978 $user_ID = $current_user->ID;
1979
1980 $_content_editor_dfw = false;
1981 $is_IE = false;
1982 $_wp_editor_expand = true;
1983
1984 $form_action = 'mainwp_editpost';
1985 $nonce_action = 'update-post_' . $post_ID;
1986
1987 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post_ID ) . "' />";
1988
1989 $referer = wp_get_referer();
1990
1991 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1992 if ( isset( $_GET['boilerplate'] ) ) {
1993 if ( 'auto-draft' === $post->post_status ) {
1994 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Boilerplate Post', 'mainwp' ) : esc_html__( 'Create New Boilerplate Page', 'mainwp' );
1995 } else {
1996 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Boilerplate Post', 'mainwp' ) : esc_html__( 'Edit Boilerplate Page', 'mainwp' );
1997 }
1998 } elseif ( 'auto-draft' === $post->post_status ) {
1999 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Bulk Post', 'mainwp' ) : esc_html__( 'Create New Bulk Page', 'mainwp' );
2000 } else {
2001 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Bulk Post', 'mainwp' ) : esc_html__( 'Edit Bulk Page', 'mainwp' );
2002 }
2003
2004 $note_title = apply_filters( 'mainwp_bulkpost_edit_title', $note_title, $post );
2005
2006 $message = '';
2007 if ( isset( $_GET['message'] ) && 1 === (int) $_GET['message'] ) {
2008 if ( 'bulkpost' === $post_type ) {
2009 $message = esc_html__( 'Post updated.', 'mainwp' );
2010 } else {
2011 $message = esc_html__( 'Page updated.', 'mainwp' );
2012 }
2013 }
2014
2015 // phpcs:enable
2016 ?>
2017 <div class="ui alt segment" id="mainwp-add-new-bulkpost">
2018 <form name="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="post" class="ui form">
2019 <?php wp_nonce_field( $nonce_action ); ?>
2020 <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID; ?>" />
2021 <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
2022 <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
2023 <input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
2024 <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" />
2025 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />
2026 <input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
2027 <?php
2028 if ( 'draft' !== get_post_status( $post ) ) {
2029 wp_original_referer_field( true, 'previous' );
2030 }
2031 echo $form_extra; // phpcs:ignore WordPress.Security.EscapeOutput
2032 ?>
2033 <div class="mainwp-main-content">
2034 <?php do_action( 'mainwp_top_bulkpost_edit_content', $post ); ?>
2035 <div class="ui red message" id="mainwp-message-zone" style="display:none"></div>
2036 <?php
2037 if ( $message ) {
2038 ?>
2039 <div class="ui yellow message"><?php echo esc_html( $message ); ?></div>
2040 <?php
2041 }
2042 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2043 ?>
2044 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp_boilerplate_info_notice' ) ) : ?>
2045 <?php if ( isset( $_GET['boilerplate'] ) ) : ?>
2046 <div class="ui message info">
2047 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp_boilerplate_info_notice"></i>
2048 <div><?php echo esc_html__( 'Boilerplate gives you the ability to create quickly, edit, and remove repetitive pages or posts across your network of child sites. Using the available placeholders (tokens), you can customize these pages for each site.', 'mainwp' ); ?></div>
2049 <div><?php echo esc_html__( 'This is the perfect solution for commonly repeated pages such as your "Privacy Policy", "About Us", "Terms of Use", "Support Policy" or any other page with standard text that you need to distribute across your sites.', 'mainwp' ); ?></div>
2050 </div>
2051 <?php endif; ?>
2052 <?php endif; ?>
2053
2054
2055 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-create-new-bulkpost-info-message' ) ) : ?>
2056 <?php if ( ! isset( $_GET['boilerplate'] ) ) : ?>
2057 <div class="ui message info">
2058 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-create-new-bulkpost-info-message"></i>
2059 <?php if ( 'bulkpost' === $post_type ) : ?>
2060 <?php printf( esc_html__( 'Create a new bulk post. Scheduling posts on Child Sites is almost the same as publishing it. The only difference is before clicking the Publish button is setting it to Scheduled status and setting the time. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/create-a-new-post/" target="_blank">', '</a>' ); ?>
2061 <?php else : ?>
2062 <?php printf( esc_html__( 'Create a new bulk page. Scheduling pages on Child Sites is almost the same as publishing it. The only difference is before clicking the Publish button is setting it to Scheduled status and setting the time. For additional help, please check this %1$shelp documentation%2$s.', 'mainwp' ), '<a href="https://kb.mainwp.com/docs/create-a-new-page/" target="_blank">', '</a>' ); ?>
2063 <?php endif; ?>
2064 </div>
2065 <?php endif; ?>
2066 <?php endif; ?>
2067 <?php // phpcs:enable ?>
2068
2069 <h3 class="header" id="bulkpost-title"><?php echo esc_html( $note_title ); ?></h3>
2070
2071 <div class="field">
2072 <label><?php esc_html_e( 'Title', 'mainwp' ); ?></label>
2073 <input type="text" name="post_title" id="title" value="<?php echo ( 'Auto Draft' !== $post->post_title ) ? esc_attr( $post->post_title ) : ''; ?>" value="" autocomplete="off" spellcheck="true">
2074 </div>
2075 <div class="field">
2076 <?php do_action( 'mainwp_before_bulkpost_editor', $post ); ?>
2077 <div id="postdivrich" class="postarea
2078 <?php
2079 if ( $_wp_editor_expand ) {
2080 echo ' wp-editor-expand';
2081 }
2082 ?>
2083 ">
2084 <?php
2085 $default_settings = array(
2086 '_content_editor_dfw' => $_content_editor_dfw,
2087 'drag_drop_upload' => true,
2088 'tabfocus_elements' => 'content-html,save-post',
2089 'editor_height' => 300,
2090 'quicktags' => true,
2091 'media_buttons' => true,
2092 'tinymce' => array(
2093 'resize' => false,
2094 'wp_autoresize_on' => $_wp_editor_expand,
2095 'add_unload_trigger' => false,
2096 'wp_keep_scroll_position' => ! $is_IE,
2097 ),
2098 );
2099
2100 $ed_settings = apply_filters( 'mainwp_bulkpost_editor_settings', false, $post );
2101 if ( is_array( $ed_settings ) && ! empty( $ed_settings ) ) {
2102 $ed_settings = array_merge( $default_settings, $ed_settings );
2103 } else {
2104 $ed_settings = $default_settings;
2105 }
2106
2107 remove_editor_styles();
2108 wp_editor(
2109 $post->post_content,
2110 'content',
2111 $ed_settings
2112 );
2113
2114 ?>
2115 <table id="post-status-info"><tbody><tr>
2116 <td id="wp-word-count" class="hide-if-no-js"><?php printf( esc_html__( 'Word count: %s', 'mainwp' ), '<span class="word-count">0</span>' ); ?></td>
2117 <td class="autosave-info">
2118 <span class="autosave-message">&nbsp;</span>
2119 <?php
2120 if ( 'auto-draft' !== $post->post_status ) {
2121 echo '<span id="last-edit">';
2122 $last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) );
2123 if ( $last_user ) {
2124 printf( esc_html__( 'Last edited by %1$s on %2$s at %3$s', 'mainwp' ), esc_html( $last_user->display_name ), mysql2date( esc_html__( 'F j, Y' ), $post->post_modified ), mysql2date( esc_html__( 'g:i a' ), $post->post_modified ) ); // phpcs:ignore WordPress.Security.EscapeOutput
2125 } else {
2126 printf( esc_html__( 'Last edited on %1$s at %2$s', 'mainwp' ), mysql2date( esc_html__( 'F j, Y' ), $post->post_modified ), mysql2date( esc_html__( 'g:i a' ), $post->post_modified ) ); // phpcs:ignore WordPress.Security.EscapeOutput
2127 }
2128 echo '</span>';
2129 }
2130 ?>
2131 </td>
2132 <td id="content-resize-handle" class="hide-if-no-js"><br /></td>
2133 </tr></tbody></table>
2134 </div>
2135 </div>
2136 <div class="field" id="add-slug-div">
2137 <label><?php esc_html_e( 'Slug', 'mainwp' ); ?></label>
2138 <?php MainWP_System::instance()->metaboxes->add_slug( $post ); ?>
2139 </div>
2140 <?php if ( 'bulkpost' === $post_type ) { ?>
2141 <div class="field">
2142 <label><?php esc_html_e( 'Excerpt', 'mainwp' ); ?></label>
2143 <textarea rows="1" name="excerpt" id="excerpt"><?php echo esc_attr( $post->post_excerpt ); ?></textarea>
2144 <em><?php esc_html_e( 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme.', 'mainwp' ); ?></em>
2145 </div>
2146 <div class="field">
2147 <label><?php esc_html_e( 'Tags', 'mainwp' ); ?></label>
2148 <?php MainWP_System::instance()->metaboxes->add_tags( $post ); ?>
2149 <em><?php esc_html_e( 'Separate tags with commas', 'mainwp' ); ?></em>
2150 </div>
2151 <?php } ?>
2152 <div class="field">
2153 <?php self::post_custom_meta_box( $post ); ?>
2154 </div>
2155
2156 <div class="field postbox-container">
2157 <?php
2158
2159 /**
2160 * Edit bulkpost
2161 *
2162 * First on the Edit post screen after default fields.
2163 *
2164 * @param object $post Object containing the Post data.
2165 * @param string $post_type Post type.
2166 */
2167 do_action( 'mainwp_bulkpost_edit', $post, $post_type );
2168
2169 self::do_meta_boxes( null, 'normal', $post );
2170
2171 self::do_meta_boxes( null, 'advanced', $post );
2172
2173 /**
2174 * Edit bulkpost metaboxes
2175 *
2176 * Fires after all built-in meta boxes have been added.
2177 *
2178 * @param object $post Object containing the Post data.
2179 * @param string $post_type Post type.
2180 *
2181 * @see https://developer.wordpress.org/reference/hooks/add_meta_boxes/
2182 */
2183 do_action( 'add_meta_boxes', $post_type, $post );
2184
2185 self::do_meta_boxes( $post_type, 'normal', $post );
2186
2187 ?>
2188 </div>
2189 </div>
2190 <?php
2191
2192 $sites_default = array(
2193 'type' => 'checkbox',
2194 'show_group' => true,
2195 'show_select_all' => true,
2196 'class' => '',
2197 'style' => '',
2198
2199 );
2200 $sites_settings = array();
2201 $sites_settings = apply_filters( 'mainwp_bulkpost_select_sites_settings', $sites_settings, $post );
2202
2203 if ( is_array( $sites_settings ) && ! empty( $sites_settings ) ) {
2204 $sites_settings = array_merge( $sites_default, $sites_settings );
2205 } else {
2206 $sites_settings = $sites_default;
2207 }
2208
2209 $sel_sites = array();
2210 $sel_groups = array();
2211 ?>
2212 <div class="mainwp-side-content mainwp-no-padding">
2213 <?php do_action( 'mainwp_bulkpost_edit_top_side', $post, $post_type ); ?>
2214 <div class="mainwp-select-sites ui fluid accordion mainwp-sidebar-accordion">
2215 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
2216 <div class="content active">
2217 <?php
2218 $sel_params = array(
2219 'type' => $sites_settings['type'],
2220 'show_group' => $sites_settings['show_group'],
2221 'show_select_all' => $sites_settings['show_select_all'],
2222 'class' => $sites_settings['class'],
2223 'style' => $sites_settings['style'],
2224 'selected_sites' => $sel_sites,
2225 'selected_groups' => $sel_groups,
2226 'post_id' => $post_ID,
2227 'show_client' => true,
2228 );
2229 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
2230 ?>
2231 <input type="hidden" name="select_sites_nonce" id="select_sites_nonce" value="<?php echo esc_attr( wp_create_nonce( 'select_sites_' . $post->ID ) ); ?>" />
2232 </div>
2233 </div>
2234 <div class="ui fitted divider"></div>
2235 <?php
2236 if ( 'bulkpost' === $post_type ) {
2237 self::render_categories( $post );
2238 }
2239 self::render_post_fields( $post, $post_type );
2240 ?>
2241 <?php self::do_meta_boxes( $post_type, 'side', $post ); ?>
2242 <div class="ui fitted divider"></div>
2243 <?php
2244 /**
2245 * Action: mainwp_edit_posts_before_submit_button
2246 *
2247 * Fires right before the Submit button.
2248 *
2249 * @param object $post Object containing the Post data.
2250 * @param string $post_type Post type.
2251 *
2252 * @since 4.0
2253 */
2254 do_action( 'mainwp_edit_posts_before_submit_button', $post, $post_type );
2255 $is_demo = MainWP_Demo_Handle::is_demo_mode();
2256 ?>
2257 <div class="mainwp-search-submit" id="bulkpost-publishing-action">
2258 <?php
2259 if ( $is_demo ) {
2260 MainWP_Demo_Handle::get_instance()->render_demo_disable_button( '<input type="submit" disabled="disabled" class="ui big green fluid button disabled" value="' . esc_attr__( 'Publish', 'mainwp' ) . '" />' );
2261 } else {
2262 ?>
2263 <input type="submit" name="publish" id="publish" class="ui big green fluid button" value="<?php esc_attr_e( 'Publish', 'mainwp' ); ?>">
2264 <?php } ?>
2265 </div>
2266 <?php
2267 /**
2268 * Action: mainwp_edit_posts_after_submit_button
2269 *
2270 * Fires right after the Submit button.
2271 *
2272 * @since 4.0
2273 */
2274 do_action( 'mainwp_edit_posts_after_submit_button' );
2275 ?>
2276 </div>
2277 </form>
2278 <script type="text/javascript">
2279 jQuery( document ).ready( function () {
2280 jQuery( '#publish' ).on( 'click', function() {
2281 jQuery( '#mainwp-publish-dimmer' ).show();
2282 } );
2283 } );
2284 </script>
2285 <div class="ui active inverted dimmer" id="mainwp-publish-dimmer" style="display:none">
2286 <div class="ui text loader"><?php esc_html_e( 'Publishing...', 'mainwp' ); ?></div>
2287 </div>
2288 <div class="ui clearing hidden divider"></div>
2289 </div>
2290 <?php
2291 self::render_footer( 'BulkAdd' );
2292 }
2293
2294 /**
2295 * Renders Select Categories form
2296 *
2297 * @param object $post Post object.
2298 */
2299 public static function render_categories( $post ) {
2300 ?>
2301 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2302 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Categories', 'mainwp' ); ?></div>
2303 <?php
2304 $categories = array();
2305 if ( $post ) {
2306 $categories = base64_decode( get_post_meta( $post->ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2307 $categories = explode( ',', $categories );
2308 }
2309 if ( ! is_array( $categories ) ) {
2310 $categories = array();
2311 }
2312
2313 $uncat = esc_html__( 'Uncategorized', 'mainwp' );
2314 $post_only = false;
2315 if ( $post ) {
2316 $post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
2317 }
2318 ?>
2319 <div class="content active">
2320 <input type="hidden" name="post_category_nonce" id="post_category_nonce" value="<?php echo esc_attr( wp_create_nonce( 'post_category_' . $post->ID ) ); ?>" />
2321 <div class="field">
2322 <div class="ui checkbox">
2323 <input type="checkbox" name="post_only_existing" id="post_only_existing" value="1" <?php echo $post_only ? 'checked' : ''; ?>>
2324 <label><?php esc_html_e( 'Post only to existing categories', 'mainwp' ); ?></label>
2325 </div>
2326 </div>
2327 <div class="field">
2328 <select name="post_category[]" id="categorychecklist" multiple="" class="ui fluid dropdown">
2329 <option value=""><?php esc_html_e( 'Select categories', 'mainwp' ); ?></option>
2330 <?php if ( ! in_array( $uncat, $categories ) ) : ?>
2331 <option value="<?php esc_attr_e( 'Uncategorized', 'mainwp' ); ?>" class="sitecategory"><?php esc_html_e( 'Uncategorized', 'mainwp' ); ?></option>
2332 <?php endif; ?>
2333 <?php foreach ( $categories as $cat ) : ?>
2334 <?php
2335 if ( empty( $cat ) ) {
2336 continue;
2337 }
2338 $cat_name = rawurldecode( $cat );
2339 ?>
2340 <option value="<?php echo esc_attr( $cat ); ?>" class="sitecategory"><?php echo esc_html( $cat_name ); ?></option>
2341 <?php endforeach; ?>
2342 </select>
2343 <?php
2344 $init_cats = '';
2345 foreach ( $categories as $cat ) {
2346 $init_cats .= "'" . esc_attr( $cat ) . "',";
2347 }
2348 $init_cats = rtrim( $init_cats, ',' );
2349 ?>
2350 <script type="text/javascript">
2351 jQuery( document ).ready( function () {
2352 jQuery( '#categorychecklist' ).dropdown( 'set selected', [<?php echo esc_attr( $init_cats ); ?>] );
2353 } );
2354 </script>
2355 </div>
2356 <div class="field">
2357 <a href="#" id="category-add-toggle" class="ui button fluid mini"><?php esc_html_e( 'Create New Category', 'mainwp' ); ?></a>
2358 </div>
2359 <div class="field" id="newcategory-field" style="display:none">
2360 <input type="text" name="newcategory" id="newcategory" value="">
2361 </div>
2362 <div class="field" id="mainwp-category-add-submit-field" style="display:none">
2363 <input type="button" id="mainwp-category-add-submit" class="ui fluid basic green mini button" value="<?php esc_attr_e( 'Add New Category', 'mainwp' ); ?>">
2364 </div>
2365 </div>
2366 </div>
2367 <div class="ui fitted divider"></div>
2368 <?php
2369 }
2370
2371 /**
2372 * Method render_post_fields()
2373 *
2374 * Render Featured Image & Post Options fields.
2375 *
2376 * @param object $post Post object.
2377 * @param mixed $post_type Post type.
2378 */
2379 public static function render_post_fields( $post, $post_type ) {
2380 ?>
2381 <div class="mainwp-search-options mainwp-post-featured-image" id="postimagediv">
2382 <?php echo '<div class="inside">'; ?>
2383 <?php self::post_thumbnail_meta_box( $post ); ?>
2384 <?php echo '</div>'; ?>
2385 </div>
2386 <div class="ui fitted divider"></div>
2387 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2388 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Discussion', 'mainwp' ); ?></div>
2389 <div class="content active">
2390 <div class="field">
2391 <div class="ui checkbox">
2392 <input type="checkbox" name="comment_status" id="comment_status" value="open" <?php checked( $post->comment_status, 'open' ); ?>>
2393 <label><?php esc_html_e( 'Allow comments', 'mainwp' ); ?></label>
2394 </div>
2395 <div class="ui checkbox">
2396 <input type="checkbox" name="ping_status" id="ping_status" value="open" <?php checked( $post->ping_status, 'open' ); ?> >
2397 <label><?php esc_html_e( 'Allow trackbacks and pingbacks', 'mainwp' ); ?></label>
2398 </div>
2399 </div>
2400 </div>
2401 </div>
2402 <div class="ui fitted divider"></div>
2403 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2404 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Publish Options', 'mainwp' ); ?></div>
2405 <div class="content active">
2406 <div class="field">
2407 <label><?php esc_html_e( 'Status', 'mainwp' ); ?></label>
2408 <select class="ui dropdown" name="mainwp_edit_post_status" id="post_status">
2409 <option value="publish" <?php echo ( 'publish' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Publish', 'mainwp' ); ?></option>
2410 <option value="draft" <?php echo ( 'draft' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Draft', 'mainwp' ); ?></option>
2411 <option value="pending" <?php echo ( 'pending' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Pending review', 'mainwp' ); ?></option>
2412 </select>
2413 </div>
2414 <?php
2415 if ( 'private' === $post->post_status ) {
2416 $post->post_password = '';
2417 $visibility = 'private';
2418 $visibility_trans = esc_html__( 'Private', 'mainwp' );
2419 } elseif ( ! empty( $post->post_password ) ) {
2420 $visibility = 'password';
2421 $visibility_trans = esc_html__( 'Password protected', 'mainwp' );
2422 } elseif ( 'bulkpost' === $post_type && is_sticky( $post->ID ) ) {
2423 $visibility = 'public';
2424 $visibility_trans = esc_html__( 'Public, Sticky', 'mainwp' );
2425 } else {
2426 $visibility = 'public';
2427 $visibility_trans = esc_html__( 'Public', 'mainwp' );
2428 }
2429 ?>
2430
2431 <div class="grouped fields">
2432 <label><?php esc_html_e( 'Visibility', 'mainwp' ); ?></label>
2433 <div class="field">
2434 <div class="ui radio checkbox">
2435 <input type="radio" name="visibility" value="public" id="visibility-radio-public" <?php echo ( 'public' === $visibility ) ? 'checked="checked"' : ''; ?>>
2436 <label><?php esc_html_e( 'Public', 'mainwp' ); ?></label>
2437 </div>
2438 </div>
2439 <?php if ( 'bulkpost' === $post_type ) { ?>
2440 <div class="field" id="sticky-field">
2441 <div class="ui checkbox">
2442 <input type="checkbox" id="sticky" name="sticky" value="sticky" <?php checked( is_sticky( $post->ID ) ); ?> />
2443 <label><?php esc_html_e( 'Stick this post to the front page', 'mainwp' ); ?></label>
2444 </div>
2445 </div>
2446 <?php } ?>
2447 <div class="field">
2448 <div class="ui radio checkbox">
2449 <input type="radio" name="visibility" value="password" id="visibility-radio-password" <?php echo ( 'password' === $visibility ) ? 'checked="checked"' : ''; ?>>
2450 <label><?php esc_html_e( 'Password protected', 'mainwp' ); ?></label>
2451 </div>
2452 </div>
2453 <div class="field" id="post_password-field" <?php echo ( 'password' === $visibility ) ? '' : 'style="display:none"'; ?>>
2454 <label><?php esc_html_e( 'Password', 'mainwp' ); ?></label>
2455 <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr( $post->post_password ); ?>" />
2456 </div>
2457 <div class="field">
2458 <div class="ui radio checkbox">
2459 <input type="radio" name="visibility" value="private" id="visibility-radio-private" <?php echo ( 'private' === $visibility ) ? 'checked="checked"' : ''; ?>>
2460 <label><?php esc_html_e( 'Private', 'mainwp' ); ?></label>
2461 </div>
2462 </div>
2463 </div>
2464 <div class="field">
2465 <label><?php esc_html_e( 'Publish', 'mainwp' ); ?></label>
2466 <select class="ui dropdown" name="post_timestamp" id="post_timestamp">
2467 <option value="immediately" <?php echo ( 'future' === $post->post_status ) ? '' : 'selected="selected"'; ?>><?php esc_html_e( 'Immediately', 'mainwp' ); ?></option>
2468 <option value="schedule" <?php echo ( 'future' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Schedule', 'mainwp' ); ?></option>
2469 </select>
2470 </div>
2471
2472 <div class="field" id="post_timestamp_value-field" <?php echo ( 'future' === $post->post_status ) ? '' : 'style="display:none"'; ?>>
2473 <div class="ui calendar mainwp_datepicker" id="schedule_post_datetime" >
2474 <div class="ui input left icon">
2475 <i class="calendar icon"></i>
2476 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Date', 'mainwp' ); ?>" id="post_timestamp_value" value="" />
2477 </div>
2478 </div>
2479 </div>
2480 </div>
2481 <div style="display:none" id="timestampdiv">
2482 <?php self::touch_time( $post ); ?>
2483 </div>
2484 </div>
2485 <?php
2486 }
2487
2488 /**
2489 * Method render_bulk_add()
2490 *
2491 * Check if user has rights,
2492 * render the bulk add tab.
2493 *
2494 * @return string Bulk add tab html.
2495 */
2496 public static function render_bulk_add() {
2497 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
2498 mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
2499 return;
2500 }
2501
2502 /**
2503 * MainWP default post to edit.
2504 *
2505 * @global string
2506 */
2507 global $_mainwp_default_post_to_edit;
2508
2509 $post_id = $_mainwp_default_post_to_edit ? $_mainwp_default_post_to_edit->ID : 0;
2510 self::render_addedit( $post_id, 'BulkAdd' );
2511 }
2512
2513 /**
2514 * Method render_bulk_edit()
2515 *
2516 * Check if user has rights,
2517 * render the bulk edit tab.
2518 *
2519 * @return string Bulk edit tab html.
2520 */
2521 public static function render_bulk_edit() {
2522 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
2523 mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
2524 return;
2525 }
2526 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2527 $post_id = isset( $_GET['post_id'] ) ? intval( $_GET['post_id'] ) : 0;
2528 // phpcs:enable
2529 self::render_addedit( $post_id, 'BulkEdit' );
2530 }
2531
2532 /**
2533 * Method render_bulk_addedit()
2534 *
2535 * Render both the Add & Edit tabs.
2536 *
2537 * @param mixed $post_id post ID.
2538 * @param mixed $what what tab is active.
2539 */
2540 public static function render_addedit( $post_id, $what ) {
2541 self::render_header( $what, $post_id );
2542 self::render_bulkpost( $post_id, 'bulkpost' );
2543 self::render_footer( $what );
2544 }
2545
2546 /**
2547 * Method hook_posts_search_handler()
2548 *
2549 * Hook Posts Search handler.
2550 *
2551 * @param mixed $data search data.
2552 * @param object $website child site object.
2553 * @param mixed $output output.
2554 *
2555 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
2556 */
2557 public static function hook_posts_search_handler( $data, $website, &$output ) {
2558 $posts = array();
2559 if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
2560 $result = $results[1];
2561 $posts = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2562 unset( $results );
2563 }
2564 $output->results[ $website->id ] = $posts;
2565 }
2566
2567 /**
2568 * Method mainwp_help_content()
2569 *
2570 * Attatch MainWP help content.
2571 */
2572 public static function mainwp_help_content() {
2573 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2574 if ( isset( $_GET['page'] ) && ( 'PostBulkManage' === $_GET['page'] || 'PostBulkAdd' === $_GET['page'] ) ) {
2575 ?>
2576 <p><?php esc_html_e( 'If you need help with managing posts, please review following help documents', 'mainwp' ); ?></p>
2577 <div class="ui relaxed bulleted list">
2578 <div class="item"><a href="https://kb.mainwp.com/docs/manage-posts/" target="_blank">Manage Posts</a></div>
2579 <div class="item"><a href="https://kb.mainwp.com/docs/create-a-new-post/" target="_blank">Create a New Post</a></div>
2580 <div class="item"><a href="https://kb.mainwp.com/docs/edit-an-existing-post/" target="_blank">Edit an Existing Post</a></div>
2581 <div class="item"><a href="https://kb.mainwp.com/docs/change-status-of-an-existing-post/" target="_blank">Change Status of an Existing Post</a></div>
2582 <div class="item"><a href="https://kb.mainwp.com/docs/view-an-existing-post/" target="_blank">View an Existing Post</a></div>
2583 <div class="item"><a href="https://kb.mainwp.com/docs/delete-posts/" target="_blank">Delete Post(s)</a></div>
2584 <?php
2585 /**
2586 * Action: mainwp_posts_help_item
2587 *
2588 * Fires at the bottom of the help articles list in the Help sidebar on the Posts page.
2589 *
2590 * Suggested HTML markup:
2591 *
2592 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2593 *
2594 * @since 4.1
2595 */
2596 do_action( 'mainwp_posts_help_item' );
2597 ?>
2598 </div>
2599 <?php
2600 }
2601 // phpcs:enable
2602 }
2603 }
2604