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

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

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