本文整理汇总了PHP中Jetpack_Options类的典型用法代码示例。如果您正苦于以下问题:PHP Jetpack_Options类的具体用法?PHP Jetpack_Options怎么用?PHP Jetpack_Options使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Jetpack_Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jetpack_site_icon_url
function jetpack_site_icon_url($blog_id = null, $size = '512', $default = false)
{
$url = '';
if (!is_int($blog_id)) {
$blog_id = get_current_blog_id();
}
if (function_exists('get_blog_option')) {
$site_icon_id = get_blog_option($blog_id, 'jetpack_site_icon_id');
} else {
$site_icon_id = Jetpack_Options::get_option('site_icon_id');
}
if (!$site_icon_id) {
if ($default === false && defined('SITE_ICON_DEFAULT_URL')) {
$url = SITE_ICON_DEFAULT_URL;
} else {
$url = $default;
}
} else {
if ($size >= 512) {
$size_data = 'full';
} else {
$size_data = array($size, $size);
}
$url_data = wp_get_attachment_image_src($site_icon_id, $size_data);
$url = $url_data[0];
}
return $url;
}
示例2: prepare_jitms
/**
* Prepare actions according to screen and post type.
*
* @since 3.8.2
*
* @param object $screen
*/
function prepare_jitms($screen)
{
global $pagenow;
$post_type = $screen->post_type;
self::$jetpack_hide_jitm = Jetpack_Options::get_option('hide_jitm');
$showphoton = empty(self::$jetpack_hide_jitm['photon']) ? 'show' : self::$jetpack_hide_jitm['photon'];
$showmanage = empty(self::$jetpack_hide_jitm['manage']) ? 'show' : self::$jetpack_hide_jitm['manage'];
$show_manage_pi = empty(self::$jetpack_hide_jitm['manage-pi']) ? 'show' : self::$jetpack_hide_jitm['manage-pi'];
$show_editor = empty(self::$jetpack_hide_jitm['editor']) ? 'show' : self::$jetpack_hide_jitm['editor'];
if ('media-new.php' == $pagenow && !Jetpack::is_module_active('photon') && 'hide' != $showphoton) {
add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
add_action('post-plupload-upload-ui', array($this, 'photon_msg'));
} else {
if ('update-core.php' == $pagenow && 'hide' != $showmanage) {
add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
add_action('admin_notices', array($this, 'manage_msg'));
} elseif ('plugins.php' === $pagenow && isset($_GET['activate']) && 'true' === $_GET['activate'] && 'hide' != $show_manage_pi) {
add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
add_action('pre_current_active_plugins', array($this, 'manage_pi_msg'));
} elseif ('post-new.php' === $pagenow && in_array($post_type, array('post', 'page')) && 'hide' != $show_editor) {
add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
add_action('admin_notices', array($this, 'editor_msg'));
}
}
}
示例3: jetpack_load_minileven
/**
* Module Name: Mobile Theme
* Module Description: Optimize your site for smartphones and tablets.
* Sort Order: 21
* Recommendation Order: 11
* First Introduced: 1.8
* Requires Connection: No
* Auto Activate: No
* Module Tags: Appearance, Mobile, Recommended
* Feature: Appearance
* Additional Search Queries: mobile, theme, minileven
*/
function jetpack_load_minileven()
{
include dirname(__FILE__) . "/minileven/minileven.php";
if (Jetpack_Options::get_option_and_ensure_autoload('wp_mobile_app_promos', '0') != '1') {
remove_action('wp_mobile_theme_footer', 'jetpack_mobile_app_promo');
}
}
示例4: record_user_event
public function record_user_event($event_type, $data = array())
{
if (!function_exists('jetpack_tracks_record_event')) {
$this->log('Error. jetpack_tracks_record_event is not defined.');
return;
}
$user = wp_get_current_user();
$site_url = get_option('siteurl');
// Check for WooCommerce
$wc_version = 'unavailable';
if (function_exists('WC')) {
$wc_version = WC()->version;
}
// Check for Jetpack
$jp_version = 'unavailable';
if (defined('JETPACK__VERSION')) {
$jp_version = JETPACK__VERSION;
}
$jetpack_blog_id = -1;
if (class_exists('Jetpack_Options') && method_exists('Jetpack_Options', 'get_option')) {
$jetpack_blog_id = Jetpack_Options::get_option('id');
}
$data['_via_ua'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$data['_via_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$data['_lg'] = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
$data['blog_url'] = $site_url;
$data['blog_id'] = $jetpack_blog_id;
$data['jetpack_version'] = $jp_version;
$data['wc_version'] = $wc_version;
$data['wp_version'] = get_bloginfo('version');
$event_type = self::$product_name . '_' . $event_type;
$this->log('Tracked the following event: ' . $event_type);
return jetpack_tracks_record_event($user, $event_type, $data);
}
示例5: user_role_change
/**
* Synchronize connected user role changes
*/
static function user_role_change($user_id)
{
if (Jetpack::is_active() && Jetpack::is_user_connected($user_id)) {
$current_user_id = get_current_user_id();
wp_set_current_user($user_id);
$role = Jetpack::translate_current_user_to_role();
$signed_role = Jetpack::sign_role($role);
wp_set_current_user($current_user_id);
$master_token = Jetpack_Data::get_access_token(JETPACK_MASTER_USER);
$master_user_id = absint($master_token->external_user_id);
if (!$master_user_id) {
return;
}
// this shouldn't happen
Jetpack::xmlrpc_async_call('jetpack.updateRole', $user_id, $signed_role);
//@todo retry on failure
//try to choose a new master if we're demoting the current one
if ($user_id == $master_user_id && 'administrator' != $role) {
$query = new WP_User_Query(array('fields' => array('id'), 'role' => 'administrator', 'orderby' => 'id', 'exclude' => array($master_user_id)));
$new_master = false;
foreach ($query->results as $result) {
$uid = absint($result->id);
if ($uid && Jetpack::is_user_connected($uid)) {
$new_master = $uid;
break;
}
}
if ($new_master) {
Jetpack_Options::update_option('master_user', $new_master);
}
// else disconnect..?
}
}
}
示例6: jetpack_json_api_configuration_screen
function jetpack_json_api_configuration_screen()
{
?>
<div class="narrow">
<form method="post">
<input type='hidden' name='action' value='save_options' />
<?php
wp_nonce_field('json-api');
?>
<table id="menu" class="form-table">
<tr valign="top"><th scope="row"><label for="json_api_full_management"><?php
_e('Allow management', 'jetpack');
?>
</label></th>
<td><label><input type='checkbox'<?php
checked(Jetpack_Options::get_option('json_api_full_management'));
?>
name='json_api_full_management' id='json_api_full_management' /> <?php
printf(__('Allow remote management of themes, plugins, and WordPress via the JSON API. (<a href="%s" title="Learn more about JSON API">More info</a>).', 'jetpack'), '//jetpack.me/support/json-api');
?>
</label></td></tr>
</table>
<p class="submit"><input type='submit' class='button-primary' value='<?php
echo esc_attr(__('Save configuration', 'jetpack'));
?>
' /></p>
</form>
</div>
<?php
}
示例7: cron_exec
/**
* Method that gets executed on the wp-cron call
*
* @since 2.3.3
* @global string $wp_version
*/
public function cron_exec()
{
$jetpack = Jetpack::init();
/*
* This should run daily. Figuring in for variances in
* WP_CRON, don't let it run more than every 23 hours at most.
*
* i.e. if it ran less than 23 hours ago, fail out.
*/
$last = (int) Jetpack_Options::get_option('last_heartbeat');
if ($last && $last + DAY_IN_SECONDS - HOUR_IN_SECONDS > time()) {
return;
}
/*
* Check for an identity crisis
*
* If one exists:
* - Bump stat for ID crisis
* - Email site admin about potential ID crisis
*/
// Coming Soon!
foreach (self::generate_stats_array('v2-') as $key => $value) {
$jetpack->stat($key, $value);
}
Jetpack_Options::update_option('last_heartbeat', time());
$jetpack->do_stats('server_side');
}
示例8: __construct
/**
* Constructor.
*/
public function __construct()
{
$theme_support = get_theme_support('social-links');
/* An array of named arguments must be passed as the second parameter
* of add_theme_support().
*/
if (!isset($theme_support[0]) || empty($theme_support[0])) {
return;
}
$this->links = Jetpack_Options::get_option('social_links', array());
global $publicize;
if (is_a($publicize, 'Publicize')) {
$this->publicize = $publicize;
$this->services = array_intersect(array_keys($this->publicize->get_services('connected')), $theme_support[0]);
add_action('customize_register', array($this, 'customize_register'));
add_filter('sanitize_option_jetpack_options', array($this, 'sanitize_link'));
}
add_filter('jetpack_has_social_links', array($this, 'has_social_links'));
add_filter('jetpack_get_social_links', array($this, 'get_social_links'));
foreach ($theme_support[0] as $service) {
add_filter("pre_option_jetpack-{$service}", array($this, 'get_social_link_filter'));
// get_option( 'jetpack-service' );
add_filter("theme_mod_jetpack-{$service}", array($this, 'get_social_link_filter'));
// get_theme_mod( 'jetpack-service' );
}
}
示例9: test_does_not_fire_jetpack_publicize_post_on_save_as_published
public function test_does_not_fire_jetpack_publicize_post_on_save_as_published()
{
$this->post->post_status = 'publish';
Jetpack_Options::delete_option(array('publicize_connections'));
wp_insert_post($this->post->to_array());
$this->assertPublicized(false, $this->post);
}
示例10: get_jetpack_modules
function get_jetpack_modules()
{
if (is_user_member_of_blog()) {
return array_values(Jetpack_Options::get_option('active_modules', array()));
}
return null;
}
示例11: verify_action
/**
* @return WP_Error|string secret_2 on success, WP_Error( error_code => error_code, error_message => error description, error_data => status code ) on failure
*
* Possible error_codes:
*
* verify_secret_1_missing
* verify_secret_1_malformed
* verify_secrets_missing: No longer have verification secrets stored
* verify_secrets_mismatch: stored secret_1 does not match secret_1 sent by Jetpack.WordPress.com
*/
function verify_action($params)
{
$action = $params[0];
$verify_secret = $params[1];
if (empty($verify_secret)) {
return $this->error(new Jetpack_Error('verify_secret_1_missing', sprintf('The required "%s" parameter is missing.', 'secret_1'), 400));
} else {
if (!is_string($verify_secret)) {
return $this->error(new Jetpack_Error('verify_secret_1_malformed', sprintf('The required "%s" parameter is malformed.', 'secret_1'), 400));
}
}
$secrets = Jetpack_Options::get_option($action);
if (!$secrets || is_wp_error($secrets)) {
Jetpack_Options::delete_option($action);
return $this->error(new Jetpack_Error('verify_secrets_missing', 'Verification took too long', 400));
}
@(list($secret_1, $secret_2, $secret_eol) = explode(':', $secrets));
if (empty($secret_1) || empty($secret_2) || empty($secret_eol) || $secret_eol < time()) {
Jetpack_Options::delete_option($action);
return $this->error(new Jetpack_Error('verify_secrets_missing', 'Verification took too long', 400));
}
if ($verify_secret !== $secret_1) {
Jetpack_Options::delete_option($action);
return $this->error(new Jetpack_Error('verify_secrets_mismatch', 'Secret mismatch', 400));
}
Jetpack_Options::delete_option($action);
return $secret_2;
}
示例12: jetpack_check_mobile
function jetpack_check_mobile()
{
if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST || defined('APP_REQUEST') && APP_REQUEST) {
return false;
}
if (!isset($_SERVER["HTTP_USER_AGENT"]) || isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'false') {
return false;
}
if (jetpack_mobile_exclude()) {
return false;
}
if (1 == Jetpack_Options::get_option_and_ensure_autoload('wp_mobile_disable', '0')) {
return false;
}
if (isset($_COOKIE['akm_mobile']) && $_COOKIE['akm_mobile'] == 'true') {
return true;
}
$is_mobile = jetpack_is_mobile();
/**
* Filter the Mobile check results.
*
* @module minileven
*
* @since 1.8.0
*
* @param bool $is_mobile Is the reader on a mobile device.
*/
return apply_filters('jetpack_check_mobile', $is_mobile);
}
示例13: get_access_token
/**
* Gets locally stored token
*
* @return object|false
*/
public static function get_access_token($user_id = false)
{
if ($user_id) {
if (!($tokens = Jetpack_Options::get_option('user_tokens'))) {
return false;
}
if ($user_id === JETPACK_MASTER_USER) {
if (!($user_id = Jetpack_Options::get_option('master_user'))) {
return false;
}
}
if (!isset($tokens[$user_id]) || !($token = $tokens[$user_id])) {
return false;
}
$token_chunks = explode('.', $token);
if (empty($token_chunks[1]) || empty($token_chunks[2])) {
return false;
}
if ($user_id != $token_chunks[2]) {
return false;
}
$token = "{$token_chunks[0]}.{$token_chunks[1]}";
} else {
$token = Jetpack_Options::get_option('blog_token');
if (empty($token)) {
return false;
}
}
return (object) array('secret' => $token, 'external_user_id' => (int) $user_id);
}
示例14: maybe_register_cpt
/**
* Registers the custom post types and adds action/filter handlers, but
* only if the site supports it
*/
function maybe_register_cpt()
{
// Add an option to enable the CPT
add_action('admin_init', array($this, 'settings_api_init'));
// Check on theme switch if theme supports CPT and setting is disabled
add_action('after_switch_theme', array($this, 'activation_post_type_support'));
$setting = Jetpack_Options::get_option_and_ensure_autoload(self::OPTION_NAME, '0');
// Bail early if Testimonial option is not set and the theme doesn't declare support
if (empty($setting) && !$this->site_supports_custom_post_type()) {
return;
}
if ((!defined('IS_WPCOM') || !IS_WPCOM) && !Jetpack::is_module_active('custom-content-types')) {
return;
}
// Enable Omnisearch for CPT.
if (class_exists('Jetpack_Omnisearch_Posts')) {
new Jetpack_Omnisearch_Posts(self::CUSTOM_POST_TYPE);
}
// CPT magic
$this->register_post_types();
add_action(sprintf('add_option_%s', self::OPTION_NAME), array($this, 'flush_rules_on_enable'), 10);
add_action(sprintf('update_option_%s', self::OPTION_NAME), array($this, 'flush_rules_on_enable'), 10);
add_action(sprintf('publish_%s', self::CUSTOM_POST_TYPE), array($this, 'flush_rules_on_first_testimonial'));
add_action('after_switch_theme', array($this, 'flush_rules_on_switch'));
// Admin Customization
add_filter('enter_title_here', array($this, 'change_default_title'));
add_filter(sprintf('manage_%s_posts_columns', self::CUSTOM_POST_TYPE), array($this, 'edit_title_column_label'));
add_filter('post_updated_messages', array($this, 'updated_messages'));
add_action('customize_register', array($this, 'customize_register'));
// Only add the 'Customize' sub-menu if the theme supports it.
$num_testimonials = self::count_testimonials();
if (!empty($num_testimonials) && current_theme_supports(self::CUSTOM_POST_TYPE)) {
add_action('admin_menu', array($this, 'add_customize_page'));
}
if (defined('IS_WPCOM') && IS_WPCOM) {
// Track all the things
add_action(sprintf('add_option_%s', self::OPTION_NAME), array($this, 'new_activation_stat_bump'));
add_action(sprintf('update_option_%s', self::OPTION_NAME), array($this, 'update_option_stat_bump'), 11, 2);
add_action(sprintf('publish_%s', self::CUSTOM_POST_TYPE), array($this, 'new_testimonial_stat_bump'));
// Add to Dotcom XML sitemaps
add_filter('wpcom_sitemap_post_types', array($this, 'add_to_sitemap'));
} else {
// Add to Jetpack XML sitemap
add_filter('jetpack_sitemap_post_types', array($this, 'add_to_sitemap'));
}
// Adjust CPT archive and custom taxonomies to obey CPT reading setting
add_filter('pre_get_posts', array($this, 'query_reading_setting'), 20);
add_filter('infinite_scroll_settings', array($this, 'infinite_scroll_click_posts_per_page'));
// Register [jetpack_testimonials] always and
// register [testimonials] if [testimonials] isn't already set
add_shortcode('jetpack_testimonials', array($this, 'jetpack_testimonial_shortcode'));
if (!shortcode_exists('testimonials')) {
add_shortcode('testimonials', array($this, 'jetpack_testimonial_shortcode'));
}
// If CPT was enabled programatically and no CPT items exist when user switches away, disable
if ($setting && $this->site_supports_custom_post_type()) {
add_action('switch_theme', array($this, 'deactivation_post_type_support'));
}
}
示例15: jetpack_get_freshly_pressed_data
function jetpack_get_freshly_pressed_data()
{
if (is_single()) {
wp_send_json_success(array('blog_id' => Jetpack_Options::get_option('id'), 'post_id' => get_the_ID()));
} else {
wp_send_json_error(array('message' => 'Not Singular'));
}
}