Changeset 1384104
- Timestamp:
- 04/01/2016 11:44:09 AM (10 years ago)
- Location:
- restrict-partial-content/trunk
- Files:
-
- 1 added
- 2 edited
-
readme.txt (modified) (3 diffs)
-
restrict-partial-content.php (modified) (5 diffs)
-
restrict-rules.php (added)
Legend:
- Unmodified
- Added
- Removed
-
restrict-partial-content/trunk/readme.txt
r1372172 r1384104 4 4 Requires at least: 3.9.1 5 5 Tested up to: 4.4.2 6 Stable tag: 1. 26 Stable tag: 1.3 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 43 43 5. 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. 44 44 45 6. 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 45 47 Some examples 46 48 Example 1 … … 52 54 This will show only when the user is logged in with a subscriber role and the open_time has passed 53 55 56 Example 3 57 [restrict rule="2"] secret here[/restrict] 58 This will apply rule with id 2. Rules can be defined from inside the WP dashboard. 59 60 == Screenshots == 61 1. Restrict Rule Definition.png 62 2. screenshot-2.png 63 64 54 65 == Changelog == 66 = 1.3 = 67 Now allows rules to be created and applied 68 55 69 = 1.2 = 56 70 Added parameter "condition" for greater flexibility in controlling when the criteria matches -
restrict-partial-content/trunk/restrict-partial-content.php
r1370717 r1384104 4 4 * Plugin URI: http://wordpress.org/plugins/restrict-partial-content/ 5 5 * Description: This plugin helps to protect specific portion of the content 6 * Version: 1. 26 * Version: 1.3 7 7 * Author: Waqas Ahmed 8 8 * Author URI: http://speedsoftsol.com … … 11 11 12 12 13 13 include 'restrict-rules.php'; 14 14 15 15 /** Rendering the output when the shortcode is placed **/ … … 20 20 'allow_user' => 'all', 21 21 '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' 23 24 ), $atts ) ); 24 25 … … 29 30 $user_id_restrict = 1; 30 31 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 31 43 //Find the server date 32 44 $server_date = strtotime(current_time('Y-m-d H:i:s')); // use current_time 33 45 //Calculate diff 34 46 $interval = 0; 35 if ($open_time != 'No Time') { 47 $open_time = trim($open_time); 48 if ($open_time != 'No Time' && $open_time!="") { 36 49 $content_opening_date = strtotime($open_time); 37 50 $interval = $content_opening_date - $server_date; … … 43 56 44 57 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 } 50 71 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 } 66 81 } 67 82 } 68 83 } 69 84 70 85 $condition = strtolower ($condition); 71 86 $condition = trim ($condition); 72 87 73 88 //Just in case someone puts in wrong condition - default to any 74 if ($condition != "any" ||$condition!= "all") {89 if ($condition != "any" && $condition!= "all") { 75 90 $condition="any"; 76 91 }
Note: See TracChangeset
for help on using the changeset viewer.