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;
 }
 /**
  * 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
0
/**
 * 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');
    }
}
 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);
 }
 /**
  * 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
0
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 
}
 /**
  * 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');
 }
 /**
  * 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' );
     }
 }
 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);
 }
 function get_jetpack_modules()
 {
     if (is_user_member_of_blog()) {
         return array_values(Jetpack_Options::get_option('active_modules', array()));
     }
     return null;
 }
 /**
  * @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
0
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);
}
 /**
  * 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
0
 /**
  * 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'));
     }
 }
 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'));
     }
 }
 function __construct()
 {
     $this->jetpack = Jetpack::init();
     self::$block_page_rendering_for_idc = Jetpack::validate_sync_error_idc_option() && !Jetpack_Options::get_option('safe_mode_confirmed');
     if (!self::$block_page_rendering_for_idc) {
         add_action('admin_enqueue_scripts', array($this, 'additional_styles'));
     }
 }
示例#17
0
 function fetch_options()
 {
     $options = $this->in_jetpack() ? Jetpack_Options::get_option('wpcc_options') : get_option('wpcc_options');
     $args = wp_parse_args($options, $this->default_options());
     $args['new_user_override'] = defined('WPCC_NEW_USER_OVERRIDE') ? WPCC_NEW_USER_OVERRIDE : false;
     $args['match_by_email'] = defined('WPCC_MATCH_BY_EMAIL') ? WPCC_MATCH_BY_EMAIL : true;
     return $args;
 }
示例#18
0
function jetpack_enhanced_distribution_feed_id()
{
    (int) ($id = Jetpack_Options::get_option('id'));
    if ($id > 0) {
        $output = sprintf('<site xmlns="com-wordpress:feed-additions:1">%d</site>', $id);
        echo $output;
    }
}
 public function default_action()
 {
     $args = $this->input();
     if (isset($args['autoupdate']) && is_bool($args['autoupdate'])) {
         Jetpack_Options::update_option('autoupdate_core', $args['autoupdate']);
     }
     return true;
 }
 function autoupdate_core($update, $item)
 {
     $autoupdate_core = Jetpack_Options::get_option('autoupdate_core', false);
     if ($autoupdate_core) {
         return $autoupdate_core;
     }
     return $update;
 }
示例#21
0
function jetpack_enhanced_distribution_before_activate_default_modules()
{
    $old_version = Jetpack_Options::get_option('old_version');
    list($old_version) = explode(':', $old_version);
    if (version_compare($old_version, '1.9-something', '>=')) {
        return;
    }
    Jetpack::check_privacy(__FILE__);
}
示例#22
0
 private function __construct()
 {
     global $pagenow;
     $jetpack_hide_jitm = Jetpack_Options::get_option('hide_jitm');
     if ('media-new.php' == $pagenow && !Jetpack::is_module_active('photon') && 'hide' != $jetpack_hide_jitm['photon']) {
         add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
         add_action('post-plupload-upload-ui', array($this, 'photon_msg'));
     }
 }
 function has_videopress()
 {
     // TODO - this only works on wporg site - need to detect videopress option for remote Jetpack site on WPCOM
     $videopress = Jetpack_Options::get_option('videopress', array());
     if (isset($videopress['blog_id']) && $videopress['blog_id'] > 0) {
         return true;
     }
     return false;
 }
 public function get_all_callables()
 {
     // get_all_callables should run as the master user always.
     $current_user_id = get_current_user_id();
     wp_set_current_user(Jetpack_Options::get_option('master_user'));
     $callables = array_combine(array_keys($this->callable_whitelist), array_map(array($this, 'get_callable'), array_values($this->callable_whitelist)));
     wp_set_current_user($current_user_id);
     return $callables;
 }
 /**
  * Gets the value for which connection banner to show, and initializes if not set.
  *
  * @since 4.4.0
  *
  * @return int
  */
 static function get_random_connection_banner_value()
 {
     $random_connection_banner = Jetpack_Options::get_option('connection_banner_ab');
     if (!$random_connection_banner) {
         $random_connection_banner = mt_rand(1, 2);
         Jetpack_Options::update_option('connection_banner_ab', $random_connection_banner);
     }
     return $random_connection_banner;
 }
 /**
  * Get Jetpack Details
  *
  * ## OPTIONS
  *
  * None. Simply returns details about whether or not your blog
  * is connected, its Jetpack version, and WordPress.com blog_id.
  *
  * ## EXAMPLES
  *
  * wp jetpack status
  *
  */
 public function status($args, $assoc_args)
 {
     if (Jetpack::is_active()) {
         WP_CLI::success(__('Jetpack is currently connected to WordPress.com', 'jetpack'));
         WP_CLI::line(sprintf(__('The Jetpack Version is %s', 'jetpack'), JETPACK__VERSION));
         WP_CLI::line(sprintf(__('The WordPress.com blog_id is %d', 'jetpack'), Jetpack_Options::get_option('id')));
     } else {
         WP_CLI::line(__('Jetpack is not currently connected to WordPress.com', 'jetpack'));
     }
 }
 function test_sync_deactivate_module_event()
 {
     Jetpack_Options::update_option('active_modules', array('stuff'));
     Jetpack::deactivate_module('stuff');
     $this->client->do_sync();
     $events = $this->server_event_storage->get_all_events('jetpack_deactivate_module');
     $event = $events[0];
     $this->assertEquals('jetpack_deactivate_module', $event->action);
     $this->assertEquals('stuff', $event->args[0]);
     $this->assertEquals(1, count($events));
 }
 function test_delete_non_compact_option_returns_true_when_successfully_deleted()
 {
     Jetpack_Options::update_option('migrate_for_idc', true);
     // Make sure the option is set
     $this->assertTrue(Jetpack_Options::get_option('migrate_for_idc'));
     $deleted = Jetpack_Options::delete_option('migrate_for_idc');
     // Was the option successfully deleted?
     $this->assertFalse(Jetpack_Options::get_option('migrate_for_idc'));
     // Did Jetpack_Options::delete_option() properly return true?
     $this->assertTrue($deleted);
 }
 function test_clear_all_idc_options_clears_expected()
 {
     $options = array('sync_error_idc', 'safe_mode_confirmed', 'migrate_for_idc');
     foreach ($options as $option) {
         Jetpack_Options::update_option($option, true);
         $this->assertTrue(Jetpack_Options::get_option($option));
     }
     Jetpack_IDC::clear_all_idc_options();
     foreach ($options as $option) {
         $this->assertFalse(Jetpack_Options::get_option($option));
     }
 }
 /**
  * Get the WordPress.com blog ID of your own site.
  *
  * @since 1.0.0
  *
  * @param  absint $blog_id WordPress.com blog ID.
  * @return absint $blog_id WordPress.com blog ID.
  */
 public function get_blog_details($blog_id)
 {
     // Get the blog's ID.
     if (class_exists('Jetpack_Options')) {
         $blog_id = Jetpack_Options::get_option('id');
     }
     if ($blog_id) {
         return absint($blog_id);
     } else {
         return home_url();
     }
 }