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