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

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

2,728 lines 130.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Post Page.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Posts
12 *
13 * @uses MainWP_Bulk_Add
14 */
15 class MainWP_Post { // 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_can( '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_can( '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_can( '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
1731 /**
1732 * Filters the admin post thumbnail HTML markup to return.
1733 *
1734 * @since 2.9.0
1735 * @since 3.5.0 Added the `$post_id` parameter.
1736 * @since 4.6.0 Added the `$thumbnail_id` parameter.
1737 *
1738 * @param string $content Admin post thumbnail HTML markup.
1739 * @param int $post_id Post ID.
1740 * @param int $thumbnail_id Thumbnail ID.
1741 */
1742 return apply_filters( 'mainwp_admin_post_thumbnail_html', $html, $_post->ID, $thumbnail_id );
1743 }
1744
1745 /**
1746 * Method post_thumbnail_meta_box()
1747 *
1748 * Renders the post thumbnail meta box.
1749 *
1750 * @param mixed $pos Post ID.
1751 */
1752 public static function post_thumbnail_meta_box( $pos ) {
1753 $thumbnail_id = get_post_meta( $pos->ID, '_thumbnail_id', true );
1754 echo static::wp_post_thumbnail_html( $thumbnail_id, $pos->ID ); // phpcs:ignore WordPress.Security.EscapeOutput
1755 }
1756
1757 /**
1758 * Method touch_time()
1759 *
1760 * Add time stamps to Post for screen readers.
1761 *
1762 * @param object $post Current Post object.
1763 * @param integer $edit Whether or not this is an edit or new post.
1764 * @param integer $for_post For post.
1765 * @param integer $tab_index Tabindex position.
1766 * @param integer $multi Multi.
1767 *
1768 * @return string Hidden time stamps html.
1769 */
1770 public static function touch_time( $post, $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { //phpcs:ignore -- NOSONAR - complex method.
1771
1772 /**
1773 * WordPress Locale.
1774 *
1775 * @global string
1776 */
1777 global $wp_locale;
1778
1779 $_post = get_post( $post );
1780
1781 if ( $for_post ) {
1782 $edit = ! ( in_array( $_post->post_status, array( 'draft', 'pending' ) ) && ( ! $_post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) );
1783 }
1784
1785 $tab_index_attribute = '';
1786
1787 if ( 0 < (int) $tab_index ) {
1788 $tab_index_attribute = " tabindex=\"$tab_index\"";
1789 }
1790
1791 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
1792 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
1793 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
1794 $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
1795 $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
1796 $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
1797 $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
1798
1799 $cur_jj = current_time( 'd' );
1800 $cur_mm = current_time( 'm' );
1801 $cur_aa = current_time( 'Y' );
1802 $cur_hh = current_time( 'H' );
1803 $cur_mn = current_time( 'i' );
1804
1805 $month = '<label><span class="screen-reader-text">' . esc_html__( 'Month', 'mainwp' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
1806
1807 for ( $i = 1; $i < 13; ++$i ) {
1808 $monthnum = zeroise( $i, 2 );
1809 $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
1810 $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
1811 $month .= sprintf( esc_html__( '%1$s-%2$s', 'mainwp' ), $monthnum, $monthtext ) . "</option>\n";
1812 }
1813
1814 $month .= '</select></label>';
1815
1816 $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>';
1817 $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>';
1818 $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>';
1819 $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>';
1820
1821 echo '<div class="timestamp-wrap">';
1822 printf( esc_html__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'mainwp' ), $month, $day, $year, $hour, $minute ); // phpcs:ignore WordPress.Security.EscapeOutput
1823
1824 echo '</div><input type="hidden" id="ss" name="ss" value="' . esc_attr( $ss ) . '" />';
1825
1826 if ( $multi ) {
1827 return;
1828 }
1829
1830 echo "\n\n";
1831 $map = array(
1832 'mm' => array( $mm, $cur_mm ),
1833 'jj' => array( $jj, $cur_jj ),
1834 'aa' => array( $aa, $cur_aa ),
1835 'hh' => array( $hh, $cur_hh ),
1836 'mn' => array( $mn, $cur_mn ),
1837 );
1838
1839 foreach ( $map as $timeunit => $value ) {
1840 list( $unit, $curr ) = $value;
1841
1842 echo '<input type="hidden" id="hidden_' . esc_attr( $timeunit ) . '" name="hidden_' . esc_attr( $timeunit ) . '" value="' . esc_attr( $unit ) . '" />' . "\n";
1843 $cur_timeunit = 'cur_' . $timeunit;
1844 echo '<input type="hidden" id="' . esc_attr( $cur_timeunit ) . '" name="' . esc_attr( $cur_timeunit ) . '" value="' . esc_attr( $curr ) . '" />' . "\n";
1845 }
1846 }
1847
1848 /**
1849 * Method do_meta_boxes()
1850 *
1851 * Render meta boxes.
1852 *
1853 * @param mixed $screen Current page tab.
1854 * @param mixed $context Context.
1855 * @param mixed $input_obj Object.
1856 *
1857 * @return string Metabox html
1858 */
1859 public static function do_meta_boxes( $screen, $context, $input_obj ) { // phpcs:ignore -- NOSONAR - current complexity required to achieve desired results. Purll Request solutions appreciated.
1860
1861 /**
1862 * WordPress Meta Boxes array.
1863 *
1864 * @global object
1865 */
1866 global $wp_meta_boxes;
1867 static $already_sorted = false;
1868
1869 if ( empty( $screen ) ) {
1870 $screen = get_current_screen();
1871 } elseif ( is_string( $screen ) ) {
1872 $screen = convert_to_screen( $screen );
1873 }
1874
1875 $page = $screen->id;
1876
1877 if ( 'mainwp_page_PostBulkAdd' === $page || 'mainwp_page_PostBulkEdit' === $page ) {
1878 $page = 'bulkpost';
1879 } elseif ( 'mainwp_page_PageBulkAdd' === $page || 'mainwp_page_PageBulkEdit' === $page ) {
1880 $page = 'bulkpage';
1881 }
1882
1883 printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
1884
1885 $sorted = get_user_option( "meta-box-order_$page" );
1886 if ( ! $already_sorted && $sorted ) {
1887 foreach ( $sorted as $widget_context => $ids ) {
1888 foreach ( explode( ',', $ids ) as $id ) {
1889 if ( $id && 'dashboard_browser_nag' !== $id ) {
1890 add_meta_box( $id, null, null, $screen, $widget_context, 'sorted' );
1891 }
1892 }
1893 }
1894 }
1895
1896 $already_sorted = true;
1897
1898 $i = 0;
1899
1900 if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1901 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
1902 if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1903 foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1904 if ( false === $box || ! $box['title'] ) {
1905 continue;
1906 }
1907
1908 $block_compatible = true;
1909 if ( is_array( $box['args'] ) ) {
1910 if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
1911 continue;
1912 }
1913
1914 if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
1915 $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
1916 unset( $box['args']['__block_editor_compatible_meta_box'] );
1917 }
1918
1919 if ( ! $block_compatible && $screen->is_block_editor() ) {
1920 $box['old_callback'] = $box['callback'];
1921 $box['callback'] = 'do_block_editor_incompatible_meta_box';
1922 }
1923
1924 if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
1925 $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
1926 unset( $box['args']['__back_compat_meta_box'] );
1927 }
1928 }
1929
1930 ++$i;
1931 echo '<div id="' . esc_attr( $box['id'] ) . '" class="postbox" >' . "\n";
1932 if ( 'dashboard_browser_nag' !== $box['id'] ) {
1933 $widget_title = $box['title'];
1934
1935 if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
1936 $widget_title = $box['args']['__widget_basename'];
1937 unset( $box['args']['__widget_basename'] );
1938 }
1939
1940 echo '<button type="button" class="handlediv" aria-expanded="true">';
1941 echo '<span class="screen-reader-text">' . sprintf( esc_html__( 'Toggle panel: %s', 'mainwp' ), esc_html( $widget_title ) ) . '</span>'; // phpcs:ignore WordPress.Security.EscapeOutput
1942 echo '<span class="toggle-indicator" aria-hidden="true"></span>';
1943 echo '</button>';
1944 }
1945 echo "<h2 class='hndle'><span>{" . esc_html( $box['title'] ) . "}</span></h2>\n";
1946 echo '<div class="inside">' . "\n";
1947
1948 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1949 if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
1950 $plugin = _get_plugin_from_callback( $box['callback'] );
1951 if ( $plugin ) {
1952 ?>
1953 <div class="error inline">
1954 <p>
1955 <?php
1956 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
1957 ?>
1958 </p>
1959 </div>
1960 <?php
1961 }
1962 }
1963 // phpcs:enable
1964 call_user_func( $box['callback'], $input_obj, $box );
1965 echo "</div>\n";
1966 echo "</div>\n";
1967 }
1968 }
1969 }
1970 }
1971
1972 echo '</div>';
1973
1974 return $i;
1975 }
1976
1977 /**
1978 * Renders bulkpost to edit.
1979 *
1980 * @param mixed $post_id Post ID.
1981 * @param mixed $input_type Post type.
1982 *
1983 * @return string Edit bulk post html.
1984 *
1985 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_slug()
1986 * @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_tags()
1987 * @uses \MainWP\Dashboard\MainWP_UI
1988 */
1989 public static function render_bulkpost( $post_id, $input_type ) { //phpcs:ignore -- NOSONAR - complex method.
1990 $post = get_post( $post_id );
1991
1992 if ( $post ) {
1993 $post_type = $post->post_type;
1994 $post_type_object = get_post_type_object( $post_type );
1995 }
1996
1997 if ( ! $post_type_object || $input_type !== $post_type || ( 'bulkpost' !== $post_type && 'bulkpage' !== $post_type ) ) {
1998 esc_html_e( 'Invalid post type.', 'mainwp' );
1999 return;
2000 }
2001
2002 // to support custom render bulkpost.
2003 $custom_posting = apply_filters( 'mainwp_custom_render_bulkpost', false, $post_id, $post_type );
2004
2005 if ( $custom_posting ) {
2006 return;
2007 }
2008
2009 $post_ID = $post->ID;
2010
2011 /**
2012 * Current user global.
2013 *
2014 * @global string
2015 */
2016 global $current_user;
2017
2018 $user_ID = $current_user->ID;
2019
2020 $_content_editor_dfw = false;
2021 $is_IE = false;
2022 $_wp_editor_expand = true;
2023
2024 $form_action = 'mainwp_editpost';
2025 $nonce_action = 'update-post_' . $post_ID;
2026
2027 $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr( $post_ID ) . "' />";
2028
2029 $referer = wp_get_referer();
2030
2031 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2032 if ( isset( $_GET['boilerplate'] ) ) {
2033 if ( 'auto-draft' === $post->post_status ) {
2034 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Boilerplate Post', 'mainwp' ) : esc_html__( 'Create New Boilerplate Page', 'mainwp' );
2035 } else {
2036 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Boilerplate Post', 'mainwp' ) : esc_html__( 'Edit Boilerplate Page', 'mainwp' );
2037 }
2038 } elseif ( 'auto-draft' === $post->post_status ) {
2039 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Bulk Post', 'mainwp' ) : esc_html__( 'Create New Bulk Page', 'mainwp' );
2040 } else {
2041 $note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Bulk Post', 'mainwp' ) : esc_html__( 'Edit Bulk Page', 'mainwp' );
2042 }
2043
2044 $note_title = apply_filters( 'mainwp_bulkpost_edit_title', $note_title, $post );
2045
2046 $message = '';
2047 if ( isset( $_GET['message'] ) && 1 === (int) $_GET['message'] ) {
2048 if ( 'bulkpost' === $post_type ) {
2049 $message = esc_html__( 'Post updated.', 'mainwp' );
2050 } else {
2051 $message = esc_html__( 'Page updated.', 'mainwp' );
2052 }
2053 }
2054
2055 // phpcs:enable
2056 ?>
2057 <div class="ui alt segment" id="mainwp-add-new-bulkpost">
2058 <form name="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post" id="post" class="ui form">
2059 <?php wp_nonce_field( $nonce_action ); ?>
2060 <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID; ?>" />
2061 <input type="hidden" id="hiddenaction" name="action" value="<?php echo esc_attr( $form_action ); ?>" />
2062 <input type="hidden" id="originalaction" name="originalaction" value="<?php echo esc_attr( $form_action ); ?>" />
2063 <input type="hidden" id="post_author" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
2064 <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ); ?>" />
2065 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status ); ?>" />
2066 <input type="hidden" id="referredby" name="referredby" value="<?php echo $referer ? esc_url( $referer ) : ''; ?>" />
2067 <?php
2068 if ( 'draft' !== get_post_status( $post ) ) {
2069 wp_original_referer_field( true, 'previous' );
2070 }
2071 echo $form_extra; // phpcs:ignore WordPress.Security.EscapeOutput
2072 ?>
2073 <div class="mainwp-main-content">
2074 <?php do_action( 'mainwp_top_bulkpost_edit_content', $post ); ?>
2075 <div class="ui red message" id="mainwp-message-zone" style="display:none"></div>
2076 <?php
2077 if ( $message ) {
2078 ?>
2079 <div class="ui yellow message"><?php echo esc_html( $message ); ?></div>
2080 <?php
2081 }
2082 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2083 ?>
2084 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp_boilerplate_info_notice' ) ) : ?>
2085 <?php if ( isset( $_GET['boilerplate'] ) ) : ?>
2086 <div class="ui message info">
2087 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp_boilerplate_info_notice"></i>
2088 <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>
2089 <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>
2090 </div>
2091 <?php endif; ?>
2092 <?php endif; ?>
2093
2094
2095 <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-create-new-bulkpost-info-message' ) ) : ?>
2096 <?php if ( ! isset( $_GET['boilerplate'] ) ) : ?>
2097 <div class="ui message info">
2098 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-create-new-bulkpost-info-message"></i>
2099 <?php if ( 'bulkpost' === $post_type ) : ?>
2100 <?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>' ); ?>
2101 <?php else : ?>
2102 <?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>' ); ?>
2103 <?php endif; ?>
2104 </div>
2105 <?php endif; ?>
2106 <?php endif; ?>
2107 <?php // phpcs:enable ?>
2108
2109 <h3 class="header" id="bulkpost-title"><?php echo esc_html( $note_title ); ?></h3>
2110
2111 <div class="field">
2112 <label><?php esc_html_e( 'Title', 'mainwp' ); ?></label>
2113 <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">
2114 </div>
2115 <div class="field">
2116 <?php do_action( 'mainwp_before_bulkpost_editor', $post ); ?>
2117 <div id="postdivrich" class="postarea
2118 <?php
2119 if ( $_wp_editor_expand ) {
2120 echo ' wp-editor-expand';
2121 }
2122 ?>
2123 ">
2124 <?php
2125 $default_settings = array(
2126 '_content_editor_dfw' => $_content_editor_dfw,
2127 'drag_drop_upload' => true,
2128 'tabfocus_elements' => 'content-html,save-post',
2129 'editor_height' => 300,
2130 'quicktags' => true,
2131 'media_buttons' => true,
2132 'tinymce' => array(
2133 'resize' => false,
2134 'wp_autoresize_on' => $_wp_editor_expand,
2135 'add_unload_trigger' => false,
2136 'wp_keep_scroll_position' => ! $is_IE,
2137 ),
2138 );
2139
2140 $ed_settings = apply_filters( 'mainwp_bulkpost_editor_settings', false, $post );
2141 if ( is_array( $ed_settings ) && ! empty( $ed_settings ) ) {
2142 $ed_settings = array_merge( $default_settings, $ed_settings );
2143 } else {
2144 $ed_settings = $default_settings;
2145 }
2146
2147 remove_editor_styles();
2148 wp_editor(
2149 $post->post_content,
2150 'content',
2151 $ed_settings
2152 );
2153
2154 ?>
2155 <table id="post-status-info"><tbody><tr>
2156 <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>
2157 <td class="autosave-info">
2158 <span class="autosave-message">&nbsp;</span>
2159 <?php
2160 if ( 'auto-draft' !== $post->post_status ) {
2161 echo '<span id="last-edit">';
2162 $last_user = get_userdata( get_post_meta( $post_ID, '_edit_last', true ) );
2163 if ( $last_user ) {
2164 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
2165 } else {
2166 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
2167 }
2168 echo '</span>';
2169 }
2170 ?>
2171 </td>
2172 <td id="content-resize-handle" class="hide-if-no-js"><br /></td>
2173 </tr></tbody></table>
2174 </div>
2175 </div>
2176 <div class="field" id="add-slug-div">
2177 <label><?php esc_html_e( 'Slug', 'mainwp' ); ?></label>
2178 <?php MainWP_System::instance()->metaboxes->add_slug( $post ); ?>
2179 </div>
2180 <?php if ( 'bulkpost' === $post_type ) { ?>
2181 <div class="field">
2182 <label><?php esc_html_e( 'Excerpt', 'mainwp' ); ?></label>
2183 <textarea rows="1" name="excerpt" id="excerpt"><?php echo esc_attr( $post->post_excerpt ); ?></textarea>
2184 <em><?php esc_html_e( 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme.', 'mainwp' ); ?></em>
2185 </div>
2186 <div class="field">
2187 <label><?php esc_html_e( 'Tags', 'mainwp' ); ?></label>
2188 <?php MainWP_System::instance()->metaboxes->add_tags( $post ); ?>
2189 <em><?php esc_html_e( 'Separate tags with commas', 'mainwp' ); ?></em>
2190 </div>
2191 <?php } ?>
2192 <div class="field">
2193 <?php static::post_custom_meta_box( $post ); ?>
2194 </div>
2195
2196 <div class="field postbox-container">
2197 <?php
2198
2199 /**
2200 * Edit bulkpost
2201 *
2202 * First on the Edit post screen after default fields.
2203 *
2204 * @param object $post Object containing the Post data.
2205 * @param string $post_type Post type.
2206 */
2207 do_action( 'mainwp_bulkpost_edit', $post, $post_type );
2208
2209 static::do_meta_boxes( null, 'normal', $post );
2210
2211 static::do_meta_boxes( null, 'advanced', $post );
2212
2213 /**
2214 * Edit bulkpost metaboxes
2215 *
2216 * Fires after all built-in meta boxes have been added.
2217 *
2218 * @param object $post Object containing the Post data.
2219 * @param string $post_type Post type.
2220 *
2221 * @see https://developer.wordpress.org/reference/hooks/add_meta_boxes/
2222 */
2223 do_action( 'add_meta_boxes', $post_type, $post );
2224
2225 static::do_meta_boxes( $post_type, 'normal', $post );
2226
2227 ?>
2228 </div>
2229 </div>
2230 <?php
2231
2232 $sites_default = array(
2233 'type' => 'checkbox',
2234 'show_group' => true,
2235 'show_select_all' => true,
2236 'class' => '',
2237 'style' => '',
2238
2239 );
2240 $sites_settings = array();
2241 $sites_settings = apply_filters( 'mainwp_bulkpost_select_sites_settings', $sites_settings, $post );
2242
2243 if ( is_array( $sites_settings ) && ! empty( $sites_settings ) ) {
2244 $sites_settings = array_merge( $sites_default, $sites_settings );
2245 } else {
2246 $sites_settings = $sites_default;
2247 }
2248
2249 $sel_sites = array();
2250 $sel_groups = array();
2251 ?>
2252 <div class="mainwp-side-content mainwp-no-padding">
2253 <?php do_action( 'mainwp_bulkpost_edit_top_side', $post, $post_type ); ?>
2254 <div class="mainwp-select-sites ui fluid accordion mainwp-sidebar-accordion">
2255 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Sites', 'mainwp' ); ?></div>
2256 <div class="content active">
2257 <?php
2258 $sel_params = array(
2259 'type' => $sites_settings['type'],
2260 'show_group' => $sites_settings['show_group'],
2261 'show_select_all' => $sites_settings['show_select_all'],
2262 'class' => $sites_settings['class'],
2263 'style' => $sites_settings['style'],
2264 'selected_sites' => $sel_sites,
2265 'selected_groups' => $sel_groups,
2266 'post_id' => $post_ID,
2267 'show_client' => true,
2268 );
2269 MainWP_UI_Select_Sites::select_sites_box( $sel_params );
2270 ?>
2271 <input type="hidden" name="select_sites_nonce" id="select_sites_nonce" value="<?php echo esc_attr( wp_create_nonce( 'select_sites_' . $post->ID ) ); ?>" />
2272 </div>
2273 </div>
2274 <div class="ui fitted divider"></div>
2275 <?php
2276 if ( 'bulkpost' === $post_type ) {
2277 static::render_categories_list( $post );
2278 }
2279 static::render_post_fields( $post, $post_type );
2280 ?>
2281 <?php static::do_meta_boxes( $post_type, 'side', $post ); ?>
2282 <div class="ui fitted divider"></div>
2283 <?php
2284 /**
2285 * Action: mainwp_edit_posts_before_submit_button
2286 *
2287 * Fires right before the Submit button.
2288 *
2289 * @param object $post Object containing the Post data.
2290 * @param string $post_type Post type.
2291 *
2292 * @since 4.0
2293 */
2294 do_action( 'mainwp_edit_posts_before_submit_button', $post, $post_type );
2295 $is_demo = MainWP_Demo_Handle::is_demo_mode();
2296 ?>
2297 <div class="mainwp-search-submit" id="bulkpost-publishing-action">
2298 <?php
2299 if ( $is_demo ) {
2300 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' ) . '" />' );
2301 } else {
2302 ?>
2303 <input type="submit" name="publish" id="publish" class="ui big green fluid button" value="<?php esc_attr_e( 'Publish', 'mainwp' ); ?>">
2304 <?php } ?>
2305 </div>
2306 <?php
2307 /**
2308 * Action: mainwp_edit_posts_after_submit_button
2309 *
2310 * Fires right after the Submit button.
2311 *
2312 * @since 4.0
2313 */
2314 do_action( 'mainwp_edit_posts_after_submit_button' );
2315 ?>
2316 </div>
2317 </form>
2318 <script type="text/javascript">
2319 jQuery( document ).ready( function () {
2320 jQuery( '#publish' ).on( 'click', function() {
2321 jQuery( '#mainwp-publish-dimmer' ).show();
2322 } );
2323 } );
2324 </script>
2325 <div class="ui active inverted dimmer" id="mainwp-publish-dimmer" style="display:none">
2326 <div class="ui text loader"><?php esc_html_e( 'Publishing...', 'mainwp' ); ?></div>
2327 </div>
2328 <div class="ui clearing hidden divider"></div>
2329 </div>
2330 <?php
2331 static::render_footer( 'BulkAdd' );
2332 }
2333
2334 /**
2335 * Renders Select Categories form
2336 *
2337 * @param object $post Post object.
2338 */
2339 public static function render_categories_list( $post ) {
2340
2341 ?>
2342 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2343 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Categories', 'mainwp' ); ?></div>
2344
2345 <?php
2346 $categories = array();
2347 if ( $post ) {
2348 $categories = base64_decode( get_post_meta( $post->ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2349 $categories = explode( ',', $categories );
2350 }
2351 if ( ! is_array( $categories ) ) {
2352 $categories = array();
2353 }
2354
2355 $uncat = esc_html__( 'Uncategorized', 'mainwp' );
2356 $post_only = false;
2357 if ( $post ) {
2358 $post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
2359 }
2360 ?>
2361 <div class="content active">
2362 <input type="hidden" name="post_category_nonce" id="post_category_nonce" value="<?php echo esc_attr( wp_create_nonce( 'post_category_' . $post->ID ) ); ?>" />
2363 <div class="field">
2364 <div class="ui checkbox">
2365 <input type="checkbox" name="post_only_existing" id="post_only_existing" value="1" <?php echo $post_only ? 'checked' : ''; ?>>
2366 <label><?php esc_html_e( 'Post only to existing categories', 'mainwp' ); ?></label>
2367 </div>
2368 </div>
2369 <div class="field">
2370
2371 <div class="ui selection dropdown multiple search fluid" id="categorychecklist">
2372 <input type="hidden" name="post_category[]">
2373 <div class="text"><?php esc_html_e( 'Select categories', 'mainwp' ); ?></div>
2374 <i class="dropdown icon"></i>
2375 <div class="menu">
2376 <?php if ( ! in_array( $uncat, $categories ) ) : ?>
2377 <div class="item" data-value="<?php esc_attr_e( 'Uncategorized', 'mainwp' ); ?>" class="sitecategory-list"><?php esc_html_e( 'Uncategorized', 'mainwp' ); ?></div>
2378 <?php endif; ?>
2379
2380 <?php foreach ( $categories as $cat ) : ?>
2381 <?php
2382 if ( empty( $cat ) ) {
2383 continue;
2384 }
2385 $cat_name = rawurldecode( $cat );
2386 ?>
2387 <div class="item" data-value="<?php echo esc_attr( $cat ); ?>" class="sitecategory-list"><?php echo esc_html( $cat_name ); ?></div>
2388 <?php endforeach; ?>
2389 </div>
2390 </div>
2391
2392 <?php
2393 $init_cats = '';
2394 foreach ( $categories as $cat ) {
2395 $init_cats .= "'" . esc_attr( $cat ) . "',";
2396 }
2397 $init_cats = rtrim( $init_cats, ',' );
2398 ?>
2399
2400 <script type="text/javascript">
2401 jQuery( document ).ready( function () {
2402 jQuery( '#categorychecklist' ).dropdown( 'set selected', [<?php echo $init_cats; //phpcs:ignore -- safe. ?>] );
2403 } );
2404 </script>
2405
2406 </div>
2407 <div class="field">
2408 <a href="#" id="category-add-toggle" class="ui button fluid mini"><?php esc_html_e( 'Create New Category', 'mainwp' ); ?></a>
2409 </div>
2410 <div class="field" id="newcategory-field" style="display:none">
2411 <input type="text" name="newcategory" id="newcategory" value="">
2412 </div>
2413 <div class="field" id="mainwp-category-add-submit-field" style="display:none">
2414 <input type="button" id="mainwp-category-add-submit" class="ui fluid basic green mini button" value="<?php esc_attr_e( 'Add New Category', 'mainwp' ); ?>">
2415 </div>
2416 </div>
2417 </div>
2418 <div class="ui fitted divider"></div>
2419 <?php
2420 }
2421
2422 /**
2423 * Renders Select Categories form
2424 *
2425 * @param object $post Post object.
2426 */
2427 public static function render_categories( $post ) {
2428 ?>
2429 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2430 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Select Categories', 'mainwp' ); ?></div>
2431 <?php
2432 $categories = array();
2433 if ( $post ) {
2434 $categories = base64_decode( get_post_meta( $post->ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2435 $categories = explode( ',', $categories );
2436 }
2437 if ( ! is_array( $categories ) ) {
2438 $categories = array();
2439 }
2440
2441 $uncat = esc_html__( 'Uncategorized', 'mainwp' );
2442 $post_only = false;
2443 if ( $post ) {
2444 $post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
2445 }
2446 ?>
2447 <div class="content active">
2448 <input type="hidden" name="post_category_nonce" id="post_category_nonce" value="<?php echo esc_attr( wp_create_nonce( 'post_category_' . $post->ID ) ); ?>" />
2449 <div class="field">
2450 <div class="ui checkbox">
2451 <input type="checkbox" name="post_only_existing" id="post_only_existing" value="1" <?php echo $post_only ? 'checked' : ''; ?>>
2452 <label><?php esc_html_e( 'Post only to existing categories', 'mainwp' ); ?></label>
2453 </div>
2454 </div>
2455 <div class="field">
2456 <select name="post_category[]" id="categorychecklist" multiple="" class="ui fluid dropdown">
2457 <option value=""><?php esc_html_e( 'Select categories', 'mainwp' ); ?></option>
2458 <?php if ( ! in_array( $uncat, $categories ) ) : ?>
2459 <option value="<?php esc_attr_e( 'Uncategorized', 'mainwp' ); ?>" class="sitecategory-list"><?php esc_html_e( 'Uncategorized', 'mainwp' ); ?></option>
2460 <?php endif; ?>
2461 <?php foreach ( $categories as $cat ) : ?>
2462 <?php
2463 if ( empty( $cat ) ) {
2464 continue;
2465 }
2466 $cat_name = rawurldecode( $cat );
2467 ?>
2468 <option value="<?php echo esc_attr( $cat ); ?>" class="sitecategory-list"><?php echo esc_html( $cat_name ); ?></option>
2469 <?php endforeach; ?>
2470 </select>
2471 <?php
2472 $init_cats = '';
2473 foreach ( $categories as $cat ) {
2474 $init_cats .= "'" . esc_attr( $cat ) . "',";
2475 }
2476 $init_cats = rtrim( $init_cats, ',' );
2477 ?>
2478 <script type="text/javascript">
2479 jQuery( document ).ready( function () {
2480 jQuery( '#categorychecklist' ).dropdown( 'set selected', [<?php echo $init_cats; //phpcs:ignore -- safe. ?>] );
2481 } );
2482 </script>
2483 </div>
2484 <div class="field">
2485 <a href="#" id="category-add-toggle" class="ui button fluid mini"><?php esc_html_e( 'Create New Category', 'mainwp' ); ?></a>
2486 </div>
2487 <div class="field" id="newcategory-field" style="display:none">
2488 <input type="text" name="newcategory" id="newcategory" value="">
2489 </div>
2490 <div class="field" id="mainwp-category-add-submit-field" style="display:none">
2491 <input type="button" id="mainwp-category-add-submit" class="ui fluid basic green mini button" value="<?php esc_attr_e( 'Add New Category', 'mainwp' ); ?>">
2492 </div>
2493 </div>
2494 </div>
2495 <div class="ui fitted divider"></div>
2496 <?php
2497 }
2498
2499 /**
2500 * Method render_post_fields()
2501 *
2502 * Render Featured Image & Post Options fields.
2503 *
2504 * @param object $post Post object.
2505 * @param mixed $post_type Post type.
2506 */
2507 public static function render_post_fields( $post, $post_type ) { // phpcs:ignore -- NOSONAR - complex.
2508 ?>
2509 <div class="mainwp-search-options mainwp-post-featured-image" id="postimagediv">
2510 <?php echo '<div class="inside">'; ?>
2511 <?php static::post_thumbnail_meta_box( $post ); ?>
2512 <?php echo '</div>'; ?>
2513 </div>
2514 <div class="ui fitted divider"></div>
2515 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2516 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Discussion', 'mainwp' ); ?></div>
2517 <div class="content active">
2518 <div class="field">
2519 <div class="ui checkbox">
2520 <input type="checkbox" name="comment_status" id="comment_status" value="open" <?php checked( $post->comment_status, 'open' ); ?>>
2521 <label><?php esc_html_e( 'Allow comments', 'mainwp' ); ?></label>
2522 </div>
2523 <div class="ui checkbox">
2524 <input type="checkbox" name="ping_status" id="ping_status" value="open" <?php checked( $post->ping_status, 'open' ); ?> >
2525 <label><?php esc_html_e( 'Allow trackbacks and pingbacks', 'mainwp' ); ?></label>
2526 </div>
2527 </div>
2528 </div>
2529 </div>
2530 <div class="ui fitted divider"></div>
2531 <div class="mainwp-search-options ui fluid accordion mainwp-sidebar-accordion">
2532 <div class="title active"><i class="dropdown icon"></i> <?php esc_html_e( 'Publish Options', 'mainwp' ); ?></div>
2533 <div class="content active">
2534 <div class="field">
2535 <label><?php esc_html_e( 'Status', 'mainwp' ); ?></label>
2536 <select class="ui dropdown" name="mainwp_edit_post_status" id="post_status">
2537 <option value="publish" <?php echo ( 'publish' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Publish', 'mainwp' ); ?></option>
2538 <option value="draft" <?php echo ( 'draft' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Draft', 'mainwp' ); ?></option>
2539 <option value="pending" <?php echo ( 'pending' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Pending review', 'mainwp' ); ?></option>
2540 </select>
2541 </div>
2542 <?php
2543 if ( 'private' === $post->post_status ) {
2544 $post->post_password = '';
2545 $visibility = 'private';
2546 } elseif ( ! empty( $post->post_password ) ) {
2547 $visibility = 'password';
2548 } elseif ( 'bulkpost' === $post_type && is_sticky( $post->ID ) ) {
2549 $visibility = 'public';
2550 } else {
2551 $visibility = 'public';
2552 }
2553 ?>
2554
2555 <div class="grouped fields">
2556 <label><?php esc_html_e( 'Visibility', 'mainwp' ); ?></label>
2557 <div class="field">
2558 <div class="ui radio checkbox">
2559 <input type="radio" name="visibility" value="public" id="visibility-radio-public" <?php echo ( 'public' === $visibility ) ? 'checked="checked"' : ''; ?>>
2560 <label><?php esc_html_e( 'Public', 'mainwp' ); ?></label>
2561 </div>
2562 </div>
2563 <?php if ( 'bulkpost' === $post_type ) { ?>
2564 <div class="field" id="sticky-field">
2565 <div class="ui checkbox">
2566 <input type="checkbox" id="sticky" name="sticky" value="sticky" <?php checked( is_sticky( $post->ID ) ); ?> />
2567 <label><?php esc_html_e( 'Stick this post to the front page', 'mainwp' ); ?></label>
2568 </div>
2569 </div>
2570 <?php } ?>
2571 <div class="field">
2572 <div class="ui radio checkbox">
2573 <input type="radio" name="visibility" value="password" id="visibility-radio-password" <?php echo ( 'password' === $visibility ) ? 'checked="checked"' : ''; ?>>
2574 <label><?php esc_html_e( 'Password protected', 'mainwp' ); ?></label>
2575 </div>
2576 </div>
2577 <div class="field" id="post_password-field" <?php echo ( 'password' === $visibility ) ? '' : 'style="display:none"'; ?>>
2578 <label><?php esc_html_e( 'Password', 'mainwp' ); ?></label>
2579 <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr( $post->post_password ); ?>" />
2580 </div>
2581 <div class="field">
2582 <div class="ui radio checkbox">
2583 <input type="radio" name="visibility" value="private" id="visibility-radio-private" <?php echo ( 'private' === $visibility ) ? 'checked="checked"' : ''; ?>>
2584 <label><?php esc_html_e( 'Private', 'mainwp' ); ?></label>
2585 </div>
2586 </div>
2587 </div>
2588 <div class="field">
2589 <label><?php esc_html_e( 'Publish', 'mainwp' ); ?></label>
2590 <select class="ui dropdown" name="post_timestamp" id="post_timestamp">
2591 <option value="immediately" <?php echo ( 'future' === $post->post_status ) ? '' : 'selected="selected"'; ?>><?php esc_html_e( 'Immediately', 'mainwp' ); ?></option>
2592 <option value="schedule" <?php echo ( 'future' === $post->post_status ) ? 'selected="selected"' : ''; ?>><?php esc_html_e( 'Schedule', 'mainwp' ); ?></option>
2593 </select>
2594 </div>
2595
2596 <div class="field" id="post_timestamp_value-field" <?php echo ( 'future' === $post->post_status ) ? '' : 'style="display:none"'; ?>>
2597 <div class="ui calendar mainwp_datepicker" id="schedule_post_datetime" >
2598 <div class="ui input left icon">
2599 <i class="calendar icon"></i>
2600 <input type="text" autocomplete="off" placeholder="<?php esc_attr_e( 'Date', 'mainwp' ); ?>" id="post_timestamp_value" value="" />
2601 </div>
2602 </div>
2603 </div>
2604 </div>
2605 <div style="display:none" id="timestampdiv">
2606 <?php static::touch_time( $post ); ?>
2607 </div>
2608 </div>
2609 <?php
2610 }
2611
2612 /**
2613 * Method render_bulk_add()
2614 *
2615 * Check if user has rights,
2616 * render the bulk add tab.
2617 *
2618 * @return string Bulk add tab html.
2619 */
2620 public static function render_bulk_add() {
2621 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
2622 \mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
2623 return;
2624 }
2625
2626 /**
2627 * MainWP default post to edit.
2628 *
2629 * @global string
2630 */
2631 global $_mainwp_default_post_to_edit;
2632
2633 $post_id = $_mainwp_default_post_to_edit ? $_mainwp_default_post_to_edit->ID : 0;
2634 static::render_addedit( $post_id, 'BulkAdd' );
2635 }
2636
2637 /**
2638 * Method render_bulk_edit()
2639 *
2640 * Check if user has rights,
2641 * render the bulk edit tab.
2642 *
2643 * @return string Bulk edit tab html.
2644 */
2645 public static function render_bulk_edit() {
2646 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
2647 \mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
2648 return;
2649 }
2650 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2651 $post_id = isset( $_GET['post_id'] ) ? intval( $_GET['post_id'] ) : 0;
2652 // phpcs:enable
2653 static::render_addedit( $post_id, 'BulkEdit' );
2654 }
2655
2656 /**
2657 * Method render_bulk_addedit()
2658 *
2659 * Render both the Add & Edit tabs.
2660 *
2661 * @param mixed $post_id post ID.
2662 * @param mixed $what what tab is active.
2663 */
2664 public static function render_addedit( $post_id, $what ) {
2665 static::render_header( $what, $post_id );
2666 static::render_bulkpost( $post_id, 'bulkpost' );
2667 static::render_footer( $what );
2668 }
2669
2670 /**
2671 * Method hook_posts_search_handler()
2672 *
2673 * Hook Posts Search handler.
2674 *
2675 * @param mixed $data search data.
2676 * @param object $website child site object.
2677 * @param mixed $output output.
2678 *
2679 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
2680 */
2681 public static function hook_posts_search_handler( $data, $website, &$output ) {
2682 $posts = array();
2683 if ( 0 < preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) ) {
2684 $result = $results[1];
2685 $posts = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
2686 unset( $results );
2687 }
2688 $output->results[ $website->id ] = $posts;
2689 }
2690
2691 /**
2692 * Method mainwp_help_content()
2693 *
2694 * Creates the MainWP Help Documentation List for the help component in the sidebar.
2695 */
2696 public static function mainwp_help_content() {
2697 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
2698 if ( isset( $_GET['page'] ) && ( 'PostBulkManage' === $_GET['page'] || 'PostBulkAdd' === $_GET['page'] ) ) {
2699 ?>
2700 <p><?php esc_html_e( 'If you need help with managing posts, please review following help documents', 'mainwp' ); ?></p>
2701 <div class="ui list">
2702 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-posts/" target="_blank">Manage Posts</a></div>
2703 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-posts/#create-a-new-post" target="_blank">Create a New Post</a></div>
2704 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-posts/#edit-an-existing-post" target="_blank">Edit an Existing Post</a></div>
2705 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-posts/#change-status-of-an-existing-post" target="_blank">Change Status of an Existing Post</a></div>
2706 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-posts/#view-an-existing-post" target="_blank">View an Existing Post</a></div>
2707 <div class="item"><i class="external alternate icon"></i> <a href="https://kb.mainwp.com/docs/manage-posts/#delete-post" target="_blank">Delete Post(s)</a></div>
2708 <?php
2709 /**
2710 * Action: mainwp_posts_help_item
2711 *
2712 * Fires at the bottom of the help articles list in the Help sidebar on the Posts page.
2713 *
2714 * Suggested HTML markup:
2715 *
2716 * <div class="item"><a href="Your custom URL">Your custom text</a></div>
2717 *
2718 * @since 4.1
2719 */
2720 do_action( 'mainwp_posts_help_item' );
2721 ?>
2722 </div>
2723 <?php
2724 }
2725 // phpcs:enable
2726 }
2727 }
2728