/** * Resets roles to WordPress defaults. * * @return void */ function backupToolReset() { check_admin_referer('capsman-reset-defaults'); require_once ABSPATH . 'wp-admin/includes/schema.php'; if (!function_exists('populate_roles')) { ak_admin_error(__('Needed function to create default roles not found!', 'capsman-enhanced')); return; } $roles = array_keys(ak_get_roles(true)); foreach ($roles as $role) { remove_role($role); } populate_roles(); $this->cm->setAdminCapability(); $msg = __('Roles and Capabilities reset to WordPress defaults', 'capsman-enhanced'); if (function_exists('pp_populate_roles')) { pp_populate_roles(); } else { // force PP to repopulate roles $pp_ver = get_option('pp_c_version', true); if ($pp_ver && is_array($pp_ver)) { $pp_ver['version'] = preg_match("/dev|alpha|beta|rc/i", $pp_ver['version']) ? '0.1-beta' : 0.1; } else { $pp_ver = array('version' => '0.1', 'db_version' => '1.0'); } update_option('pp_c_version', $pp_ver); delete_option('ppperm_added_role_caps_10beta'); } ak_admin_notify($msg); }
public static function version_updated($prev_version) { // single-pass do loop to easily skip unnecessary version checks do { if (!$prev_version) { if (get_option('pp_version') && !get_option('pp_group_index_drop_done')) { // previous installation of PP < 2.0 ? update_option('pp_need_group_index_drop', true); // flag groups index drop to be launched from PP Options } break; // no need to run through version comparisons if no previous version } if (version_compare($prev_version, '2.1.47-dev', '<')) { if (!get_option('pp_post_blockage_priority')) { // previously, post-assigned reading/editing blockages could be overriden by category-assigned additions update_option('ppperm_legacy_exception_handling', true); } } else { break; } if (version_compare($prev_version, '2.1.35', '<')) { require_once dirname(__FILE__) . '/update-exceptions_pp.php'; // Previously, page exceptions were propagated to all descendents, including attachments (but this is unnecessary and potentially undesirable) _ppc_delete_propagated_attachment_exceptions(); _ppc_expose_attachment_exception_items(); // "include" exceptions for Read/Edit operations are exposed but not deleted, since they affect access to other media // Previously, propagated exceptions were not removed when parent exception assign_for was changed to item only. Expose them by setting inherited_from to 0 _ppc_expose_orphaned_exception_items(); } else { break; } if (version_compare($prev_version, '2.1.33', '<')) { if ($enabled_taxonomies = get_option('pp_enabled_taxonomies')) { // previously, post_tag was disabled by default but implicitly enabled for front-end filtering $enabled_taxonomies['post_tag'] = true; update_option('pp_enabled_taxonomies', $enabled_taxonomies); } } else { break; } if (version_compare($prev_version, '2.1.16-beta', '<')) { global $wpdb; $wpdb->query("UPDATE {$wpdb->ppc_exceptions} SET for_item_source = 'post' WHERE for_item_source = 'all'"); } else { break; } if (version_compare($prev_version, '2.1.10-beta', '<')) { // this was defaulted to true in past versions update_site_option('pp_beta_updates', false); } else { break; } if (version_compare($prev_version, '2.1.6-beta', '<')) { // added pp caps for exception assignment from Post/Term edit screen by non-Administrators if (!get_option('ppperm_added_role_caps_21beta')) { pp_populate_roles(); } } else { break; } if (version_compare($prev_version, '2.1.1-beta', '<')) { global $wpdb; // ancestors are no longer buffered in this manner $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name = 'pp_page_ancestors'"); $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '%_ancestors_pp'"); } else { break; } if (version_compare($prev_version, '2.0.29-beta', '<')) { global $wpdb; // change from [Anonymous] to {Anonymous} for consistency with {Authenticated} and to move to bottom of groups listing $wpdb->update($wpdb->pp_groups, array('group_name' => '{Anonymous}'), array('metagroup_type' => 'wp_role', 'metagroup_id' => 'wp_anon')); $wpdb->update($wpdb->pp_groups, array('group_name' => '{All}'), array('metagroup_type' => 'wp_role', 'metagroup_id' => 'wp_all')); } else { break; } if (version_compare($prev_version, '2.0.16-beta', '<')) { // move existing support key from options table to sitemeta (checking current site and main site) if (PP_MULTISITE && !get_site_option('pp_network_key_set')) { if (!($key_data = get_option('pp_support_key'))) { global $blog_id; if ($blog_id != 1) { $restore_blog_id = $blog_id; switch_to_blog(1); } $key_data = get_option('pp_support_key'); if (!empty($restore_blog_id)) { switch_to_blog($restore_blog_id); } } if ($key_data) { update_site_option('pp_support_key', $key_data); update_site_option('pp_network_key_set', true); } } } else { break; } if (version_compare($prev_version, '2.0.3-beta3', '<')) { global $wpdb; $wpdb->update($wpdb->ppc_exceptions, array('for_item_status' => ''), array('via_item_source' => 'post')); // fix importer glitch // delete orphaned exceptions if ($orphan_ids = $wpdb->get_col("SELECT eitem_id FROM {$wpdb->ppc_exception_items} AS i INNER JOIN {$wpdb->ppc_exceptions} AS e ON e.exception_id = i.exception_id " . "WHERE ( e.via_item_source = 'post' AND i.item_id NOT IN ( SELECT ID FROM {$wpdb->posts} ) ) OR ( e.via_item_source = 'term' AND i.item_id NOT IN ( SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} ) )")) { $wpdb->query("DELETE FROM {$wpdb->ppc_exception_items} WHERE eitem_id IN ('" . implode("','", $orphan_ids) . "')"); } // force regen of buffered ancestors array (prev versions botched it when tt_id != term_id) $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '%_ancestors_pp'"); } else { break; } if (version_compare($prev_version, '2.0.2-beta', '<')) { global $wpdb; // added "Authenticated" metagroup self::sync_wproles(); if (!get_option('pp_group_index_drop_done')) { update_option('pp_need_group_index_drop', true); // flag groups index drop to be launched from PP Options } } } while (0); // end single-pass version check loop /* if ( $prev_version && is_admin() ) { if ( preg_match( "/dev|alpha|beta|rc/i", PPC_VERSION ) && ! preg_match( "/dev|alpha|beta|rc/i", $prev_version ) ) { ppc_notice( __( 'You have installed a development / beta version of Press Permit Core. If this is a concern, see Permissions > Settings > Install > Beta Updates.', 'pp' ), 'updated' ); } } */ }
function _pp_act_on_init() { if (defined('INIT_ACTION_DONE_PP') || ppc_interrupt_init()) { return; } define('INIT_ACTION_DONE_PP', true); // --- version check --- $ver = get_option('pp_c_version'); if (!$ver || empty($ver['db_version']) || version_compare(PPC_DB_VERSION, $ver['db_version'], '!=')) { require_once dirname(__FILE__) . '/db-setup_pp.php'; PP_DB_Setup::db_setup($ver['db_version']); if (!$ver) { require_once dirname(__FILE__) . '/admin/update_pp.php'; PP_Updated::version_updated(''); } update_option('pp_c_version', array('version' => PPC_VERSION, 'db_version' => PPC_DB_VERSION)); } if ($ver && !empty($ver['version'])) { // These maintenance operations only apply when a previous version of PP was installed if (version_compare(PPC_VERSION, $ver['version'], '!=')) { require_once dirname(__FILE__) . '/admin/update_pp.php'; PP_Updated::version_updated($ver['version']); update_option('pp_c_version', array('version' => PPC_VERSION, 'db_version' => PPC_DB_VERSION)); } if (PP_MULTISITE && !pp_get_option('wp_role_sync')) { require_once dirname(__FILE__) . '/admin/update_pp.php'; PP_Updated::sync_wproles(); } } else { // first execution after install if (!get_option('ppperm_added_role_caps_21beta')) { pp_populate_roles(); } } // --- end version check --- global $pp_default_options, $pp_site_options, $pp_cap_helper; $pp_default_options = apply_filters('pp_default_options', $pp_default_options); // already loaded these early, so apply filter again for extensions $pp_site_options = apply_filters('pp_options', $pp_site_options); if (PP_MULTISITE) { global $pp_netwide_options; $pp_netwide_options = apply_filters('pp_netwide_options', array('support_key', 'beta_updates')); } // PP_Cap_Helper() instantiation forces type-specific cap names for enabled post types and taxonomies require_once dirname(__FILE__) . '/cap-helper_pp.php'; $pp_cap_helper = new PP_Cap_Helper(); do_action('pp_pre_init'); if (is_admin()) { load_plugin_textdomain('pp', false, PPC_FOLDER . '/languages'); pp_admin_init(); } }