本文整理汇总了PHP中Jetpack::get_default_modules方法的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack::get_default_modules方法的具体用法?PHP Jetpack::get_default_modules怎么用?PHP Jetpack::get_default_modules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jetpack
的用法示例。
在下文中一共展示了Jetpack::get_default_modules方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_default_modules_include_mandatory_modules
function test_default_modules_include_mandatory_modules()
{
// Arrange
$jpm = WPCOM_VIP_Jetpack_Mandatory::init();
// Act
$default_modules = Jetpack::get_default_modules();
// Assert
foreach ($jpm->get_mandatory_modules() as $mandatory_module) {
$this->assertTrue(in_array($mandatory_module, $default_modules));
}
}
示例2: get_page_hook
function get_page_hook()
{
$title = _x('Jetpack', 'The menu item label', 'jetpack');
list($jetpack_version) = explode(':', Jetpack_Options::get_option('version'));
if ($jetpack_version && $jetpack_version != JETPACK__VERSION && ($new_modules = Jetpack::get_default_modules($jetpack_version, JETPACK__VERSION)) && is_array($new_modules) && ($new_modules_count = count($new_modules)) && (Jetpack::is_active() || Jetpack::is_development_mode())) {
$new_count_i18n = number_format_i18n($new_modules_count);
$span_title = esc_attr(sprintf(_n('One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack'), $new_count_i18n));
$format = _x('Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack');
$update_markup = "<span class='update-plugins count-{$new_modules_count}' title='{$span_title}'><span class='update-count'>{$new_count_i18n}</span></span>";
$title = sprintf($format, $update_markup);
}
// Add the main admin Jetpack menu with possible information about new
// modules
add_menu_page('Jetpack', $title, 'jetpack_admin_page', 'jetpack', array($this, 'render'), 'div');
// also create the submenu
return add_submenu_page('jetpack', $title, $title, 'jetpack_admin_page', 'jetpack');
}
示例3: admin_menu
function admin_menu()
{
list($jetpack_version) = explode(':', Jetpack_Options::get_option('version'));
if ($jetpack_version && $jetpack_version != JETPACK__VERSION && ($new_modules = Jetpack::get_default_modules($jetpack_version, JETPACK__VERSION)) && is_array($new_modules) && ($new_modules_count = count($new_modules)) && (Jetpack::is_active() || Jetpack::is_development_mode())) {
$new_modules_count_i18n = number_format_i18n($new_modules_count);
$span_title = esc_attr(sprintf(_n('One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack'), $new_modules_count_i18n));
$title = sprintf('Jetpack %s', "<span class='update-plugins count-{$new_modules_count}' title='{$span_title}'><span class='update-count'>{$new_modules_count_i18n}</span></span>");
} else {
$title = __('Jetpack', 'jetpack');
}
$hook = add_menu_page('Jetpack', $title, 'read', 'jetpack', array($this, 'admin_page'), 'div');
$debugger_hook = add_submenu_page(null, __('Jetpack Debugging Center', 'jetpack'), '', 'manage_options', 'jetpack-debugger', array($this, 'debugger_page'));
add_action("admin_head-{$debugger_hook}", array('Jetpack_Debugger', 'jetpack_debug_admin_head'));
add_action("load-{$hook}", array($this, 'admin_page_load'));
add_action("load-{$hook}", array($this, 'admin_help'));
add_action("admin_head-{$hook}", array($this, 'admin_head'));
add_filter('custom_menu_order', array($this, 'admin_menu_order'));
add_filter('menu_order', array($this, 'jetpack_menu_order'));
add_action("admin_print_styles-{$hook}", array($this, 'admin_styles'));
add_action("admin_print_scripts-{$hook}", array($this, 'admin_scripts'));
do_action('jetpack_admin_menu', $hook);
}
示例4: reset
/**
* Reset Jetpack options and settings to default
*
* ## OPTIONS
*
* modules: Resets modules to default state ( get_default_modules() )
*
* options: Resets all Jetpack options except:
* - All private options (Blog token, user token, etc...)
* - id (The Client ID/WP.com Blog ID of this site)
* - master_user
* - version
* - activated
*
* ## EXAMPLES
*
* wp jetpack reset options
* wp jetpack reset modules
*
* @synopsis <modules|options>
*/
public function reset($args, $assoc_args)
{
$action = isset($args[0]) ? $args[0] : 'prompt';
if (!in_array($action, array('options', 'modules'))) {
WP_CLI::error(sprintf(__('%s is not a valid command.', 'jetpack'), $action));
}
// Are you sure?
jetpack_cli_are_you_sure();
switch ($action) {
case 'options':
$options_to_reset = Jetpack::get_jetpack_options_for_reset();
// Reset the Jetpack options
_e("Resetting Jetpack Options...\n", "jetpack");
sleep(1);
// Take a breath
foreach ($options_to_reset['jp_options'] as $option_to_reset) {
Jetpack_Options::delete_option($option_to_reset);
usleep(100000);
WP_CLI::success(sprintf(__('%s option reset', 'jetpack'), $option_to_reset));
}
// Reset the WP options
_e("Resetting the jetpack options stored in wp_options...\n", "jetpack");
usleep(500000);
// Take a breath
foreach ($options_to_reset['wp_options'] as $option_to_reset) {
delete_option($option_to_reset);
usleep(100000);
WP_CLI::success(sprintf(__('%s option reset', 'jetpack'), $option_to_reset));
}
// Reset to default modules
_e("Resetting default modules...\n", "jetpack");
usleep(500000);
// Take a breath
$default_modules = Jetpack::get_default_modules();
Jetpack::update_active_modules($default_modules);
WP_CLI::success(__('Modules reset to default.', 'jetpack'));
// Jumpstart option is special
Jetpack_Options::update_option('jumpstart', 'new_connection');
WP_CLI::success(__('jumpstart option reset', 'jetpack'));
break;
case 'modules':
$default_modules = Jetpack::get_default_modules();
Jetpack::update_active_modules($default_modules);
WP_CLI::success(__('Modules reset to default.', 'jetpack'));
break;
case 'prompt':
WP_CLI::error(__('Please specify if you would like to reset your options, or modules', 'jetpack'));
break;
}
}
示例5: admin_menu
function admin_menu()
{
list($jetpack_version) = explode(':', Jetpack_Options::get_option('version'));
if ($jetpack_version && $jetpack_version != JETPACK__VERSION && ($new_modules = Jetpack::get_default_modules($jetpack_version, JETPACK__VERSION)) && is_array($new_modules) && ($new_modules_count = count($new_modules)) && (Jetpack::is_active() || Jetpack::is_development_mode())) {
$new_modules_count_i18n = number_format_i18n($new_modules_count);
$span_title = esc_attr(sprintf(_n('One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack'), $new_modules_count_i18n));
$title = sprintf('Jetpack %s', "<span class='update-plugins count-{$new_modules_count}' title='{$span_title}'><span class='update-count'>{$new_modules_count_i18n}</span></span>");
} else {
$title = __('Slim Jetpack', 'jetpack');
}
//slim// Move the admin menu to settings
$hook = add_submenu_page('options-general.php', $title, $title, 'read', 'jetpack', array($this, 'admin_page'), 'div');
$debugger_hook = add_submenu_page(null, __('Jetpack Debugging Center', 'jetpack'), '', 'manage_options', 'jetpack-debugger', array($this, 'debugger_page'));
add_action("admin_head-{$debugger_hook}", array('Jetpack_Debugger', 'jetpack_debug_admin_head'));
add_action("load-{$hook}", array($this, 'admin_page_load'));
if (version_compare($GLOBALS['wp_version'], '3.3', '<')) {
if (isset($_GET['page']) && 'jetpack' == $_GET['page']) {
add_contextual_help($hook, $this->jetpack_help());
}
} else {
//slim//add_action( "load-$hook", array( $this, 'admin_help' ) );
}
add_action("admin_head-{$hook}", array($this, 'admin_head'));
add_filter('custom_menu_order', array($this, 'admin_menu_order'));
add_filter('menu_order', array($this, 'jetpack_menu_order'));
add_action("admin_print_styles-{$hook}", array($this, 'admin_styles'));
add_action("admin_print_scripts-{$hook}", array($this, 'admin_scripts'));
if (function_exists('akismet_conf')) {
function akismet_reload_menu()
{
add_submenu_page('options-general.php', __('Akismet'), __('Akismet'), 'manage_options', 'akismet-key-config', 'akismet_conf');
add_submenu_page('edit-comments.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
}
add_action('jetpack_admin_menu', 'akismet_reload_menu');
}
do_action('jetpack_admin_menu', $hook);
}
示例6: activate_default_modules
public static function activate_default_modules($min_version = false, $max_version = false, $other_modules = array(), $redirect = true)
{
$jetpack = Jetpack::init();
$modules = Jetpack::get_default_modules($min_version, $max_version);
$modules = array_merge($other_modules, $modules);
// Look for standalone plugins and disable if active.
$to_deactivate = array();
foreach ($modules as $module) {
if (isset($jetpack->plugins_to_deactivate[$module])) {
$to_deactivate[$module] = $jetpack->plugins_to_deactivate[$module];
}
}
$deactivated = array();
foreach ($to_deactivate as $module => $deactivate_me) {
list($probable_file, $probable_title) = $deactivate_me;
if (Jetpack_Client_Server::deactivate_plugin($probable_file, $probable_title)) {
$deactivated[] = $module;
}
}
if ($deactivated && $redirect) {
Jetpack::state('deactivated_plugins', join(',', $deactivated));
$url = add_query_arg(array('action' => 'activate_default_modules', '_wpnonce' => wp_create_nonce('activate_default_modules')), add_query_arg(compact('min_version', 'max_version', 'other_modules'), Jetpack::admin_url('page=jetpack')));
wp_safe_redirect($url);
exit;
}
/**
* Fires before default modules are activated.
*
* @since 1.9.0
*
* @param string $min_version Minimum version number required to use modules.
* @param string $max_version Maximum version number required to use modules.
* @param array $other_modules Array of other modules to activate alongside the default modules.
*/
do_action('jetpack_before_activate_default_modules', $min_version, $max_version, $other_modules);
// Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating
Jetpack::restate();
Jetpack::catch_errors(true);
$active = Jetpack::get_active_modules();
foreach ($modules as $module) {
if (did_action("jetpack_module_loaded_{$module}")) {
$active[] = $module;
Jetpack_Options::update_option('active_modules', array_unique($active));
continue;
}
if (in_array($module, $active)) {
$module_info = Jetpack::get_module($module);
if (!$module_info['deactivate']) {
$state = in_array($module, $other_modules) ? 'reactivated_modules' : 'activated_modules';
if ($active_state = Jetpack::state($state)) {
$active_state = explode(',', $active_state);
} else {
$active_state = array();
}
$active_state[] = $module;
Jetpack::state($state, implode(',', $active_state));
}
continue;
}
$file = Jetpack::get_module_path($module);
if (!file_exists($file)) {
continue;
}
// we'll override this later if the plugin can be included without fatal error
if ($redirect) {
wp_safe_redirect(Jetpack::admin_url('page=jetpack'));
}
Jetpack::state('error', 'module_activation_failed');
Jetpack::state('module', $module);
ob_start();
require $file;
/**
* Fires when a specific module is activated.
*
* @since 1.9.0
*
* @param string $module Module slug.
*/
do_action('jetpack_activate_module', $module);
$active[] = $module;
$state = in_array($module, $other_modules) ? 'reactivated_modules' : 'activated_modules';
if ($active_state = Jetpack::state($state)) {
$active_state = explode(',', $active_state);
} else {
$active_state = array();
}
$active_state[] = $module;
Jetpack::state($state, implode(',', $active_state));
Jetpack_Options::update_option('active_modules', array_unique($active));
ob_end_clean();
}
Jetpack::state('error', false);
Jetpack::state('module', false);
Jetpack::catch_errors(false);
/**
* Fires when default modules are activated.
*
* @since 1.9.0
*
* @param string $min_version Minimum version number required to use modules.
//.........这里部分代码省略.........
示例7: admin_menu
function admin_menu()
{
list($jetpack_version) = explode(':', Jetpack::get_option('version'));
if ($jetpack_version && $jetpack_version != JETPACK__VERSION && ($new_modules = Jetpack::get_default_modules($jetpack_version, JETPACK__VERSION)) && is_array($new_modules) && ($new_modules_count = count($new_modules)) && $this->is_active()) {
$new_modules_count_i18n = number_format_i18n($new_modules_count);
$span_title = esc_attr(sprintf(_n('One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack'), $new_modules_count_i18n));
$title = sprintf('Jetpack %s', "<span class='update-plugins count-{$new_modules_count}' title='{$span_title}'><span class='update-count'>{$new_modules_count_i18n}</span></span>");
} else {
$title = 'Jetpack';
}
$hook = add_menu_page('Jetpack', $title, 'manage_options', 'jetpack', array(&$this, 'admin_page'), '');
if (isset($_GET['page']) && 'jetpack' == $_GET['page']) {
add_contextual_help($hook, $this->jetpack_help());
}
add_action("load-{$hook}", array(&$this, 'admin_page_load'));
add_action("admin_head-{$hook}", array(&$this, 'admin_head'));
add_filter('custom_menu_order', array(&$this, 'admin_menu_order'));
add_filter('menu_order', array(&$this, 'jetpack_menu_order'));
if (Jetpack::is_active()) {
add_action("admin_print_styles-{$hook}", array(&$this, 'admin_styles'));
}
add_action("admin_print_scripts-{$hook}", array(&$this, 'admin_scripts'));
do_action('jetpack_admin_menu');
}
示例8: admin_menu
function admin_menu()
{
// @todo: Remove in Jetpack class itself.
remove_action('admin_menu', array($this->jetpack, 'admin_menu'), 999);
$title = _x('Jetpack', 'The menu item label', 'jetpack');
list($jetpack_version) = explode(':', Jetpack_Options::get_option('version'));
if ($jetpack_version && $jetpack_version != JETPACK__VERSION && ($new_modules = Jetpack::get_default_modules($jetpack_version, JETPACK__VERSION)) && is_array($new_modules) && ($new_modules_count = count($new_modules)) && (Jetpack::is_active() || Jetpack::is_development_mode())) {
$new_count_i18n = number_format_i18n($new_modules_count);
$span_title = esc_attr(sprintf(_n('One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack'), $new_count_i18n));
$format = _x('Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack');
$update_markup = "<span class='update-plugins count-{$new_modules_count}' title='{$span_title}'><span class='update-count'>{$new_count_i18n}</span></span>";
$title = sprintf($format, $update_markup);
}
$callback = empty($_GET['configure']) ? array($this, 'admin_page') : array($this, 'admin_page_nojs_configurable');
$hook = add_menu_page('Jetpack', $title, 'jetpack_admin_page', 'jetpack', $callback, 'div');
add_action("load-{$hook}", array($this, 'admin_help'));
add_action("load-{$hook}", array($this, 'admin_page_load'));
add_action("admin_head-{$hook}", array($this, 'admin_head'));
add_action("admin_footer-{$hook}", array($this, 'main_page_js_templates'));
add_action("admin_print_styles-{$hook}", array($this, 'admin_styles'));
add_action("admin_print_scripts-{$hook}", array($this, 'admin_scripts'));
do_action('jetpack_admin_menu', $hook);
add_filter('custom_menu_order', array($this, 'admin_menu_order'));
add_filter('menu_order', array($this, 'jetpack_menu_order'));
}
示例9: reset_jetpack_options
/**
* Reset Jetpack options
*
* @since 4.3.0
*
* @param WP_REST_Request $data {
* Array of parameters received by request.
*
* @type string $options Available options to reset are options|modules
* }
*
* @return bool|WP_Error True if options were reset. Otherwise, a WP_Error instance with the corresponding error.
*/
public static function reset_jetpack_options($data)
{
$param = $data->get_json_params();
if (!isset($param['reset']) || $param['reset'] !== true) {
return new WP_Error('invalid_param', esc_html__('Invalid Parameter', 'jetpack'), array('status' => 404));
}
if (isset($data['options'])) {
$data = $data['options'];
switch ($data) {
case 'options':
$options_to_reset = Jetpack::get_jetpack_options_for_reset();
// Reset the Jetpack options
foreach ($options_to_reset['jp_options'] as $option_to_reset) {
Jetpack_Options::delete_option($option_to_reset);
}
foreach ($options_to_reset['wp_options'] as $option_to_reset) {
delete_option($option_to_reset);
}
// Reset to default modules
$default_modules = Jetpack::get_default_modules();
Jetpack::update_active_modules($default_modules);
// Jumpstart option is special
Jetpack_Options::update_option('jumpstart', 'new_connection');
return rest_ensure_response(array('code' => 'success', 'message' => esc_html__('Jetpack options reset.', 'jetpack')));
break;
case 'modules':
$default_modules = Jetpack::get_default_modules();
Jetpack::update_active_modules($default_modules);
return rest_ensure_response(array('code' => 'success', 'message' => esc_html__('Modules reset to default.', 'jetpack')));
break;
default:
return new WP_Error('invalid_param', esc_html__('Invalid Parameter', 'jetpack'), array('status' => 404));
}
}
return new WP_Error('required_param', esc_html__('Missing parameter "type".', 'jetpack'), array('status' => 404));
}
示例10: activate_default_modules
function activate_default_modules()
{
$modules = Jetpack::get_default_modules();
// Check each module for fatal errors, a la wp-admin/plugins.php::activate before activating
$redirect = menu_page_url('jetpack', false);
Jetpack::catch_errors(true);
foreach ($modules as $module) {
$active = Jetpack::get_active_modules();
wp_redirect(add_query_arg(array('error' => 'module_activation_failed', 'module' => urlencode($module)), $redirect));
// we'll override this later if the plugin can be included without fatal error
ob_start();
require Jetpack::get_module_path($module);
$active[] = $module;
if ($active_state = Jetpack::state('activated_modules')) {
$active_state = explode(',', $active_state);
} else {
$active_state = array();
}
$active_state[] = $module;
Jetpack::state('activated_modules', implode(',', $active_state));
update_option('jetpack_active_modules', array_unique($active));
ob_end_clean();
}
Jetpack::catch_errors(false);
}