Plugin Directory

Changeset 425987


Ignore:
Timestamp:
08/19/2011 07:03:01 PM (15 years ago)
Author:
btks
Message:

Version 0.1.3

Location:
wordpress-restrictions
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • wordpress-restrictions/tags/0.1.3/readme.txt

    r425713 r425987  
    33Donate link: http://sonicedges.com/
    44Tags: wordpress, restrictions, permissions, capabilities, users, roles
    5 Requires at least: 3.0
     5Requires at least: 3.1
    66Tested up to: 3.2.1
    7 Stable tag: 0.1.2
     7Stable tag: 0.1.3
    88
    99WordPress Restrictions allows you to set restrictions on when and what content can be edited/deleted on your WordPress Install.
     
    1616
    1717<ul>
    18     <li>Options to set a timeframe (in days) when editors and authors can delete or edit posts.</li>
     18    <li>Options to set a timeframe (in days) when editors / authors can delete or edit posts.</li>
    1919    <li>Options to set a timeframe (in days) when editors can delete or edit pages.</li>
    2020    <li>Options to exclude certain Users, Posts, and Pages from restrictions set within WordPress Restrictions.</li>
     21    <li>Options to set a limit on the number of posts an author / edit may make each day.</li>
    2122</ul>
    2223
  • wordpress-restrictions/tags/0.1.3/wp-restrictions.php

    r425713 r425987  
    44Plugin URI: http://sonicedges.com/plugins/wordpress-restrictions/
    55Description: With WordPress Restrictions, you can specify when and what content may be edited/deleted by Editors and/or Authors.
    6 Version: 0.1.2
     6Version: 0.1.3
    77Author: Brandon Smith
    88Author URI: http://sonicedges.com/
    99*/
    1010
    11 define('WP_REST_VERSION', '0.1.2');
     11define('WP_REST_VERSION', '0.1.3');
     12define('WP_REST_CURR_DAY', date("j"));
     13define('WP_REST_CURR_MONTH', date("n"));
     14define('WP_REST_CURR_YEAR', date("Y"));
     15
     16function wp_restrictions() {
     17    wp_restrictions::get_user_role(); // Define Current User's Role
     18    wp_restrictions::get_user_id(); // Define Current User's ID
     19    wp_restrictions_max_posts(); // Restricts # of Posts per Day
     20}
     21
     22class wp_restrictions {
     23    public function get_user_role() {
     24        if (current_user_can('editor') || current_user_can('author')) {
     25            if (current_user_can('editor')) {
     26                $role = 'editor';
     27            } else {
     28                $role = 'author';
     29            }
     30        }
     31        define('WP_REST_ROLE', $role);
     32    }
     33    public function get_user_id() {
     34        global $current_user;
     35        get_currentuserinfo();
     36        $user_id = $current_user->ID;
     37        define('WP_REST_UID', $user_id);
     38    }
     39}
    1240
    1341function wp_restrictions_excluded_user($user_id) {
     
    249277                    'edit_post' => $_POST['editor_edit_posts'],
    250278                    'delete_page' => $_POST['editor_delete_pages'],
    251                     'edit_page' => $_POST['editor_edit_pages']
     279                    'edit_page' => $_POST['editor_edit_pages'],
     280                    'max_posts' => $_POST['editor_max_posts']
    252281                ),
    253282                'author' => array(
    254283                    'delete_post' => $_POST['author_delete_posts'],
    255                     'edit_post' => $_POST['author_edit_posts']
     284                    'edit_post' => $_POST['author_edit_posts'],
     285                    'max_posts' => $_POST['author_max_posts']
    256286                ),
    257287                'excluded' => array(
     
    279309    <h3>WordPress Restrictions</h3>
    280310    <p>I (Brandon Smith) developed WordPress Restrictions to offer an easier and more practicable solution to control what can be edited/deleted on your WordPress Install. While several other plugins already allow you to modify WordPress User Roles and Capabilities, they require that you tweak the default settings of each user role or create a new user role (which can get a bit confusing for the average webmaster). With WordPress Restrictions, you can specify when and what content may be edited by Editors and/or Authors. If you need help or assistance, or would like to submit a feature request, please contact me at btks1995@gmail.com.</p>
    281     <form name="wp_role_security" method="POST" action="">
     311    <form name="wordpress_restrictions" method="POST" action="">
    282312    <h3>Restrictions for Editors</h3>
    283313    <label>Delete Posts Timeframe (In Days): </label><input type="text" name="editor_delete_posts" value="<?php echo $wp_restrictions['editor']['delete_post']; ?>" /><span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be deletable by <strong>EDITORS</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
     
    285315    <label>Edit Posts Timeframe (In Days): </label><input type="text" name="editor_edit_posts" value="<?php echo $wp_restrictions['editor']['edit_post']; ?>" /> <span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be editable by <strong>EDITORS</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
    286316    <label>Edit Pages Timeframe (In Days): </label><input type="text" name="editor_edit_pages" value="<?php echo $wp_restrictions['editor']['edit_page']; ?>" /> <span style="margin-left: 5px;">Specify a Number of Days. A page published on 8-16-2011 would be deletable by <strong>EDITORS</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
     317    <label>Max Number of Posts a Day: </label><input type="text" name="editor_max_posts" value="<?php echo $wp_restrictions['editor']['max_posts']; ?>" /> <span style="margin-left: 5px;">Specify a Number. If you input a number of '5', then each <strong>EDITOR</strong> can make up to 5 posts within 24 hours.</span><br />
    287318
    288319    <h3>Restrictions for Authors</h3>
    289320    <label>Delete Posts Timeframe (In Days): </label><input type="text" name="author_delete_posts" value="<?php echo $wp_restrictions['author']['delete_post']; ?>" /><span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be deletable by the <strong>AUTHOR</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
    290321    <label>Edit Posts Timeframe (In Days): </label><input type="text" name="author_edit_posts" value="<?php echo $wp_restrictions['author']['edit_post']; ?>" /> <span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be editable by the <strong>AUTHOR</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
     322    <label>Max Number of Posts a Day: </label><input type="text" name="author_max_posts" value="<?php echo $wp_restrictions['author']['max_posts']; ?>" /> <span style="margin-left: 5px;">Specify a Number. If you input a number of '5', then each <strong>AUTHOR</strong> can make up to 5 posts within 24 hours.</span><br />
    291323
    292324    <h3>Exclude Restrictions</h3>
     
    316348}
    317349
     350function wp_restrictions_max_posts() {
     351    global $wp_query;
     352    if (WP_REST_ROLE == 'editor' || WP_REST_ROLE == 'author' && !wp_restrictions_excluded_user(WP_REST_UID)) {
     353        $wp_query = new WP_Query(array('author' => WP_REST_UID, 'monthnum' => WP_REST_CURR_MONTH, 'day' => WP_REST_CURR_DAY, 'year' => WP_REST_CURR_YEAR));
     354        while($wp_query->have_posts()) : $wp_query->the_post();
     355            $post_count = $wp_query->post_count;
     356        endwhile;
     357        wp_reset_postdata();
     358
     359        $wp_restrictions = get_option('wp_restrictions');
     360        $max_posts = $wp_restrictions[WP_REST_ROLE]['max_posts'];
     361
     362        if ($post_count >= $wp_restrictions[WP_REST_ROLE]['max_posts']) {
     363            remove_submenu_page('edit.php', 'post-new.php');
     364
     365            if (strpos($_SERVER['REQUEST_URI'], 'post-new.php')) {
     366                    wp_die("You're only allowed to publish $max_posts posts within 24 hours. Please try again tomorrow.");
     367            }
     368        }
     369    }
     370}
     371
    318372function wp_restrictions_uninstall() {
    319373    delete_option('wp_restrictions');
     
    321375}
    322376
    323 add_action('admin_init', 'wp_restrictions_user_role');
     377// WordPress Restrictions Actions
     378add_action('admin_init', 'wp_restrictions');
    324379add_action('admin_menu', 'wp_restrictions_menu');
     380
     381// WordPress Restrictions Filters
    325382add_filter('map_meta_cap', 'wp_restrictions_mmc', 10, 4);
    326383
  • wordpress-restrictions/trunk/readme.txt

    r425713 r425987  
    33Donate link: http://sonicedges.com/
    44Tags: wordpress, restrictions, permissions, capabilities, users, roles
    5 Requires at least: 3.0
     5Requires at least: 3.1
    66Tested up to: 3.2.1
    7 Stable tag: 0.1.2
     7Stable tag: 0.1.3
    88
    99WordPress Restrictions allows you to set restrictions on when and what content can be edited/deleted on your WordPress Install.
     
    1616
    1717<ul>
    18     <li>Options to set a timeframe (in days) when editors and authors can delete or edit posts.</li>
     18    <li>Options to set a timeframe (in days) when editors / authors can delete or edit posts.</li>
    1919    <li>Options to set a timeframe (in days) when editors can delete or edit pages.</li>
    2020    <li>Options to exclude certain Users, Posts, and Pages from restrictions set within WordPress Restrictions.</li>
     21    <li>Options to set a limit on the number of posts an author / edit may make each day.</li>
    2122</ul>
    2223
  • wordpress-restrictions/trunk/wp-restrictions.php

    r425713 r425987  
    44Plugin URI: http://sonicedges.com/plugins/wordpress-restrictions/
    55Description: With WordPress Restrictions, you can specify when and what content may be edited/deleted by Editors and/or Authors.
    6 Version: 0.1.2
     6Version: 0.1.3
    77Author: Brandon Smith
    88Author URI: http://sonicedges.com/
    99*/
    1010
    11 define('WP_REST_VERSION', '0.1.2');
     11define('WP_REST_VERSION', '0.1.3');
     12define('WP_REST_CURR_DAY', date("j"));
     13define('WP_REST_CURR_MONTH', date("n"));
     14define('WP_REST_CURR_YEAR', date("Y"));
     15
     16function wp_restrictions() {
     17    wp_restrictions::get_user_role(); // Define Current User's Role
     18    wp_restrictions::get_user_id(); // Define Current User's ID
     19    wp_restrictions_max_posts(); // Restricts # of Posts per Day
     20}
     21
     22class wp_restrictions {
     23    public function get_user_role() {
     24        if (current_user_can('editor') || current_user_can('author')) {
     25            if (current_user_can('editor')) {
     26                $role = 'editor';
     27            } else {
     28                $role = 'author';
     29            }
     30        }
     31        define('WP_REST_ROLE', $role);
     32    }
     33    public function get_user_id() {
     34        global $current_user;
     35        get_currentuserinfo();
     36        $user_id = $current_user->ID;
     37        define('WP_REST_UID', $user_id);
     38    }
     39}
    1240
    1341function wp_restrictions_excluded_user($user_id) {
     
    249277                    'edit_post' => $_POST['editor_edit_posts'],
    250278                    'delete_page' => $_POST['editor_delete_pages'],
    251                     'edit_page' => $_POST['editor_edit_pages']
     279                    'edit_page' => $_POST['editor_edit_pages'],
     280                    'max_posts' => $_POST['editor_max_posts']
    252281                ),
    253282                'author' => array(
    254283                    'delete_post' => $_POST['author_delete_posts'],
    255                     'edit_post' => $_POST['author_edit_posts']
     284                    'edit_post' => $_POST['author_edit_posts'],
     285                    'max_posts' => $_POST['author_max_posts']
    256286                ),
    257287                'excluded' => array(
     
    279309    <h3>WordPress Restrictions</h3>
    280310    <p>I (Brandon Smith) developed WordPress Restrictions to offer an easier and more practicable solution to control what can be edited/deleted on your WordPress Install. While several other plugins already allow you to modify WordPress User Roles and Capabilities, they require that you tweak the default settings of each user role or create a new user role (which can get a bit confusing for the average webmaster). With WordPress Restrictions, you can specify when and what content may be edited by Editors and/or Authors. If you need help or assistance, or would like to submit a feature request, please contact me at btks1995@gmail.com.</p>
    281     <form name="wp_role_security" method="POST" action="">
     311    <form name="wordpress_restrictions" method="POST" action="">
    282312    <h3>Restrictions for Editors</h3>
    283313    <label>Delete Posts Timeframe (In Days): </label><input type="text" name="editor_delete_posts" value="<?php echo $wp_restrictions['editor']['delete_post']; ?>" /><span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be deletable by <strong>EDITORS</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
     
    285315    <label>Edit Posts Timeframe (In Days): </label><input type="text" name="editor_edit_posts" value="<?php echo $wp_restrictions['editor']['edit_post']; ?>" /> <span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be editable by <strong>EDITORS</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
    286316    <label>Edit Pages Timeframe (In Days): </label><input type="text" name="editor_edit_pages" value="<?php echo $wp_restrictions['editor']['edit_page']; ?>" /> <span style="margin-left: 5px;">Specify a Number of Days. A page published on 8-16-2011 would be deletable by <strong>EDITORS</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
     317    <label>Max Number of Posts a Day: </label><input type="text" name="editor_max_posts" value="<?php echo $wp_restrictions['editor']['max_posts']; ?>" /> <span style="margin-left: 5px;">Specify a Number. If you input a number of '5', then each <strong>EDITOR</strong> can make up to 5 posts within 24 hours.</span><br />
    287318
    288319    <h3>Restrictions for Authors</h3>
    289320    <label>Delete Posts Timeframe (In Days): </label><input type="text" name="author_delete_posts" value="<?php echo $wp_restrictions['author']['delete_post']; ?>" /><span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be deletable by the <strong>AUTHOR</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
    290321    <label>Edit Posts Timeframe (In Days): </label><input type="text" name="author_edit_posts" value="<?php echo $wp_restrictions['author']['edit_post']; ?>" /> <span style="margin-left: 5px;">Specify a Number of Days. A post published on 8-16-2011 would be editable by the <strong>AUTHOR</strong> until 8-20-2011 if the timeframe was 4 Days.</span><br />
     322    <label>Max Number of Posts a Day: </label><input type="text" name="author_max_posts" value="<?php echo $wp_restrictions['author']['max_posts']; ?>" /> <span style="margin-left: 5px;">Specify a Number. If you input a number of '5', then each <strong>AUTHOR</strong> can make up to 5 posts within 24 hours.</span><br />
    291323
    292324    <h3>Exclude Restrictions</h3>
     
    316348}
    317349
     350function wp_restrictions_max_posts() {
     351    global $wp_query;
     352    if (WP_REST_ROLE == 'editor' || WP_REST_ROLE == 'author' && !wp_restrictions_excluded_user(WP_REST_UID)) {
     353        $wp_query = new WP_Query(array('author' => WP_REST_UID, 'monthnum' => WP_REST_CURR_MONTH, 'day' => WP_REST_CURR_DAY, 'year' => WP_REST_CURR_YEAR));
     354        while($wp_query->have_posts()) : $wp_query->the_post();
     355            $post_count = $wp_query->post_count;
     356        endwhile;
     357        wp_reset_postdata();
     358
     359        $wp_restrictions = get_option('wp_restrictions');
     360        $max_posts = $wp_restrictions[WP_REST_ROLE]['max_posts'];
     361
     362        if ($post_count >= $wp_restrictions[WP_REST_ROLE]['max_posts']) {
     363            remove_submenu_page('edit.php', 'post-new.php');
     364
     365            if (strpos($_SERVER['REQUEST_URI'], 'post-new.php')) {
     366                    wp_die("You're only allowed to publish $max_posts posts within 24 hours. Please try again tomorrow.");
     367            }
     368        }
     369    }
     370}
     371
    318372function wp_restrictions_uninstall() {
    319373    delete_option('wp_restrictions');
     
    321375}
    322376
    323 add_action('admin_init', 'wp_restrictions_user_role');
     377// WordPress Restrictions Actions
     378add_action('admin_init', 'wp_restrictions');
    324379add_action('admin_menu', 'wp_restrictions_menu');
     380
     381// WordPress Restrictions Filters
    325382add_filter('map_meta_cap', 'wp_restrictions_mmc', 10, 4);
    326383
Note: See TracChangeset for help on using the changeset viewer.