get_setting() static public method

autoloaded on page load rather than re-queried every time.
static public get_setting ( $setting )
 static function prevent_publicize_blacklisted_posts($should_publicize, $post)
 {
     if (in_array($post->post_type, Jetpack_Sync_Settings::get_setting('post_types_blacklist'))) {
         return false;
     }
     return $should_publicize;
 }
 static function prevent_publicize_blacklisted_posts($should_publicize, $post)
 {
     require_once dirname(__FILE__) . '/class.jetpack-sync-settings.php';
     if (in_array($post->post_type, Jetpack_Sync_Settings::get_setting('post_types_blacklist'))) {
         return false;
     }
     return $should_publicize;
 }
 function filter_blacklisted_post_types($args)
 {
     $post = $args[1];
     if (in_array($post->post_type, Jetpack_Sync_Settings::get_setting('post_types_blacklist'))) {
         return false;
     }
     return $args;
 }
 /**
  * Should we allow the meta key to be synced?
  *
  * @param string $meta_key The meta key.
  *
  * @return bool
  */
 function is_meta_key_allowed($meta_key)
 {
     if ('_' === $meta_key[0] && !in_array($meta_key, Jetpack_Sync_Defaults::$default_whitelist_meta_keys) && !wp_startswith($meta_key, '_wpas_skip_')) {
         return false;
     }
     if (in_array($meta_key, Jetpack_Sync_Settings::get_setting('meta_blacklist'))) {
         return false;
     }
     return true;
 }
 function filter_post_content_and_add_links($post_object)
 {
     global $post;
     $post = $post_object;
     // return non existant post
     $post_type = get_post_type_object($post->post_type);
     if (empty($post_type) || !is_object($post_type)) {
         $non_existant_post = new stdClass();
         $non_existant_post->ID = $post->ID;
         $non_existant_post->post_modified = $post->post_modified;
         $non_existant_post->post_modified_gmt = $post->post_modified_gmt;
         $non_existant_post->post_status = 'jetpack_sync_non_registered_post_type';
         return $non_existant_post;
     }
     /**
      * Filters whether to prevent sending post data to .com
      *
      * Passing true to the filter will prevent the post data from being sent
      * to the WordPress.com.
      * Instead we pass data that will still enable us to do a checksum against the
      * Jetpacks data but will prevent us from displaying the data on in the API as well as
      * other services.
      * @since 4.2.0
      *
      * @param boolean false prevent post data from being synced to WordPress.com
      * @param mixed $post WP_POST object
      */
     if (apply_filters('jetpack_sync_prevent_sending_post_data', false, $post)) {
         // We only send the bare necessary object to be able to create a checksum.
         $blocked_post = new stdClass();
         $blocked_post->ID = $post->ID;
         $blocked_post->post_modified = $post->post_modified;
         $blocked_post->post_modified_gmt = $post->post_modified_gmt;
         $blocked_post->post_status = 'jetpack_sync_blocked';
         return $blocked_post;
     }
     // lets not do oembed just yet.
     $this->remove_embed();
     if (0 < strlen($post->post_password)) {
         $post->post_password = '******' . wp_generate_password(10, false);
     }
     /** This filter is already documented in core. wp-includes/post-template.php */
     if (Jetpack_Sync_Settings::get_setting('render_filtered_content') && $post_type->public) {
         $post->post_content_filtered = apply_filters('the_content', $post->post_content);
         $post->post_excerpt_filtered = apply_filters('the_excerpt', $post->post_excerpt);
     }
     $this->add_embed();
     if (has_post_thumbnail($post->ID)) {
         $image_attributes = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
         if (is_array($image_attributes) && isset($image_attributes[0])) {
             $post->featured_image = $image_attributes[0];
         }
     }
     $post->permalink = get_permalink($post->ID);
     $post->shortlink = wp_get_shortlink($post->ID);
     $post->dont_email_post_to_subs = Jetpack::is_module_active('subscriptions') ? get_post_meta($post->ID, '_jetpack_dont_email_post_to_subs', true) : true;
     // Don't email subscription if the subscription module is not active.
     return $post;
 }
 public function expand_post_ids($args)
 {
     $post_ids = $args[0];
     $posts = array_filter(array_map(array('WP_Post', 'get_instance'), $post_ids));
     $posts = array_map(array($this, 'filter_post_content_and_add_links'), $posts);
     $posts = array_values($posts);
     // reindex in case posts were deleted
     return array($posts, $this->get_metadata($post_ids, 'post', Jetpack_Sync_Settings::get_setting('post_meta_whitelist')), $this->get_term_relationships($post_ids));
 }
 private function enable_queue_rate_limit()
 {
     $this->queue_rate_limit = Jetpack_Sync_Settings::get_setting('queue_max_writes_sec');
     $this->items_added_since_last_pause = 0;
     $this->last_pause_time = microtime(true);
     add_action('jpsq_item_added', array($this, 'queue_item_added'));
     add_action('jpsq_items_added', array($this, 'queue_items_added'));
 }
 function set_defaults()
 {
     $this->sync_queue = new Jetpack_Sync_Queue('sync');
     $this->full_sync_queue = new Jetpack_Sync_Queue('full_sync');
     $this->set_queue_size_limit(Jetpack_Sync_Settings::get_setting('max_queue_size'));
     $this->set_queue_lag_limit(Jetpack_Sync_Settings::get_setting('max_queue_lag'));
 }
 function test_post_types_blacklist_can_be_appended_in_settings()
 {
     register_post_type('filter_me', array('public' => true, 'label' => 'Filter Me'));
     $post_id = $this->factory->post->create(array('post_type' => 'filter_me'));
     $this->sender->do_sync();
     // first, show that post is being synced
     $this->assertTrue(!!$this->server_replica_storage->get_post($post_id));
     Jetpack_Sync_Settings::update_settings(array('post_types_blacklist' => array('filter_me')));
     $post_id = $this->factory->post->create(array('post_type' => 'filter_me'));
     $this->sender->do_sync();
     $this->assertFalse($this->server_replica_storage->get_post($post_id));
     // also assert that the post types blacklist still contains the hard-coded values
     $setting = Jetpack_Sync_Settings::get_setting('post_types_blacklist');
     $this->assertTrue(in_array('filter_me', $setting));
     foreach (Jetpack_Sync_Defaults::$blacklisted_post_types as $hardcoded_blacklist_post_type) {
         $this->assertTrue(in_array($hardcoded_blacklist_post_type, $setting));
     }
 }
 function continue_enqueuing($configs = null, $enqueue_status = null)
 {
     if (!$this->is_started() || $this->get_status_option('queue_finished')) {
         return;
     }
     // if full sync queue is full, don't enqueue more items
     $max_queue_size_full_sync = Jetpack_Sync_Settings::get_setting('max_queue_size_full_sync');
     $full_sync_queue = new Jetpack_Sync_Queue('full_sync');
     $available_queue_slots = $max_queue_size_full_sync - $full_sync_queue->size();
     if ($available_queue_slots <= 0) {
         return;
     } else {
         $remaining_items_to_enqueue = min(Jetpack_Sync_Settings::get_setting('max_enqueue_full_sync'), $available_queue_slots);
     }
     if (!$configs) {
         $configs = $this->get_config();
     }
     if (!$enqueue_status) {
         $enqueue_status = $this->get_enqueue_status();
     }
     foreach (Jetpack_Sync_Modules::get_modules() as $module) {
         $module_name = $module->name();
         // skip module if not configured for this sync or module is done
         if (!isset($configs[$module_name]) || !$configs[$module_name] || !$enqueue_status[$module_name] || true === $enqueue_status[$module_name][2]) {
             continue;
         }
         list($items_enqueued, $next_enqueue_state) = $module->enqueue_full_sync_actions($configs[$module_name], $remaining_items_to_enqueue, $enqueue_status[$module_name][2]);
         $enqueue_status[$module_name][2] = $next_enqueue_state;
         // if items were processed, subtract them from the limit
         if (!is_null($items_enqueued) && $items_enqueued > 0) {
             $enqueue_status[$module_name][1] += $items_enqueued;
             $remaining_items_to_enqueue -= $items_enqueued;
         }
         // stop processing if we've reached our limit of items to enqueue
         if (0 >= $remaining_items_to_enqueue) {
             $this->set_enqueue_status($enqueue_status);
             return;
         }
     }
     $this->set_enqueue_status($enqueue_status);
     // setting autoload to true means that it's faster to check whether we should continue enqueuing
     $this->update_status_option('queue_finished', time(), true);
     /**
      * Fires when a full sync ends. This action is serialized
      * and sent to the server with checksums so that we can confirm the
      * sync was successful.
      *
      * @since 4.2.0
      */
     do_action('jetpack_full_sync_end', '');
 }
 static function schedule_full_sync($modules = null, $time_offset = 1)
 {
     if (!self::sync_allowed()) {
         return false;
     }
     if (Jetpack_Sync_Settings::get_setting('avoid_wp_cron')) {
         // run queuing inline
         set_time_limit(0);
         self::do_full_sync($modules);
         return false;
     }
     if (self::is_scheduled_full_sync()) {
         self::unschedule_all_full_syncs();
     }
     if ($modules) {
         wp_schedule_single_event(time() + $time_offset, 'jetpack_sync_full', array($modules));
     } else {
         wp_schedule_single_event(time() + $time_offset, 'jetpack_sync_full');
     }
     if ($time_offset === 1) {
         spawn_cron();
     }
     return true;
 }
 public function test_sync_whitelisted_comment_meta()
 {
     Jetpack_Sync_Settings::update_settings(array('comment_meta_whitelist' => array()));
     $this->setSyncClientDefaults();
     // check that these values exists in the whitelist options
     $white_listed_comment_meta = Jetpack_Sync_Defaults::$comment_meta_whitelist;
     $comment_ids = $this->factory->comment->create_post_comments($this->post_id);
     // update all the comment meta
     foreach ($white_listed_comment_meta as $meta_key) {
         add_comment_meta($comment_ids[0], $meta_key, 'foo', 'comment');
     }
     $this->sender->do_sync();
     foreach ($white_listed_comment_meta as $meta_key) {
         $this->assertOptionIsSynced($meta_key, 'foo', 'comment', $comment_ids[0]);
     }
     $whitelist = Jetpack_Sync_Settings::get_setting('comment_meta_whitelist');
     $whitelist_and_option_keys_difference = array_diff($whitelist, $white_listed_comment_meta);
     // Are we testing all the options
     $unique_whitelist = array_unique($whitelist);
     $this->assertEquals(count($unique_whitelist), count($whitelist), 'The duplicate keys are: ' . print_r(array_diff_key($whitelist, array_unique($whitelist)), 1));
     $this->assertTrue(empty($whitelist_and_option_keys_difference), 'Some whitelisted options don\'t have a test: ' . print_r($whitelist_and_option_keys_difference, 1));
 }
 public function expand_comment_ids($args)
 {
     $comment_ids = $args[0];
     $comments = get_comments(array('include_unapproved' => true, 'comment__in' => $comment_ids));
     return array($comments, $this->get_metadata($comment_ids, 'comment', Jetpack_Sync_Settings::get_setting('comment_meta_whitelist')));
 }
 function is_post_type_allowed($post_id)
 {
     $post = get_post($post_id);
     return !in_array($post->post_type, Jetpack_Sync_Settings::get_setting('post_types_blacklist'));
 }