本文整理汇总了PHP中Jetpack::is_module方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack::is_module方法的具体用法?PHP Jetpack::is_module怎么用?PHP Jetpack::is_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jetpack
的用法示例。
在下文中一共展示了Jetpack::is_module方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf7_jetpack_admin_notices
function wpcf7_jetpack_admin_notices()
{
global $wpdb;
if (!class_exists('Jetpack') || !Jetpack::is_module('contact-form') || !in_array('contact-form', Jetpack::get_active_modules())) {
return;
}
$q = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_old_cf7_unit_id'";
if (!$wpdb->get_var($q)) {
return;
}
$desc_link = wpcf7_link(__('http://contactform7.com/jetpack-overrides-contact-forms/', 'contact-form-7'), __('Jetpack Overrides Contact Forms', 'contact-form-7'));
?>
<div class="notice notice-warning">
<p><?php
echo sprintf(esc_html(__('Jetpack may cause problems for other plugins in certain cases. For more details, see %s.', 'contact-form-7')), $desc_link);
?>
</p>
</div>
<?php
}
示例2: validate_modules
/**
* Walks through submitted themes to make sure they are valid
* @return bool|WP_Error
*/
protected function validate_modules()
{
foreach ($this->modules as $module) {
if (!Jetpack::is_module($module)) {
return new WP_Error('unknown_jetpack_module', sprintf(__('Module not found: `%s`.', 'jetpack'), $module), 404);
}
}
return true;
}
示例3: render_nojs_configurable
function render_nojs_configurable()
{
echo '<div class="clouds-sm"></div>';
echo '<div class="wrap configure-module">';
$module_name = preg_replace('/[^\\da-z\\-]+/', '', $_GET['configure']);
if (Jetpack::is_module($module_name) && current_user_can('jetpack_configure_modules')) {
Jetpack::admin_screen_configure_module($module_name);
} else {
echo '<h2>' . esc_html__('Error, bad module.', 'jetpack') . '</h2>';
}
echo '</div><!-- /wrap -->';
}
示例4: wpcf7_jetpack_admin_notices
function wpcf7_jetpack_admin_notices()
{
if (!class_exists('Jetpack') || !Jetpack::is_module('contact-form') || !in_array('contact-form', Jetpack::get_active_modules())) {
return;
}
$url = 'http://contactform7.com/jetpack-overrides-contact-forms/';
?>
<div class="error">
<p><?php
echo sprintf(__('<strong>Jetpack may cause problems for other plugins in certain cases.</strong> <a href="%s" target="_blank">See how to avoid it.</a>', 'wpcf7'), $url);
?>
</p>
</div>
<?php
}
示例5: admin_head
function admin_head()
{
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) {
/**
* Fires in the <head> of a particular Jetpack configuation page.
*
* The dynamic portion of the hook name, `$_GET['configure']`,
* refers to the slug of module, such as 'stats', 'sso', etc.
* A complete hook for the latter would be
* 'jetpack_module_configuation_head_sso'.
*
* @since 3.0.0
*/
do_action('jetpack_module_configuration_head_' . $_GET['configure']);
}
}
示例6: wpcf7_jetpack_admin_notices
function wpcf7_jetpack_admin_notices()
{
global $wpdb;
if (!class_exists('Jetpack') || !Jetpack::is_module('contact-form') || !in_array('contact-form', Jetpack::get_active_modules())) {
return;
}
$q = "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_old_cf7_unit_id'";
if (!$wpdb->get_var($q)) {
return;
}
$url = 'http://contactform7.com/jetpack-overrides-contact-forms/';
?>
<div class="error">
<p><?php
echo sprintf(__('<strong>Jetpack may cause problems for other plugins in certain cases.</strong> <a href="%s" target="_blank">See how to avoid it.</a>', 'wpcf7'), $url);
?>
</p>
</div>
<?php
}
示例7: admin_page_load
//.........这里部分代码省略.........
}
if ($titles) {
$this->message .= '<br /><br />' . wp_sprintf(__('The following modules have been updated: %l.', 'jetpack'), $titles);
}
}
$this->message .= Jetpack::jetpack_comment_notice();
break;
case 'jetpack-manage':
$this->message = '<strong>' . sprintf(__('You are all set! Your site can now be managed from <a href="%s" target="_blank">wordpress.com/sites</a>.', 'jetpack'), 'https://wordpress.com/sites') . '</strong>';
if ($activated_manage) {
$this->message .= '<br /><strong>' . __('Manage has been activated for you!', 'jetpack') . '</strong>';
}
break;
case 'module_activated':
if ($module = Jetpack::get_module(Jetpack::state('module'))) {
$this->message = sprintf(__('<strong>%s Activated!</strong> You can deactivate at any time by clicking the Deactivate link next to each module.', 'jetpack'), $module['name']);
$this->stat('module-activated', Jetpack::state('module'));
}
break;
case 'module_deactivated':
$modules = Jetpack::state('module');
if (!$modules) {
break;
}
$module_names = array();
foreach (explode(',', $modules) as $module_slug) {
$module = Jetpack::get_module($module_slug);
if ($module) {
$module_names[] = $module['name'];
}
$this->stat('module-deactivated', $module_slug);
}
if (!$module_names) {
break;
}
$this->message = wp_sprintf(_nx('<strong>%l Deactivated!</strong> You can activate it again at any time using the activate link next to each module.', '<strong>%l Deactivated!</strong> You can activate them again at any time using the activate links next to each module.', count($module_names), '%l = list of Jetpack module/feature names', 'jetpack'), $module_names);
break;
case 'module_configured':
$this->message = __('<strong>Module settings were saved.</strong> ', 'jetpack');
break;
case 'already_authorized':
$this->message = __('<strong>Your Jetpack is already connected.</strong> ', 'jetpack');
break;
case 'authorized':
$this->message = __('<strong>You’re fueled up and ready to go, Jetpack is now active.</strong> ', 'jetpack');
$this->message .= Jetpack::jetpack_comment_notice();
break;
case 'linked':
$this->message = __('<strong>You’re fueled up and ready to go.</strong> ', 'jetpack');
$this->message .= Jetpack::jetpack_comment_notice();
break;
case 'unlinked':
$user = wp_get_current_user();
$this->message = sprintf(__('<strong>You have unlinked your account (%s) from WordPress.com.</strong>', 'jetpack'), $user->user_login);
break;
case 'switch_master':
global $current_user;
$is_master_user = $current_user->ID == Jetpack_Options::get_option('master_user');
$master_userdata = get_userdata(Jetpack_Options::get_option('master_user'));
if ($is_master_user) {
$this->message = __('You have successfully set yourself as Jetpack’s primary user.', 'jetpack');
} else {
$this->message = sprintf(_x('You have successfully set %s as Jetpack’s primary user.', '%s is a username', 'jetpack'), $master_userdata->user_login);
}
break;
}
$deactivated_plugins = Jetpack::state('deactivated_plugins');
if (!empty($deactivated_plugins)) {
$deactivated_plugins = explode(',', $deactivated_plugins);
$deactivated_titles = array();
foreach ($deactivated_plugins as $deactivated_plugin) {
if (!isset($this->plugins_to_deactivate[$deactivated_plugin])) {
continue;
}
$deactivated_titles[] = '<strong>' . str_replace(' ', ' ', $this->plugins_to_deactivate[$deactivated_plugin][1]) . '</strong>';
}
if ($deactivated_titles) {
if ($this->message) {
$this->message .= "<br /><br />\n";
}
$this->message .= wp_sprintf(_n('Jetpack contains the most recent version of the old %l plugin.', 'Jetpack contains the most recent versions of the old %l plugins.', count($deactivated_titles), 'jetpack'), $deactivated_titles);
$this->message .= "<br />\n";
$this->message .= _n('The old version has been deactivated and can be removed from your site.', 'The old versions have been deactivated and can be removed from your site.', count($deactivated_titles), 'jetpack');
}
}
$this->privacy_checks = Jetpack::state('privacy_checks');
if ($this->message || $this->error || $this->privacy_checks || $this->can_display_jetpack_manage_notice()) {
add_action('jetpack_notices', array($this, 'admin_notices'));
}
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) {
/**
* Fires when a module configuration page is loaded.
* The dynamic part of the hook is the configure parameter from the URL.
*
* @since 1.1.0
*/
do_action('jetpack_module_configuration_load_' . $_GET['configure']);
}
add_filter('jetpack_short_module_description', 'wptexturize');
}
示例8: admin_page
function admin_page()
{
global $current_user;
$role = $this->translate_current_user_to_role();
$is_connected = Jetpack::is_active();
$module = false;
?>
<div class="wrap" id="jetpack-settings">
<h2 style="display: none"></h2> <!-- For WP JS message relocation -->
<div id="jp-header"<?php
if ($is_connected) {
?>
class="small"<?php
}
?>
>
<div id="jp-clouds">
<?php
if ($is_connected) {
?>
<div id="jp-disconnect">
<a href="<?php
echo wp_nonce_url(Jetpack::admin_url(array('action' => 'disconnect')), 'jetpack-disconnect');
?>
"><?php
_e('Connected to WordPress.com', 'jetpack');
?>
</a>
<span><?php
_e('Disconnect from WordPress.com', 'jetpack');
?>
</span>
</div>
<?php
}
?>
<h3><?php
_e('Jetpack by WordPress.com', 'jetpack');
?>
</h3>
<?php
if (!$is_connected) {
?>
<div id="jp-notice">
<p><?php
_e('Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack');
?>
</p>
</div>
<?php
}
?>
</div>
</div>
<?php
do_action('jetpack_notices');
?>
<?php
// If the connection has not been made then show the marketing text.
?>
<?php
if (!$is_connected) {
?>
<div id="jp-info">
<a href="<?php
echo $this->build_connect_url();
?>
" class="jp-button" id="wpcom-connect"><?php
_e('Connect to WordPress.com', 'jetpack');
?>
</a>
<p><?php
_e("To enable all of the Jetpack features you’ll need to connect your website to WordPress.com using the button to the right. Once you’ve made the connection you’ll activate all the delightful features below.", 'jetpack');
?>
</p>
</div>
<?php
}
?>
<?php
// If we select the configure option for a module, show the configuration screen.
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure'])) {
$this->admin_screen_configure_module($_GET['configure']);
// List all the available modules.
} else {
$this->admin_screen_list_modules();
?>
<div id="survey" class="jp-survey">
<div class="jp-survey-container">
<div class="jp-survey-text">
<h4><?php
_e('Have feedback on Jetpack?', 'jetpack');
//.........这里部分代码省略.........
示例9: admin_page_load
//.........这里部分代码省略.........
wp_safe_redirect(Jetpack::admin_url('disconnected=true'));
exit;
case 'reconnect':
if (!current_user_can('jetpack_reconnect')) {
$error = 'cheatin';
break;
}
check_admin_referer('jetpack-reconnect');
Jetpack::log('reconnect');
$this->disconnect();
wp_redirect($this->build_connect_url(true, false, 'reconnect'));
exit;
case 'deactivate':
if (!current_user_can('jetpack_deactivate_modules')) {
$error = 'cheatin';
break;
}
$modules = stripslashes($_GET['module']);
check_admin_referer("jetpack_deactivate-{$modules}");
foreach (explode(',', $modules) as $module) {
Jetpack::log('deactivate', $module);
Jetpack::deactivate_module($module);
Jetpack::state('message', 'module_deactivated');
}
Jetpack::state('module', $modules);
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
exit;
case 'unlink':
$redirect = isset($_GET['redirect']) ? $_GET['redirect'] : '';
check_admin_referer('jetpack-unlink');
Jetpack::log('unlink');
$this->unlink_user();
Jetpack::state('message', 'unlinked');
if ('sub-unlink' == $redirect) {
wp_safe_redirect(admin_url());
} else {
wp_safe_redirect(Jetpack::admin_url(array('page' => $redirect)));
}
exit;
default:
/**
* Fires when a Jetpack admin page is loaded with an unrecognized parameter.
*
* @since 2.6.0
*
* @param string sanitize_key( $_GET['action'] ) Unrecognized URL parameter.
*/
do_action('jetpack_unrecognized_action', sanitize_key($_GET['action']));
}
}
if (!($error = $error ? $error : Jetpack::state('error'))) {
self::activate_new_modules(true);
}
$message_code = Jetpack::state('message');
if (Jetpack::state('optin-manage')) {
$activated_manage = $message_code;
$message_code = 'jetpack-manage';
}
switch ($message_code) {
case 'jetpack-manage':
$this->message = '<strong>' . sprintf(__('You are all set! Your site can now be managed from <a href="%s" target="_blank">wordpress.com/sites</a>.', 'jetpack'), 'https://wordpress.com/sites') . '</strong>';
if ($activated_manage) {
$this->message .= '<br /><strong>' . __('Manage has been activated for you!', 'jetpack') . '</strong>';
}
break;
}
$deactivated_plugins = Jetpack::state('deactivated_plugins');
if (!empty($deactivated_plugins)) {
$deactivated_plugins = explode(',', $deactivated_plugins);
$deactivated_titles = array();
foreach ($deactivated_plugins as $deactivated_plugin) {
if (!isset($this->plugins_to_deactivate[$deactivated_plugin])) {
continue;
}
$deactivated_titles[] = '<strong>' . str_replace(' ', ' ', $this->plugins_to_deactivate[$deactivated_plugin][1]) . '</strong>';
}
if ($deactivated_titles) {
if ($this->message) {
$this->message .= "<br /><br />\n";
}
$this->message .= wp_sprintf(_n('Jetpack contains the most recent version of the old %l plugin.', 'Jetpack contains the most recent versions of the old %l plugins.', count($deactivated_titles), 'jetpack'), $deactivated_titles);
$this->message .= "<br />\n";
$this->message .= _n('The old version has been deactivated and can be removed from your site.', 'The old versions have been deactivated and can be removed from your site.', count($deactivated_titles), 'jetpack');
}
}
$this->privacy_checks = Jetpack::state('privacy_checks');
if ($this->message || $this->error || $this->privacy_checks || $this->can_display_jetpack_manage_notice()) {
add_action('jetpack_notices', array($this, 'admin_notices'));
}
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure']) && current_user_can('manage_options')) {
/**
* Fires when a module configuration page is loaded.
* The dynamic part of the hook is the configure parameter from the URL.
*
* @since 1.1.0
*/
do_action('jetpack_module_configuration_load_' . $_GET['configure']);
}
add_filter('jetpack_short_module_description', 'wptexturize');
}
示例10: render_nojs_configurable
function render_nojs_configurable($module_name)
{
$module_name = preg_replace('/[^\\da-z\\-]+/', '', $_GET['configure']);
include_once JETPACK__PLUGIN_DIR . '_inc/header.php';
echo '<div class="wrap configure-module">';
if (Jetpack::is_module($module_name) && current_user_can('jetpack_configure_modules')) {
Jetpack::admin_screen_configure_module($module_name);
} else {
echo '<h2>' . esc_html__('Error, bad module.', 'jetpack') . '</h2>';
}
echo '</div><!-- /wrap -->';
}
示例11: admin_page
function admin_page()
{
global $current_user;
$role = $this->translate_current_user_to_role();
$is_connected = Jetpack::is_active();
$module = false;
?>
<div class="wrap" id="jetpack-settings">
<div id="jp-header"<?php
if ($is_connected) {
?>
class="small"<?php
}
?>
>
<div id="jp-clouds">
<?php
if ($is_connected) {
?>
<div id="jp-disconnect">
<a href="<?php
echo wp_nonce_url(Jetpack::admin_url(array('action' => 'disconnect')), 'jetpack-disconnect');
?>
"><?php
_e('Connected to WordPress.com', 'jetpack');
?>
</a>
<span><?php
_e('Disconnect from WordPress.com', 'jetpack');
?>
</span>
</div>
<?php
}
?>
<h3><?php
_e('Jetpack by WordPress.com', 'jetpack');
?>
</h3>
<?php
if (!$is_connected) {
?>
<div id="jp-notice">
<p><?php
_e('Jetpack supercharges your self-hosted WordPress site with the awesome cloud power of WordPress.com.', 'jetpack');
?>
</p>
</div>
<?php
}
?>
</div>
</div>
<h2 style="display: none"></h2> <!-- For WP JS message relocation -->
<?php
do_action('jetpack_notices');
?>
<?php
// If the connection has not been made then show the marketing text.
?>
<?php
if (!$is_connected) {
?>
<div id="jp-info">
<a href="<?php
echo $this->build_connect_url();
?>
" class="jp-button" id="wpcom-connect"><?php
_e('Connect to WordPress.com', 'jetpack');
?>
</a>
<p><?php
_e("To enable all of the Jetpack features you’ll need to connect your website to WordPress.com using the button to the right. Once you’ve made the connection you’ll activate all the delightful features below.", 'jetpack');
?>
</p>
</div>
<?php
}
?>
<?php
// If we select the configure option for a module, show the configuration screen.
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure'])) {
$this->admin_screen_configure_module($_GET['configure']);
// List all the available modules.
} else {
$this->admin_screen_list_modules();
?>
<?php
if ($is_connected) {
?>
<p id="news-sub"><?php
_e('Checking email updates status…', 'jetpack');
//.........这里部分代码省略.........
示例12: module
/**
* Manage Jetpack Modules
*
* ## OPTIONS
*
* list : View all available modules, and their status.
* activate all : Activate all modules
* deactivate all: Deactivate all modules
*
* activate <module_slug> : Activate a module.
* deactivate <module_slug> : Deactivate a module.
* toggle <module_slug> : Toggle a module on or off.
*
* ## EXAMPLES
*
* wp jetpack module list
* wp jetpack module activate stats
* wp jetpack module deactivate stats
* wp jetpack module toggle stats
*
* wp jetpack module activate all
* wp jetpack module deactivate all
*
* @synopsis <list|activate|deactivate|toggle> [<module_name>]
*/
public function module($args, $assoc_args)
{
$action = isset($args[0]) ? $args[0] : 'list';
if (!in_array($action, array('list', 'activate', 'deactivate', 'toggle'))) {
WP_CLI::error(sprintf(__('%s is not a valid command.', 'jetpack'), $action));
}
if (in_array($action, array('activate', 'deactivate', 'toggle'))) {
if (isset($args[1])) {
$module_slug = $args[1];
if ('all' !== $module_slug && !Jetpack::is_module($module_slug)) {
WP_CLI::error(sprintf(__('%s is not a valid module.', 'jetpack'), $module_slug));
}
if ('toggle' == $action) {
$action = Jetpack::is_module_active($module_slug) ? 'deactivate' : 'activate';
}
// Bulk actions
if ('all' == $args[1]) {
$action = 'deactivate' == $action ? 'deactivate_all' : 'activate_all';
}
// VaultPress needs to be handled elsewhere.
if (in_array($action, array('activate', 'deactivate', 'toggle')) && 'vaultpress' == $args[1]) {
WP_CLI::error(sprintf(_x('Please visit %s to configure your VaultPress subscription.', '%s is a website', 'jetpack'), esc_url('https://vaultpress.com/jetpack/')));
}
} else {
WP_CLI::line(__('Please specify a valid module.', 'jetpack'));
$action = 'list';
}
}
switch ($action) {
case 'list':
WP_CLI::line(__('Available Modules:', 'jetpack'));
$modules = Jetpack::get_available_modules();
sort($modules);
foreach ($modules as $module_slug) {
if ('vaultpress' == $module_slug) {
continue;
}
$active = Jetpack::is_module_active($module_slug) ? __('Active', 'jetpack') : __('Inactive', 'jetpack');
WP_CLI::line("\t" . str_pad($module_slug, 24) . $active);
}
break;
case 'activate':
$module = Jetpack::get_module($module_slug);
Jetpack::log('activate', $module_slug);
Jetpack::activate_module($module_slug, false, false);
WP_CLI::success(sprintf(__('%s has been activated.', 'jetpack'), $module['name']));
break;
case 'activate_all':
$modules = Jetpack::get_available_modules();
Jetpack::update_active_modules($modules);
WP_CLI::success(__('All modules activated!', 'jetpack'));
break;
case 'deactivate':
$module = Jetpack::get_module($module_slug);
Jetpack::log('deactivate', $module_slug);
Jetpack::deactivate_module($module_slug);
WP_CLI::success(sprintf(__('%s has been deactivated.', 'jetpack'), $module['name']));
break;
case 'deactivate_all':
Jetpack::delete_active_modules();
WP_CLI::success(__('All modules deactivated!', 'jetpack'));
break;
case 'toggle':
// Will never happen, should have been handled above and changed to activate or deactivate.
break;
}
}
示例13: update_data
/**
* If it's a valid Jetpack module and configuration parameters have been sent, update it.
*
* @since 4.3.0
*
* @param WP_REST_Request $data {
* Array of parameters received by request.
*
* @type string $slug Module slug.
* }
*
* @return bool|WP_Error True if module was updated. Otherwise, a WP_Error instance with the corresponding error.
*/
public function update_data($data)
{
// If it's null, we're trying to update many module options from different modules.
if (is_null($data['slug'])) {
// Value admitted by Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list that will make it return all module options.
// It will not be passed. It's just checked in this method to pass that method a string or array.
$data['slug'] = 'any';
} else {
if (!Jetpack::is_module($data['slug'])) {
return new WP_Error('not_found', esc_html__('The requested Jetpack module was not found.', 'jetpack'), array('status' => 404));
}
if (!Jetpack::is_module_active($data['slug'])) {
return new WP_Error('inactive', esc_html__('The requested Jetpack module is inactive.', 'jetpack'), array('status' => 409));
}
}
// Get parameters to update the module.
$params = $data->get_json_params();
// Exit if no parameters were passed.
if (!is_array($params)) {
return new WP_Error('missing_options', esc_html__('Missing options.', 'jetpack'), array('status' => 404));
}
// Get available module options.
$options = Jetpack_Core_Json_Api_Endpoints::get_updateable_data_list('any' === $data['slug'] ? $params : $data['slug']);
// Prepare to toggle module if needed
$toggle_module = new Jetpack_Core_API_Module_Toggle_Endpoint(new Jetpack_IXR_Client());
// Options that are invalid or failed to update.
$invalid = array_keys(array_diff_key($params, $options));
$not_updated = array();
// Remove invalid options
$params = array_intersect_key($params, $options);
// Used if response is successful. The message can be overwritten and additional data can be added here.
$response = array('code' => 'success', 'message' => esc_html__('The requested Jetpack data updates were successful.', 'jetpack'));
// If there are modules to activate, activate them first so they're ready when their options are set.
foreach ($params as $option => $value) {
if ('modules' === $options[$option]['jp_group']) {
// Used if there was an error. Can be overwritten with specific error messages.
$error = '';
// Set to true if the module toggling was successful.
$updated = false;
// Check if user can toggle the module.
if ($toggle_module->can_request()) {
// Activate or deactivate the module according to the value passed.
$toggle_result = $value ? $toggle_module->activate_module($option) : $toggle_module->deactivate_module($option);
if (is_wp_error($toggle_result)) {
$error = $toggle_result->get_error_message();
} else {
$updated = true;
}
} else {
$error = Jetpack_Core_Json_Api_Endpoints::$user_permissions_error_msg;
}
// The module was not toggled.
if (!$updated) {
$not_updated[$option] = $error;
}
// Remove module from list so we don't go through it again.
unset($params[$option]);
}
}
foreach ($params as $option => $value) {
// Used if there was an error. Can be overwritten with specific error messages.
$error = '';
// Set to true if the option update was successful.
$updated = false;
// Get option attributes, including the group it belongs to.
$option_attrs = $options[$option];
// If this is a module option and the related module isn't active for any reason, continue with the next one.
if ('settings' !== $option_attrs['jp_group']) {
if (!Jetpack::is_module($option_attrs['jp_group'])) {
$not_updated[$option] = esc_html__('The requested Jetpack module was not found.', 'jetpack');
continue;
}
if (!Jetpack::is_module_active($option_attrs['jp_group'])) {
$not_updated[$option] = esc_html__('The requested Jetpack module is inactive.', 'jetpack');
continue;
}
}
// Properly cast value based on its type defined in endpoint accepted args.
$value = Jetpack_Core_Json_Api_Endpoints::cast_value($value, $option_attrs);
switch ($option) {
case 'monitor_receive_notifications':
$monitor = new Jetpack_Monitor();
// If we got true as response, consider it done.
$updated = true === $monitor->update_option_receive_jetpack_monitor_notification($value);
break;
case 'post_by_email_address':
if ('create' == $value) {
//.........这里部分代码省略.........
示例14: update_module
/**
* If it's a valid Jetpack module and configuration parameters have been sent, update it.
*
* @since 4.1.0
*
* @param WP_REST_Request $data {
* Array of parameters received by request.
*
* @type string $slug Module slug.
* }
*
* @return bool|WP_Error True if module was updated. Otherwise, a WP_Error instance with the corresponding error.
*/
public static function update_module($data)
{
if (!Jetpack::is_module($data['slug'])) {
return new WP_Error('not_found', esc_html__('The requested Jetpack module was not found.', 'jetpack'), array('status' => 404));
}
if (!Jetpack::is_module_active($data['slug'])) {
return new WP_Error('inactive', esc_html__('The requested Jetpack module is inactive.', 'jetpack'), array('status' => 409));
}
// Get parameters to update the module.
$param = $data->get_json_params();
// Exit if no parameters were passed.
if (!is_array($param)) {
return new WP_Error('missing_option', esc_html__('Missing option.', 'jetpack'), array('status' => 404));
}
// Get option name and value.
$option = key($param);
$value = current($param);
// Get available module options.
$options = self::get_module_available_options();
// If option is invalid, don't go any further.
if (!in_array($option, array_keys($options))) {
return new WP_Error('invalid_param', esc_html(sprintf(__('The option %s is invalid for this module.', 'jetpack'), $option)), array('status' => 404));
}
// Used if response is successful. The message can be overwritten and additional data can be added here.
$response = array('code' => 'success', 'message' => esc_html__('The requested Jetpack module was updated.', 'jetpack'));
// Used if there was an error. Can be overwritten with specific error messages.
/* Translators: the variable is a module option name. */
$error = sprintf(__('The option %s was not updated.', 'jetpack'), $option);
// Set to true if the option update was successful.
$updated = false;
// Properly cast value based on its type defined in endpoint accepted args.
$value = self::cast_value($value, $options[$option]);
switch ($option) {
case 'monitor_receive_notifications':
$monitor = new Jetpack_Monitor();
// If we got true as response, consider it done.
$updated = true === $monitor->update_option_receive_jetpack_monitor_notification($value);
break;
case 'post_by_email_address':
if ('create' == $value) {
$result = self::_process_post_by_email('jetpack.createPostByEmailAddress', esc_html__('Unable to create the Post by Email address. Please try again later.', 'jetpack'));
} elseif ('regenerate' == $value) {
$result = self::_process_post_by_email('jetpack.regeneratePostByEmailAddress', esc_html__('Unable to regenerate the Post by Email address. Please try again later.', 'jetpack'));
} elseif ('delete' == $value) {
$result = self::_process_post_by_email('jetpack.deletePostByEmailAddress', esc_html__('Unable to delete the Post by Email address. Please try again later.', 'jetpack'));
} else {
$result = false;
}
// If we got an email address (create or regenerate) or 1 (delete), consider it done.
if (preg_match('/[a-z0-9]+@post.wordpress.com/', $result)) {
$response[$option] = $result;
$updated = true;
} elseif (1 == $result) {
$updated = true;
} elseif (is_array($result) && isset($result['message'])) {
$error = $result['message'];
}
break;
case 'jetpack_protect_key':
$protect = Jetpack_Protect_Module::instance();
if ('create' == $value) {
$result = $protect->get_protect_key();
} else {
$result = false;
}
// If we got one of Protect keys, consider it done.
if (preg_match('/[a-z0-9]{40,}/i', $result)) {
$response[$option] = $result;
$updated = true;
}
break;
case 'jetpack_protect_global_whitelist':
$updated = jetpack_protect_save_whitelist(explode(PHP_EOL, str_replace(' ', '', $value)));
if (is_wp_error($updated)) {
$error = $updated->get_error_message();
}
break;
case 'show_headline':
case 'show_thumbnails':
$grouped_options = $grouped_options_current = Jetpack_Options::get_option('relatedposts');
$grouped_options[$option] = $value;
// If option value was the same, consider it done.
$updated = $grouped_options_current != $grouped_options ? Jetpack_Options::update_option('relatedposts', $grouped_options) : true;
break;
case 'google':
case 'bing':
case 'pinterest':
//.........这里部分代码省略.........
示例15: enqueue_preview_scripts
/**
* Enqueue preview scripts.
*
* @since 4.5.0
* @access public
*/
public function enqueue_preview_scripts()
{
wp_enqueue_script('customize-partial-refresh-preview');
$wp_scripts = wp_scripts();
$wp_styles = wp_styles();
/*
* Core does not rebuild MediaElement.js audio and video players when DOM subtrees change.
* The Jetpack Infinite Scroll handles this when a post-load event is triggered.
* Ideally this should be incorporated into Core.
*
* Hard-coded reference to a Jetpack module's event is not relevant for #coremerge.
*/
if (class_exists('Jetpack')) {
$exports = array();
$handle = 'customize-partial-jetpack-support';
$src = $this->dir_url . 'js/plugin-support/jetpack.js';
$deps = array('customize-partial-refresh-preview');
$in_footer = true;
wp_enqueue_script($handle, $src, $deps, $this->get_version(), $in_footer);
if (Jetpack::is_module_active('infinite-scroll')) {
$exports['infiniteScroll'] = array('themeSupport' => current_theme_supports('infinite-scroll'));
}
if (Jetpack::is_module('widgets')) {
$exports['widgets'] = array('scripts' => array('google-maps' => array('src' => 'https://maps.googleapis.com/maps/api/js?sensor=false'), 'contact-info-map-js' => array('src' => plugins_url('modules/widgets/contact-info/contact-info-map.js', JETPACK__PLUGIN_FILE), 'deps' => array('jquery', 'google-maps'))), 'styles' => array('contact-info-map-css' => array('src' => plugins_url('modules/widgets/contact-info/contact-info-map.css', JETPACK__PLUGIN_FILE))));
}
wp_scripts()->add_data($handle, 'data', sprintf('var _customizeSelectiveRefreshJetpackExports = %s;', wp_json_encode($exports)));
}
add_action('wp_footer', array($this, 'export_preview_data'), 1000);
}
开发者ID:rheinardkorf,项目名称:wp-customize-partial-refresh,代码行数:35,代码来源:class-wp-customize-selective-refresh.php