/** * Called by WPCOM_Liveblog::load(), * it attaches the new command. */ public static function load() { add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_filter('liveblog_before_insert_entry', array(__CLASS__, 'strip_input'), 1); add_filter('liveblog_before_update_entry', array(__CLASS__, 'strip_input'), 1); // Allow the features to be seperated in multiple ways: via spaces, // pipes or commas. This line explodes via spaces and pipes then // proceeds to explode it via commas. This allows for the tidy: // feature_one, feature_two, feature_three self::$features = explode(',', preg_replace('~[ |]+~', ',', self::$features)); self::$features = array_filter(self::$features, 'strlen'); // We pass these features into a filter to allow other plugins, // themes, etc. to enable or disable any of the features. self::$features = apply_filters('liveblog_features', self::$features); // This is the autocomplete prefix regex. $regex_prefix = '~(?:(?<!\\S)|>?)((?:'; // This is the autocomplete postfix regex. $regex_postfix = '){1}([0-9_\\-\\p{L}]*[_\\-\\p{L}][0-9_\\-\\p{L}]*))(?:<)?~um'; // We loop every feature and set them up individually. foreach (self::$features as $name) { // Grab the class from what we expect the classname to be. // WPCOM_Liveblog_Entry_Extend_Feature_{{ $name }} $class = __CLASS__ . '_Feature_' . ucfirst($name); $feature = new $class(); // Add all the basic (common) feature filters. add_filter('liveblog_extend_autocomplete', array($feature, 'get_config'), 10); add_filter('liveblog_before_insert_entry', array($feature, 'filter'), 10); add_filter('liveblog_before_update_entry', array($feature, 'filter'), 10); add_filter('liveblog_before_preview_entry', array($feature, 'filter'), 10); add_filter('liveblog_before_edit_entry', array($feature, 'revert'), 10); // Set the prefixes to the filtered prefixes. // This allows themes, plugins, etc. to change prefixes. $feature->set_prefixes(apply_filters('liveblog_' . $name . '_prefixes', $feature->get_prefixes())); // We apply the prefixes to the regex so we can match them // during the autocomplete and matching process. $regex = $regex_prefix . implode('|', $feature->get_prefixes()) . $regex_postfix; $feature->set_regex(apply_filters('liveblog_' . $name . '_regex', $regex)); // Finally, simply load the feature as it may have it's // own setup that it is required to complete. $feature->load(); } // Allow external sources to build the autocomplete config that is // used by the frontend javascript for autocomplete matching. self::$autocomplete = apply_filters('liveblog_extend_autocomplete', self::$autocomplete); }