function scoper_version_updated($prev_version)
{
    if (function_exists('wpp_cache_flush')) {
        wpp_cache_flush_all_sites();
    }
    // single-pass do loop to easily skip unnecessary version checks
    do {
        // roles were stored with invalid assign_for value under some conditions
        if (version_compare($prev_version, '1.3.45-beta', '<')) {
            global $wpdb;
            scoper_query("UPDATE {$wpdb->user2role2object_rs} SET assign_for = 'entity' WHERE assign_for = ''");
        }
        // file filtering rules were not written for new attachments if restriction was based solely on category restrictions
        if (version_compare($prev_version, '1.3.29-beta', '<')) {
            scoper_flush_site_rules();
            scoper_expire_file_rules();
        }
        // Delete any roles or restrictions inappropriately stored for attachments, revisions or auto-drafts
        if (version_compare($prev_version, '1.3', '<')) {
            global $wpdb;
            scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE role_type = 'wp' AND scope='blog' AND obj_or_term_id = '0'");
            scoper_sync_wproles();
            scoper_query("DELETE FROM {$wpdb->role_scope_rs} WHERE src_or_tx_name = 'post' AND obj_or_term_id IN ( SELECT ID FROM {$wpdb->posts} WHERE post_type IN ('attachment', 'revision') OR post_status = 'auto-draft' )");
            scoper_query("DELETE FROM {$wpdb->user2role2object_rs} WHERE src_or_tx_name = 'post' AND obj_or_term_id IN ( SELECT ID FROM {$wpdb->posts} WHERE post_type IN ('attachment', 'revision') OR post_status = 'auto-draft' )");
        }
        // 1.3.RC4 changed RS cache path to subfolder, so flush the root-stored cache one last time (only for MU / Multisite due to potentially large # of folders, files)
        if (IS_MU_RS && version_compare($prev_version, '1.3.RC4', '<') && !defined('SKIP_CACHE_MAINT_RS')) {
            global $wpp_object_cache;
            $wpp_object_cache = new WP_Persistent_Object_Cache(false);
            $wpp_object_cache->global_groups = array('');
            // forces use of cache root for this maint operation
            $wpp_object_cache->rm_cache_dir('');
            // will delete any files and folders in cache root except .htaccess
            $wpp_object_cache->cache_enabled = false;
            // avoid further updating cache in this http session
        }
        // 1.2.8 Beta disabled caps for custom post type roles under some circumstances
        if (version_compare($prev_version, '1.2.7', '>') && version_compare($prev_version, '1.2.8', '<')) {
            if ($disabled_role_caps = get_option('scoper_disabled_role_caps')) {
                $okay_role_prefix = array('rs_post', 'rs_page', 'rs_category', 'rs_link', 'rs_ngg');
                foreach (array_keys($disabled_role_caps) as $role_handle) {
                    $role_okay = false;
                    foreach ($okay_role_prefix as $pfx) {
                        if (0 === strpos($role_handle, $pfx)) {
                            $role_okay = true;
                            break;
                        }
                    }
                    if (!$role_okay) {
                        unset($disabled_role_caps[$role_handle]);
                        $_modified = true;
                    }
                }
                if (!empty($_modified)) {
                    update_option('scoper_disabled_role_caps', $disabled_role_caps);
                }
            }
        }
        // changes to taxonomy options storage in 1.1.8
        if (version_compare($prev_version, '1.1.8', '<')) {
            global $wp_taxonomies;
            $enable_tx = get_option('scoper_enable_wp_taxonomies');
            $old_use_term_roles = get_option('scoper_use_term_roles');
            $use_term_roles = array();
            if (is_array($old_use_term_roles)) {
                // convert existing use_term_roles entries to new array key structure
                foreach ($old_use_term_roles as $src_otype => $val) {
                    if (is_array($val)) {
                        // don't do this twice!
                        break 2;
                    }
                    if (strpos($src_otype, ':')) {
                        $arr_src_otype = explode(':', $src_otype);
                        $src_name = $arr_src_otype[0];
                        if ('post' == $src_name) {
                            $use_term_roles[$src_otype]['category'] = intval($val);
                        } elseif ('link' == $src_name) {
                            $use_term_roles[$src_otype]['link_category'] = intval($val);
                        } elseif ('ngg_gallery' == $src_name) {
                            $use_term_roles[$src_otype]['ngg_album'] = intval($val);
                        }
                        // compat workaround for old versions of Role Scoping for NGG which use old otype option key structure
                    }
                }
            }
            if (is_array($enable_tx)) {
                // Post_tag and custom taxonomies were activated for scoping via enable_wp_taxonomies storage.  Move those entries to use_term_roles instead.
                foreach ($enable_tx as $taxonomy => $val) {
                    if ('post_tag' == $taxonomy) {
                        $use_term_roles['post:post'][$taxonomy] = intval($val);
                    } elseif ($taxonomy && !in_array($taxonomy, array('category', 'link_category'))) {
                        if ($wp_tx = get_taxonomy($taxonomy)) {
                            $object_types = (array) $wp_tx->object_type;
                            foreach ($object_types as $object_type) {
                                $use_term_roles["post:{$object_type}"][$taxonomy] = intval($val);
                            }
                        }
                    }
                }
            }
            if ($use_term_roles) {
                update_option('scoper_use_term_roles', $use_term_roles);
            }
            //delete_option( 'scoper_enable_wp_taxonomies' );
        } else {
            break;
        }
        if (version_compare($prev_version, '1.1', '<')) {
            // htaccess rules modified in v1.1
            scoper_flush_site_rules();
            scoper_expire_file_rules();
            // Option update did not set autoload to no prior to 1.1
            global $wpdb;
            $wpdb->query("UPDATE {$wpdb->options} SET autoload = 'no' WHERE option_name LIKE 'scoper_%' AND option_name != 'scoper_version'");
            // stopped storing needless postmeta data for parent=0 in 1.1
            global $wpdb;
            $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_value = '0' AND meta_key = '_scoper_last_parent'");
        } else {
            break;
        }
        // stopped using rs_get_page_children() in 1.0.8
        if (version_compare($prev_version, '1.0.8', '<')) {
            delete_option('scoper_page_children');
        } else {
            break;
        }
        if (version_compare($prev_version, '1.0.0', '<')) {
            include dirname(__FILE__) . '/update-legacy_rs.php';
            scoper_version_updated_from_legacy($prev_version);
        }
    } while (0);
    // end single-pass version check loop
}
 function sync_wproles($user_ids = '', $role_name = '', $blog_id_arg = '')
 {
     require_once dirname(__FILE__) . '/update_rs.php';
     scoper_sync_wproles($user_ids, $role_name, $blog_id_arg);
 }
