Changeset 905029
- Timestamp:
- 04/29/2014 08:17:30 PM (12 years ago)
- Location:
- voce-seo/trunk
- Files:
-
- 5 edited
-
admin/admin.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
-
vendor/autoload.php (modified) (1 diff)
-
vendor/composer/autoload_real.php (modified) (4 diffs)
-
voce-seo.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
voce-seo/trunk/admin/admin.php
r886992 r905029 2 2 3 3 class VSEO_Admin { 4 4 5 public static function init() { 5 6 require_once(__DIR__ . '/field-callbacks.php'); 6 7 VSEO_Metabox::init(); 7 } 8 VSEO_Taxonomy::init(); 9 } 10 8 11 } 9 12 10 13 class VSEO_Metabox { 14 11 15 public static function init() { 12 add_action('add_meta_boxes', function($post_type) { 13 if(get_post_type_object($post_type)->publicly_queryable || $post_type == 'page') { 14 add_meta_box('vseo_meta', 'SEO Settings', array( 'VSEO_Metabox', 'meta_box' ), 15 $post_type, 'advanced'); 16 } 16 add_action( 'add_meta_boxes', function($post_type) { 17 if ( get_post_type_object( $post_type )->publicly_queryable || $post_type == 'page' ) { 18 add_meta_box( 'vseo_meta', 'SEO Settings', array( 'VSEO_Metabox', 'meta_box' ), $post_type, 'advanced' ); 19 } 17 20 }, 99 ); 18 21 19 add_action( 'save_post', array(__CLASS__, 'on_save_post'));20 } 21 22 public static function meta_box( $post) {23 $post_type = get_post_type( $post);24 $tabs = self::get_metabox_tabs( $post_type);25 $vseo_meta = ( array) get_post_meta( $post->ID, 'vseo_meta', true );22 add_action( 'save_post', array( __CLASS__, 'on_save_post' ) ); 23 } 24 25 public static function meta_box( $post ) { 26 $post_type = get_post_type( $post ); 27 $tabs = self::get_metabox_tabs( $post_type ); 28 $vseo_meta = ( array ) get_post_meta( $post->ID, 'vseo_meta', true ); 26 29 ?> 27 30 <div class="vseo-metabox-tabs-div"> 28 31 <ul class="vseo-metabox-tabs" id="vseo-metabox-tabs"> 29 32 <?php 30 foreach($tabs as $tab_id => $tab) { 31 sprintf('<li class="vseo-%1$s"><a class="vseo_tablink" href="#vseo_%1$s">%2$s</a></li>', 32 $tab_id, esc_html($tab['label'])); 33 foreach ( $tabs as $tab_id => $tab ) { 34 sprintf( '<li class="vseo-%1$s"><a class="vseo_tablink" href="#vseo_%1$s">%2$s</a></li>', $tab_id, esc_html( $tab['label'] ) ); 33 35 } 34 36 ?> 35 37 </ul> 36 <?php foreach ($tabs as $tab_id => $tab) : ?>38 <?php foreach ( $tabs as $tab_id => $tab ) : ?> 37 39 <div class="vseotab" id="vseo-<?php echo $tab_id ?>"> 38 <?php foreach(self::get_metabox_fields($tab_id, $post_type) as $field_id => $field): ?> 39 <p> 40 <label><?php echo $field['title']; ?></label> 41 <?php echo call_user_func_array( $field['display_callback'], array( 42 'vseo' . $field_id, 43 isset( $vseo_meta[$field_id] ) ? $vseo_meta[$field_id] : null, 44 isset( $field['args'] ) ? $field['args'] : array( ) ) 45 ); ?> 46 </p> 40 <?php foreach ( self::get_metabox_fields( $tab_id, $post_type ) as $field_id => $field ): ?> 41 <p> 42 <label><?php echo $field['title']; ?></label> 43 <?php 44 echo call_user_func_array( $field['display_callback'], array( 45 'vseo' . $field_id, 46 isset( $vseo_meta[$field_id] ) ? $vseo_meta[$field_id] : null, 47 isset( $field['args'] ) ? $field['args'] : array() ) 48 ); 49 ?> 50 </p> 47 51 <?php endforeach; ?> 48 52 </div> … … 50 54 </div> 51 55 <?php 52 wp_nonce_field( 'vseo_update_meta', 'vseo_nonce');53 } 54 55 public static function on_save_post( $post_id) {56 if (wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)) {56 wp_nonce_field( 'vseo_update_meta', 'vseo_nonce' ); 57 } 58 59 public static function on_save_post( $post_id ) { 60 if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) { 57 61 return $post_id; 58 62 } 59 if (isset($_REQUEST['vseo_nonce']) && wp_verify_nonce($_REQUEST['vseo_nonce'], 'vseo_update_meta')) {60 $post_type = get_post_type( $post_id);61 $tabs = self::get_metabox_tabs( $post_type);62 $vseo_meta = ( array) get_post_meta( $post_id, 'vseo_meta', true );63 64 foreach ($tabs as $tab_id => $tab) {65 foreach (self::get_metabox_fields($tab_id, $post_type) as $field_id => $field) {66 if (isset($field['sanitize_callback'])) {67 $vseo_meta[$field_id] = call_user_func_array( $field['sanitize_callback'], array(68 isset( $_REQUEST['vseo' . $field_id]) ? $_REQUEST['vseo' . $field_id] : null,63 if ( isset( $_REQUEST['vseo_nonce'] ) && wp_verify_nonce( $_REQUEST['vseo_nonce'], 'vseo_update_meta' ) ) { 64 $post_type = get_post_type( $post_id ); 65 $tabs = self::get_metabox_tabs( $post_type ); 66 $vseo_meta = ( array ) get_post_meta( $post_id, 'vseo_meta', true ); 67 68 foreach ( $tabs as $tab_id => $tab ) { 69 foreach ( self::get_metabox_fields( $tab_id, $post_type ) as $field_id => $field ) { 70 if ( isset( $field['sanitize_callback'] ) ) { 71 $vseo_meta[$field_id] = call_user_func_array( $field['sanitize_callback'], array( 72 isset( $_REQUEST['vseo' . $field_id] ) ? $_REQUEST['vseo' . $field_id] : null, 69 73 $field['args'] 70 ));74 ) ); 71 75 } 72 76 } 73 77 } 74 update_post_meta( $post_id, 'vseo_meta', $vseo_meta);75 } 76 } 77 78 private function get_metabox_tabs( $post_type) {78 update_post_meta( $post_id, 'vseo_meta', $vseo_meta ); 79 } 80 } 81 82 private function get_metabox_tabs( $post_type ) { 79 83 $metabox_tabs = array( 80 84 'general' => array( … … 88 92 ) 89 93 ); 90 return apply_filters( 'vseo_metabox_tabs', $metabox_tabs, $post_type);91 } 92 93 private function get_metabox_fields( $tab, $post_type) {94 return apply_filters( 'vseo_metabox_tabs', $metabox_tabs, $post_type ); 95 } 96 97 private function get_metabox_fields( $tab, $post_type ) { 94 98 $tab_fields = array( 95 99 'general' => array( … … 154 158 'title' => '301 Redirect URL', 155 159 ), 156 157 160 ), 158 161 'social' => array( 162 'og_title' => array( 163 'display_callback' => 'vseo_field_text', 164 'sanitize_callback' => 'vseo_sanitize_meta_text', 165 'args' => array( 166 'description' => '<span class="description">If you don\'t want to use the post or SEO title for sharing the post on Facebook/Open Graph but want another title there, write it here.</span>', 167 ), 168 'title' => 'Facebook/Open Graph Title', 169 ), 159 170 'og_description' => array( 160 171 'display_callback' => 'vseo_field_textarea', 161 172 'sanitize_callback' => 'vseo_sanitize_meta_text', 162 173 'args' => array( 163 'description' => '<span class="description">If you don\'t want to use the meta description for sharing the post on Facebook but want another description there, write it here.</span>', 164 ), 165 'title' => 'Facebook Description', 166 ), 174 'description' => '<span class="description">If you don\'t want to use the meta description for sharing the post on Facebook/Open Graph but want another description there, write it here.</span>', 175 ), 176 'title' => 'Facebook/Open Graph Description', 177 ), 178 'twitter_title' => array( 179 'display_callback' => 'vseo_field_text', 180 'sanitize_callback' => 'vseo_sanitize_meta_text', 181 'args' => array( 182 'description' => '<span class="description">If you don\'t want to use the post or SEO title for sharing the post on Twitter but want another title there, write it here.</span>', 183 ), 184 'title' => 'Twitter Title', 185 ), 167 186 'twitter_description' => array( 168 187 'display_callback' => 'vseo_field_textarea', 169 188 'sanitize_callback' => 'vseo_sanitize_meta_text', 170 189 'args' => array( 171 'description' => '<span class="description">If you don\'t want to use the meta description for Twitter card but want another descriptionthere, write it here.</span>',190 'description' => '<span class="description">If you don\'t want to use the meta title for sharing the post on Facebook/Open Graph but want another title there, write it here.</span>', 172 191 ), 173 192 'title' => 'Twitter Description', 174 193 ), 175 176 194 ), 177 195 ); 178 196 179 if ( !apply_filters( 'vseo_use_facebook_meta', true ) ) {197 if ( !apply_filters( 'vseo_use_facebook_meta', true ) ) { 180 198 unset( $tab_fields['social']['og_description'] ); 181 199 } 182 200 183 if ( !apply_filters( 'vseo_use_twitter_meta', true ) ) {201 if ( !apply_filters( 'vseo_use_twitter_meta', true ) ) { 184 202 unset( $tab_fields['social']['twitter_description'] ); 185 203 } 186 204 187 205 188 return apply_filters('vseo_metabox_fields', isset($tab_fields[$tab]) ? 189 $tab_fields[$tab] : array(), $tab, $post_type); 190 191 } 192 206 return apply_filters( 'vseo_metabox_fields', isset( $tab_fields[$tab] ) ? 207 $tab_fields[$tab] : array(), $tab, $post_type ); 208 } 193 209 194 210 } 211 212 class VSEO_Taxonomy { 213 214 public static $option_key = 'vseo_term_meta'; 215 216 public static function init() { 217 $taxonomies = get_taxonomies( '', 'names' ); 218 foreach ( $taxonomies as $taxonomy ) { 219 add_action( $taxonomy . '_add_form_fields', array( __CLASS__, 'add_new_meta_field' ), 10, 1 ); 220 add_action( $taxonomy . '_edit_form_fields', array( __CLASS__, 'edit_meta_field' ), 10, 2 ); 221 add_action( 'edited_' . $taxonomy, array( __CLASS__, 'save_meta' ), 10, 2 ); 222 add_action( 'create_' . $taxonomy, array( __CLASS__, 'save_meta' ), 10, 2 ); 223 } 224 } 225 226 public static function add_new_meta_field( $taxonomy ) { 227 ?> 228 <div class="form-field"> 229 <label for="term_meta[title]"><?php _e( 'SEO title', 'voce_seo' ); ?></label> 230 <input type="text" name="term_meta[title]" id="term_meta[title]" value=""> 231 <p class="description"><?php _e( 'Blank for default', 'voce_seo' ); ?></p> 232 </div> 233 <input type="hidden" value="<?php echo $taxonomy; ?>" name="voce_seo_taxonomy"> 234 <?php 235 wp_nonce_field( 'voce_seo_term', 'voce_seo_term' ); 236 } 237 238 public static function edit_meta_field( $term, $taxonomy ) { 239 $term_id = $term->term_id; 240 $term_meta = get_option( self::$option_key ); 241 ?> 242 <tr class="form-field"> 243 <th scope="row" valign="top"><label for="term_meta[title]"><?php _e( 'SEO Title', 'voce_seo' ); ?></label></th> 244 <td> 245 <input type="text" name="term_meta[title]" id="term_meta[title]" value="<?php echo isset( $term_meta[ $taxonomy . '_' . $term_id ]['title'] ) ? esc_attr( $term_meta[ $taxonomy . '_' . $term_id ]['title'] ) : ''; ?>"> 246 </td> 247 </tr> 248 <input type="hidden" value="<?php echo $taxonomy; ?>" name="voce_seo_taxonomy"> 249 <?php 250 wp_nonce_field( 'voce_seo_term', 'voce_seo_term' ); 251 } 252 253 function save_meta( $term_id ) { 254 if ( 255 isset( $_POST['term_meta'] ) && 256 check_admin_referer( 'voce_seo_term', 'voce_seo_term' ) 257 ) { 258 $_POST = array_map( 'stripslashes_deep', $_POST ); //prevent escaping from option value http://codex.wordpress.org/Function_Reference/stripslashes_deep 259 $taxonomy = $_POST['voce_seo_taxonomy']; 260 261 $term_meta = get_option( self::$option_key ); 262 $cat_keys = array_keys( $_POST['term_meta'] ); 263 $meta_data = array(); 264 foreach ( $cat_keys as $key ) { 265 if ( isset( $_POST['term_meta'][$key] ) ) { 266 $meta_data[$key] = $_POST['term_meta'][$key]; 267 } 268 } 269 $term_meta[ $taxonomy . '_' . $term_id ] = $meta_data; 270 update_option( self::$option_key, $term_meta ); 271 } 272 } 273 274 } -
voce-seo/trunk/readme.txt
r888812 r905029 3 3 Tags: SEO 4 4 Requires at least: 3.7.0 5 Tested up to: 3. 8.16 Stable tag: 0. 2.85 Tested up to: 3.9 6 Stable tag: 0.3.0 7 7 License: GPLv2 or later 8 8 … … 15 15 16 16 == Changelog == 17 18 = Version 0.3.0 = 19 * Adding ability to set separate Facebook, Twitter and SEO title 20 21 = Version 0.2.9 = 22 * Adding ability to set title and description meta for taxonomy terms, set in the taxonomy term admin page 17 23 18 24 = Version 0.2.8 = -
voce-seo/trunk/vendor/autoload.php
r888812 r905029 5 5 require_once __DIR__ . '/composer' . '/autoload_real.php'; 6 6 7 return ComposerAutoloaderInit45 9250e25a8c6d6781ca5f7b5a361fd0::getLoader();7 return ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92::getLoader(); -
voce-seo/trunk/vendor/composer/autoload_real.php
r888812 r905029 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit45 9250e25a8c6d6781ca5f7b5a361fd05 class ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92 6 6 { 7 7 private static $loader; … … 20 20 } 21 21 22 spl_autoload_register(array('ComposerAutoloaderInit45 9250e25a8c6d6781ca5f7b5a361fd0', 'loadClassLoader'), true, true);22 spl_autoload_register(array('ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92', 'loadClassLoader'), true, true); 23 23 self::$loader = $loader = new \Composer\Autoload\ClassLoader(); 24 spl_autoload_unregister(array('ComposerAutoloaderInit45 9250e25a8c6d6781ca5f7b5a361fd0', 'loadClassLoader'));24 spl_autoload_unregister(array('ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92', 'loadClassLoader')); 25 25 26 26 $vendorDir = dirname(__DIR__); … … 46 46 $includeFiles = require __DIR__ . '/autoload_files.php'; 47 47 foreach ($includeFiles as $file) { 48 composerRequire45 9250e25a8c6d6781ca5f7b5a361fd0($file);48 composerRequire45346c1a6487f4809dbca4cfc1532f92($file); 49 49 } 50 50 … … 53 53 } 54 54 55 function composerRequire45 9250e25a8c6d6781ca5f7b5a361fd0($file)55 function composerRequire45346c1a6487f4809dbca4cfc1532f92($file) 56 56 { 57 57 require $file; -
voce-seo/trunk/voce-seo.php
r888812 r905029 2 2 /* 3 3 Plugin Name: Voce SEO 4 Version: 0. 2.84 Version: 0.3.0 5 5 Plugin URI: http://voceconnect.com/ 6 6 Description: An SEO plugin taking things from both WP SEO and All in One SEO but leaving out the VIP incompatible pieces. … … 90 90 } 91 91 92 } 92 } elseif ( is_tax() || is_category() || is_tag() ) { 93 $new_title = self::get_term_seo_title(); 94 } 93 95 94 96 if ( !empty( $new_title ) ) { … … 111 113 return $title; 112 114 } 115 116 private static function get_term_seo_title(){ 117 $queried_object = get_queried_object(); 118 $term_id = $queried_object->term_id; 119 $taxonomy = $queried_object->taxonomy; 120 $option_key = $taxonomy . '_' . $term_id; 121 $term_meta = get_option( 'vseo_term_meta' ); 122 if ( ! isset( $term_meta[ $option_key ]['title'] ) ) { 123 return; 124 } 125 $seo_title = $term_meta[ $option_key ]['title']; 126 $title_filter = 'single_cat_title'; 127 if ( is_tax() ){ 128 $title_filter = 'single_term_filter'; 129 } elseif( is_tag() ) { 130 $title_filter = 'single_tag_filter'; 131 } 132 $new_title = apply_filters( $title_filter, $seo_title ); 133 return $new_title; 134 } 113 135 114 136 private static function upgrade_check() { … … 132 154 $description = self::get_meta_description(); 133 155 $queried_object = get_queried_object(); 134 if ( isset( $queried_object->post_type ) ) {156 if ( isset( $queried_object->post_type ) || ( is_tax() || is_category() || is_tag() ) ) { 135 157 $og_description = self::get_seo_meta( 'og_description', get_queried_object_id() ); 136 158 if ( ! $og_description ) 137 159 $og_description = $description; 138 $meta_objects = self::create_meta_object( 'og:description', 'meta', array( 'property' => 'og:description', 'content' => esc_attr( $og_description ) ), $meta_objects );139 }140 141 $meta_objects = self::create_meta_object( 'og:title', 'meta', array( 'property' => 'og:title', 'content' => esc_attr( self::get_ ogtitle() ) ), $meta_objects );160 /* og_description is not required, so if it is not set, do not output it */ 161 if ( $og_description ) $meta_objects = self::create_meta_object( 'og:description', 'meta', array( 'property' => 'og:description', 'content' => esc_attr( $og_description ) ), $meta_objects ); 162 } 163 $meta_objects = self::create_meta_object( 'og:title', 'meta', array( 'property' => 'og:title', 'content' => esc_attr( self::get_social_title( 'og_title' ) ) ), $meta_objects ); 142 164 143 165 $meta_objects = self::create_meta_object( 'og:type', 'meta', array( 'property' => 'og:type', 'content' => apply_filters( 'vseo_ogtype', 'article' ) ), $meta_objects ); … … 157 179 $description = self::get_meta_description(); 158 180 $queried_object = get_queried_object(); 159 if ( isset( $queried_object->post_type ) ) {181 if ( isset( $queried_object->post_type ) || ( is_tax() || is_category() || is_tag() ) ) { 160 182 $twitter_description = self::get_seo_meta( 'twitter_description', get_queried_object_id() ); 161 183 if ( ! $twitter_description ) … … 164 186 } 165 187 166 $meta_objects = self::create_meta_object( 'twitter:title', 'meta', array( 'name' => 'twitter:title', 'content' => esc_attr( self::get_ ogtitle() ) ), $meta_objects );188 $meta_objects = self::create_meta_object( 'twitter:title', 'meta', array( 'name' => 'twitter:title', 'content' => esc_attr( self::get_social_title( 'twitter_title' ) ) ), $meta_objects ); 167 189 168 190 $meta_objects = self::create_meta_object( 'twitter:card', 'meta', array( 'name' => 'twitter:card', 'content' => apply_filters( 'vseo_twittercard', 'summary' ) ), $meta_objects ); … … 232 254 } 233 255 234 public static function get_ ogtitle() {256 public static function get_social_title( $meta_key ) { 235 257 if ( is_home() || is_front_page() ) { 236 258 $title = get_bloginfo( 'name' ); … … 240 262 } else if ( is_singular() ) { 241 263 global $post; 242 $title = empty( $post->post_title ) ? ' ' : wp_kses( $post->post_title, array() ) ; 264 $title = self::get_seo_meta( $meta_key ); 265 if ( ! $title ) { 266 $vseo_meta = (array) get_post_meta( $post->ID, 'vseo_meta', true );; 267 $title = $vseo_meta['title']; 268 if ( ! $title ) { 269 $title = empty( $post->post_title ) ? ' ' : wp_kses( $post->post_title, array() ) ; 270 } 271 } 272 } else if ( is_tax() || is_category() || is_tag() ){ 273 $title = self::get_term_seo_title(); 243 274 } else { 244 275 $title = ''; … … 283 314 } 284 315 } else { 285 if ( is_search() ) { 286 $description = ''; 287 } else { 288 $description = get_bloginfo( 'description', 'display' ); 289 } 316 if ( is_tax() || is_category() || is_tag() ) { 317 $queried_object = get_queried_object(); 318 $term_id = $queried_object->term_id; 319 $taxonomy = $queried_object->taxonomy; 320 $description = term_description( $term_id, $taxonomy ); 321 322 } elseif ( is_search() ) { 323 $description = ''; 324 } else { 325 $description = get_bloginfo( 'description', 'display' ); 326 } 290 327 } 291 328
Note: See TracChangeset
for help on using the changeset viewer.