2011-07-28 6 views
1

基本的に私はWordPressにカスタムポストを保存しています。私はサーバー側でカスタム検証を行うことにしました。以下は私のコードを単純化したものです。私がここで抱えている問題は、チェックにもかかわらず、フィールドが満たされているにもかかわらず、それ自体が保留中のモードに降格しているようです。カスタムポスト検証とそれからサーバーサイドでチェックされた検証後に発行 - wordpress

add_action ('save_post', 'save_campaigns', 10, 2); 

add_action ('save_post', 'completion_validator', 20, 2); 

function save_campaigns($pid, $post) 
{ 
    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || $post->post_tatus == 'auto-draft') return $pid; 
    if ($post->post_type != 'work') return $pid; 

    update_post_meta($pid, 'campaign_client', $_POST['campaign_client']); 

} 

function completion_validator($pid, $post) 
{ 
    // don't do on autosave or when new posts are first created 
    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || $post->post_status == 'auto-draft') return $pid; 
    if ($post->post_type != 'work') return $pid; 

    // init completion marker (add more as needed) 
    $meta_missing = false; 

    // retrieve meta to be validated 
    $clientmeta = get_post_meta($pid, 'campaign_client', true); 

    // just checking it's not empty - you could do other tests... 
    if (empty($clientmeta) or empty($shortcopymeta) or empty($longcopymeta) or empty($gallerymeta) or empty($thumbnailmeta)) 
    { 
     $meta_missing = true; 
    } 

    // on attempting to publish - check for completion and intervene if necessary 
    if ((isset($_POST['publish']) || isset($_POST['save'])) && $_POST['post_status'] == 'publish') 
    { 
     // don't allow publishing while any of these are incomplete 
     if ($meta_missing == true) 
     { 
      global $wpdb; 
      $wpdb->update($wpdb->posts, array('post_status' => 'pending'), array('ID' =>$pid)); 
      // filter the query URL to change the published message 
      add_filter('redirect_post_location', create_function('$location','return add_query_arg("message", "4", $location);')); 

     } 
    } 
} 

答えて

0

投稿が公開されると、私の知る限り、それが呼び出す動作はpublish_postとなります。

関連する問題