2012-06-06 2 views
0

거의 4-5 개월 이후 사용자 역할이 자동으로 특정 개수의 게시물 개수로 변경되는이 문제를 해결하기 위해 노력하고 있습니다. 만약 x 사용자가 < = 10 게시자라면 기여자 역할을 맡습니다. < = 20 저자 역할 ..Wordpress : 게시물 수에 조건부 역할 변경 근거

모든 사람들의 도움을 받아이 코드를 얻을 수있었습니다.

<?php 

add_action('save_post', 'update_roles'); 
    function update_roles($post_id) { 

     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 
      return $post_id; 

     // Get the author 
     $author = wp_get_current_user(); 

     // Set variables for current user information 
     $count = count_user_posts($author->ID); 
     $current_role = (array) get_user_meta($author->ID, 'wp_capabilities'); 

     get_currentuserinfo(); 
     global $user_level; 

     // Do the checks to see if they have the roles and if not update them. 
     if (($user_level != 10) && ($count > 3 && $count <= 5) && (array_key_exists('contributor', $current_role[0]))) { 
      $user_id_role = new WP_User($author->ID); 
      $user_id_role->set_role('author'); 

     } elseif (($user_level != 10) && ($count > 5 && $count <= 9) && (array_key_exists('author', $current_role[0]))) { 

      $user_id_role = new WP_User($author->ID); 
      $user_id_role->set_role('editor'); 

     } elseif ($user_level != 10){ 

      $user_id_role = new WP_User($author->ID); 
      $user_id_role->set_role('contributor'); 

     } return $post_id; 

    } 

?> 

이 코드는 약간의 시간과 약간의 시간은 전혀 반응하지 않습니다. 이 코드는 버그가 있으며 일단 어떻게 든 자동으로 역할을 변경하고 다시 역할을 아래쪽으로 변경하면 게시물 수가 자동으로 변경되지 않습니다. 게시물에 영향을 미치지 않는 것보다 게시물을 삭제해도 동일합니다. 그러나 항상 게시물 수를 고려해야하며 게시 횟수에 즉각적인 영향을 주어야합니다.

저는이 문제에 정말로 지치고 있지만, 전체 사이트는이 코드만을 기반으로합니다. 그래서 나는 위대한 사람들에게 도움을 필요로합니다.

감사합니다 많이 많이 많이 ..

답변

0

내가 있기 때문에 사용자의 역할을 시작하는 실수가 무슨 생각 : 사용자 레벨이 10과

if (($user_level != 10) && ($count > 3 && $count <= 5) && (array_key_exists( 'contributor', $current_role[0]))) { 
     $user_id_role = new WP_User($author->ID); 
     $user_id_role->set_role('author'); 

경우 게시물 개수가 3과 작은 이상의 전공은 5 세트의 사용자 역할과 같은

하지만 두 번째

} elseif (($user_level != 10) && ($count > 5 && $count <= 9) && (array_key_exists('author', $current_role[0]))) { 

     $user_id_role = new WP_User($author->ID); 
     $user_id_role->set_role('editor'); 

당신의 저자 예를 들어, 사용자가 4 개의 게시물을 게시하고 역할이 작성자 인 경우 조건부 태그가 작동하지 않으면 조건부 태그가 시작된다는 것을 다시 말하십시오.