Beispiel #1
0
 /**
  * Retrieve Role based on ID
  *
  * @return WP_Role|null
  *
  * @access protected
  */
 protected function retrieveSubject()
 {
     $roles = new WP_Roles();
     $role = $roles->get_role($this->getId());
     if (is_null($role)) {
         aam_Core_Console::write('Role ' . $this->getId() . ' does not exist');
     } elseif (isset($role->capabilities)) {
         //add role capability as role id, weird WordPress behavior
         //example is administrator capability
         $role->capabilities[$this->getId()] = true;
     }
     return $role;
 }
 /**
  * Run the Manager
  *
  * @return string
  *
  * @access public
  */
 public function run()
 {
     //check if plugins/advanced-access-manager/extension is writable
     if (!is_writable(AAM_BASE_DIR . 'extension')) {
         aam_Core_Console::add(__('Folder advanced-access-manager/extension is not writable', 'aam'));
     }
     return $this->loadTemplate(dirname(__FILE__) . '/tmpl/extension.phtml');
 }
Beispiel #3
0
 /**
  *
  * @param type $zip
  * @return boolean
  */
 protected function insert($zip)
 {
     $response = true;
     if (is_wp_error(unzip_file($zip, $this->_basedir))) {
         aam_Core_Console::write('Failed to insert extension');
         $response = false;
     }
     return $response;
 }
 /**
  *
  * @param type $filename
  */
 protected function parseConfig($filename)
 {
     //include third party library
     if (!class_exists('Zend_Config')) {
         require_once AAM_LIBRARY_DIR . 'Zend/Exception.php';
         require_once AAM_LIBRARY_DIR . 'Zend/Config/Exception.php';
         require_once AAM_LIBRARY_DIR . 'Zend/Config.php';
         require_once AAM_LIBRARY_DIR . 'Zend/Config/Ini.php';
     }
     //parse ini file
     try {
         $this->setTree(new Zend_Config_Ini($filename));
     } catch (Zend_Config_Exception $e) {
         aam_Core_Console::add('ConfigPress parsing error');
     }
 }
Beispiel #5
0
 * Autoloader for project Advanced Access Manager
 *
 * Try to load a class if prefix is mvb_
 *
 * @param string $class_name
 */
function aam_autoload($class_name)
{
    $chunks = explode('_', strtolower($class_name));
    $prefix = array_shift($chunks);
    if ($prefix === 'aam') {
        $base_path = AAM_BASE_DIR . '/application';
        $path = $base_path . '/' . implode('/', $chunks) . '.php';
        if (file_exists($path)) {
            require $path;
        }
    }
}
spl_autoload_register('aam_autoload');
//make sure that we have always content dir
if (!file_exists(AAM_TEMP_DIR)) {
    if (@mkdir(AAM_TEMP_DIR)) {
        //silence the directory
        file_put_contents(AAM_TEMP_DIR . '/index.php', '');
    } else {
        aam_Core_Console::add(__('Failed to create wp-content/aam folder', 'aam'));
    }
} elseif (!is_writable(AAM_TEMP_DIR)) {
    aam_Core_Console::add(__('Folder wp-content/aam is not writable', 'aam'));
}
load_plugin_textdomain('aam', false, basename(AAM_BASE_DIR) . '/lang');
 /**
  * Bootstrap the Extension
  *
  * In case of any errors, the output can be found in console
  *
  * @param string $extension
  *
  * @return void
  *
  * @access protected
  */
 protected function bootstrapExtension($extension)
 {
     $bootstrap = $this->_basedir . "/{$extension}/index.php";
     if (file_exists($bootstrap) && !isset($this->_cache[$extension])) {
         //bootstrap the extension
         $this->_cache[$extension] = (require_once $bootstrap);
         //check if activation hook still present and trigger warning if yes
         if (file_exists($this->_basedir . "/{$extension}/activation.php")) {
             aam_Core_Console::add("Activation hook for {$extension} is not deleted");
         }
     }
 }
Beispiel #7
0
 /**
  *
  * @param type $param
  * @param type $default
  * @return type
  */
 protected function parseParam($param, $default)
 {
     if (is_object($param) && isset($param->userFunc)) {
         $func = trim($param->userFunc);
         if (is_string($func) && is_callable($func)) {
             $response = call_user_func($func);
         } else {
             aam_Core_Console::write("ConfigPress userFunc {$func} failure");
             $response = $default;
         }
     } else {
         $response = $param;
     }
     return $response;
 }
Beispiel #8
0
 /**
  * Trigger Subject native methods
  *
  * @param string $name
  * @param array  $arguments
  *
  * @return mixed
  *
  * @access public
  */
 public function __call($name, $arguments)
 {
     $subject = $this->getSubject();
     //make sure that method is callable
     if (method_exists($subject, $name)) {
         $response = call_user_func_array(array($subject, $name), $arguments);
     } else {
         aam_Core_Console::write("Method {$name} does not exist in " . get_class($subject));
         $response = null;
     }
     return $response;
 }