function stats_configuration_load() { if (isset($_POST['action']) && $_POST['action'] == 'save_options' && $_POST['_wpnonce'] == wp_create_nonce('stats')) { $options = stats_get_options(); $options['admin_bar'] = isset($_POST['admin_bar']) && $_POST['admin_bar']; $options['hide_smile'] = isset($_POST['hide_smile']) && $_POST['hide_smile']; $options['roles'] = array('administrator'); foreach (get_editable_roles() as $role => $details) { if (isset($_POST["role_{$role}"]) && $_POST["role_{$role}"]) { $options['roles'][] = $role; } } $options['count_roles'] = array(); foreach (get_editable_roles() as $role => $details) { if (isset($_POST["count_role_{$role}"]) && $_POST["count_role_{$role}"]) { $options['count_roles'][] = $role; } } stats_set_options($options); stats_update_blog(); Jetpack::state('message', 'module_configured'); wp_safe_redirect(Jetpack::module_configuration_url('stats')); exit; } }
function stats_get_blog_id($api_key) { $options = stats_get_options(); require_once ABSPATH . WPINC . '/class-IXR.php'; $client = new IXR_Client(STATS_XMLRPC_SERVER); extract(parse_url(get_option('home'))); $path = rtrim($path, '/'); if (empty($path)) { $path = '/'; } $client->query('wpStats.get_blog_id', $api_key, stats_get_blog()); if ($client->isError()) { if ($client->getErrorCode() == -32300) { $options['error'] = __('Your blog was unable to connect to WordPress.com. Please ask your host for help. (' . $client->getErrorMessage() . ')', 'stats'); } else { $options['error'] = $client->getErrorMessage(); } stats_set_options($options); return false; } else { $options['error'] = false; } $response = $client->getResponse(); $blog_id = isset($response['blog_id']) ? (int) $response['blog_id'] : false; $options['host'] = $host; $options['path'] = $path; $options['blog_id'] = $blog_id; stats_set_options($options); stats_set_api_key($api_key); return $blog_id; }