2017-12-27 8 views
1

사용자가 새 WordPress 게시물을 통해 새 태그를 만들려고 할 때 오류를 표시해야합니다.새 태그가 Wordpress에서 생성 될 때 오류 표시

예 : 분류 기준이 '편집자'인 사용자가 워드 프레스에서 새 게시물을 만들고 분류법에 존재하지 않는 태그를 추가합니다. 페이지 상단에 관리자 오류를 표시하고 싶습니다. 게시 또는 업데이트.

이 새로운 태그를

add_action('create_term','undo_create_term',10, 3); 

function undo_create_term ($term_id, $tt_id, $taxonomy) { 
    if (!current_user_can('editor')) { 
     if($taxonomy == 'post_tag') { 
      wp_delete_term($term_id,$taxonomy); 
     } 
    } 
} 
+0

예! 그래서 현재 오류가 지속적으로 보여, 나는 사용자가 게시물에 새 태그를 추가하려고 할 때만 표시해야합니다. –

+0

코드의 해당 부분을 포함하도록 위의 내용을 편집했습니다 –

답변

0

당신은 일시적 변수 또는 유사한 전략을 수립해야 할 것이다 감지 코드입니다

function my_error_notice() { 
if (!current_user_can('editor')) { 
    ?> 
    <div class="error notice"> 
     <p><?php _e('Sorry only the Administrators are allowed to create new tags, please select from the prepopulated suggestions or contact an Administrator for more assistence.', 'my_plugin_textdomain'); ?></p> 
    </div> 
    <?php 
} 

add_action('admin_notices', 'my_error_notice'); 

오류를 보여줍니다 내 코드입니다 WP 때문에 게시물을 저장 한 후 리디렉션합니다.

다음은 기본적인 아이디어입니다. 응용 프로그램에서 작동하도록 조정하는 것은 사용자의 몫입니다.

function my_error_notice() { 
    $show_notice = get_transient('show_post_tag_notice'); 
    if (! $show_notice) { 
     return; 
    } 

    delete_transient('show_post_tag_notice'); 

    if (!current_user_can('editor')) { ?> 
    <div class="error notice"> 
     <p><?php _e('Sorry only the Administrators are allowed to create new tags, please select from the prepopulated suggestions or contact an Administrator for more assistence.', 'my_plugin_textdomain'); ?></p> 
    </div> 
    <?php 
    } 
} 

add_action('admin_notices', 'my_error_notice'); 

add_action('create_term','undo_create_term',10, 3); 

function undo_create_term ($term_id, $tt_id, $taxonomy) { 
    if (!current_user_can('editor')) { 
     if($taxonomy == 'post_tag') { 
      wp_delete_term($term_id,$taxonomy); 
      set_transient('show_post_tag_notice', true); 
     } 
    } 
} 
+0

이것이 필요한 부분에 적합합니다. 양해 해 주셔서 감사합니다. –