post_status;
if ( 'publish' === $post_status ) {
$post_status = get_post_meta( $id, '_edit_post_status', true );
}
/**
* Page status
*
* Sets page status when posting 'bulkpage' to child sites.
*
* @param int $id Page ID.
*
* @since Unknown
*/
$post_status = apply_filters( 'mainwp_posting_bulkpost_post_status', $post_status, $id );
$new_post = array(
'post_title' => $_post->post_title,
'post_content' => $_post->post_content,
'post_status' => $post_status,
'post_date' => $_post->post_date,
'post_date_gmt' => $_post->post_date_gmt,
'post_type' => 'page',
'post_name' => $post_slug,
'post_excerpt' => MainWP_Utility::esc_content( $_post->post_excerpt, 'mixed' ),
'post_password' => $_post->post_password,
'comment_status' => $_post->comment_status,
'ping_status' => $_post->ping_status,
'mainwp_post_id' => $_post->ID,
);
if ( ! empty( $featured_image_id ) ) {
$img = wp_get_attachment_image_src( $featured_image_id, 'full' );
$post_featured_image = $img[0];
$attachment = get_post( $featured_image_id );
$featured_image_data = array(
'alt' => get_post_meta( $featured_image_id, '_wp_attachment_image_alt', true ),
'caption' => MainWP_Utility::esc_content( $attachment->post_excerpt, 'mixed' ),
'description' => $attachment->post_content,
'title' => htmlspecialchars( $attachment->post_title ),
);
}
$galleries = get_post_galleries( $id, false );
$post_gallery_images = array();
if ( is_array( $galleries ) ) {
foreach ( $galleries as $gallery ) {
if ( isset( $gallery['ids'] ) ) {
$attached_images = explode( ',', $gallery['ids'] );
foreach ( $attached_images as $attachment_id ) {
$attachment = get_post( $attachment_id );
if ( $attachment ) {
$post_gallery_images[] = array(
'id' => $attachment_id,
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => MainWP_Utility::esc_content( $attachment->post_excerpt, 'mixed' ),
'description' => $attachment->post_content,
'src' => $attachment->guid,
'image_url' => wp_get_attachment_image_url( $attachment_id ), // to fix src/guid missing the file name.
'title' => htmlspecialchars( $attachment->post_title ),
);
}
}
}
}
}
$dbwebsites = array();
if ( 'site' === $selected_by ) {
foreach ( $selected_sites as $k ) {
if ( MainWP_Utility::ctype_digit( $k ) ) {
$website = MainWP_DB::instance()->get_website_by_id( $k );
if ( '' === $website->sync_errors && ! MainWP_System_Utility::is_suspended_site( $website ) ) {
$dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields );
}
}
}
} elseif ( 'client' === $selected_by ) {
if ( is_array( $selected_clients ) ) {
$websites = MainWP_DB_Client::instance()->get_websites_by_client_ids(
$selected_clients,
array(
'select_data' => $data_fields,
)
);
if ( $websites ) {
foreach ( $websites as $website ) {
if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
continue;
}
$dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields );
}
}
}
} elseif ( 'group' === $selected_by ) {
foreach ( $selected_groups as $k ) {
if ( MainWP_Utility::ctype_digit( $k ) ) {
$websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_by_group_id( $k ) );
while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
if ( '' !== $website->sync_errors || MainWP_System_Utility::is_suspended_site( $website ) ) {
continue;
}
$dbwebsites[ $website->id ] = MainWP_Utility::map_site( $website, $data_fields );
}
MainWP_DB::free_result( $websites );
}
}
}
$output = new \stdClass();
$output->ok = array();
$output->errors = array();
if ( ! empty( $dbwebsites ) ) {
// prepare $post_custom values.
$new_post_custom = array();
foreach ( $post_custom as $meta_key => $meta_values ) {
$new_meta_values = array();
foreach ( $meta_values as $key_value => $meta_value ) {
if ( is_serialized( $meta_value ) ) {
$meta_value = unserialize( $meta_value ); // phpcs:ignore -- internal value safe.
}
$new_meta_values[ $key_value ] = $meta_value;
}
$new_post_custom[ $meta_key ] = $new_meta_values;
}
$post_data = array(
'new_post' => base64_encode( wp_json_encode( $new_post ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
'post_custom' => base64_encode( wp_json_encode( $new_post_custom ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
'post_featured_image' => ( null !== $post_featured_image ) ? base64_encode( $post_featured_image ) : null, // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
'post_gallery_images' => base64_encode( wp_json_encode( $post_gallery_images ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
'mainwp_upload_dir' => base64_encode( wp_json_encode( $mainwp_upload_dir ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
'featured_image_data' => ( null !== $featured_image_data ) ? base64_encode( wp_json_encode( $featured_image_data ) ) : null, // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible.
);
/**
* Posting new page
*
* Sets Page data to post to child sites.
*
* @param int $id Page ID.
*
* @since Unknown
*/
$post_data = apply_filters( 'mainwp_bulkpage_posting', $post_data, $id );
MainWP_Connect::fetch_urls_authed( $dbwebsites, 'newpost', $post_data, array( MainWP_Bulk_Add::get_class_name(), 'posting_bulk_handler' ), $output );
}
foreach ( $dbwebsites as $website ) {
if ( isset( $output->ok[ $website->id ] ) && ( 1 === (int) $output->ok[ $website->id ] ) && ( isset( $output->added_id[ $website->id ] ) ) ) {
$links = isset( $output->link[ $website->id ] ) ? $output->link[ $website->id ] : null;
do_action_deprecated( 'mainwp-post-posting-page', array( $website, $output->added_id[ $website->id ], $links ), '4.0.7.2', 'mainwp_post_posting_page' ); // @deprecated Use 'mainwp_post_posting_page' instead. NOSONAR - not IP.
do_action_deprecated( 'mainwp-bulkposting-done', array( $_post, $website, $output ), '4.0.7.2', 'mainwp_bulkposting_done' ); // @deprecated Use 'mainwp_bulkposting_done' instead. NOSONAR - not IP.
/**
* Posting page
*
* Fires while posting page.
*
* @param object $website Object containing child site data.
* @param int $output->added_id[ $website->id ] Child site ID.
* @param array $links Links.
*
* @since Unknown
*/
do_action( 'mainwp_post_posting_page', $website, $output->added_id[ $website->id ], $links );
/**
* Posting page completed
*
* Fires after the page posting process is completed.
*
* @param array $_post Array containing the post data.
* @param object $website Object containing child site data.
* @param array $output Output data.
*
* @since Unknown
*/
do_action( 'mainwp_bulkposting_done', $_post, $website, $output );
}
}
/**
* After posting a new page
*
* Sets data after the posting process to show the process feedback.
*
* @param array $_post Array containing the post data.
* @param array $dbwebsites Array containing processed sites.
* @param array $output Output data.
*
* @since Unknown
*/
$after_posting = apply_filters_deprecated( 'mainwp-after-posting-bulkpage-result', array( false, $_post, $dbwebsites, $output ), '4.0.7.2', 'mainwp_after_posting_bulkpage_result' ); // @deprecated Use 'mainwp_after_posting_bulkpage_result' instead. NOSONAR - not IP.
$after_posting = apply_filters( 'mainwp_after_posting_bulkpage_result', $after_posting, $_post, $dbwebsites, $output );
if ( false === $after_posting ) {
?>
name ) ); ?>
: ok[ $website->id ] ) && 1 === (int) $output->ok[ $website->id ] ? esc_html( $succes_message ) . '
View Page' : 'ERROR: ' . $output->errors[ $website->id ]; // phpcs:ignore WordPress.Security.EscapeOutput ?>
ok[ $website->id ] ) && 1 === (int) $output->ok[ $website->id ] ) {
++$countSites;
++$countRealItems;
}
}
}
} else {
?>