Plugin Directory

Changeset 1384104


Ignore:
Timestamp:
04/01/2016 11:44:09 AM (10 years ago)
Author:
speedito
Message:

Rules for restriction - 1.3

Location:
restrict-partial-content/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • restrict-partial-content/trunk/readme.txt

    r1372172 r1384104  
    44Requires at least: 3.9.1
    55Tested up to: 4.4.2
    6 Stable tag: 1.2
     6Stable tag: 1.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    43435. condition => options are "any" and "all" - "any" will mean that any single parameter that matches the criteria will result in the protected content being shown. "all" will mean that only when all criteria is matched will the restricted content be shown.
    4444
     456. rule => Now you can define rules and use these easily. This gives the flexibility of changing the criteria in one location and having it apply everywhere that the rule has been used. If the rule parameter is used then it will overrule the other parameters.
     46
    4547Some examples
    4648Example 1
     
    5254This will show only when the user is logged in with a subscriber role and the open_time has passed
    5355
     56Example 3
     57[restrict rule="2"] secret here[/restrict]
     58This will apply rule with id 2. Rules can be defined from inside the WP dashboard.
     59
     60== Screenshots ==
     611. Restrict Rule Definition.png
     622. screenshot-2.png
     63
     64
    5465== Changelog ==
     66= 1.3 =
     67Now allows rules to be created and applied
     68
    5569= 1.2 =
    5670Added parameter "condition" for greater flexibility in controlling when the criteria matches
  • restrict-partial-content/trunk/restrict-partial-content.php

    r1370717 r1384104  
    44 * Plugin URI: http://wordpress.org/plugins/restrict-partial-content/
    55 * Description: This plugin helps to protect specific portion of the content
    6  * Version: 1.2
     6 * Version: 1.3
    77 * Author: Waqas Ahmed
    88 * Author URI: http://speedsoftsol.com
     
    1111
    1212
    13 
     13include 'restrict-rules.php';
    1414
    1515/** Rendering the output when the shortcode is placed **/
     
    2020        'allow_user' => 'all',
    2121        'message' => ' [This content is restricted. Either login with the correct access or wait till the content is available for everyone.] ',
    22         'open_time' => 'No Time'
     22        'open_time' => 'No Time',
     23        'rule' => 'None'
    2324    ), $atts ) );
    2425
     
    2930    $user_id_restrict = 1;
    3031
     32    //If rule is supplied then get the data from that rule
     33    if ($rule != 'None') {
     34        $rule_data = get_metadata ('post', $rule);
     35       
     36        $allow_role = $rule_data['allow_role'][0];
     37        $allow_user = $rule_data['allow_user'][0];
     38        $open_time = $rule_data['open_time'][0];
     39        $condition = $rule_data['open_condition'][0];
     40        $message = $rule_data['restrict_message'][0];
     41    }
     42   
    3143    //Find the server date
    3244    $server_date = strtotime(current_time('Y-m-d H:i:s')); // use current_time
    3345    //Calculate diff
    3446    $interval = 0;
    35     if ($open_time != 'No Time') {
     47    $open_time = trim($open_time);
     48    if ($open_time != 'No Time' && $open_time!="") {
    3649        $content_opening_date = strtotime($open_time);
    3750        $interval = $content_opening_date - $server_date;
     
    4356
    4457
    45     // Find current user role and ID
    46     $user_info = wp_get_current_user();
    47     $user_role = $user_info->roles[0];
    48     $user_id = $user_info->ID;
    49     $user_name = $user_info->user_login;
     58    // Find current user role and ID - only when a user is logged in
     59    if (is_user_logged_in()) {
     60        $user_info = wp_get_current_user();
     61        $user_role = $user_info->roles[0];
     62        $user_id = $user_info->ID;
     63        $user_name = $user_info->user_login;
     64   
     65        //Check for ids/names
     66        $user_list = explode (",", $allow_user);
     67        $user_list_trimmed = array_map('trim', $user_list);
     68        if ($user_id !== 0 && (in_array($user_id, $user_list_trimmed) || in_array($user_name, $user_list_trimmed) )) {
     69            $user_id_restrict = 0;
     70        }
    5071
    51     //Check for ids/names
    52     $user_list = explode (",", $allow_user);
    53     $user_list_trimmed = array_map('trim', $user_list);
    54     if ($user_id !== 0 && (in_array($user_id, $user_list_trimmed) || in_array($user_name, $user_list_trimmed) )) {
    55         $user_id_restrict = 0;
    56     }
    57 
    58     //Check for roles
    59     $allow_role = strtolower ($allow_role);
    60     $role_list = explode (",", $allow_role);
    61     $role_list_trimmed = array_map('trim', $role_list);
    62     if ( $user_id !== 0) {
    63         foreach ( $user_info->roles as $user_role ) {
    64             if ( in_array ($user_role, $role_list_trimmed) ) {
    65                 $user_role_restrict = 0;
     72        //Check for roles
     73        $allow_role = strtolower ($allow_role);
     74        $role_list = explode (",", $allow_role);
     75        $role_list_trimmed = array_map('trim', $role_list);
     76        if ( $user_id !== 0) {
     77            foreach ( $user_info->roles as $user_role ) {
     78                if ( in_array ($user_role, $role_list_trimmed) ) {
     79                    $user_role_restrict = 0;
     80                }
    6681            }
    6782        }
    6883    }
    69 
     84   
    7085    $condition = strtolower ($condition);
    7186    $condition = trim ($condition);
    7287
    7388    //Just in case someone puts in wrong condition - default to any
    74     if ($condition != "any" || $condition!= "all") {
     89    if ($condition != "any" && $condition!= "all") {
    7590        $condition="any";
    7691    }
Note: See TracChangeset for help on using the changeset viewer.