0

Wordpress で、( Capabilitiesに基づいて) ユーザーがカスタムの時間後に公開された投稿を編集できないようにするにはどうすればよいですか。

たとえば、投稿が 3 日以上経過している投稿を編集できるユーザー (作成者) は編集できず、投稿が 20 日以上経過している投稿を編集できるユーザーpublish_posts(編集moderate_comments者) は編集できません。もちろん、管理者はいつでも編集できます。

そのようなことはどのように可能ですか?

4

2 に答える 2

1

これはwordpress.stackexchange.com に関する質問の複製です。以下に私の答えをコピーしました。

Wordpress のuser_has_cap フィルター コーデックス ページからサンプル コードを取得し、それを変更しました。次のコードをテーマの functions.php に追加します。

function restrict_editing_old_posts( $allcaps, $cap, $args ) {

  // Bail out if we're not asking to edit a post ...
  if( 'edit_post' != $args[0]
    // ... or user is admin
    || ! empty( $allcaps['manage_options'] )
    // ... or user already cannot edit the post
    || empty( $allcaps['edit_posts'] ) )
      return $allcaps;

  // Load the post data:  
  $post = get_post( $args[2] );

  // Bail out if the post isn't published:    
  if( 'publish' != $post->post_status )
      return $allcaps;

  $post_date = strtotime( $post->post_date );
  //if post is older than 30 days ... 
  if( $post_date < strtotime( '-30 days' )
    // ... or if older than 4 days and user is not Editor
    || ( empty($allcaps['moderate_comments']) 
    && $post_date < strtotime('-4 days') ) ) {
      $allcaps[$cap[0]] = FALSE;  
  }
  return $allcaps;
}
add_filter( 'user_has_cap', 'restrict_editing_old_posts', 10, 3 );
于 2012-10-19T15:58:49.963 に答える
-1

これはプラグイン内で機能するはずです

    function remove_edit() {

    // Adjust 604800 to the number of days in seconds that you want to check against. Posts will only appear if they are newer than that time.//
     if ( !current_user_can( 'manage_options' ) && (current_user_can('edit_posts') && ((current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') * 3600) ) < 604800) )
     {
        unset( $actions['edit'] );
     }
   }
   add_filter('post_row_actions','remove_edit',10,1);

ワードプレスコーデックスからhttp://codex.wordpress.org/Roles_and_Capabilities#edit_posts

edit_posts
  Since 2.0
  Allows access to Administration Panel options:
   Posts
   Posts > Add New
   Comments
   Comments > Awaiting Moderation
于 2012-10-17T16:35:08.490 に答える