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

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

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