コード例 #1
0
 /**
  * Pass some variables to js for the edit / post page overview, snippet preview, etc.
  *
  * @return  array
  */
 public function localize_script()
 {
     if (isset($_GET['post'])) {
         $post_id = (int) WPSEO_Option::validate_int($_GET['post']);
         $post = get_post($post_id);
     } else {
         global $post;
     }
     if (!is_object($post) || !isset($post->post_type) || $this->is_metabox_hidden($post->post_type) === true) {
         return array();
     }
     $options = get_option('wpseo_titles');
     $date = '';
     if (isset($options['showdate-' . $post->post_type]) && $options['showdate-' . $post->post_type] === true) {
         $date = $this->get_post_date($post);
         self::$meta_length = self::$meta_length - (strlen($date) + 5);
         self::$meta_length_reason = __(' (because of date display)', 'wordpress-seo');
     }
     self::$meta_length_reason = apply_filters('wpseo_metadesc_length_reason', self::$meta_length_reason, $post);
     self::$meta_length = apply_filters('wpseo_metadesc_length', self::$meta_length, $post);
     unset($date);
     $title_template = '';
     if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') {
         $title_template = $options['title-' . $post->post_type];
     }
     // If there's no title template set, use the default, otherwise title preview won't work.
     if ($title_template == '') {
         $title_template = '%%title%% - %%sitename%%';
     }
     $metadesc_template = '';
     if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] !== '') {
         $metadesc_template = $options['metadesc-' . $post->post_type];
     }
     $sample_permalink = get_sample_permalink($post->ID);
     $sample_permalink = str_replace('%page', '%post', $sample_permalink[0]);
     $cached_replacement_vars = array();
     foreach (array('date', 'id', 'sitename', 'sitedesc', 'sep', 'page', 'currenttime', 'currentdate', 'currentday', 'currentmonth', 'currentyear') as $var) {
         $cached_replacement_vars[$var] = wpseo_replace_vars('%%' . $var . '%%', $post);
     }
     return array_merge($cached_replacement_vars, array('field_prefix' => self::$form_prefix, 'keyword_header' => __('Your focus keyword was found in:', 'wordpress-seo'), 'article_header_text' => __('Article Heading: ', 'wordpress-seo'), 'page_title_text' => __('Page title: ', 'wordpress-seo'), 'page_url_text' => __('Page URL: ', 'wordpress-seo'), 'content_text' => __('Content: ', 'wordpress-seo'), 'meta_description_text' => __('Meta description: ', 'wordpress-seo'), 'choose_image' => __('Use Image', 'wordpress-seo'), 'wpseo_meta_desc_length' => self::$meta_length, 'wpseo_title_template' => $title_template, 'wpseo_metadesc_template' => $metadesc_template, 'wpseo_permalink_template' => $sample_permalink, 'wpseo_keyword_suggest_nonce' => wp_create_nonce('wpseo-get-suggest'), 'wpseo_replace_vars_nonce' => wp_create_nonce('wpseo-replace-vars'), 'no_parent_text' => __('(no parent)')));
 }