2017-11-01 1 views
0

WordPress 게시물의 내용이 필요한지 알고 싶습니다. 나는 사용자가 내용없이 게시물을 저장할 수 있기를 원하지 않는다. 내가 어떻게 할 수 있는지 알고 있니?WordPress에 게시 할 내용이 필요합니다.

감사합니다.

+0

T 사용자가 우회 할 수 있다는 완벽한 검증이 필요하지 않은 경우 JavaScript가 가장 쉬울 것입니다. 스크립트를 추가하려면'admin_enqueue_scripts' 훅을 사용하십시오. – janh

답변

0

먼저 관리자 조치

add_action('admin_enqueue_scripts', array($this, 'my_admin_scripts')); 

function my_admin_scripts($page) { 
    global $post; 

    if ($page == "post-new.php" OR $page == "post.php") { 
     wp_register_script('my-custom-admin-scripts', plugins_url('/js/my-admin-post.js',dirname(__FILE__)), array('jquery', 'jquery-ui-sortable') , null, true); 
     wp_enqueue_script('my-custom-admin-scripts');    
    }   
} 

에 사용자 지정 스크립트를 추가하고 다음 JS 코드에서 JQuery와에 의해 필요한 atribute를 넣어 (/js/my-admin-post.js) :

// JavaScript Document 
jQuery(document).ready(function($) { 
    $('#title').attr('required', true); 
    $('#content').attr('required', true); 
    $('#_my_custom_field').attr('required', true); 
}); 
0

당신은 아무 내용이없는 경우 그러나 당신이 초안 상태로 게시물을 강제 수, PHP를 사용하여 저장되는 게시물을 막을 수 없다 :

function bb_47052258_check_post_status($post_id){ 

    // Return if this is a revision post 
    if (wp_is_post_revision($post_id)){ 
     return; 
    } 

    // Get the post 
    $post = get_post($post_id); 

    // (Optional) Return if the post is not a "post" post-type 
    if($post->post_type != 'post'){ 
     return; 
    } 

    // Return if the post content is not an empty string 
    if($post->post_content !== ''){ 
     return; 
    }   

    // Remove this action to prevent an infinite loop 
    remove_action('save_post', 'bb_47052258_check_post_status'); 

    // Update the post status 
    wp_update_post(array(
     'ID'   => $post->ID, 
     'post_status' => 'draft' 
    )); 

    // Add this action back again 
    add_action('save_post', 'bb_47052258_check_post_status'); 
} 

// Initially add the action 
add_action('save_post', 'bb_47052258_check_post_status'); 
관련 문제