本文整理汇总了PHP中Jetpack::state方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack::state方法的具体用法?PHP Jetpack::state怎么用?PHP Jetpack::state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jetpack
的用法示例。
在下文中一共展示了Jetpack::state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jetpack_json_api_configuration_load
function jetpack_json_api_configuration_load()
{
if (isset($_POST['action']) && $_POST['action'] == 'save_options' && wp_verify_nonce($_POST['_wpnonce'], 'json-api')) {
Jetpack_Options::update_option('json_api_full_management', isset($_POST['json_api_full_management']));
Jetpack::state('message', 'module_configured');
wp_safe_redirect(Jetpack::module_configuration_url('json-api'));
exit;
}
}
示例2: test_jetpack_client_server_authorize_data_error
/**
* @author scotchfield
* @runInSeparateProcess
* @covers Jetpack_Client_Server::authorize
* @since 3.2
*/
public function test_jetpack_client_server_authorize_data_error()
{
$author_id = $this->factory->user->create(array('role' => 'administrator'));
wp_set_current_user($author_id);
$client_server = $this->getMock('Jetpack_Client_Server', array('check_admin_referer', 'wp_safe_redirect', 'do_exit'));
$data_error = 'test_error';
$_GET['error'] = $data_error;
$client_server->authorize();
$this->assertEquals($data_error, Jetpack::state('error'));
}
示例3: minileven_configuration_load
function minileven_configuration_load()
{
if (isset($_POST['action']) && $_POST['action'] == 'save_options' && $_POST['_wpnonce'] == wp_create_nonce('minileven')) {
if (isset($_POST['wp_mobile_excerpt'])) {
update_option('wp_mobile_excerpt', '1' == $_POST['wp_mobile_excerpt'] ? '1' : '0');
}
update_option('wp_mobile_app_promos', isset($_POST['wp_mobile_app_promos']) ? '1' : '0');
Jetpack::state('message', 'module_configured');
wp_safe_redirect(Jetpack::module_configuration_url('minileven'));
exit;
}
}
示例4: jetpack_configuration_load
public function jetpack_configuration_load()
{
if (Jetpack::is_user_connected() && !self::is_active()) {
Jetpack::deactivate_module($this->module);
Jetpack::state('message', 'module_deactivated');
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
die;
}
if (!empty($_POST['action']) && $_POST['action'] == 'monitor-save') {
check_admin_referer('monitor-settings');
$this->update_option_receive_jetpack_monitor_notification(isset($_POST['receive_jetpack_monitor_notification']));
Jetpack::state('message', 'module_configured');
wp_safe_redirect(Jetpack::module_configuration_url($this->module));
}
}
示例5: jetpack_monitor_toggle
/**
* Module Name: Monitor
* Module Description: Jetpack Monitor will keep tabs on your site, and alert you the moment that downtime is detected.
* Sort Order: 55
* First Introduced: 2.6
* Requires Connection: Yes
* Auto Activate: No
*/
function jetpack_monitor_toggle()
{
$jetpack = Jetpack::init();
if (!$jetpack->current_user_is_connection_owner()) {
Jetpack::state('module', 'monitor');
Jetpack::state('error', 'master_user_required');
// Technically this call to `wp_safe_redirect` is not required because
// `Jetpack::activate_module` already sets up a redirect. However, this
// might not stay the case forever so it's clearer to do it here as well.
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
die;
}
$jetpack->sync->register('noop');
if (false !== strpos(current_filter(), 'jetpack_activate_module_')) {
Jetpack::check_privacy(__FILE__);
}
}
示例6: client_authorize
/**
* Authorizations
*/
function client_authorize()
{
$data = stripslashes_deep($_GET);
$data['auth_type'] = 'client';
$jetpack = $this->get_jetpack();
$role = $jetpack->translate_current_user_to_role();
$redirect = isset($data['redirect']) ? esc_url_raw((string) $data['redirect']) : '';
$this->check_admin_referer("jetpack-authorize_{$role}_{$redirect}");
$result = $this->authorize($data);
if (is_wp_error($result)) {
Jetpack::state('error', $result->get_error_code());
}
if (wp_validate_redirect($redirect)) {
$this->wp_safe_redirect($redirect);
} else {
$this->wp_safe_redirect(Jetpack::admin_url());
}
$this->do_exit();
}
示例7: maybe_initialize_hooks
/**
* Will initialize hooks to display the new and legacy connection banners if the current user can
* connect Jetpack, if Jetpack has not been deactivated, and if the current page is the plugins page.
*
* This method should not be called if the site is connected to WordPress.com or if the site is in development mode.
*
* @since 4.4.0
*
* @param $current_screen
*/
function maybe_initialize_hooks($current_screen)
{
// Don't show the connect notice anywhere but the plugins.php after activating
if ('plugins' !== $current_screen->base) {
return;
}
if (!current_user_can('jetpack_connect')) {
return;
}
if (self::check_ab_test_not_expired() && 2 == self::get_random_connection_banner_value()) {
add_action('admin_notices', array($this, 'render_banner'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_banner_scripts'));
} else {
add_action('admin_notices', array($this, 'render_legacy_banner'));
}
add_action('admin_print_styles', array(Jetpack::init(), 'admin_banner_styles'));
if (Jetpack::state('network_nag')) {
add_action('network_admin_notices', array($this, 'network_connect_notice'));
}
}
示例8: jetpack_my_jetpack_change_user
function jetpack_my_jetpack_change_user()
{
if (!isset($_POST['_my_jetpack_nonce']) || !wp_verify_nonce($_POST['_my_jetpack_nonce'], 'jetpack_change_primary_user')) {
wp_die(__('Failed permissions, please try again.', 'jetpack'));
exit;
}
if (isset($_POST['jetpack-new-master'])) {
$old_master_user = Jetpack_Options::get_option('master_user');
$new_master_user = $_POST['jetpack-new-master'];
$user_token = Jetpack_Data::get_access_token($new_master_user);
$is_user_connected = $user_token && !is_wp_error($user_token);
if (current_user_can('manage_options') && $is_user_connected) {
Jetpack::log('switch_master_user', array('old_master' => $old_master_user, 'new_master' => $new_master_user));
Jetpack_Options::update_option('master_user', $new_master_user);
Jetpack::state('message', 'switch_master');
//My Jetpack primary user successfully changed, send to MC Stats
Jetpack::init()->stat('admin', 'change-primary-successful');
Jetpack::init()->do_stats('server_side');
// Change the blog owner dotcom side
$this->wpcom_switch_blog_owner($new_master_user);
}
}
}
示例9: stats_print_wp_remote_error
function stats_print_wp_remote_error($get, $url)
{
$state_name = 'stats_remote_error_' . substr(md5($url), 0, 8);
$previous_error = Jetpack::state($state_name);
$error = md5(serialize(compact('get', 'url')));
Jetpack::state($state_name, $error);
if ($error !== $previous_error) {
?>
<div class="wrap">
<p><?php
_e('We were unable to get your stats just now. Please reload this page to try again.', 'jetpack');
?>
</p>
</div>
<?php
return;
}
?>
<div class="wrap">
<p><?php
printf(__('We were unable to get your stats just now. Please reload this page to try again. If this error persists, please <a href="%1$s" target="_blank">contact support</a>. In your report please include the information below.', 'jetpack'), 'http://support.wordpress.com/contact/?jetpack=needs-service');
?>
</p>
<pre>
User Agent: "<?php
echo esc_html($_SERVER['HTTP_USER_AGENT']);
?>
"
Page URL: "http<?php
echo (is_ssl() ? 's' : '') . '://' . esc_html($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
?>
"
API URL: "<?php
echo esc_url($url);
?>
"
<?php
if (is_wp_error($get)) {
foreach ($get->get_error_codes() as $code) {
foreach ($get->get_error_messages($code) as $message) {
?>
<?php
print $code . ': "' . $message . '"';
?>
<?php
}
}
} else {
$get_code = wp_remote_retrieve_response_code($get);
$content_length = strlen(wp_remote_retrieve_body($get));
?>
Response code: "<?php
print $get_code;
?>
"
Content length: "<?php
print $content_length;
?>
"
<?php
}
?>
</pre>
</div>
<?php
}
示例10: deactivate_jetpack_modules
static function deactivate_jetpack_modules()
{
check_ajax_referer(self::AJAX_NONCE, 'nonce');
// shamelessly copied from class.jetpack.php
$modules = $_REQUEST['modules'];
$modules = array_map('sanitize_key', $modules);
// $modules_filtered = Jetpack::init()->filter_default_modules( $modules );
foreach ($modules as $module_slug) {
Jetpack::log('deactivate', $module_slug);
Jetpack::deactivate_module($module_slug);
Jetpack::state('message', 'module_deactivated');
}
wp_send_json_success($modules);
}
示例11: jetpack_configuration_load
/**
* Runs before the VideoPress Configuration screen loads, useful
* to update options and yield errors.
*/
function jetpack_configuration_load()
{
$this->enqueue_admin_scripts();
/**
* Save configuration
*/
if (!empty($_POST['action']) && $_POST['action'] == 'videopress-save') {
check_admin_referer('videopress-settings');
$options = $this->get_options();
if (isset($_POST['blog_id']) && in_array($_POST['blog_id'], wp_list_pluck($options['blogs'], 'blog_id'))) {
$options['blog_id'] = $_POST['blog_id'];
}
// Allow the None setting too.
if (isset($_POST['blog_id']) && $_POST['blog_id'] == 0) {
$options['blog_id'] = 0;
}
/**
* @see $this->can()
*/
if (isset($_POST['videopress-access']) && in_array($_POST['videopress-access'], array('', 'read', 'edit', 'delete'))) {
$options['access'] = $_POST['videopress-access'];
}
$options['freedom'] = isset($_POST['videopress-freedom']);
$options['hd'] = isset($_POST['videopress-hd']);
// Allow upload only if some level of access has been granted, and uploads were allowed.
$options['allow-upload'] = false;
if (!empty($options['access']) && isset($_POST['videopress-upload'])) {
$options['allow-upload'] = true;
}
$this->update_options($options);
Jetpack::state('message', 'module_configured');
wp_safe_redirect(Jetpack::module_configuration_url($this->module));
}
/**
* Refresh the list of available WordPress.com blogs
*/
if (!empty($_GET['videopress']) && $_GET['videopress'] == 'refresh-blogs') {
check_admin_referer('videopress-settings');
$options = $this->get_options();
$result = $this->query('jetpack.vpGetBlogs');
if (!is_wp_error($result)) {
$options['blogs'] = $result;
$this->update_options($options);
}
wp_safe_redirect(Jetpack::module_configuration_url($this->module));
}
}
示例12: page_admin_scripts
function page_admin_scripts()
{
if ($this->is_redirecting) {
return;
// No need for scripts on a fallback page
}
$is_dev_mode = Jetpack::is_development_mode();
// Enqueue jp.js and localize it
wp_enqueue_script('react-plugin', plugins_url('_inc/build/admin.js', JETPACK__PLUGIN_FILE), array(), JETPACK__VERSION, true);
if (!$is_dev_mode) {
// Required for Analytics
wp_enqueue_script('jp-tracks', '//stats.wp.com/w.js', array(), gmdate('YW'), true);
}
$localeSlug = explode('_', get_locale());
$localeSlug = $localeSlug[0];
// Collecting roles that can view site stats
$stats_roles = array();
$enabled_roles = function_exists('stats_get_option') ? stats_get_option('roles') : array('administrator');
foreach (get_editable_roles() as $slug => $role) {
$stats_roles[$slug] = array('name' => translate_user_role($role['name']), 'canView' => is_array($enabled_roles) ? in_array($slug, $enabled_roles, true) : false);
}
$response = rest_do_request(new WP_REST_Request('GET', '/jetpack/v4/module/all'));
$modules = $response->get_data();
// Preparing translated fields for JSON encoding by transforming all HTML entities to
// respective characters.
foreach ($modules as $slug => $data) {
$modules[$slug]['name'] = html_entity_decode($data['name']);
$modules[$slug]['description'] = html_entity_decode($data['description']);
$modules[$slug]['short_description'] = html_entity_decode($data['short_description']);
$modules[$slug]['long_description'] = html_entity_decode($data['long_description']);
}
// Add objects to be passed to the initial state of the app
wp_localize_script('react-plugin', 'Initial_State', array('WP_API_root' => esc_url_raw(rest_url()), 'WP_API_nonce' => wp_create_nonce('wp_rest'), 'pluginBaseUrl' => plugins_url('', JETPACK__PLUGIN_FILE), 'connectionStatus' => array('isActive' => Jetpack::is_active(), 'isStaging' => Jetpack::is_staging_site(), 'devMode' => array('isActive' => $is_dev_mode, 'constant' => defined('JETPACK_DEV_DEBUG') && JETPACK_DEV_DEBUG, 'url' => site_url() && false === strpos(site_url(), '.'), 'filter' => apply_filters('jetpack_development_mode', false)), 'isPublic' => '1' == get_option('blog_public'), 'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option()), 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), 'isDevVersion' => Jetpack::is_development_version(), 'currentVersion' => JETPACK__VERSION, 'happinessGravIds' => jetpack_get_happiness_gravatar_ids(), 'getModules' => $modules, 'showJumpstart' => jetpack_show_jumpstart(), 'rawUrl' => Jetpack::build_raw_urls(get_home_url()), 'adminUrl' => esc_url(admin_url()), 'stats' => array('data' => array('general' => false, 'day' => false, 'week' => false, 'month' => false), 'roles' => $stats_roles), 'settingNames' => array('jetpack_holiday_snow_enabled' => function_exists('jetpack_holiday_snow_option_name') ? jetpack_holiday_snow_option_name() : false), 'userData' => array('currentUser' => jetpack_current_user_data()), 'locale' => $this->get_i18n_data(), 'localeSlug' => $localeSlug, 'jetpackStateNotices' => array('messageCode' => Jetpack::state('message'), 'errorCode' => Jetpack::state('error'), 'errorDescription' => Jetpack::state('error_description')), 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), 'currentIp' => function_exists('jetpack_protect_get_ip') ? jetpack_protect_get_ip() : false));
}
示例13: jetpack_sites_list
/**
* Provides functionality for the Jetpack > Sites page.
* Does not do the display!
*
* @since 2.9
*/
public function jetpack_sites_list()
{
Jetpack::init();
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'subsiteregister':
/*
* @todo check_admin_referer( 'jetpack-subsite-register' );
*/
Jetpack::log('subsiteregister');
// If !$_GET['site_id'] stop registration and error
if (!isset($_GET['site_id']) || empty($_GET['site_id'])) {
// Log error to state cookie for display later
/**
* @todo Make state messages show on Jetpack NA pages
**/
Jetpack::state('missing_site_id', 'Site ID must be provided to register a sub-site');
break;
}
// Send data to register endpoint and retrieve shadow blog details
$result = $this->do_subsiteregister();
$url = $this->get_url('network_admin_page');
if (is_wp_error($result)) {
$url = add_query_arg('action', 'connection_failed', $url);
} else {
$url = add_query_arg('action', 'connected', $url);
}
wp_safe_redirect($url);
break;
case 'subsitedisconnect':
Jetpack::log('subsitedisconnect');
if (!isset($_GET['site_id']) || empty($_GET['site_id'])) {
Jetpack::state('missing_site_id', 'Site ID must be provided to disconnect a sub-site');
break;
}
$this->do_subsitedisconnect();
break;
case 'connected':
case 'connection_failed':
add_action('jetpack_notices', array($this, 'show_jetpack_notice'));
break;
}
}
}
示例14: page_admin_scripts
function page_admin_scripts()
{
// Enqueue jp.js and localize it
wp_enqueue_script('react-plugin', plugins_url('_inc/build/admin.js', JETPACK__PLUGIN_FILE), array(), time(), true);
wp_enqueue_style('dops-css', plugins_url('_inc/build/dops-style.css', JETPACK__PLUGIN_FILE), array(), time());
wp_enqueue_style('components-css', plugins_url('_inc/build/style.min.css', JETPACK__PLUGIN_FILE), array(), time());
$localeSlug = explode('_', get_locale());
$localeSlug = $localeSlug[0];
// Add objects to be passed to the initial state of the app
wp_localize_script('react-plugin', 'Initial_State', array('WP_API_root' => esc_url_raw(rest_url()), 'WP_API_nonce' => wp_create_nonce('wp_rest'), 'pluginBaseUrl' => plugins_url('', JETPACK__PLUGIN_FILE), 'connectionStatus' => array('isActive' => Jetpack::is_active(), 'isStaging' => Jetpack::is_staging_site(), 'devMode' => array('isActive' => Jetpack::is_development_mode(), 'constant' => defined('JETPACK_DEV_DEBUG') && JETPACK_DEV_DEBUG, 'url' => site_url() && false === strpos(site_url(), '.'), 'filter' => apply_filters('jetpack_development_mode', false))), 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), 'isDevVersion' => Jetpack::is_development_version(), 'currentVersion' => JETPACK__VERSION, 'happinessGravIds' => jetpack_get_happiness_gravatar_ids(), 'getModules' => Jetpack_Core_Json_Api_Endpoints::get_modules(), 'showJumpstart' => jetpack_show_jumpstart(), 'rawUrl' => Jetpack::build_raw_urls(get_home_url()), 'adminUrl' => esc_url(admin_url()), 'statsData' => build_initial_stats_shape(), 'settingNames' => array('jetpack_holiday_snow_enabled' => function_exists('jetpack_holiday_snow_option_name') ? jetpack_holiday_snow_option_name() : false), 'userData' => array('othersLinked' => jetpack_get_other_linked_users(), 'currentUser' => jetpack_current_user_data()), 'locale' => $this->get_i18n_data(), 'localeSlug' => $localeSlug, 'jetpackStateNotices' => array('messageCode' => Jetpack::state('message'), 'errorCode' => Jetpack::state('error'), 'errorDescription' => Jetpack::state('error_description'))));
}
示例15: handle_unrecognized_action
function handle_unrecognized_action($action)
{
switch ($action) {
case 'bulk-activate':
if (!current_user_can('jetpack_activate_modules')) {
break;
}
$modules = (array) $_GET['modules'];
$modules = array_map('sanitize_key', $modules);
check_admin_referer('bulk-jetpack_page_jetpack_modules');
foreach ($modules as $module) {
Jetpack::log('activate', $module);
Jetpack::activate_module($module, false);
}
// The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end.
wp_safe_redirect(wp_get_referer());
exit;
case 'bulk-deactivate':
if (!current_user_can('jetpack_deactivate_modules')) {
break;
}
$modules = (array) $_GET['modules'];
$modules = array_map('sanitize_key', $modules);
check_admin_referer('bulk-jetpack_page_jetpack_modules');
foreach ($modules as $module) {
Jetpack::log('deactivate', $module);
Jetpack::deactivate_module($module);
Jetpack::state('message', 'module_deactivated');
}
Jetpack::state('module', $modules);
wp_safe_redirect(wp_get_referer());
exit;
default:
return;
}
}