ID, $thumbnail_id );
}
/**
* Method post_thumbnail_meta_box()
*
* Renders the post thumbnail meta box.
*
* @param mixed $pos Post ID.
*/
public static function post_thumbnail_meta_box( $pos ) {
$thumbnail_id = get_post_meta( $pos->ID, '_thumbnail_id', true );
echo static::wp_post_thumbnail_html( $thumbnail_id, $pos->ID ); // phpcs:ignore WordPress.Security.EscapeOutput
}
/**
* Method touch_time()
*
* Add time stamps to Post for screen readers.
*
* @param object $post Current Post object.
* @param integer $edit Whether or not this is an edit or new post.
* @param integer $for_post For post.
* @param integer $tab_index Tabindex position.
* @param integer $multi Multi.
*
* @return string Hidden time stamps html.
*/
public static function touch_time( $post, $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { //phpcs:ignore -- NOSONAR - complex method.
/**
* WordPress Locale.
*
* @global string
*/
global $wp_locale;
$_post = get_post( $post );
if ( $for_post ) {
$edit = ! ( in_array( $_post->post_status, array( 'draft', 'pending' ) ) && ( ! $_post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) );
}
$tab_index_attribute = '';
if ( 0 < (int) $tab_index ) {
$tab_index_attribute = " tabindex=\"$tab_index\"";
}
$post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
$jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
$mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
$aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
$hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
$mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
$ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
$cur_jj = current_time( 'd' );
$cur_mm = current_time( 'm' );
$cur_aa = current_time( 'Y' );
$cur_hh = current_time( 'H' );
$cur_mn = current_time( 'i' );
$month = '
' . esc_html__( 'Month', 'mainwp' ) . ' \n";
for ( $i = 1; $i < 13; ++$i ) {
$monthnum = zeroise( $i, 2 );
$monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
$month .= "\t\t\t" . '';
$month .= sprintf( esc_html__( '%1$s-%2$s', 'mainwp' ), $monthnum, $monthtext ) . " \n";
}
$month .= ' ';
$day = '
' . esc_html__( 'Day', 'mainwp' ) . ' ';
$year = '
' . esc_html__( 'Year', 'mainwp' ) . ' ';
$hour = '
' . esc_html__( 'Hour', 'mainwp' ) . ' ';
$minute = '
' . esc_html__( 'Minute', 'mainwp' ) . ' ';
echo '
';
printf( esc_html__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'mainwp' ), $month, $day, $year, $hour, $minute ); // phpcs:ignore WordPress.Security.EscapeOutput
echo '
';
if ( $multi ) {
return;
}
echo "\n\n";
$map = array(
'mm' => array( $mm, $cur_mm ),
'jj' => array( $jj, $cur_jj ),
'aa' => array( $aa, $cur_aa ),
'hh' => array( $hh, $cur_hh ),
'mn' => array( $mn, $cur_mn ),
);
foreach ( $map as $timeunit => $value ) {
list( $unit, $curr ) = $value;
echo '
' . "\n";
$cur_timeunit = 'cur_' . $timeunit;
echo '
' . "\n";
}
}
/**
* Method do_meta_boxes()
*
* Render meta boxes.
*
* @param mixed $screen Current page tab.
* @param mixed $context Context.
* @param mixed $input_obj Object.
*
* @return string Metabox html
*/
public static function do_meta_boxes( $screen, $context, $input_obj ) { // phpcs:ignore -- NOSONAR - current complexity required to achieve desired results. Purll Request solutions appreciated.
/**
* WordPress Meta Boxes array.
*
* @global object
*/
global $wp_meta_boxes;
static $already_sorted = false;
if ( empty( $screen ) ) {
$screen = get_current_screen();
} elseif ( is_string( $screen ) ) {
$screen = convert_to_screen( $screen );
}
$page = $screen->id;
if ( 'mainwp_page_PostBulkAdd' === $page || 'mainwp_page_PostBulkEdit' === $page ) {
$page = 'bulkpost';
} elseif ( 'mainwp_page_PageBulkAdd' === $page || 'mainwp_page_PageBulkEdit' === $page ) {
$page = 'bulkpage';
}
if ( ! is_array( $wp_meta_boxes ) || empty( $wp_meta_boxes[ $page ][ $context ] ) ) {
return;
}
printf( '
', esc_attr( $context ) );
$sorted = get_user_option( "meta-box-order_$page" );
if ( ! $already_sorted && $sorted ) {
foreach ( $sorted as $widget_context => $ids ) {
foreach ( explode( ',', $ids ) as $id ) {
if ( $id && 'dashboard_browser_nag' !== $id ) {
add_meta_box( $id, null, null, $screen, $widget_context, 'sorted' );
}
}
}
}
$already_sorted = true;
$i = 0;
if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
if ( false === $box || ! isset( $box['title'] ) ) {
continue;
}
$block_compatible = true;
if ( isset( $box['args'] ) && is_array( $box['args'] ) ) {
if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
continue;
}
if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
$block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
unset( $box['args']['__block_editor_compatible_meta_box'] );
}
if ( ! $block_compatible && $screen->is_block_editor() ) {
$box['old_callback'] = $box['callback'];
$box['callback'] = 'do_block_editor_incompatible_meta_box';
}
if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
$block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
unset( $box['args']['__back_compat_meta_box'] );
}
}
++$i;
echo '
' . "\n";
if ( 'dashboard_browser_nag' !== $box['id'] && isset( $box['args'] ) && is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
unset( $box['args']['__widget_basename'] );
}
$title = $box['title'];
if ( empty( $box['metabox-custom'] ) && ! empty( $title ) ) {
$title = '{' . $title . '}';
}
echo '\n";
echo '
' . "\n";
// phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
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'] ) ) {
$plugin = _get_plugin_from_callback( $box['callback'] );
if ( $plugin ) {
?>
{' . esc_html( $plugin['Name'] ) . '}' ); // phpcs:ignore WordPress.Security.EscapeOutput
?>
\n";
echo "
\n";
}
}
}
}
echo '
';
return $i;
}
/**
* Renders bulkpost to edit.
*
* @param mixed $post_id Post ID.
* @param mixed $input_type Post type.
*
* @return string Edit bulk post html.
*
* @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_slug()
* @uses \MainWP\Dashboard\MainWP_Meta_Boxes::add_tags()
* @uses \MainWP\Dashboard\MainWP_UI
*/
public static function render_bulkpost( $post_id, $input_type ) { //phpcs:ignore -- NOSONAR - complex method.
$post = get_post( $post_id );
if ( $post ) {
$post_type = $post->post_type;
$post_type_object = get_post_type_object( $post_type );
}
if ( ! $post_type_object || $input_type !== $post_type || ( 'bulkpost' !== $post_type && 'bulkpage' !== $post_type ) ) {
esc_html_e( 'Invalid post type.', 'mainwp' );
return;
}
// to support custom render bulkpost.
$custom_posting = apply_filters( 'mainwp_custom_render_bulkpost', false, $post_id, $post_type );
if ( $custom_posting ) {
return;
}
$post_ID = $post->ID;
$GLOBAL['bulkpost_edit'] = $post;
/**
* Current user global.
*
* @global string
*/
global $current_user;
$user_ID = $current_user->ID;
$_content_editor_dfw = false;
$is_IE = false;
$_wp_editor_expand = true;
$form_action = 'mainwp_editpost';
$nonce_action = 'update-post_' . $post_ID;
$form_extra = "
";
$referer = wp_get_referer();
// phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( isset( $_GET['boilerplate'] ) ) {
if ( 'auto-draft' === $post->post_status ) {
$note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Boilerplate Post', 'mainwp' ) : esc_html__( 'Create New Boilerplate Page', 'mainwp' );
} else {
$note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Boilerplate Post', 'mainwp' ) : esc_html__( 'Edit Boilerplate Page', 'mainwp' );
}
} elseif ( 'auto-draft' === $post->post_status ) {
$note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Create New Bulk Post', 'mainwp' ) : esc_html__( 'Create New Bulk Page', 'mainwp' );
} else {
$note_title = ( 'bulkpost' === $post_type ) ? esc_html__( 'Edit Bulk Post', 'mainwp' ) : esc_html__( 'Edit Bulk Page', 'mainwp' );
}
$note_title = apply_filters( 'mainwp_bulkpost_edit_title', $note_title, $post );
$message = '';
if ( isset( $_GET['message'] ) && 1 === (int) $_GET['message'] ) {
if ( 'bulkpost' === $post_type ) {
$message = esc_html__( 'Post updated.', 'mainwp' );
} else {
$message = esc_html__( 'Page updated.', 'mainwp' );
}
}
// phpcs:enable
?>
ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
$categories = explode( ',', $categories );
}
if ( ! is_array( $categories ) ) {
$categories = array();
}
$uncat = esc_html__( 'Uncategorized', 'mainwp' );
$post_only = false;
if ( $post ) {
$post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
}
?>
ID, '_categories', true ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
$categories = explode( ',', $categories );
}
if ( ! is_array( $categories ) ) {
$categories = array();
}
$uncat = esc_html__( 'Uncategorized', 'mainwp' );
$post_only = false;
if ( $post ) {
$post_only = get_post_meta( $post->ID, '_post_to_only_existing_categories', true );
}
?>
'; ?>
'; ?>
post_status ) ? 'selected="selected"' : ''; ?>>
post_status ) ? 'selected="selected"' : ''; ?>>
post_status ) ? 'selected="selected"' : ''; ?>>
post_status ) {
$post->post_password = '';
$visibility = 'private';
} elseif ( ! empty( $post->post_password ) ) {
$visibility = 'password';
} elseif ( 'bulkpost' === $post_type && is_sticky( $post->ID ) ) {
$visibility = 'public';
} else {
$visibility = 'public';
}
?>
post_status ) ? '' : 'selected="selected"'; ?>>
post_status ) ? 'selected="selected"' : ''; ?>>
post_status ) ? '' : 'style="display:none"'; ?>>
ID : 0;
static::render_addedit( $post_id, 'BulkAdd' );
}
/**
* Method render_bulk_edit()
*
* Check if user has rights,
* render the bulk edit tab.
*
* @return string Bulk edit tab html.
*/
public static function render_bulk_edit() {
if ( ! \mainwp_current_user_can( 'dashboard', 'manage_posts' ) ) {
\mainwp_do_not_have_permissions( esc_html__( 'manage posts', 'mainwp' ) );
return;
}
// phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$post_id = isset( $_GET['post_id'] ) ? intval( $_GET['post_id'] ) : 0;
// phpcs:enable
static::render_addedit( $post_id, 'BulkEdit' );
}
/**
* Method render_bulk_addedit()
*
* Render both the Add & Edit tabs.
*
* @param mixed $post_id post ID.
* @param mixed $what what tab is active.
*/
public static function render_addedit( $post_id, $what ) {
static::render_header( $what, $post_id );
static::render_bulkpost( $post_id, 'bulkpost' );
static::render_footer( $what );
}
/**
* Method hook_posts_search_handler()
*
* Hook Posts Search handler.
*
* @param mixed $data search data.
* @param object $website child site object.
* @param mixed $output output.
*
* @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response()
*/
public static function hook_posts_search_handler( $data, $website, &$output ) {
$posts = array();
if ( 0 < preg_match( '/
(.*)<\/mainwp>/', $data, $results ) ) {
$result = $results[1];
$posts = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
unset( $results );
}
$output->results[ $website->id ] = $posts;
}
/**
* Method mainwp_help_content()
*
* Creates the MainWP Help Documentation List for the help component in the sidebar.
*/
public static function mainwp_help_content() {
// phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( isset( $_GET['page'] ) && ( 'PostBulkManage' === $_GET['page'] || 'PostBulkAdd' === $_GET['page'] ) ) {
?>
*
* @since 4.1
*/
do_action( 'mainwp_posts_help_item' );
?>