Skip to content

Instantly share code, notes, and snippets.

@suth
Created March 5, 2015 16:04
Show Gist options
  • Save suth/301708ddd7e8e4d36bc4 to your computer and use it in GitHub Desktop.
Save suth/301708ddd7e8e4d36bc4 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Video Importer Temporary Drafts
Plugin URI: https://refactored.co
Description: Temporarily saves imported posts as a draft so any publishing logic doesn't run until custom fields are saved
Version: 1.0
Author: Refactored Co.
Author URI: https://refactored.co
*/
function temporarily_save_imported_video_as_draft( $post ) {
$post['post_status'] = 'draft';
return $post;
}
add_filter( 'refactored_video_importer/post_array', 'temporarily_save_imported_video_as_draft', 10, 1 );
function update_imported_video_status_after_saving_custom_fields( $post_id, $provider, $video_array, $source_id, $import_options ) {
if ( $import_options['post_status'] != 'draft' ) {
$post = array(
'ID' => $post_id,
'post_status' => $import_options['post_status']
);
wp_update_post( $post );
}
}
add_action( 'refactored_video_importer/single_video_imported', 'update_imported_post_status_after_saving_custom_fields', 15, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment