在设置的时间段后阻止发布更新和删除

时间:2014-07-20 作者:pereyra

正在尝试从here 到我的用例:

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

    // Bail out if we\'re not asking to edit or delete a post ...
    if( \'edit_post\' != $args[0] && \'delete_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;

    //if post is older than 30 days. Change it to meet your needs
    if( strtotime( $post->post_date ) < strtotime( \'-30 day\' ) ) {
         //Then disallow editing.
         $allcaps[$cap[0]] = FALSE;
    }
    return $allcaps;
}
add_filter( \'user_has_cap\', \'wpbeginner_restrict_editing\', 10, 3 );
这很有效,但是我如何使用秒或分钟,而不是天?比如说,“300秒”似乎不起作用。

1 个回复
SO网友:Caspar

PHP manual 可接受的单位strtotime() 是:

unit    ((\'sec\' | \'second\' | \'min\' | \'minute\' | \'hour\' | \'day\' | \'fortnight\' | \'forthnight\' | \'month\' | \'year\') \'s\'?) | \'weeks\' | daytext
尝试使用-300 second (不是seconds).

结束

相关推荐