/** * Init function. */ public static function wpcf_access_plugins_loaded() { // Force roles initialization // WP is lazy and it does not initialize $wp_roles if user is not logged in. global $wp_roles; global $wpcf_access; // Set main global $wpcf_access $wpcf_access = new stdClass(); $model = TAccess_Loader::get('MODEL/Access'); if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } // Access works standalone now define('WPCF_PLUS', true); if (!defined('WPCF_ACCESS_DEBUG')) { define('WPCF_ACCESS_DEBUG', false); } // TODO Not used yet // Take a snapshot (to restore on deactivation???) /*$snapshot = get_option('wpcf_access_snapshot', array()); if (empty($snapshot)) { $snapshot = get_option('wp_user_roles', array()); update_option('wpcf_access_snapshot', $snapshot); }*/ // Settings $wpcf_access->settings = new stdClass(); // TYpes $wpcf_access->settings->types = $model->getAccessTypes(); // Taxonomies $wpcf_access->settings->tax = $model->getAccessTaxonomies(); // Third party $wpcf_access->settings->third_party = $model->getAccessThirdParty(); $wpcf_access->third_party = array(); $wpcf_access->third_party_post = array(); $wpcf_access->third_party_caps = array(); // Rules $wpcf_access->rules = new stdClass(); $wpcf_access->rules->types = array(); $wpcf_access->rules->taxonomies = array(); // Other $wpcf_access->errors = array(); $wpcf_access->shared_taxonomies = array(); $wpcf_access->upload_files = array(); $wpcf_access->debug = array(); $wpcf_access->debug_hooks_with_args = array(); $wpcf_access->debug_all_hooks = array(); $wpcf_access = apply_filters('types_access', $wpcf_access); // Setup roles self::$roles = self::wpcf_get_editable_roles(); // Set locale $locale = get_locale(); TAccess_Loader::loadLocale('wpcf-access', 'access-' . $locale . '.mo'); // Load admin code if (is_admin()) { // import/export ajax hook add_action('wp_ajax_access_import_export', array(__CLASS__, 'import_export_hook')); /* * Admin functions. */ /* * Menu functions. */ add_action('admin_menu', array(__CLASS__, 'wpcf_access_admin_menu_hook')); /* * Post functions. */ TAccess_Loader::load('CLASS/Post'); //TAccess_Loader::load('CLASS/Admin'); } add_action('init', array(__CLASS__, 'wpcf_access_init'), 9); add_action('init', array(__CLASS__, 'wpcf_access_late_init'), 9999); add_action('init', array(__CLASS__, 'wpcf_access_get_taxonomies_shared_init'), 19); TAccess_Loader::load('CLASS/Ajax'); /* * Hooks to collect and map settings. */ add_filter('wpcf_type', array(__CLASS__, 'wpcf_access_init_types_rules'), 10, 2); add_action('wpcf_type_registered', array(__CLASS__, 'wpcf_access_collect_types_rules')); add_filter('wpcf_taxonomy_data', array(__CLASS__, 'wpcf_access_init_tax_rules'), 10, 3); // WATCHOUT: this hook callback does not exist //add_action('wpcf_taxonomy_registered', array(__CLASS__, 'wpcf_access_collect_tax_rules')); add_action('registered_post_type', array(__CLASS__, 'wpcf_access_registered_post_type_hook'), 10, 2); add_action('registered_taxonomy', array(__CLASS__, 'wpcf_access_registered_taxonomy_hook'), 10, 3); add_filter('types_access_check', array(__CLASS__, 'wpcf_access_filter_rules'), 15, 3); //TAccess_Loader::load('CLASS/Collect'); /* * Check functions. * * 'user_has_cap' is main WP filter we use to filter capability check. * All changes are done on-the-fly and per call. No caching. * * WP accepts $allcaps array of capabilities returned. * It?s actually property of $WP_User->allcaps. * * TODO we should use other way to assign capabilities * This is runing on each current_user_can() call and it might happen docens of times per pagenow * At least we have added caching per cap * */ // if (is_admin()){ //Changed priority to zero because conflict with Wordpres Seo //add_filter('user_has_cap', array(__CLASS__, 'wpcf_access_user_has_cap_filter'), 15, 3); add_filter('user_has_cap', array(__CLASS__, 'wpcf_access_user_has_cap_filter'), 0, 3); //} // add_filter('role_has_cap', 'wpcf_access_role_has_cap_filter', 10, 3); //TAccess_Loader::load('CLASS/Check'); /* * Exceptions. */ add_filter('types_access_check', array(__CLASS__, 'wpcf_access_exceptions_check'), 10, 3); //TAccess_Loader::load('CLASS/Exceptions'); /* * Access hooks. */ //TAccess_Loader::load('CLASS/Hooks'); /* * Dependencies definitions. */ add_action('admin_footer', array(__CLASS__, 'wpcf_access_dependencies_render_js')); //TODO: Review this hook, why we load this in frontend //add_action('wp_footer', array(__CLASS__, 'wpcf_access_dependencies_render_js')); add_filter('types_access_dependencies', array(__CLASS__, 'wpcf_access_dependencies_filter')); //TAccess_Loader::load('CLASS/Dependencies'); TAccess_Loader::load('CLASS/Upload'); TAccess_Loader::load('CLASS/Debug'); do_action('wpcf_access_plugins_loaded'); }