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; }
function run($atts = array(), $content = '') { $errors = am4Errors::getInstance(); if (!am4PluginsManager::getAPI()->isLoggedIn()) { return do_shortcode($errors->get($atts['guest_error'])); } if (!am4PluginsManager::getAPI()->isUserActive()) { return do_shortcode($errors->get($atts['user_error'])); } $access = new am4UserAccess(); //User is logged in let's check his access level; if ($atts['have']) { $records = $this->convertToAccessRequirement($atts['have']); if (!$access->anyTrue($records)) { return do_shortcode($errors->get($atts['user_error'])); } } if ($atts['not_have']) { $records = $this->convertToAccessRequirement($atts['not_have']); if (!$access->allFalse($records)) { return do_shortcode($errors->get($atts['user_error'])); } } return do_shortcode($content); }
function haveAccess($requirements, am4_Settings_Abstract $settings) { $access = new am4UserAccess(); if ($settings->{'affiliate'} && $access->isAffiliate()) { return true; } return $access->anyTrue($requirements); }
function run($atts = array(), $content = '') { if (!is_array($atts)) { $atts = array(); } if (am4PluginsManager::skipProtection()) { return do_shortcode($content); } if (array_key_exists('notactive', $atts)) { return $this->getPlugin()->getShortCodeByName('am4guest')->run($atts, $content); } $errors = new am4_Settings_Error(); if (!am4PluginsManager::getAPI()->isLoggedIn()) { return do_shortcode($errors->getTextByName(@$atts['guest_error'])); } if (!am4PluginsManager::getAPI()->isUserActive()) { return do_shortcode($errors->getTextByName(@$atts['user_error'])); } $access = new am4UserAccess(); //User is logged in let's check his access level; if (!empty($atts['have'])) { $records = $this->convertToAccessRequirement(@$atts['have']); if (!$access->anyTrue($records)) { return do_shortcode($errors->getTextByName(@$atts['user_error'])); } } if (!empty($atts['not_have'])) { $records = $this->convertToAccessRequirement(@$atts['not_have']); if (!$access->allFalse($records)) { return do_shortcode($errors->getTextByName(@$atts['user_error'])); } } return do_shortcode($content); }
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; }