Exemple #1
0
 function isWidgetAvailable($widget, $instance)
 {
     $api = am4PluginsManager::getAPI();
     // Allow to see all widgets for admin users;
     if (am4PluginsManager::skipProtection()) {
         return true;
     }
     if (in_array('guest', (array) $instance['access'])) {
         return $api->isLoggedIn() ? false : true;
     }
     // Check access options;
     $access = new am4UserAccess();
     $not_have = true;
     if (in_array('not_have', (array) $instance['access'])) {
         if ($access->allFalse(am4AccessRequirement::createRequirements($instance['not_have']))) {
             $not_have = true;
         } else {
             $not_have = false;
         }
     }
     $have = true;
     if (in_array('have', (array) $instance['access'])) {
         if ($access->anyTrue(am4AccessRequirement::createRequirements($instance['have']))) {
             $have = true;
         } else {
             $have = false;
         }
     }
     return $have && $not_have;
 }
 function isWidgetAvailable($widget, $instance)
 {
     $api = am4PluginsManager::getAPI();
     // Allow to see all widgets for admin users;
     if (current_user_can("manage_options")) {
         return true;
     }
     if (!$api->isLoggedIn()) {
         if (in_array('guest', (array) $instance['access'])) {
             return true;
         }
         return false;
     }
     // Check access options;
     $access = new am4UserAccess();
     if (in_array('not_have', (array) $instance['access']) && $access->allFalse(am4AccessRequirement::createRequirements($instance['not_have']))) {
         return true;
     }
     if (in_array('have', (array) $instance['access']) && $access->anyTrue(am4AccessRequirement::createRequirements($instance['have']))) {
         return true;
     }
     return false;
 }
Exemple #3
0
 function filter_WpNavMenuObjects($items, $args)
 {
     if (am4PluginsManager::skipProtection()) {
         return $items;
     }
     $access = new am4UserAccess();
     $type = $access->isLoggedIn() ? "user" : "guest";
     foreach ($items as $id => $i) {
         switch ($i->object) {
             case 'page':
             case 'post':
                 // get_page and get_post are identical;
                 $page = get_page($i->object_id);
                 $settings = $this->getPostAccess($page);
                 if ($settings->{'only_guest'}) {
                     if ($type != 'guest') {
                         unset($items['id']);
                     }
                 } else {
                     if ($settings->{'protected'} && !$this->haveAccess($this->getPostRequirements($page), $settings) && $settings->{$type . '_action_menu'} == 'hide') {
                         unset($items[$id]);
                     }
                 }
                 break;
             case 'category':
                 $settings = new am4_Settings_Category($i->object_id);
                 if ($settings->{'protected'} && !$this->haveAccess(am4AccessRequirement::createRequirements($settings->{'access'}), $settings) && $settings->{$type . '_action_cat_menu'} == 'hide') {
                     unset($items[$id]);
                 }
                 break;
         }
     }
     return $items;
 }
Exemple #4
0
 function checkRequirement(am4AccessRequirement $r)
 {
     foreach ($this->getRecords() as $a) {
         if ($r->checkAccess($a)) {
             return true;
         }
     }
     return false;
 }
 function filter_WpNavMenuObjects($items, $args)
 {
     if (current_user_can("manage_options")) {
         return $items;
     }
     $access = new am4UserAccess();
     $type = $access->isLoggedIn() ? "user" : "guest";
     foreach ($items as $id => $i) {
         switch ($i->object) {
             case 'page':
                 $page = get_page($i->object_id);
                 $settings = $this->getPostAccess($page);
                 if ($settings['protected'] && !$access->anyTrue($this->getPostRequirements($page)) && $settings[$type . '_action_menu'] == 'hide') {
                     unset($items[$id]);
                 }
                 break;
             case 'category':
                 $cat_settings = get_option(AM4_CAT_OPTION);
                 $settings = $cat_settings[$i->object_id];
                 if (!$settings) {
                     break;
                 }
                 if ($settings['protected'] && !$access->anyTrue(am4AccessRequirement::createRequirements($settings['access'])) && $settings[$type . '_action_cat_menu'] == 'hide') {
                     unset($items[$id]);
                 }
                 break;
         }
     }
     return $items;
 }