/**
  * Add the actions and filters for the option
  *
  * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  * is updated early on and if so, change the call to schedule these for a later action on add/update
  * instead of running them straight away
  *
  * @return \WPSEO_Taxonomy_Meta
  */
 protected function __construct()
 {
     parent::__construct();
     /* On succesfull update/add of the option, flush the W3TC cache */
     add_action('add_option_' . $this->option_name, array('WPSEO_Utils', 'flush_w3tc_cache'));
     add_action('update_option_' . $this->option_name, array('WPSEO_Utils', 'flush_w3tc_cache'));
 }
 /**
  * Add the actions and filters for the option
  *
  * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  * is updated early on and if so, change the call to schedule these for a later action on add/update
  * instead of running them straight away
  *
  * @return \WPSEO_Option_Wpseo
  */
 protected function __construct()
 {
     parent::__construct();
     /* Clear the cache on update/add */
     add_action('add_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
     add_action('update_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
 }
 /**
  * Filter POST variables.
  *
  * @param string $var_name
  *
  * @return mixed
  */
 private function filter_input_post($var_name)
 {
     $val = filter_input(INPUT_POST, $var_name);
     if ($val) {
         return WPSEO_Option::sanitize_text_field($val);
     }
     return '';
 }
 /**
  * Add the actions and filters for the option
  *
  * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  * is updated early on and if so, change the call to schedule these for a later action on add/update
  * instead of running them straight away
  *
  * @return \WPSEO_Option_Wpseo
  */
 protected function __construct()
 {
     parent::__construct();
     /* Clear the cache on update/add */
     add_action('add_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
     add_action('update_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
     /**
      * Filter the `wpseo` option defaults.
      *
      * @param array $defaults Array the defaults for the `wpseo` option attributes.
      */
     $this->defaults = apply_filters('wpseo_option_wpseo_defaults', $this->defaults);
 }
 /**
  * Add the actions and filters for the option
  *
  * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  * is updated early on and if so, change the call to schedule these for a later action on add/update
  * instead of running them straight away
  *
  * @return \WPSEO_Option_Wpseo
  */
 protected function __construct()
 {
     /*
     Dirty fix for making certain defaults available during activation while still only
     	   defining them once
     */
     foreach (self::$desc_defaults as $key => $value) {
         $this->defaults[$key] = $value;
     }
     parent::__construct();
     /* Clear the cache on update/add */
     add_action('add_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
     add_action('update_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
 }
Beispiel #6
0
 /**
  * Updates the user metas that (might) have been set on the user profile page.
  *
  * @param    int $user_id of the updated user
  */
 function process_user_option_update($user_id)
 {
     if (isset($_POST['wpseo_author_title'])) {
         check_admin_referer('wpseo_user_profile_update', 'wpseo_nonce');
         update_user_meta($user_id, 'wpseo_title', isset($_POST['wpseo_author_title']) ? WPSEO_Option::sanitize_text_field($_POST['wpseo_author_title']) : '');
         update_user_meta($user_id, 'wpseo_metadesc', isset($_POST['wpseo_author_metadesc']) ? WPSEO_Option::sanitize_text_field($_POST['wpseo_author_metadesc']) : '');
         update_user_meta($user_id, 'wpseo_metakey', isset($_POST['wpseo_author_metakey']) ? WPSEO_Option::sanitize_text_field($_POST['wpseo_author_metakey']) : '');
         update_user_meta($user_id, 'wpseo_excludeauthorsitemap', isset($_POST['wpseo_author_exclude']) ? WPSEO_Option::sanitize_text_field($_POST['wpseo_author_exclude']) : '');
     }
 }
    exit;
}
global $wpseo_admin_pages;
$options = get_site_option('wpseo_ms');
if (isset($_POST['wpseo_submit'])) {
    check_admin_referer('wpseo-network-settings');
    foreach (array('access', 'defaultblog') as $opt) {
        $options[$opt] = $_POST['wpseo_ms'][$opt];
    }
    WPSEO_Options::update_site_option('wpseo_ms', $options);
    add_settings_error('wpseo_ms', 'settings_updated', __('Settings Updated.', 'wordpress-seo'), 'updated');
}
if (isset($_POST['wpseo_restore_blog'])) {
    check_admin_referer('wpseo-network-restore');
    if (isset($_POST['wpseo_ms']['restoreblog']) && is_numeric($_POST['wpseo_ms']['restoreblog'])) {
        $restoreblog = (int) WPSEO_Option::validate_int($_POST['wpseo_ms']['restoreblog']);
        $blog = get_blog_details($restoreblog);
        if ($blog) {
            WPSEO_Options::reset_ms_blog($restoreblog);
            add_settings_error('wpseo_ms', 'settings_updated', sprintf(__('%s restored to default SEO settings.', 'wordpress-seo'), esc_html($blog->blogname)), 'updated');
        } else {
            add_settings_error('wpseo_ms', 'settings_updated', sprintf(__('Blog %s not found.', 'wordpress-seo'), esc_html($restoreblog)), 'error');
        }
        unset($restoreblog);
    }
}
/* Set up selectbox dropdowns for smaller networks (usability) */
$use_dropdown = true;
if (get_blog_count() > 100) {
    $use_dropdown = false;
} else {
 /**
  * Validate the post meta values
  *
  * @static
  *
  * @param	mixed	$meta_value	The new value
  * @param	string	$meta_key	The full meta key (including prefix)
  * @return	string				Validated meta value
  */
 public static function sanitize_post_meta($meta_value, $meta_key)
 {
     $field_def = self::$meta_fields[self::$fields_index[$meta_key]['subset']][self::$fields_index[$meta_key]['key']];
     $clean = self::$defaults[$meta_key];
     switch (true) {
         case $meta_key === self::$meta_prefix . 'linkdex':
             $int = WPSEO_Option::validate_int($meta_value);
             if ($int !== false && $int >= 0) {
                 $clean = strval($int);
                 // Convert to string to make sure default check works
             }
             break;
         case $field_def['type'] === 'checkbox':
             // Only allow value if it's one of the predefined options
             if (in_array($meta_value, array('on', 'off'), true)) {
                 $clean = $meta_value;
             }
             break;
         case $field_def['type'] === 'select' || $field_def['type'] === 'radio':
             // Only allow value if it's one of the predefined options
             if (isset($field_def['options'][$meta_value])) {
                 $clean = $meta_value;
             }
             break;
         case $field_def['type'] === 'multiselect' && $meta_key === self::$meta_prefix . 'meta-robots-adv':
             $clean = self::validate_meta_robots_adv($meta_value);
             break;
         case $field_def['type'] === 'text' && $meta_key === self::$meta_prefix . 'canonical':
         case $field_def['type'] === 'text' && $meta_key === self::$meta_prefix . 'redirect':
             // Validate as url(-part)
             $url = WPSEO_Option::sanitize_url($meta_value);
             if ($url !== '') {
                 $clean = $url;
             }
             break;
         case $field_def['type'] === 'upload' && $meta_key === self::$meta_prefix . 'opengraph-image':
             // Validate as url
             $url = WPSEO_Option::sanitize_url($meta_value, array('http', 'https', 'ftp', 'ftps'));
             if ($url !== '') {
                 $clean = $url;
             }
             break;
         case $field_def['type'] === 'textarea':
             if (is_string($meta_value)) {
                 // Remove line breaks and tabs
                 // @todo [JRF => Yoast] verify that line breaks and the likes aren't allowed/recommended in meta header fields
                 $meta_value = str_replace(array("\n", "\r", "\t", '  '), ' ', $meta_value);
                 $clean = WPSEO_Option::sanitize_text_field(trim($meta_value));
             }
             break;
         case 'multiselect' === $field_def['type']:
             $clean = $meta_value;
             break;
         case $field_def['type'] === 'text':
         default:
             if (is_string($meta_value)) {
                 $clean = WPSEO_Option::sanitize_text_field(trim($meta_value));
             }
             break;
     }
     $clean = apply_filters('wpseo_sanitize_post_meta_' . $meta_key, $clean, $meta_value, $field_def, $meta_key);
     return $clean;
 }
        /**
         * Generate a snippet preview.
         *
         * @return string
         */
        function snippet()
        {
            if (isset($_GET['post'])) {
                $post_id = (int) WPSEO_Option::validate_int($_GET['post']);
                $post = get_post($post_id);
            } else {
                global $post;
            }
            $options = WPSEO_Options::get_all();
            $date = '';
            if (is_object($post) && isset($options['showdate-' . $post->post_type]) && $options['showdate-' . $post->post_type] === true) {
                $date = $this->get_post_date($post);
            }
            $title = self::get_value('title');
            $desc = self::get_value('metadesc');
            $slug = is_object($post) && isset($post->post_name) ? $post->post_name : '';
            if ($slug !== '') {
                $slug = sanitize_title($title);
            }
            if (is_string($date) && $date !== '') {
                $datestr = '<span class="date">' . $date . ' - </span>';
            } else {
                $datestr = '';
            }
            $content = '<div id="wpseosnippet">
				<a class="title" id="wpseosnippet_title" href="#">' . esc_html($title) . '</a>';
            $content .= '<span class="url">' . str_replace('http://', '', get_bloginfo('url')) . '/' . esc_html($slug) . '/</span>';
            $content .= '<p class="desc">' . $datestr . '<span class="autogen"></span><span class="content">' . esc_html($desc) . '</span></p>';
            $content .= '</div>';
            $content = apply_filters('wpseo_snippet', $content, $post, compact('title', 'desc', 'date', 'slug'));
            return $content;
        }
Beispiel #10
0
 /**
  * Returns post in metabox context
  *
  * @returns WP_Post
  */
 private function get_metabox_post()
 {
     if (isset($_GET['post'])) {
         $post_id = (int) WPSEO_Option::validate_int($_GET['post']);
         $post = get_post($post_id);
     } else {
         global $post;
     }
     return $post;
 }
 /**
  * Fallback funciton for WP SEO functionality, sanitize_url
  *
  * @param $string
  *
  * @return mixed
  */
 public static function yoast_wpseo_video_sanitize_url($string)
 {
     if (method_exists('WPSEO_Utils', 'sanitize_url')) {
         return WPSEO_Utils::sanitize_url($string, array('http', 'https', 'ftp', 'ftps'));
     }
     return WPSEO_Option::sanitize_url($string, array('http', 'https', 'ftp', 'ftps'));
 }
 /**
  * Add the actions and filters for the option
  *
  * @return \WPSEO_Option_Woo
  */
 protected function __construct()
 {
     parent::__construct();
     // Set and translate the valid data types
     $this->valid_data_types = array('price' => __('Price', 'yoast-woo-seo'), 'stock' => __('Stock', 'yoast-woo-seo'));
 }
 /**
  * Only run parent constructor in multisite context.
  */
 public function __construct()
 {
     if (is_multisite()) {
         parent::__construct();
     }
 }
 /**
  * Add the actions and filters for the option
  *
  * @return \WPSEO_Option_Video
  */
 protected function __construct()
 {
     parent::__construct();
 }
 /**
  * Add the actions and filters for the option
  *
  * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  * is updated early on and if so, change the call to schedule these for a later action on add/update
  * instead of running them straight away
  *
  * @return \WPSEO_Option_Titles
  */
 protected function __construct()
 {
     parent::__construct();
     add_action('update_option_' . $this->option_name, array('WPSEO_Utils', 'clear_cache'));
     add_action('init', array($this, 'end_of_init'), 999);
 }
 /**
  * Add the actions and filters for the option
  *
  * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  *       is updated early on and if so, change the call to schedule these for a later action on add/update
  *       instead of running them straight away
  *
  * @return \WPSEO_Option_XML
  */
 protected function __construct()
 {
     parent::__construct();
     add_action('update_option_' . $this->option_name, array('WPSEO_Utils', 'clear_rewrites'));
     add_action('update_option_' . $this->option_name, array('WPSEO_Sitemaps_Cache', 'clear'));
 }