ほぼ4〜5か月以来、特定の投稿数でユーザーの役割が自動的に変更されるというこの問題を解決しようとしています。xユーザーの投稿が10未満の場合、作成者の役割が20未満の場合、投稿者の役割になります。
あなたのすべての人々の助けを借りて、私はこのコードを達成することができました。
<?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;
}
?>
このコードはいつかは機能しますが、まったく反応しません。このコードはバグがあり、一度何らかの方法で役割を自動変更し、役割を再び下側に変更すると、投稿数ごとに自動変更されることはありません。投稿を削除しても、まったく影響がない場合も同じです。ただし、常に投稿数を考慮する必要があり、差し迫って投稿数に影響するはずです。
私は本当にこれに飽きていますが、私のサイト全体はこのコードのみに基づいています。だから私は本当にあなたに素晴らしい人々の助けが必要です。
どうもありがとうございました。