Skip to content

Instantly share code, notes, and snippets.

@Xhynk
Created October 12, 2018 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xhynk/0b5f363c45ed16d6ab14598065eb01bd to your computer and use it in GitHub Desktop.
Save Xhynk/0b5f363c45ed16d6ab14598065eb01bd to your computer and use it in GitHub Desktop.
Update Bulk Content Masks
add_action( 'init', 'insert_content_masks' );
function insert_content_masks(){
$array_of_mask_urls = array(
'https://landing-page.com/page-1',
'https://landing-page.com/page-2',
'https://landing-page.com/page-3',
// …
'https://landing-page.com/page-xxx',
);
if( current_user_can( 'administrator' ) ){
$cm_args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
$cm_query = new WP_Query( $cm_args );
$count = 0;
if( $cm_query->have_posts() ){
while( $cm_query->have_posts() ){
$post_id = get_the_ID();
$errors = array();
// Set URL
if( ! update_post_meta( $post_id, 'content_mask_url', $array_of_mask_urls[$count] ) );
$errors[] = 'URL Set Failed on post '. $post_id;
// Enable Content Mask
if( ! update_post_meta( $post_id, 'content_mask_url', $array_of_mask_urls[$count] ) );
$errors[] = 'CM Enable Set Failed on post '. $post_id;
if( empty( $errors ) ){
$count++;
} else {
wp_die( 'Updating Failed on Post: '. $post_id );
}
}
wp_reset_postdata();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment