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

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

2,729 lines 130.3 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 { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
16
17 // phpcs:disable Generic.Metrics.CyclomaticComplexity -- NOSONAR 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( static::get_class_name(), 'render_header' ) ); // @deprecated Use 'mainwp_pageheader_post' instead.
58 add_action( 'mainwp_pageheader_post', array( static::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( static::get_class_name(), 'render_footer' ) );
71 add_action( 'mainwp_pagefooter_post', array( static::get_class_name(), 'render_footer' ) );
72
73 add_filter( 'admin_post_thumbnail_html', array( static::get_class_name(), 'admin_post_thumbnail_html' ), 10, 3 );
74
75 add_action( 'mainwp_help_sidebar_content', array( static::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( static::get_class_name(), 'render' ) );
90 add_action( 'load-' . $_page, array( static::get_class_name(), 'on_load_page' ) );
91 add_filter( 'manage_' . $_page . '_columns', array( static::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( static::get_class_name(), 'render_bulk_add' ) );
95 add_action( 'load-' . $_page, array( static::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( static::get_class_name(), 'render_bulk_edit' ) );
100 add_action( 'load-' . $_page, array( static::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. NOSONAR - not IP.
124 static::$subPages = apply_filters( 'mainwp_getsubpages_post', $sub_pages );
125
126 if ( isset( static::$subPages ) && is_array( static::$subPages ) ) {
127 foreach ( static::$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 static::init_left_menu( static::$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( static::get_class_name(), 'admin_head' ) );
147 add_filter( 'hidden_columns', array( static::get_class_name(), 'get_hidden_columns' ), 10, 3 );
148 add_action( 'mainwp_screen_options_modal_bottom', array( static::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 static::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 static::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 = static::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() { // phpcs:ignore -- NOSONAR - complex.
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( static::$subPages ) && is_array( static::$subPages ) ) {
340 foreach ( static::$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 static::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 ) { // phpcs:ignore -- NOSONAR - complex.
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( static::$subPages ) && is_array( static::$subPages ) ) {
479 foreach ( static::$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() { // phpcs:ignore -- NOSONAR - complex.
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 static::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 static::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 static::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(function(){ mainwp_show_post( ' . intval( $_REQUEST['siteid'] ) . ', ' . intval( $_REQUEST['postid'] ) . ', undefined ) } );</script>';
754 } elseif ( isset( $_REQUEST['siteid'] ) && isset( $_REQUEST['userid'] ) ) {
755 echo '<script>jQuery(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 ) && ! empty( $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 static::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() { //phpcs:ignore -- NOSONAR - complex.
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 array $params Other params.
876 *
877 * @uses \MainWP\Dashboard\MainWP_Cache::echo_body()
878 * @uses \MainWP\Dashboard\MainWP_Utility::enabled_wp_seo()
879 */
880 public static function render_table( $cached = true, $keyword = '', $dtsstart = '', $dtsstop = '', $status = '', $params = array() ) {
881
882 if ( ! is_array( $params ) ) {
883 $params = array();
884 }
885
886 $groups = isset( $params['groups'] ) ? $params['groups'] : '';
887 $sites = isset( $params['sites'] ) ? $params['sites'] : '';
888 $postId = isset( $params['postId'] ) ? $params['postId'] : 0;
889 $userId = isset( $params['userId'] ) ? $params['userId'] : 0;
890 $post_type = isset( $params['post_type'] ) ? $params['post_type'] : '';
891 $search_on = isset( $params['search_on'] ) ? $params['search_on'] : 'all';
892 $clients = isset( $params['clients'] ) ? $params['clients'] : '';
893
894 ?>
895
896 <div id="mainwp-message-zone"></div>
897
898 <div id="mainwp-loading-posts-row" style="display: none;">
899 <div class="ui active inverted dimmer">
900 <div class="ui indeterminate large text loader"><?php esc_html_e( 'Loading Posts...', 'mainwp' ); ?></div>
901 </div>
902 </div>
903
904 <?php
905 /**
906 * Action: mainwp_before_posts_table
907 *
908 * Fires before the Manage Posts table.
909 *
910 * @since 4.1
911 */
912 do_action( 'mainwp_before_posts_table' );
913 ?>
914 <table id="mainwp-posts-table" class="ui unstackable single line table" style="width:100%">
915 <thead class="full-width">
916 <tr>
917 <th id="check-column-all" class="no-sort collapsing check-column"><span class="ui checkbox"><input id="cb-select-all-top" type="checkbox" /></span></th>
918 <?php
919 /**
920 * Action: mainwp_posts_table_header
921 *
922 * Adds new column header to the Manage posts table.
923 *
924 * @since 4.1
925 */
926 do_action( 'mainwp_posts_table_header' );
927 ?>
928 <th id="title"><?php esc_html_e( 'Title', 'mainwp' ); ?></th>
929 <th id="author" class="min-tablet"><?php esc_html_e( 'Author', 'mainwp' ); ?></th>
930 <th id="categories" class="min-tablet"><?php esc_html_e( 'Categories', 'mainwp' ); ?></th>
931 <th id="tags" class="min-tablet"><?php esc_html_e( 'Tags', 'mainwp' ); ?></th>
932 <?php if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) : ?>
933 <th id="post-type"><?php esc_html_e( 'Post Type', 'mainwp' ); ?></th>
934 <?php endif; ?>
935 <?php if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) : ?>
936 <th id="comments"><i class="comment icon"></i></th>
937 <?php endif; ?>
938 <th id="date" class="min-tablet"><?php esc_html_e( 'Last Modified', 'mainwp' ); ?></th>
939 <th id="status" class=""><?php esc_html_e( 'Status', 'mainwp' ); ?></th>
940 <?php if ( MainWP_Utility::enabled_wp_seo() ) : ?>
941 <th id="seo-links"><?php esc_html_e( 'Links', 'mainwp' ); ?></th>
942 <th id="seo-linked"><?php esc_html_e( 'Linked', 'mainwp' ); ?></th>
943 <th id="seo-score"><?php esc_html_e( 'SEO Score', 'mainwp' ); ?></th>
944 <th id="seo-readability"><?php esc_html_e( 'Readability score', 'mainwp' ); ?></th>
945 <?php endif; ?>
946 <th id="website" class="min-tablet"><?php esc_html_e( 'Site', 'mainwp' ); ?></th>
947 <th id="posts-actions" class="no-sort min-tablet not-selectable"></th>
948 </tr>
949 </thead>
950
951 <tbody id="mainwp-posts-list">
952 <?php
953 if ( $cached ) {
954 MainWP_Cache::echo_body( 'Post' );
955 } else {
956 MainWP_Cache::init_cache( 'Post' );
957 static::render_table_body( $keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId, $post_type, $search_on, false, $clients );
958 }
959 ?>
960 </tbody>
961 </table>
962 <?php
963 /**
964 * Action: mainwp_after_posts_table
965 *
966 * Fires after the Manage Posts table.
967 *
968 * @since 4.1
969 */
970 do_action( 'mainwp_after_posts_table' );
971
972 $table_features = array(
973 'searching' => 'true',
974 'paging' => 'true',
975 'info' => 'true',
976 'stateSave' => 'true',
977 'scrollX' => 'true',
978 'colReorder' => '{columns:":not(.check-column):not(:last-child)"}',
979 'order' => '[]',
980 'responsive' => 'true',
981 );
982
983 /**
984 * Filter: mainwp_posts_table_fatures
985 *
986 * Filters the Manage Posts table features.
987 *
988 * @since 4.1
989 */
990 $table_features = apply_filters( 'mainwp_posts_table_fatures', $table_features );
991 if ( $cached ) {
992 ?>
993 <script type="text/javascript">
994 jQuery( document ).ready( function () {
995 let responsive = <?php echo esc_html( $table_features['responsive'] ); ?>;
996 if( jQuery( window ).width() > 1140 ) {
997 responsive = false;
998 }
999 try {
1000 jQuery("#mainwp-posts-table").DataTable().destroy(); // to fix re-init database issue.
1001 $manage_posts_table = jQuery('#mainwp-posts-table').DataTable( {
1002 "responsive" : responsive,
1003 "searching" : <?php echo esc_html( $table_features['searching'] ); ?>,
1004 "colReorder" : <?php echo $table_features['colReorder']; // phpcs:ignore -- specical chars. ?>,
1005 "stateSave": <?php echo esc_html( $table_features['stateSave'] ); ?>,
1006 "paging": <?php echo esc_html( $table_features['paging'] ); ?>,
1007 "info": <?php echo esc_html( $table_features['info'] ); ?>,
1008 "order": <?php echo esc_html( $table_features['order'] ); ?>,
1009 "scrollX" : <?php echo esc_html( $table_features['scrollX'] ); ?>,
1010 "lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ],
1011 "columnDefs": [ {
1012 "targets": 'no-sort',
1013 "orderable": false
1014 } ],
1015 "language" : { "emptyTable": "<?php esc_html_e( 'Use the search options to find the post you want to manage.', 'mainwp' ); ?>" },
1016 "preDrawCallback": function( settings ) {
1017 setTimeout(() => { // to fix.
1018 jQuery( '#mainwp-posts-table-wrapper table .ui.dropdown' ).dropdown();
1019 jQuery( '#mainwp-posts-table-wrapper table .ui.checkbox' ).checkbox();
1020 mainwp_datatable_fix_menu_overflow();
1021 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
1022 }, 1000);
1023 },
1024 select: {
1025 items: 'row',
1026 style: 'multi+shift',
1027 selector: 'tr>td:not(.not-selectable)'
1028 }
1029 } ).on('select', function (e, dt, type, indexes) {
1030 if( 'row' == type ){
1031 dt.rows(indexes)
1032 .nodes()
1033 .to$().find('td.check-column .ui.checkbox' ).checkbox('set checked');
1034 }
1035 }).on('deselect', function (e, dt, type, indexes) {
1036 if( 'row' == type ){
1037 dt.rows(indexes)
1038 .nodes()
1039 .to$().find('td.check-column .ui.checkbox' ).checkbox('set unchecked');
1040 }
1041 }).on( 'columns-reordered', function () {
1042 console.log('columns-reordered');
1043 setTimeout(() => { // to fix.
1044 jQuery( '#mainwp-posts-table .ui.dropdown' ).dropdown();
1045 jQuery( '#mainwp-posts-table .ui.checkbox' ).checkbox();
1046 mainwp_datatable_fix_menu_overflow();
1047 mainwp_table_check_columns_init(); // ajax: to fix checkbox all.
1048 }, 1000);
1049 });
1050 } catch ( err ) {
1051 // to fix js error.
1052 }
1053
1054 _init_manage_sites_screen = function() {
1055 jQuery( '#mainwp-overview-screen-options-modal input[type=checkbox][id^="mainwp_show_column_"]' ).each( function() {
1056 let col_id = jQuery( this ).attr( 'id' );
1057 col_id = col_id.replace( "mainwp_show_column_", "" );
1058 try {
1059 $manage_posts_table.column( '#' + col_id ).visible( jQuery(this).is( ':checked' ) );
1060 } catch(err) {
1061 // to fix js error.
1062 }
1063 } );
1064 };
1065 _init_manage_sites_screen();
1066
1067 } );
1068 </script>
1069 <?php
1070 }
1071 }
1072
1073 /**
1074 * Method render_table_body()
1075 *
1076 * Render Posts table body.
1077 *
1078 * @param mixed $keyword Search keywords.
1079 * @param mixed $dtsstart Date & time of Session start.
1080 * @param mixed $dtsstop Date & time of Session stop.
1081 * @param mixed $status Page statuses.
1082 * @param mixed $groups Groups to display.
1083 * @param mixed $sites Site URLS.
1084 * @param integer $postId Post ID.
1085 * @param integer $userId Current user ID.
1086 * @param string $post_type Post type.
1087 * @param string $search_on Site on all sites. Default = all.
1088 * @param bool $table_content Generate table content only. Default = false.
1089 * @param mixed $clients Clients.
1090 *
1091 * @return void
1092 *
1093 * @uses \MainWP\Dashboard\MainWP_Cache::init_cache()
1094 * @uses \MainWP\Dashboard\MainWP_Cache::add_context()
1095 * @uses \MainWP\Dashboard\MainWP_Cache::add_body()
1096 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
1097 * @uses \MainWP\Dashboard\MainWP_DB::query()
1098 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
1099 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_by_group_id()
1100 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
1101 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
1102 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
1103 * @uses \MainWP\Dashboard\MainWP_Utility::map_site()
1104 * @uses \MainWP\Dashboard\MainWP_Utility::enabled_wp_seo()
1105 */
1106 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 -- NOSONAR - complex function.
1107
1108 $data_fields = MainWP_System_Utility::get_default_map_site_fields();
1109
1110 $dbwebsites = array();
1111 if ( '' !== $sites ) {
1112 foreach ( $sites as $v ) {
1113 if ( MainWP_Utility::ctype_digit( $v ) ) {
1114 $website = MainWP_DB::instance()->get_website_by_id( $v );
1115 if ( empty( $website->sync_errors ) && ! MainWP_System_Utility::is_suspended_site( $website ) ) {
1116 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
1117 $website,
1118 $data_fields
1119 );
1120 }
1121 }
1122 }
1123 }
1124 if ( '' !== $groups ) {
1125 foreach ( $groups as $v ) {
1126 if ( MainWP_Utility::ctype_digit( $v ) ) {
1127 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $v ) );
1128 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
1129 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
1130 continue;
1131 }
1132 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
1133 $website,
1134 $data_fields
1135 );
1136 }
1137 MainWP_DB::free_result( $websites );
1138 }
1139 }
1140 }
1141 if ( '' !== $clients && is_array( $clients ) ) {
1142 $websites = MainWP_DB_Client::instance()->get_websites_by_client_ids(
1143 $clients,
1144 array(
1145 'select_data' => $data_fields,
1146 )
1147 );
1148
1149 foreach ( $websites as $website ) {
1150 if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
1151 continue;
1152 }
1153 $dbwebsites[ $website->id ] = MainWP_Utility::map_site(
1154 $website,
1155 $data_fields
1156 );
1157 }
1158 }
1159
1160 $output = new \stdClass();
1161 $output->errors = array();
1162 $output->posts = 0;
1163 $output->table_rows = '';
1164
1165 if ( ! empty( $dbwebsites ) ) {
1166 $post_data = array(
1167 'keyword' => $keyword,
1168 'dtsstart' => $dtsstart,
1169 'dtsstop' => $dtsstop,
1170 'status' => $status,
1171 'search_on' => $search_on,
1172 'maxRecords' => ( ( false === get_option( 'mainwp_maximumPosts' ) ) ? 50 : get_option( 'mainwp_maximumPosts' ) ),
1173 );
1174
1175 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) {
1176 $post_data['post_type'] = $post_type;
1177 if ( 'any' === $post_type ) {
1178 $post_data['exclude_page_type'] = 1;
1179 }
1180 }
1181
1182 if ( MainWP_Utility::enabled_wp_seo() ) {
1183 $post_data['WPSEOEnabled'] = 1;
1184 }
1185
1186 if ( isset( $postId ) && ( '' !== $postId ) ) {
1187 $post_data['postId'] = $postId;
1188 } elseif ( isset( $userId ) && ( '' !== $userId ) ) {
1189 $post_data['userId'] = $userId;
1190 }
1191
1192 /**
1193 * Get all posts data
1194 *
1195 * Set search parameters for the fetch process.
1196 *
1197 * @since 3.4
1198 */
1199 $post_data = apply_filters( 'mainwp_get_all_posts_data', $post_data );
1200 MainWP_Connect::fetch_urls_authed(
1201 $dbwebsites,
1202 'get_all_posts',
1203 $post_data,
1204 array(
1205 static::get_class_name(),
1206 'posts_search_handler',
1207 ),
1208 $output
1209 );
1210 echo $output->table_rows; // phpcs:ignore WordPress.Security.EscapeOutput
1211 }
1212
1213 if ( ! $table_content ) {
1214 MainWP_Cache::add_body( 'Post', $output->table_rows );
1215 MainWP_Cache::add_context(
1216 'Post',
1217 array(
1218 'count' => $output->posts,
1219 'keyword' => $keyword,
1220 'dtsstart' => $dtsstart,
1221 'dtsstop' => $dtsstop,
1222 'status' => $status,
1223 'sites' => ( '' !== $sites ) ? $sites : '',
1224 'groups' => ( '' !== $groups ) ? $groups : '',
1225 'clients' => ( '' !== $clients ) ? $clients : '',
1226 'search_on' => $search_on,
1227 )
1228 );
1229
1230 if ( 0 === $output->posts ) {
1231 MainWP_Cache::add_body( 'Post', '' );
1232 }
1233 }
1234 }
1235
1236 /**
1237 * Method get_status()
1238 *
1239 * Get Post status.
1240 *
1241 * @param mixed $status Post status.
1242 *
1243 * @return string $status Post status.
1244 */
1245 private static function get_status( $status ) {
1246 if ( 'publish' === $status ) {
1247 return 'Published';
1248 }
1249
1250 return esc_html( ucfirst( $status ) );
1251 }
1252
1253 /**
1254 * Method posts_search_handler()
1255 *
1256 * Post page search handler.
1257 *
1258 * @param mixed $data Search data.
1259 * @param mixed $website Child Sites ID.
1260 * @param mixed $output Html to output.
1261 *
1262 * @return string Returned search results html.
1263 *
1264 * @uses \MainWP\Dashboard\MainWP_Cache::add_body()
1265 * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
1266 * @uses \MainWP\Dashboard\MainWP_Exception
1267 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
1268 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
1269 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
1270 * @uses \MainWP\Dashboard\MainWP_Utility::esc_content()
1271 */
1272 public static function posts_search_handler( $data, $website, &$output ) { // phpcs:ignore -- NOSONAR - complex method.
1273 if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $website ) ) {
1274 return;
1275 }
1276 if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
1277 $result = $results[1];
1278 $posts = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
1279
1280 if ( is_array( $posts ) && isset( $posts['error'] ) ) {
1281 $output->errors[ $website->id ] = esc_html( $posts['error'] );
1282 return;
1283 }
1284
1285 unset( $results );
1286
1287 $child_to_dash_array = array();
1288
1289 if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) {
1290 $child_post_ids = array();
1291 foreach ( $posts as $post ) {
1292 $child_post_ids[] = $post['id'];
1293 }
1294 reset( $posts );
1295
1296 $connections_ids = apply_filters( 'mainwp_custom_post_types_get_post_connections', false, $website->id, $child_post_ids );
1297 if ( ! empty( $connections_ids ) ) {
1298 foreach ( $connections_ids as $key ) {
1299 $child_to_dash_array[ $key->child_post_id ] = $key->dash_post_id;
1300 }
1301 }
1302 }
1303
1304 $table_rows = '';
1305 foreach ( $posts as $post ) {
1306 $raw_dts = '';
1307 if ( isset( $post['dts'] ) ) {
1308 $raw_dts = $post['dts'];
1309 if ( ! stristr( $post['dts'], '-' ) ) {
1310 $post['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $post['dts'] ) );
1311 }
1312 }
1313
1314 if ( ! isset( $post['title'] ) || ( '' === $post['title'] ) ) {
1315 $post['title'] = '(No Title)';
1316 }
1317
1318 ob_start();
1319 ?>
1320
1321 <tr>
1322 <td class="check-column"><span class="ui checkbox"><input type="checkbox" name="post[]" value="1"></span></td>
1323 <?php
1324 /**
1325 * Action: mainwp_posts_table_column
1326 *
1327 * Adds a new column item in the Manage posts table.
1328 *
1329 * @param array $post Array containing the post data.
1330 * @param array $website Object containing the website data.
1331 *
1332 * @since 4.1
1333 */
1334 do_action( 'mainwp_posts_table_column', $post, $website );
1335 ?>
1336 <td class="title column-title">
1337 <strong>
1338 <abbr title="<?php echo esc_attr( $post['title'] ); ?>">
1339 <?php if ( 'trash' !== $post['status'] ) { ?>
1340 <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">
1341 <?php echo esc_html( $post['title'] ); ?>
1342 </a>
1343 <?php
1344 } else {
1345 echo esc_html( $post['title'] );
1346 }
1347 ?>
1348 </abbr>
1349 </strong>
1350 </td>
1351
1352 <td class="author column-author"><?php echo esc_html( $post['author'] ); ?></td>
1353
1354 <td class="categories column-categories"><?php echo esc_html( $post['categories'] ); ?></td>
1355
1356 <td class="tags"><?php echo esc_html( '' === $post['tags'] ? 'No Tags' : $post['tags'] ); ?></td>
1357
1358 <?php if ( is_plugin_active( 'mainwp-custom-post-types/mainwp-custom-post-types.php' ) ) : ?>
1359 <td class="post-type column-post-type"><?php echo esc_html( $post['post_type'] ); ?></td>
1360 <?php endif; ?>
1361
1362 <?php if ( is_plugin_active( 'mainwp-comments-extension/mainwp-comments-extension.php' ) ) : ?>
1363 <td class="comments column-comments">
1364 <div class="post-com-count-wrapper">
1365 <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>
1366 </div>
1367 </td>
1368 <?php endif; ?>
1369
1370 <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>
1371
1372 <td class="status column-status <?php echo 'trash' === $post['status'] ? 'post-trash' : ''; ?>"><?php echo esc_html( static::get_status( $post['status'] ) ); // phpcs:ignore WordPress.Security.EscapeOutput ?></td>
1373
1374 <?php
1375 if ( MainWP_Utility::enabled_wp_seo() ) :
1376 $count_seo_links = null;
1377 $count_seo_linked = null;
1378 $seo_score = '';
1379 $readability_score = '';
1380 if ( isset( $post['seo_data'] ) ) {
1381 $seo_data = $post['seo_data'];
1382 $count_seo_links = esc_html( $seo_data['count_seo_links'] );
1383 $count_seo_linked = esc_html( $seo_data['count_seo_linked'] );
1384 $seo_score = MainWP_Utility::esc_content( $seo_data['seo_score'], 'mixed' );
1385 $readability_score = MainWP_Utility::esc_content( $seo_data['readability_score'], 'mixed' );
1386 }
1387 ?>
1388 <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>
1389 <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>
1390 <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>
1391 <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>
1392 <?php endif; ?>
1393
1394 <td class="website column-website"><a href="<?php echo esc_url( $website->url ); ?>" target="_blank"><?php echo esc_html( $website->url ); ?></a></td>
1395 <td class="right aligned not-selectable">
1396 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $post['id'] ); ?>"/>
1397 <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|' : ''; ?>" />
1398 <input class="websiteId" type="hidden" name="id" value="<?php echo intval( $website->id ); ?>"/>
1399 <div class="ui left pointing dropdown icon mini basic green button" style="z-index: 999">
1400 <a href="javascript:void(0)"><i class="ellipsis horizontal icon"></i></a>
1401 <div class="menu">
1402 <?php if ( 'future' === $post['status'] || 'draft' === $post['status'] ) : ?>
1403 <a class="item post_submitpublish" href="#"><?php esc_html_e( 'Publish', 'mainwp' ); ?></a>
1404 <?php endif; ?>
1405
1406 <?php if ( 'pending' === $post['status'] ) : ?>
1407 <a class="item post_submitapprove" href="#"><?php esc_html_e( 'Approve', 'mainwp' ); ?></a>
1408 <?php endif; ?>
1409
1410 <?php if ( 'publish' === $post['status'] ) : ?>
1411 <a class="item post_submitunpublish" href="#"><?php esc_html_e( 'Unpublish', 'mainwp' ); ?></a>
1412 <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>
1413 <?php endif; ?>
1414
1415 <?php if ( 'trash' === $post['status'] ) : ?>
1416 <a class="item post_submitrestore" href="#"><?php esc_html_e( 'Restore', 'mainwp' ); ?></a>
1417 <a class="item post_submitdelete_perm" href="#"><?php esc_html_e( 'Delete', 'mainwp' ); ?></a>
1418 <?php endif; ?>
1419
1420 <?php if ( 'trash' !== $post['status'] ) : ?>
1421 <?php if ( isset( $child_to_dash_array[ $post['id'] ] ) ) { ?>
1422 <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>
1423 <?php } else { ?>
1424 <a class="item post_getedit" href="#"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
1425 <?php } ?>
1426 <?php do_action( 'mainwp_manage_posts_action_item', $post, $child_to_dash_array ); ?>
1427 <a class="item post_submitdelete" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
1428 <?php endif; ?>
1429 <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>
1430 <?php
1431 /**
1432 * Action: mainwp_posts_table_action
1433 *
1434 * Adds a new item in the Actions menu in Manage Posts table.
1435 *
1436 * Suggested HTML markup:
1437 * <a class="item" href="Your custom URL">Your custom label</a>
1438 *
1439 * @param array $post Array containing the post data.
1440 * @param array $website Object containing the website data.
1441 *
1442 * @since 4.1
1443 */
1444 do_action( 'mainwp_posts_table_action', $post, $website );
1445 ?>
1446 </div>
1447 </div>
1448 </td>
1449 </tr>
1450 <?php
1451 $newOutput = ob_get_clean();
1452 $table_rows .= $newOutput;
1453 ++$output->posts;
1454 }
1455 $output->table_rows .= $table_rows;
1456 unset( $posts );
1457 } else {
1458 $output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) );
1459 }
1460 }
1461
1462 /**
1463 * Method list_meta_row()
1464 *
1465 * Outputs a single row of public meta data in the Custom Fields meta box.
1466 *
1467 * @since 2.5.0
1468 *
1469 * @param array $entry Post array.
1470 * @param int $count Counter variable.
1471 *
1472 * @return string $r Custom Fields meta box HTML.
1473 *
1474 * @uses \MainWP\Dashboard\MainWP_System_Utility::maybe_unserialyze()
1475 */
1476 public static function list_meta_row( $entry, &$count ) {
1477
1478 /**
1479 * Static variable to hold update nonce.
1480 *
1481 * @static
1482 *
1483 * @var string Update nonce.
1484 */
1485 static $update_nonce = '';
1486
1487 if ( is_protected_meta( $entry['meta_key'], 'post' ) ) {
1488 return '';
1489 }
1490
1491 if ( ! $update_nonce ) {
1492 $update_nonce = wp_create_nonce( 'add-meta' );
1493 }
1494
1495 $r = '';
1496 ++$count;
1497
1498 if ( is_serialized( $entry['meta_value'] ) ) {
1499 if ( is_serialized_string( $entry['meta_value'] ) ) {
1500 $entry['meta_value'] = MainWP_System_Utility::maybe_unserialyze( $entry['meta_value'] ); //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- ok.
1501 } else {
1502 --$count;
1503 return '';
1504 }
1505 }
1506
1507 $entry['meta_key'] = esc_attr( $entry['meta_key'] ); //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- ok.
1508 $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- ok.
1509 $entry['meta_id'] = (int) $entry['meta_id'];
1510
1511 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
1512
1513 $r .= "\n\t<div class=\"two column row\" meta-id=\"" . $entry['meta_id'] . '" >';
1514 $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']}' />";
1515 $r .= "\n\t\t";
1516 $r .= "<input type=\"button\" onclick=\"mainwp_post_newmeta_submit( 'delete', this )\" class=\"ui mini button\" _ajax_nonce=\"$delete_nonce\" value=\"" . esc_attr__( 'Delete', 'mainwp' ) . '">';
1517 $r .= "\n\t\t";
1518 $r .= "<input type=\"button\" onclick=\"mainwp_post_newmeta_submit( 'update', this )\" class=\"ui mini button\" value=\"" . esc_attr__( 'Update', 'mainwp' ) . '">';
1519 $r .= '</div>';
1520 $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>";
1521 return $r;
1522 }
1523
1524 /**
1525 * Method meta_form()
1526 *
1527 * Prints the form in the Custom Fields meta box.
1528 *
1529 * @since 1.2.0
1530 *
1531 * @global wpdb $wpdb WordPress database abstraction object.
1532 *
1533 * @param WP_Post $pos Optional. The post being edited.
1534 */
1535 public static function meta_form( $pos = null ) {
1536 global $wpdb;
1537 $_post = get_post( $pos );
1538
1539 /**
1540 * Filters values for the meta key dropdown in the Custom Fields meta box.
1541 *
1542 * Returning a non-null value will effectively short-circuit and avoid a
1543 * potentially expensive query against postmeta.
1544 *
1545 * @since 4.4.0
1546 *
1547 * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null.
1548 * @param WP_Post $_post The current post object.
1549 */
1550 $keys = apply_filters( 'postmeta_form_keys', null, $_post );
1551
1552 if ( null === $keys ) {
1553 /**
1554 * Filters the number of custom fields to retrieve for the drop-down
1555 * in the Custom Fields meta box.
1556 *
1557 * @since 2.1.0
1558 *
1559 * @param int $limit Number of custom fields to retrieve. Default 30.
1560 */
1561 $limit = apply_filters( 'postmeta_form_limit', 30 );
1562 $sql = "SELECT DISTINCT meta_key
1563 FROM $wpdb->postmeta
1564 WHERE meta_key NOT BETWEEN '_' AND '_z'
1565 HAVING meta_key NOT LIKE %s
1566 ORDER BY meta_key
1567 LIMIT %d";
1568 $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); // phpcs:ignore -- unprepared SQL ok.
1569 }
1570
1571 if ( $keys ) {
1572 natcasesort( $keys );
1573 $meta_key_input_id = 'metakeyselect';
1574 } else {
1575 $meta_key_input_id = 'metakeyinput';
1576 }
1577 ?>
1578
1579 <div class="two column row" id="mainwp-metaform-row">
1580 <div class="column">
1581 <label for="<?php echo esc_attr( $meta_key_input_id ); ?>"><?php esc_html_e( 'Name', 'mainwp' ); ?></label>
1582 <?php if ( $keys ) { ?>
1583 <select id="metakeyselect" name="metakeyselect">
1584 <option value="#NONE#"><?php esc_html_e( '&mdash; Select &mdash;', 'mainwp' ); ?></option>
1585 <?php
1586 foreach ( $keys as $key ) {
1587 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $_post->ID, $key ) ) {
1588 continue;
1589 }
1590 echo "\n<option value='" . esc_attr( $key ) . "'>" . esc_html( $key ) . '</option>';
1591 }
1592 ?>
1593 </select>
1594 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
1595 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery( '#metakeyinput, #metakeyselect, #enternew, #cancelnew' ).toggle();return false;">
1596 <span id="enternew"><?php esc_html_e( 'Enter new', 'mainwp' ); ?></span>
1597 <span id="cancelnew" class="hidden"><?php esc_html_e( 'Cancel', 'mainwp' ); ?></span>
1598 </a>
1599 <?php } else { ?>
1600 <input type="text" id="metakeyinput" name="metakeyinput" value="" />
1601 <?php } ?>
1602 </div>
1603 <div class="column">
1604 <label for="metavalue"><?php esc_html_e( 'Value', 'mainwp' ); ?></label>
1605 <textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea>
1606 </div>
1607 </div>
1608 <div class="two column row">
1609 <div class="column">
1610 <input type="button" onclick="mainwp_post_newmeta_submit( 'add' )" class="ui mini button" value="<?php esc_attr_e( 'Add Custom Field', 'mainwp' ); ?>">
1611 </div>
1612 <div class="column"></div>
1613 </div>
1614 <?php
1615 }
1616
1617 /**
1618 * Method post_custom_meta_box()
1619 *
1620 * Display custom fields form fields.
1621 *
1622 * @since 2.6.0
1623 *
1624 * @param object $post Current post object.
1625 */
1626 public static function post_custom_meta_box( $post ) {
1627 ?>
1628 <div class="ui secondary segment">
1629 <div class="ui header"><?php esc_html_e( 'Custom Fields', 'mainwp' ); ?></div>
1630 <div class="ui grid">
1631 <?php
1632 $metadata = has_meta( $post->ID );
1633 foreach ( $metadata as $key => $value ) {
1634 if ( is_protected_meta( $metadata[ $key ]['meta_key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post->ID, $metadata[ $key ]['meta_key'] ) ) {
1635 unset( $metadata[ $key ] );
1636 }
1637 }
1638
1639 $count = 0;
1640 if ( $metadata ) {
1641 foreach ( $metadata as $entry ) {
1642 echo static::list_meta_row( $entry, $count ); // phpcs:ignore WordPress.Security.EscapeOutput
1643 }
1644 }
1645
1646 static::meta_form( $post );
1647 ?>
1648 </div>
1649 </div>
1650 <?php
1651 }
1652
1653 /**
1654 * Output HTML for the post thumbnail meta-box.
1655 *
1656 * @since 2.9.0
1657 *
1658 * @param int $thumbnail_id ID of the attachment used for thumbnail.
1659 * @param mixed $pos The post ID or object associated with the thumbnail, defaults to global $post.
1660 * @return string html
1661 */
1662 public static function wp_post_thumbnail_html( $thumbnail_id = null, $pos = null ) {
1663
1664 $_wp_additional_image_sizes = wp_get_additional_image_sizes();
1665
1666 $_post = get_post( $pos );
1667 $post_type_object = get_post_type_object( $_post->post_type );
1668
1669 $thumb_ok = false;
1670 $upload_iframe_src = get_upload_iframe_src( 'image', $_post->ID );
1671
1672 if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
1673 $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
1674
1675 /**
1676 * Filters the size used to display the post thumbnail image in the 'Featured Image' meta box.
1677 *
1678 * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
1679 * image size is registered, which differs from the 'thumbnail' image size
1680 * managed via the Settings > Media screen. See the `$size` parameter description
1681 * for more information on default values.
1682 *
1683 * @since 4.4.0
1684 *
1685 * @param string|array $size Post thumbnail image size to display in the meta box. Accepts any valid
1686 * image size, or an array of width and height values in pixels (in that order).
1687 * If the 'post-thumbnail' size is set, default is 'post-thumbnail'. Otherwise,
1688 * default is an array with 266 as both the height and width values.
1689 * @param int $thumbnail_id Post thumbnail attachment ID.
1690 * @param WP_Post $_post The post object associated with the thumbnail.
1691 */
1692 $size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $_post );
1693
1694 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size );
1695
1696 if ( ! empty( $thumbnail_html ) ) {
1697 $thumb_ok = true;
1698
1699 $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>';
1700 $content = '<div class="ui setment">';
1701 $content .= sprintf(
1702 $set_thumbnail_link,
1703 esc_url( $upload_iframe_src ),
1704 ' aria-describedby="set-post-thumbnail-desc"',
1705 $thumbnail_html
1706 );
1707 $content .= '<p class="hide-if-no-js howto" id="set-post-thumbnail-desc">' . esc_html__( 'Click the image to edit or update', 'mainwp' ) . '</p>';
1708 $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail">' . esc_html( $post_type_object->labels->remove_featured_image ) . '</a></p>';
1709 $content .= '</div>';
1710 }
1711 }
1712
1713 if ( ! $thumb_ok ) {
1714 $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>';
1715 $content = sprintf(
1716 $set_thumbnail_link,
1717 esc_url( $upload_iframe_src ),
1718 '',
1719 esc_html( $post_type_object->labels->set_featured_image )
1720 );
1721 }
1722
1723 $content .= '<input type="hidden" id="_thumbnail_id" name="_thumbnail_id" value="' . esc_attr( $thumbnail_id ? $thumbnail_id : '-1' ) . '" />';
1724
1725 $html = '<div class="ui fluid accordion mainwp-sidebar-accordion">';
1726 $html .= '<div class="title active"><i class="dropdown icon"></i> ' . esc_html__( 'Featured Image', 'mainwp' ) . '</div>';
1727 $html .= '<div class="content active"';
1728 $html .= $content;
1729 $html .= '</div>';
1730 $html .= '</div>';
1731
1732 /**
1733 * Filters the admin post thumbnail HTML markup to return.
1734 *
1735 * @since 2.9.0
1736 * @since 3.5.0 Added the `$post_id` parameter.
1737 * @since 4.6.0 Added the `$thumbnail_id` parameter.
1738 *
1739 * @param string $content Admin post thumbnail HTML markup.
1740 * @param int $post_id Post ID.
1741 * @param int $thumbnail_id Thumbnail ID.
1742 */
1743 return apply_filters( 'mainwp_admin_post_thumbnail_html', $html, $_post->ID, $thumbnail_id );
1744 }
1745
1746 /**
1747 * Method post_thumbnail_meta_box()
1748 *
1749 * Renders the post thumbnail meta box.
1750 *
1751 * @param mixed $pos Post ID.
1752 */
1753 public static function post_thumbnail_meta_box( $pos ) {
1754 $thumbnail_id = get_post_meta( $pos->ID, '_thumbnail_id', true );
1755 echo static::wp_post_thumbnail_html( $thumbnail_id, $pos->ID ); // phpcs:ignore WordPress.Security.EscapeOutput
1756 }
1757
1758 /**
1759 * Method touch_time()
1760 *
1761 * Add time stamps to Post for screen readers.
1762 *
1763 * @param object $post Current Post object.
1764 * @param integer $edit Whether or not this is an edit or new post.
1765 * @param integer $for_post For post.
1766 * @param integer $tab_index Tabindex position.
1767 * @param integer $multi Multi.
1768 *
1769 * @return string Hidden time stamps html.
1770 */
1771 public static function touch_time( $post, $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { //phpcs:ignore -- NOSONAR - complex method.
1772
1773 /**
1774 * WordPress Locale.
1775 *
1776 * @global string
1777 */
1778 global $wp_locale;
1779
1780 $_post = get_post( $post );
1781
1782 if ( $for_post ) {
1783 $edit = ! ( in_array( $_post->post_status, array( 'draft', 'pending' ) ) && ( ! $_post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) );
1784 }
1785
1786 $tab_index_attribute = '';
1787
1788 if ( 0 < (int) $tab_index ) {
1789 $tab_index_attribute = " tabindex=\"$tab_index\"";
1790 }
1791
1792 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
1793 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
1794 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
1795 $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
1796 $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
1797 $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
1798 $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
1799
1800 $cur_jj = current_time( 'd' );
1801 $cur_mm = current_time( 'm' );
1802 $cur_aa = current_time( 'Y' );
1803 $cur_hh = current_time( 'H' );
1804 $cur_mn = current_time( 'i' );
1805
1806 $month = '<label><span class="screen-reader-text">' . esc_html__( 'Month', 'mainwp' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
1807
1808 for ( $i = 1; $i < 13; ++$i ) {
1809 $monthnum = zeroise( $i, 2 );
1810 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
1811 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
1812 $month .= sprintf( esc_html__( '%1$s-%2$s', 'mainwp' ), $monthnum, $monthtext ) . "</option>\n";
1813 }
1814
1815 $month .= '</select></label>';
1816
1817 $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>';
1818 $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>';
1819 $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>';
1820 $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>';
1821
1822 echo '<div class="timestamp-wrap">';
1823 printf( esc_html__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'mainwp' ), $month, $day, $year, $hour, $minute ); // phpcs:ignore WordPress.Security.EscapeOutput
1824
1825 echo '</div><input type="hidden" id="ss" name="ss" value="' . esc_attr( $ss ) . '" />';
1826
1827 if ( $multi ) {
1828 return;
1829 }
1830
1831 echo "\n\n";
1832 $map = array(
1833 'mm' => array( $mm, $cur_mm ),
1834 'jj' => array( $jj, $cur_jj ),
1835 'aa' => array( $aa, $cur_aa ),
1836 'hh' => array( $hh, $cur_hh ),
1837 'mn' => array( $mn, $cur_mn ),
1838 );
1839
1840 foreach ( $map as $timeunit => $value ) {
1841 list( $unit, $curr ) = $value;
1842
1843 echo '<input type="hidden" id="hidden_' . esc_attr( $timeunit ) . '" name="hidden_' . esc_attr( $timeunit ) . '" value="' . esc_attr( $unit ) . '" />' . "\n";
1844 $cur_timeunit = 'cur_' . $timeunit;
1845 echo '<input type="hidden" id="' . esc_attr( $cur_timeunit ) . '" name="' . esc_attr( $cur_timeunit ) . '" value="' . esc_attr( $curr ) . '" />' . "\n";
1846 }
1847 }
1848
1849 /**
1850 * Method do_meta_boxes()
1851 *
1852 * Render meta boxes.
1853 *
1854 * @param mixed $screen Current page tab.
1855 * @param mixed $context Context.
1856 * @param mixed $input_obj Object.
1857 *
1858 * @return string Metabox html
1859 */
1860 public static function do_meta_boxes( $screen, $context, $input_obj ) { // phpcs:ignore -- NOSONAR - current complexity required to achieve desired results. Purll Request solutions appreciated.
1861
1862 /**
1863 * WordPress Meta Boxes array.
1864 *
1865 * @global object
1866 */
1867 global $wp_meta_boxes;
1868 static $already_sorted = false;
1869
1870 if ( empty( $screen ) ) {
1871 $screen = get_current_screen();
1872 } elseif ( is_string( $screen ) ) {
1873 $screen = convert_to_screen( $screen );
1874 }
1875
1876 $page = $screen->id;
1877
1878 if ( 'mainwp_page_PostBulkAdd' === $page || 'mainwp_page_PostBulkEdit' === $page ) {
1879 $page = 'bulkpost';
1880 } elseif ( 'mainwp_page_PageBulkAdd' === $page || 'mainwp_page_PageBulkEdit' === $page ) {
1881 $page = 'bulkpage';
1882 }
1883
1884 printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
1885
1886 $sorted = get_user_option( "meta-box-order_$page" );
1887 if ( ! $already_sorted && $sorted ) {
1888 foreach ( $sorted as $widget_context => $ids ) {
1889 foreach ( explode( ',', $ids ) as $id ) {
1890 if ( $id && 'dashboard_browser_nag' !== $id ) {
1891 add_meta_box( $id, null, null, $screen, $widget_context, 'sorted' );
1892 }
1893 }
1894 }
1895 }
1896
1897 $already_sorted = true;
1898
1899 $i = 0;
1900
1901 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1902 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
1903 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1904 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1905 if ( false === $box || ! $box['title'] ) {
1906 continue;
1907 }
1908
1909 $block_compatible = true;
1910 if ( is_array( $box['args'] ) ) {
1911 if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
1912 continue;
1913 }
1914
1915 if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
1916 $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
1917 unset( $box['args']['__block_editor_compatible_meta_box'] );
1918 }
1919
1920 if ( ! $block_compatible && $screen->is_block_editor() ) {
1921 $box['old_callback'] = $box['callback'];
1922 $box['callback'] = 'do_block_editor_incompatible_meta_box';
1923 }
1924
1925 if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
1926 $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
1927 unset( $box['args']['__back_compat_meta_box'] );
1928 }
1929 }
1930
1931 ++$i;
1932 echo '<div id="' . esc_attr( $box['id'] ) . '" class="postbox" >' . "\n";
1933 if ( 'dashboard_browser_nag' !== $box['id'] ) {
1934 $widget_title = $box['title'];
1935
1936 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
1937 $widget_title = $box['args']['__widget_basename'];
1938 unset( $box['args']['__widget_basename'] );
1939 }
1940
1941 echo '<button type="button" class="handlediv" aria-expanded="true">';
1942 echo '<span class="screen-reader-text">' . sprintf( esc_html__( 'Toggle panel: %s', 'mainwp' ), esc_html( $widget_title ) ) . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput
1943 echo '<span class="toggle-indicator" aria-hidden="true"></span>';
1944 echo '</button>';
1945 }
1946 echo "<h2 class='hndle'><span>{" . esc_html( $box['title'] ) . "}</span></h2>\n";
1947 echo '<div class="inside">' . "\n";
1948
1949 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1950 if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
1951 $plugin = _get_plugin_from_callback( $box['callback'] );
1952 if ( $plugin ) {
1953 ?>
1954 <div class="error inline">
1955 <p>
1956 <?php
1957 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
1958 ?>
1959 </p>
1960 </div>
1961 <?php
1962 }
1963 }
1964 // phpcs:enable
1965 call_user_func( $box['callback'], $input_obj, $box );
1966 echo "</div>\n";
1967 echo "</div>\n";
1968 }
1969 }
1970 }
1971 }
1972
1973 echo '</div>';
1974
1975 return $i;
1976 }
1977
1978 /**
1979 * Renders bulkpost to edit.
1980 *
1981 * @param mixed $post_id Post ID.
1982 * @param mixed $input_type Post type.
1983 *
1984 * @return string Edit bulk post html.
1985 *
1986 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_slug()
1987 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_tags()
1988 * @uses \MainWP\Dashboard\MainWP_UI
1989 */
1990 public static function render_bulkpost( $post_id, $input_type ) { //phpcs:ignore -- NOSONAR - complex method.
1991 $post = get_post( $post_id );
1992
1993 if ( $post ) {
1994 $post_type = $post->post_type;
1995 $post_type_object = get_post_type_object( $post_type );
1996 }
1997
1998 if ( ! $post_type_object || $input_type !== $post_type || ( 'bulkpost' !== $post_type && 'bulkpage' !== $post_type ) ) {
1999 esc_html_e( 'Invalid post type.', 'mainwp' );
2000 return;
2001 }
2002
2003 // to support custom render bulkpost.
2004 $custom_posting = apply_filters( 'mainwp_custom_render_bulkpost', false, $post_id, $post_type );
2005
2006 if ( $custom_posting ) {
2007 return;
2008 }
2009
2010 $post_ID = $post->ID;
2011
2012 /**
2013 * Current user global.
2014 *
2015 * @global string
2016 */
2017 global $current_user;
2018
2019 $user_ID = $current_user->ID;
2020
2021 $_content_editor_dfw = false;
2022 $is_IE = false;
2023 $_wp_editor_expand = true;
2024
2025 $form_action = 'mainwp_editpost';
2026 $nonce_action = 'update-post_' . $post_ID;
2027
2028 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post_ID ) . "' />";
2029
2030 $referer = wp_get_referer();
2031
2032 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2033 if ( isset( $_GET['boilerplate'] ) ) {
2034 if ( 'auto-draft' === $post->post_status ) {
2035 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Boilerplate Post', 'mainwp' ) : esc_html__( 'Create New Boilerplate Page', 'mainwp' );
2036 } else {
2037 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Boilerplate Post', 'mainwp' ) : esc_html__( 'Edit Boilerplate Page', 'mainwp' );
2038 }
2039 } elseif ( 'auto-draft' === $post->post_status ) {
2040 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Bulk Post', 'mainwp' ) : esc_html__( 'Create New Bulk Page', 'mainwp' );
2041 } else {
2042 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Bulk Post', 'mainwp' ) : esc_html__( 'Edit Bulk Page', 'mainwp' );
2043 }
2044
2045 $note_title = apply_filters( 'mainwp_bulkpost_edit_title', $note_title, $post );
2046
2047 $message = '';
2048 if ( isset( $_GET['message'] ) && 1 === (int) $_GET['message'] ) {
2049 if ( 'bulkpost' === $post_type ) {
2050 $message = esc_html__( 'Post updated.', 'mainwp' );
2051 } else {
2052 $message = esc_html__( 'Page updated.', 'mainwp' );
2053 }
2054 }
2055
2056 // phpcs:enable
2057 ?>
2058 <div class="ui alt segment" id="mainwp-add-new-bulkpost">
2059 <form name="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="post" class="ui form">
2060 <?php wp_nonce_field( $nonce_action ); ?>
2061 <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID; ?>" />
2062 <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
2063 <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
2064 <input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
2065 <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" />
2066 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />
2067 <input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
2068 <?php
2069 if ( 'draft' !== get_post_status( $post ) ) {
2070 wp_original_referer_field( true, 'previous' );
2071 }
2072 echo $form_extra; // phpcs:ignore WordPress.Security.EscapeOutput
2073 ?>
2074 <div class="mainwp-main-content">
2075 <?php do_action( 'mainwp_top_bulkpost_edit_content', $post ); ?>
2076 <div class="ui red message" id="mainwp-message-zone" style="display:none"></div>
2077 <?php
2078 if ( $message ) {
2079 ?>
2080 <div class="ui yellow message"><?php echo esc_html( $message ); ?></div>
2081 <?php
2082 }
2083 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2084 ?>
2085 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp_boilerplate_info_notice' ) ) : ?>
2086 <?php if ( isset( $_GET['boilerplate'] ) ) : ?>
2087 <div class="ui message info">
2088 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp_boilerplate_info_notice"></i>
2089 <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>
2090 <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>
2091 </div>
2092 <?php endif; ?>
2093 <?php endif; ?>
2094
2095
2096 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-create-new-bulkpost-info-message' ) ) : ?>
2097 <?php if ( ! isset( $_GET['boilerplate'] ) ) : ?>
2098 <div class="ui message info">
2099 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-create-new-bulkpost-info-message"></i>
2100 <?php if ( 'bulkpost' === $post_type ) : ?>
2101 <?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>' ); ?>
2102 <?php else : ?>
2103 <?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>' ); ?>
2104 <?php endif; ?>
2105 </div>
2106 <?php endif; ?>
2107 <?php endif; ?>
2108 <?php // phpcs:enable ?>
2109
2110 <h3 class="header" id="bulkpost-title"><?php echo esc_html( $note_title ); ?></h3>
2111
2112 <div class="field">
2113 <label><?php esc_html_e( 'Title', 'mainwp' ); ?></label>
2114 <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">
2115 </div>
2116 <div class="field">
2117 <?php do_action( 'mainwp_before_bulkpost_editor', $post ); ?>
2118 <div id="postdivrich" class="postarea
2119 <?php
2120 if ( $_wp_editor_expand ) {
2121 echo ' wp-editor-expand';
2122 }
2123 ?>
2124 ">
2125 <?php
2126 $default_settings = array(
2127 '_content_editor_dfw' => $_content_editor_dfw,
2128 'drag_drop_upload' => true,
2129 'tabfocus_elements' => 'content-html,save-post',
2130 'editor_height' => 300,
2131 'quicktags' => true,
2132 'media_buttons' => true,
2133 'tinymce' => array(
2134 'resize' => false,
2135 'wp_autoresize_on' => $_wp_editor_expand,
2136 'add_unload_trigger' => false,
2137 'wp_keep_scroll_position' => ! $is_IE,
2138 ),
2139 );
2140
2141 $ed_settings = apply_filters( 'mainwp_bulkpost_editor_settings', false, $post );
2142 if ( is_array( $ed_settings ) && ! empty( $ed_settings ) ) {
2143 $ed_settings = array_merge( $default_settings, $ed_settings );
2144 } else {
2145 $ed_settings = $default_settings;
2146 }
2147
2148 remove_editor_styles();
2149 wp_editor(
2150 $post->post_content,
2151 'content',
2152 $ed_settings
2153 );
2154
2155 ?>
2156 <table id="post-status-info"><tbody><tr>
2157 <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>
2158 <td class="autosave-info">
2159 <span class="autosave-message">&nbsp;</span>
2160 <?php
2161 if ( 'auto-draft' !== $post->post_status ) {
2162 echo '<span id="last-edit">';
2163 $last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) );
2164 if ( $last_user ) {
2165 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
2166 } else {
2167 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
2168 }
2169 echo '</span>';
2170 }
2171 ?>
2172 </td>
2173 <td id="content-resize-handle" class="hide-if-no-js"><br /></td>
2174 </tr></tbody></table>
2175 </div>
2176 </div>
2177 <div class="field" id="add-slug-div">
2178 <label><?php esc_html_e( 'Slug', 'mainwp' ); ?></label>
2179 <?php MainWP_System::instance()->metaboxes->add_slug( $post ); ?>
2180 </div>
2181 <?php if ( 'bulkpost' === $post_type ) { ?>
2182 <div class="field">
2183 <label><?php esc_html_e( 'Excerpt', 'mainwp' ); ?></label>
2184 <textarea rows="1" name="excerpt" id="excerpt"><?php echo esc_attr( $post->post_excerpt ); ?></textarea>
2185 <em><?php esc_html_e( 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme.', 'mainwp' ); ?></em>
2186 </div>
2187 <div class="field">
2188 <label><?php esc_html_e( 'Tags', 'mainwp' ); ?></label>
2189 <?php MainWP_System::instance()->metaboxes->add_tags( $post ); ?>
2190 <em><?php esc_html_e( 'Separate tags with commas', 'mainwp' ); ?></em>
2191 </div>
2192 <?php } ?>
2193 <div class="field">
2194 <?php static::post_custom_meta_box( $post ); ?>
2195 </div>
2196
2197 <div class="field postbox-container">
2198 <?php
2199
2200 /**
2201 * Edit bulkpost
2202 *
2203 * First on the Edit post screen after default fields.
2204 *
2205 * @param object $post Object containing the Post data.
2206 * @param string $post_type Post type.
2207 */
2208 do_action( 'mainwp_bulkpost_edit', $post, $post_type );
2209
2210 static::do_meta_boxes( null, 'normal', $post );
2211
2212 static::do_meta_boxes( null, 'advanced', $post );
2213
2214 /**
2215 * Edit bulkpost metaboxes
2216 *
2217 * Fires after all built-in meta boxes have been added.
2218 *
2219 * @param object $post Object containing the Post data.
2220 * @param string $post_type Post type.
2221 *
2222 * @see https://developer.wordpress.org/reference/hooks/add_meta_boxes/
2223 */
2224 do_action( 'add_meta_boxes', $post_type, $post );
2225
2226 static::do_meta_boxes( $post_type, 'normal', $post );
2227
2228 ?>
2229 </div>
2230 </div>
2231 <?php
2232
2233 $sites_default = array(
2234 'type' => 'checkbox',
2235 'show_group' => true,
2236 'show_select_all' => true,
2237 'class' => '',
2238 'style' => '',
2239
2240 );
2241 $sites_settings = array();
2242 $sites_settings = apply_filters( 'mainwp_bulkpost_select_sites_settings', $sites_settings, $post );
2243
2244 if ( is_array( $sites_settings ) && ! empty( $sites_settings ) ) {
2245 $sites_settings = array_merge( $sites_default, $sites_settings );
2246 } else {
2247 $sites_settings = $sites_default;
2248 }
2249
2250 $sel_sites = array();
2251 $sel_groups = array();
2252 ?>
2253 <div class="mainwp-side-content mainwp-no-padding">
2254 <?php do_action( 'mainwp_bulkpost_edit_top_side', $post, $post_type ); ?>
2255 <div class="mainwp-select-sites ui fluid accordion mainwp-sidebar-accordion">
2256 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
2257 <div class="content active">
2258 <?php
2259 $sel_params = array(
2260 'type' => $sites_settings['type'],
2261 'show_group' => $sites_settings['show_group'],
2262 'show_select_all' => $sites_settings['show_select_all'],
2263 'class' => $sites_settings['class'],
2264 'style' => $sites_settings['style'],
2265 'selected_sites' => $sel_sites,
2266 'selected_groups' => $sel_groups,
2267 'post_id' => $post_ID,
2268 'show_client' => true,
2269 );
2270 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
2271 ?>
2272 <input type="hidden" name="select_sites_nonce" id="select_sites_nonce" value="<?php echo esc_attr( wp_create_nonce( 'select_sites_' . $post->ID ) ); ?>" />
2273 </div>
2274 </div>
2275 <div class="ui fitted divider"></div>
2276 <?php
2277 if ( 'bulkpost' === $post_type ) {
2278 static::render_categories_list( $post );
2279 }
2280 static::render_post_fields( $post, $post_type );
2281 ?>
2282 <?php static::do_meta_boxes( $post_type, 'side', $post ); ?>
2283 <div class="ui fitted divider"></div>
2284 <?php
2285 /**
2286 * Action: mainwp_edit_posts_before_submit_button
2287 *
2288 * Fires right before the Submit button.
2289 *
2290 * @param object $post Object containing the Post data.
2291 * @param string $post_type Post type.
2292 *
2293 * @since 4.0
2294 */
2295 do_action( 'mainwp_edit_posts_before_submit_button', $post, $post_type );
2296 $is_demo = MainWP_Demo_Handle::is_demo_mode();
2297 ?>
2298 <div class="mainwp-search-submit" id="bulkpost-publishing-action">
2299 <?php
2300 if ( $is_demo ) {
2301 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' ) . '" />' );
2302 } else {
2303 ?>
2304 <input type="submit" name="publish" id="publish" class="ui big green fluid button" value="<?php esc_attr_e( 'Publish', 'mainwp' ); ?>">
2305 <?php } ?>
2306 </div>
2307 <?php
2308 /**
2309 * Action: mainwp_edit_posts_after_submit_button
2310 *
2311 * Fires right after the Submit button.
2312 *
2313 * @since 4.0
2314 */
2315 do_action( 'mainwp_edit_posts_after_submit_button' );
2316 ?>
2317 </div>
2318 </form>
2319 <script type="text/javascript">
2320 jQuery( document ).ready( function () {
2321 jQuery( '#publish' ).on( 'click', function() {
2322 jQuery( '#mainwp-publish-dimmer' ).show();
2323 } );
2324 } );
2325 </script>
2326 <div class="ui active inverted dimmer" id="mainwp-publish-dimmer" style="display:none">
2327 <div class="ui text loader"><?php esc_html_e( 'Publishing...', 'mainwp' ); ?></div>
2328 </div>
2329 <div class="ui clearing hidden divider"></div>
2330 </div>
2331 <?php
2332 static::render_footer( 'BulkAdd' );
2333 }
2334
2335 /**
2336 * Renders Select Categories form
2337 *
2338 * @param object $post Post object.
2339 */
2340 public static function render_categories_list( $post ) {
2341
2342 ?>
2343 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2344 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Categories', 'mainwp' ); ?></div>
2345
2346 <?php
2347 $categories = array();
2348 if ( $post ) {
2349 $categories = base64_decode( get_post_meta( $post->ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2350 $categories = explode( ',', $categories );
2351 }
2352 if ( ! is_array( $categories ) ) {
2353 $categories = array();
2354 }
2355
2356 $uncat = esc_html__( 'Uncategorized', 'mainwp' );
2357 $post_only = false;
2358 if ( $post ) {
2359 $post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
2360 }
2361 ?>
2362 <div class="content active">
2363 <input type="hidden" name="post_category_nonce" id="post_category_nonce" value="<?php echo esc_attr( wp_create_nonce( 'post_category_' . $post->ID ) ); ?>" />
2364 <div class="field">
2365 <div class="ui checkbox">
2366 <input type="checkbox" name="post_only_existing" id="post_only_existing" value="1" <?php echo $post_only ? 'checked' : ''; ?>>
2367 <label><?php esc_html_e( 'Post only to existing categories', 'mainwp' ); ?></label>
2368 </div>
2369 </div>
2370 <div class="field">
2371
2372 <div class="ui selection dropdown multiple search fluid" id="categorychecklist">
2373 <input type="hidden" name="post_category[]">
2374 <div class="text"><?php esc_html_e( 'Select categories', 'mainwp' ); ?></div>
2375 <i class="dropdown icon"></i>
2376 <div class="menu">
2377 <?php if ( ! in_array( $uncat, $categories ) ) : ?>
2378 <div class="item" data-value="<?php esc_attr_e( 'Uncategorized', 'mainwp' ); ?>" class="sitecategory-list"><?php esc_html_e( 'Uncategorized', 'mainwp' ); ?></div>
2379 <?php endif; ?>
2380
2381 <?php foreach ( $categories as $cat ) : ?>
2382 <?php
2383 if ( empty( $cat ) ) {
2384 continue;
2385 }
2386 $cat_name = rawurldecode( $cat );
2387 ?>
2388 <div class="item" data-value="<?php echo esc_attr( $cat ); ?>" class="sitecategory-list"><?php echo esc_html( $cat_name ); ?></div>
2389 <?php endforeach; ?>
2390 </div>
2391 </div>
2392
2393 <?php
2394 $init_cats = '';
2395 foreach ( $categories as $cat ) {
2396 $init_cats .= "'" . esc_attr( $cat ) . "',";
2397 }
2398 $init_cats = rtrim( $init_cats, ',' );
2399 ?>
2400
2401 <script type="text/javascript">
2402 jQuery( document ).ready( function () {
2403 jQuery( '#categorychecklist' ).dropdown( 'set selected', [<?php echo $init_cats; //phpcs:ignore -- safe. ?>] );
2404 } );
2405 </script>
2406
2407 </div>
2408 <div class="field">
2409 <a href="#" id="category-add-toggle" class="ui button fluid mini"><?php esc_html_e( 'Create New Category', 'mainwp' ); ?></a>
2410 </div>
2411 <div class="field" id="newcategory-field" style="display:none">
2412 <input type="text" name="newcategory" id="newcategory" value="">
2413 </div>
2414 <div class="field" id="mainwp-category-add-submit-field" style="display:none">
2415 <input type="button" id="mainwp-category-add-submit" class="ui fluid basic green mini button" value="<?php esc_attr_e( 'Add New Category', 'mainwp' ); ?>">
2416 </div>
2417 </div>
2418 </div>
2419 <div class="ui fitted divider"></div>
2420 <?php
2421 }
2422
2423 /**
2424 * Renders Select Categories form
2425 *
2426 * @param object $post Post object.
2427 */
2428 public static function render_categories( $post ) {
2429 ?>
2430 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2431 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Categories', 'mainwp' ); ?></div>
2432 <?php
2433 $categories = array();
2434 if ( $post ) {
2435 $categories = base64_decode( get_post_meta( $post->ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2436 $categories = explode( ',', $categories );
2437 }
2438 if ( ! is_array( $categories ) ) {
2439 $categories = array();
2440 }
2441
2442 $uncat = esc_html__( 'Uncategorized', 'mainwp' );
2443 $post_only = false;
2444 if ( $post ) {
2445 $post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
2446 }
2447 ?>
2448 <div class="content active">
2449 <input type="hidden" name="post_category_nonce" id="post_category_nonce" value="<?php echo esc_attr( wp_create_nonce( 'post_category_' . $post->ID ) ); ?>" />
2450 <div class="field">
2451 <div class="ui checkbox">
2452 <input type="checkbox" name="post_only_existing" id="post_only_existing" value="1" <?php echo $post_only ? 'checked' : ''; ?>>
2453 <label><?php esc_html_e( 'Post only to existing categories', 'mainwp' ); ?></label>
2454 </div>
2455 </div>
2456 <div class="field">
2457 <select name="post_category[]" id="categorychecklist" multiple="" class="ui fluid dropdown">
2458 <option value=""><?php esc_html_e( 'Select categories', 'mainwp' ); ?></option>
2459 <?php if ( ! in_array( $uncat, $categories ) ) : ?>
2460 <option value="<?php esc_attr_e( 'Uncategorized', 'mainwp' ); ?>" class="sitecategory-list"><?php esc_html_e( 'Uncategorized', 'mainwp' ); ?></option>
2461 <?php endif; ?>
2462 <?php foreach ( $categories as $cat ) : ?>
2463 <?php
2464 if ( empty( $cat ) ) {
2465 continue;
2466 }
2467 $cat_name = rawurldecode( $cat );
2468 ?>
2469 <option value="<?php echo esc_attr( $cat ); ?>" class="sitecategory-list"><?php echo esc_html( $cat_name ); ?></option>
2470 <?php endforeach; ?>
2471 </select>
2472 <?php
2473 $init_cats = '';
2474 foreach ( $categories as $cat ) {
2475 $init_cats .= "'" . esc_attr( $cat ) . "',";
2476 }
2477 $init_cats = rtrim( $init_cats, ',' );
2478 ?>
2479 <script type="text/javascript">
2480 jQuery( document ).ready( function () {
2481 jQuery( '#categorychecklist' ).dropdown( 'set selected', [<?php echo $init_cats; //phpcs:ignore -- safe. ?>] );
2482 } );
2483 </script>
2484 </div>
2485 <div class="field">
2486 <a href="#" id="category-add-toggle" class="ui button fluid mini"><?php esc_html_e( 'Create New Category', 'mainwp' ); ?></a>
2487 </div>
2488 <div class="field" id="newcategory-field" style="display:none">
2489 <input type="text" name="newcategory" id="newcategory" value="">
2490 </div>
2491 <div class="field" id="mainwp-category-add-submit-field" style="display:none">
2492 <input type="button" id="mainwp-category-add-submit" class="ui fluid basic green mini button" value="<?php esc_attr_e( 'Add New Category', 'mainwp' ); ?>">
2493 </div>
2494 </div>
2495 </div>
2496 <div class="ui fitted divider"></div>
2497 <?php
2498 }
2499
2500 /**
2501 * Method render_post_fields()
2502 *
2503 * Render Featured Image & Post Options fields.
2504 *
2505 * @param object $post Post object.
2506 * @param mixed $post_type Post type.
2507 */
2508 public static function render_post_fields( $post, $post_type ) { // phpcs:ignore -- NOSONAR - complex.
2509 ?>
2510 <div class="mainwp-search-options mainwp-post-featured-image" id="postimagediv">
2511 <?php echo '<div class="inside">'; ?>
2512 <?php static::post_thumbnail_meta_box( $post ); ?>
2513 <?php echo '</div>'; ?>
2514 </div>
2515 <div class="ui fitted divider"></div>
2516 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2517 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Discussion', 'mainwp' ); ?></div>
2518 <div class="content active">
2519 <div class="field">
2520 <div class="ui checkbox">
2521 <input type="checkbox" name="comment_status" id="comment_status" value="open" <?php checked( $post->comment_status, 'open' ); ?>>
2522 <label><?php esc_html_e( 'Allow comments', 'mainwp' ); ?></label>
2523 </div>
2524 <div class="ui checkbox">
2525 <input type="checkbox" name="ping_status" id="ping_status" value="open" <?php checked( $post->ping_status, 'open' ); ?> >
2526 <label><?php esc_html_e( 'Allow trackbacks and pingbacks', 'mainwp' ); ?></label>
2527 </div>
2528 </div>
2529 </div>
2530 </div>
2531 <div class="ui fitted divider"></div>
2532 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2533 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Publish Options', 'mainwp' ); ?></div>
2534 <div class="content active">
2535 <div class="field">
2536 <label><?php esc_html_e( 'Status', 'mainwp' ); ?></label>
2537 <select class="ui dropdown" name="mainwp_edit_post_status" id="post_status">
2538 <option value="publish" <?php echo ( 'publish' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Publish', 'mainwp' ); ?></option>
2539 <option value="draft" <?php echo ( 'draft' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Draft', 'mainwp' ); ?></option>
2540 <option value="pending" <?php echo ( 'pending' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Pending review', 'mainwp' ); ?></option>
2541 </select>
2542 </div>
2543 <?php
2544 if ( 'private' === $post->post_status ) {
2545 $post->post_password = '';
2546 $visibility = 'private';
2547 } elseif ( ! empty( $post->post_password ) ) {
2548 $visibility = 'password';
2549 } elseif ( 'bulkpost' === $post_type && is_sticky( $post->ID ) ) {
2550 $visibility = 'public';
2551 } else {
2552 $visibility = 'public';
2553 }
2554 ?>
2555
2556 <div class="grouped fields">
2557 <label><?php esc_html_e( 'Visibility', 'mainwp' ); ?></label>
2558 <div class="field">
2559 <div class="ui radio checkbox">
2560 <input type="radio" name="visibility" value="public" id="visibility-radio-public" <?php echo ( 'public' === $visibility ) ? 'checked="checked"' : ''; ?>>
2561 <label><?php esc_html_e( 'Public', 'mainwp' ); ?></label>
2562 </div>
2563 </div>
2564 <?php if ( 'bulkpost' === $post_type ) { ?>
2565 <div class="field" id="sticky-field">
2566 <div class="ui checkbox">
2567 <input type="checkbox" id="sticky" name="sticky" value="sticky" <?php checked( is_sticky( $post->ID ) ); ?> />
2568 <label><?php esc_html_e( 'Stick this post to the front page', 'mainwp' ); ?></label>
2569 </div>
2570 </div>
2571 <?php } ?>
2572 <div class="field">
2573 <div class="ui radio checkbox">
2574 <input type="radio" name="visibility" value="password" id="visibility-radio-password" <?php echo ( 'password' === $visibility ) ? 'checked="checked"' : ''; ?>>
2575 <label><?php esc_html_e( 'Password protected', 'mainwp' ); ?></label>
2576 </div>
2577 </div>
2578 <div class="field" id="post_password-field" <?php echo ( 'password' === $visibility ) ? '' : 'style="display:none"'; ?>>
2579 <label><?php esc_html_e( 'Password', 'mainwp' ); ?></label>
2580 <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr( $post->post_password ); ?>" />
2581 </div>
2582 <div class="field">
2583 <div class="ui radio checkbox">
2584 <input type="radio" name="visibility" value="private" id="visibility-radio-private" <?php echo ( 'private' === $visibility ) ? 'checked="checked"' : ''; ?>>
2585 <label><?php esc_html_e( 'Private', 'mainwp' ); ?></label>
2586 </div>
2587 </div>
2588 </div>
2589 <div class="field">
2590 <label><?php esc_html_e( 'Publish', 'mainwp' ); ?></label>
2591 <select class="ui dropdown" name="post_timestamp" id="post_timestamp">
2592 <option value="immediately" <?php echo ( 'future' === $post->post_status ) ? '' : 'selected="selected"'; ?>><?php esc_html_e( 'Immediately', 'mainwp' ); ?></option>
2593 <option value="schedule" <?php echo ( 'future' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Schedule', 'mainwp' ); ?></option>
2594 </select>
2595 </div>
2596
2597 <div class="field" id="post_timestamp_value-field" <?php echo ( 'future' === $post->post_status ) ? '' : 'style="display:none"'; ?>>
2598 <div class="ui calendar mainwp_datepicker" id="schedule_post_datetime" >
2599 <div class="ui input left icon">
2600 <i class="calendar icon"></i>
2601 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Date', 'mainwp' ); ?>" id="post_timestamp_value" value="" />
2602 </div>
2603 </div>
2604 </div>
2605 </div>
2606 <div style="display:none" id="timestampdiv">
2607 <?php static::touch_time( $post ); ?>
2608 </div>
2609 </div>
2610 <?php
2611 }
2612
2613 /**
2614 * Method render_bulk_add()
2615 *
2616 * Check if user has rights,
2617 * render the bulk add tab.
2618 *
2619 * @return string Bulk add tab html.
2620 */
2621 public static function render_bulk_add() {
2622 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
2623 mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
2624 return;
2625 }
2626
2627 /**
2628 * MainWP default post to edit.
2629 *
2630 * @global string
2631 */
2632 global $_mainwp_default_post_to_edit;
2633
2634 $post_id = $_mainwp_default_post_to_edit ? $_mainwp_default_post_to_edit->ID : 0;
2635 static::render_addedit( $post_id, 'BulkAdd' );
2636 }
2637
2638 /**
2639 * Method render_bulk_edit()
2640 *
2641 * Check if user has rights,
2642 * render the bulk edit tab.
2643 *
2644 * @return string Bulk edit tab html.
2645 */
2646 public static function render_bulk_edit() {
2647 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_posts' ) ) {
2648 mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
2649 return;
2650 }
2651 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2652 $post_id = isset( $_GET['post_id'] ) ? intval( $_GET['post_id'] ) : 0;
2653 // phpcs:enable
2654 static::render_addedit( $post_id, 'BulkEdit' );
2655 }
2656
2657 /**
2658 * Method render_bulk_addedit()
2659 *
2660 * Render both the Add & Edit tabs.
2661 *
2662 * @param mixed $post_id post ID.
2663 * @param mixed $what what tab is active.
2664 */
2665 public static function render_addedit( $post_id, $what ) {
2666 static::render_header( $what, $post_id );
2667 static::render_bulkpost( $post_id, 'bulkpost' );
2668 static::render_footer( $what );
2669 }
2670
2671 /**
2672 * Method hook_posts_search_handler()
2673 *
2674 * Hook Posts Search handler.
2675 *
2676 * @param mixed $data search data.
2677 * @param object $website child site object.
2678 * @param mixed $output output.
2679 *
2680 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
2681 */
2682 public static function hook_posts_search_handler( $data, $website, &$output ) {
2683 $posts = array();
2684 if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
2685 $result = $results[1];
2686 $posts = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2687 unset( $results );
2688 }
2689 $output->results[ $website->id ] = $posts;
2690 }
2691
2692 /**
2693 * Method mainwp_help_content()
2694 *
2695 * Attatch MainWP help content.
2696 */
2697 public static function mainwp_help_content() {
2698 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2699 if ( isset( $_GET['page'] ) && ( 'PostBulkManage' === $_GET['page'] || 'PostBulkAdd' === $_GET['page'] ) ) {
2700 ?>
2701 <p><?php esc_html_e( 'If you need help with managing posts, please review following help documents', 'mainwp' ); ?></p>
2702 <div class="ui relaxed bulleted list">
2703 <div class="item"><a href="https://kb.mainwp.com/docs/manage-posts/" target="_blank">Manage Posts</a> <i class="external alternate icon"></i></div>
2704 <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>
2705 <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>
2706 <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>
2707 <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>
2708 <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>
2709 <?php
2710 /**
2711 * Action: mainwp_posts_help_item
2712 *
2713 * Fires at the bottom of the help articles list in the Help sidebar on the Posts page.
2714 *
2715 * Suggested HTML markup:
2716 *
2717 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2718 *
2719 * @since 4.1
2720 */
2721 do_action( 'mainwp_posts_help_item' );
2722 ?>
2723 </div>
2724 <?php
2725 }
2726 // phpcs:enable
2727 }
2728 }
2729