Example #1
0
function stats_admin_load()
{
    if (!empty($_POST['action']) && $_POST['_wpnonce'] == wp_create_nonce('stats')) {
        switch ($_POST['action']) {
            case 'reset':
                stats_set_options(array());
                wp_redirect(stats_admin_path());
                exit;
            case 'enter_key':
                stats_check_key($_POST['api_key']);
                wp_redirect(stats_admin_path());
                exit;
            case 'add_or_replace':
                $key_check = stats_get_option('key_check');
                stats_set_api_key($key_check[0]);
                if (isset($_POST['add'])) {
                    stats_get_blog_id($key_check[0]);
                } else {
                    extract(parse_url(get_option('home')));
                    $path = rtrim($path, '/');
                    if (empty($path)) {
                        $path = '/';
                    }
                    $options = stats_get_options();
                    if (isset($_POST['recover'])) {
                        $options['blog_id'] = intval($_POST['recoverblog']);
                    } else {
                        $options['blog_id'] = intval($_POST['blog_id']);
                    }
                    $options['api_key'] = $key_check[0];
                    $options['host'] = $host;
                    $options['path'] = $path;
                    stats_set_options($options);
                    stats_update_bloginfo();
                }
                if (stats_get_option('blog_id')) {
                    stats_set_option('key_check', false);
                }
                wp_redirect(stats_admin_path());
                exit;
            case 'save_options':
                $options = stats_get_options();
                if (isset($_POST['admin_bar'])) {
                    $options['admin_bar'] = (bool) $_POST['admin_bar'];
                }
                $options['wp_me'] = isset($_POST['wp_me']) && $_POST['wp_me'];
                $options['reg_users'] = isset($_POST['reg_users']) && $_POST['reg_users'];
                $options['roles'] = array('administrator');
                foreach (get_editable_roles() as $role => $details) {
                    if (isset($_POST["role_{$role}"]) && $_POST["role_{$role}"]) {
                        $options['roles'][] = $role;
                    }
                }
                stats_set_options($options);
                wp_redirect(stats_admin_path());
                exit;
        }
    }
    $options = stats_get_options();
    if (empty($options['blog_id']) && empty($options['key_check']) && stats_get_api_key()) {
        stats_check_key(stats_get_api_key());
    }
}
Example #2
0
function stats_admin_load()
{
    global $plugin_page;
    if (!empty($_POST['action']) && $_POST['_wpnonce'] == wp_create_nonce('stats')) {
        switch ($_POST['action']) {
            case 'reset':
                stats_set_options(array());
                wp_redirect("plugins.php?page={$plugin_page}");
                exit;
            case 'enter_key':
                stats_check_key($_POST['api_key']);
                wp_redirect("plugins.php?page={$plugin_page}");
                exit;
            case 'add_or_replace':
                $key_check = stats_get_option('key_check');
                stats_set_api_key($key_check[0]);
                if (isset($_POST['add'])) {
                    stats_get_blog_id($key_check[0]);
                } else {
                    extract(parse_url(get_option('home')));
                    $path = rtrim($path, '/');
                    if (empty($path)) {
                        $path = '/';
                    }
                    $options = stats_get_options();
                    $options['blog_id'] = intval($_POST['blog_id']);
                    $options['api_key'] = $key_check[0];
                    $options['host'] = $host;
                    $options['path'] = $path;
                    stats_set_options($options);
                    stats_update_bloginfo();
                }
                if (stats_get_option('blog_id')) {
                    stats_set_option('key_check', false);
                }
                wp_redirect("plugins.php?page={$plugin_page}");
                exit;
        }
    }
    $options = stats_get_options();
    if (empty($options['blog_id']) && empty($options['key_check']) && stats_get_api_key()) {
        stats_check_key(stats_get_api_key());
    }
}