function get_jetpack_modules() { if (is_user_member_of_blog()) { return array_values(Jetpack_Options::get_option('active_modules', array())); } return null; }
/** * 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); }
/** * 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')); } } }
/** * 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'); }
/** * Module Name: Custom CSS * Module Description: Tweak your site’s CSS without modifying your theme. * Sort Order: 2 * First Introduced: 1.7 * Requires Connection: No * Auto Activate: Yes * Module Tags: Appearance * Feature: Appearance * Additional Search Queries: css, customize, custom, style, editor, less, sass, preprocessor, font, mobile, appearance, theme, stylesheet */ function jetpack_load_custom_css() { // If WordPress has the core version of Custom CSS, load our new version. // @see https://core.trac.wordpress.org/changeset/38829 if (function_exists('wp_get_custom_css')) { if (!function_exists('wp_update_custom_css_post')) { wp_die('Please run a SVN up to get the latest version of trunk, or update to at least 4.7 RC1'); } if (!Jetpack_Options::get_option('custom_css_4.7_migration')) { include_once dirname(__FILE__) . '/custom-css/migrate-to-core.php'; } else { if (defined('WP_CLI') && WP_CLI) { function jetpack_custom_css_undo_data_migration_cli() { Jetpack_Options::delete_option('custom_css_4.7_migration'); WP_CLI::success(__('Option deleted, re-migrate via `wp jetpack custom-css migrate`.', 'jetpack')); } WP_CLI::add_command('jetpack custom-css undo-migrate', 'jetpack_custom_css_undo_data_migration_cli'); } } // TODO: END DELETE THIS include_once dirname(__FILE__) . '/custom-css/custom-css/preprocessors.php'; include_once dirname(__FILE__) . '/custom-css/custom-css-4.7.php'; return; } include_once dirname(__FILE__) . "/custom-css/custom-css.php"; add_action('init', array('Jetpack_Custom_CSS', 'init')); }
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); }
/** * 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' ); } }
/** * @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; }
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; }
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 }
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; }
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; } }
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')); } }
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 autoupdate_core($update, $item) { $autoupdate_core = Jetpack_Options::get_option('autoupdate_core', false); if ($autoupdate_core) { return $autoupdate_core; } return $update; }
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')); } }
/** * 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; }
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; }
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__); }
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; }
/** * 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_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); }
/** * Get VideoPress options */ function get_options() { $defaults = array('blogs' => array(), 'blog_id' => 0, 'access' => '', 'allow-upload' => false, 'freedom' => false, 'hd' => false, 'meta' => array('max_upload_size' => 0)); $options = Jetpack_Options::get_option($this->option_name, array()); // If options have not been saved yet, check for older VideoPress plugin options. if (empty($options)) { $options['freedom'] = (bool) get_option('video_player_freedom', false); $options['hd'] = (bool) get_option('video_player_high_quality', false); } $options = array_merge($defaults, $options); return $options; }
/** * 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(); } }
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)); } }
/** * Logs when Jetpack actually updates its version option */ function wpcom_vip_log_updating_jetpack_version_option($option_name, $option_value) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $caller = 'unknown caller'; foreach ($backtrace as $call) { if ('update_option' == $call['function']) { $caller = sprintf('called by %s on line %d', str_replace(WP_CONTENT_DIR, '', $call['file']), $call['line']); break; } } $current_value = Jetpack_Options::get_option('version'); error_log('Update Jetpack version to ' . $option_value . ', ' . $caller . ' - current value is ' . $current_value . ', constant is ' . JETPACK__VERSION); }
/** * Switches to the blog and checks current user capabilities. * @return bool|WP_Error a WP_Error object or true if things are good. */ protected function validate_call($_blog_id, $capability, $check_full_management = true) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($_blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } if (is_wp_error($error = $this->check_capability($capability))) { return $error; } if ($check_full_management && !Jetpack_Options::get_option('json_api_full_management')) { return new WP_Error('unauthorized_full_access', sprintf(__('Full management mode is off for this site.', 'jetpack'), $capability), 403); } return true; }
/** * Gets the local Protect whitelist * * The 'local' part of the whitelist only really applies to multisite installs, * which can have a network wide whitelist, as well as a local list that applies * only to the current site. On single site installs, there will only be a local * whitelist. * * @return array A list of IP Address objects or an empty array */ function jetpack_protect_get_local_whitelist() { $whitelist = Jetpack_Options::get_option('protect_whitelist'); if (false === $whitelist) { // The local whitelist has never been set if (is_multisite()) { // On a multisite, we can check for a legacy site_option that existed prior to v 3.6, or default to an empty array $whitelist = get_site_option('jetpack_protect_whitelist', array()); } else { // On a single site, we can just use an empty array $whitelist = array(); } } return $whitelist; }
/** * Method that gets executed on the wp-cron call * * @since 2.3.3 * @global string $wp_version */ public function cron_exec() { /* * This should run weekly. Figuring in for variances in * WP_CRON, don't let it run more than every six days at most. * * i.e. if it ran less than six days ago, fail out. */ $last = (int) Jetpack_Options::get_option('last_heartbeat'); if ($last && $last + WEEK_IN_SECONDS - DAY_IN_SECONDS > time()) { return; } /* * Check for an identity crisis * * If one exists: * - Bump stat for ID crisis * - Email site admin about potential ID crisis */ /** * Setup an array of items that will eventually be stringified * and sent off to the Jetpack API * * Associative array with format group => values * - values should be an array that will be imploded to a string */ $jetpack = Jetpack::init(); $jetpack->stat('active-modules', implode(',', $jetpack->get_active_modules())); $jetpack->stat('active', JETPACK__VERSION); $jetpack->stat('wp-version', get_bloginfo('version')); $jetpack->stat('php-version', PHP_VERSION); $jetpack->stat('ssl', $jetpack->permit_ssl()); $jetpack->stat('language', get_bloginfo('language')); $jetpack->stat('charset', get_bloginfo('charset')); $jetpack->stat('qty-posts', wp_count_posts()->publish); $jetpack->stat('qty-pages', wp_count_posts('page')->publish); $jetpack->stat('qty-comments', wp_count_comments()->approved); $jetpack->stat('is-multisite', is_multisite() ? 'multisite' : 'singlesite'); $jetpack->stat('identitycrisis', Jetpack::check_identity_crisis(1) ? 'yes' : 'no'); // Only check a few plugins, to see if they're currently active. $plugins_to_check = array('vaultpress/vaultpress.php', 'akismet/akismet.php', 'wp-super-cache/wp-cache.php'); $plugins = array_intersect($plugins_to_check, get_option('active_plugins', array())); foreach ($plugins as $plugin) { $jetpack->stat('plugins', $plugin); } Jetpack_Options::update_option('last_heartbeat', time()); $jetpack->do_stats('server_side'); }
protected function get_container_extra_data() { global $post; $blog_id = (int) get_current_blog_id(); if (defined('IS_WPCOM') && IS_WPCOM) { $likes_blog_id = $blog_id; } else { $likes_blog_id = Jetpack_Options::get_option('id'); } if (class_exists('Jetpack_Carousel') || in_array('carousel', Jetpack::get_active_modules()) || 'carousel' == $this->link) { $extra_data = array('blog_id' => $blog_id, 'permalink' => get_permalink(isset($post->ID) ? $post->ID : 0), 'likes_blog_id' => $likes_blog_id); } else { $extra_data = null; } return $extra_data; }