Exemplo n.º 3
0
function scoper_version_updated_from_legacy($prev_version)
{
    // single-pass do loop to easily skip unnecessary version checks
    do {
        if (version_compare($prev_version, '1.0.0-rc6', '<') && version_compare($prev_version, '1.0.0-rc2', '>=')) {
            // In rc2 through rc4, we forced invalid img src attribute for image attachments on servers deemed non-apache
            // note: false === stripos( php_sapi_name(), 'apache' ) was the criteria used by the offending code
            // Need to update all affected post_content to convert attachment_id URL to file URL
            if (false === stripos(php_sapi_name(), 'apache') && !get_site_option('scoper_fixed_img_urls')) {
                global $wpdb, $wp_rewrite;
                if (!empty($wp_rewrite)) {
                    $blog_url = get_bloginfo('url');
                    if ($results = $wpdb->get_results("SELECT ID, guid, post_parent FROM {$wpdb->posts} WHERE post_type = 'attachment' && post_date > '2008-12-7'")) {
                        foreach ($results as $row) {
                            $data = array();
                            $data['post_content'] = $wpdb->get_var("SELECT post_content FROM {$wpdb->posts} WHERE ID = '{$row->post_parent}'");
                            if ($row->guid) {
                                $attachment_link_raw = $blog_url . "/?attachment_id={$row->ID}";
                                $data['post_content'] = str_replace('src="' . $attachment_link_raw, 'src="' . $row->guid, $data['post_content']);
                                $attachment_link = get_attachment_link($row->ID);
                                $data['post_content'] = str_replace('src="' . $attachment_link, 'src="' . $row->guid, $data['post_content']);
                            }
                            if (!empty($data['post_content'])) {
                                $wpdb->update($wpdb->posts, $data, array("ID" => $row->post_parent));
                            }
                        }
                    }
                    update_option('scoper_fixed_img_urls', true);
                }
            }
        } else {
            break;
        }
        // changed default teaser_hide_private otype option to separate entries for posts, pages in v1.0.0-rc4
        if (version_compare($prev_version, '1.0.0-rc4', '<')) {
            $teaser_hide_private = get_option('scoper_teaser_hide_private');
            if (isset($teaser_hide_private['post']) && !is_array($teaser_hide_private['post'])) {
                if ($teaser_hide_private['post']) {
                    // despite "for posts and pages" caption, previously this option caused pages to be hidden but posts still teased
                    update_option('scoper_teaser_hide_private', array('post:post' => 0, 'post:page' => 1));
                } else {
                    update_option('scoper_teaser_hide_private', array('post:post' => 0, 'post:page' => 0));
                }
            }
        } else {
            break;
        }
        // 0.9.15 eliminated ability to set recursive page parents
        if (version_compare($prev_version, '0.9.15', '<')) {
            scoper_fix_page_parent_recursion();
        } else {
            break;
        }
        // added WP role metagroups in v0.9.9
        if (!empty($prev_version) && version_compare($prev_version, '0.9.9', '<')) {
            global $wp_roles;
            if (!empty($wp_roles)) {
                scoper_sync_wproles();
            }
        } else {
            break;
        }
    } while (0);
    // end single-pass version check loop
}