Plugin Directory

Changeset 905029


Ignore:
Timestamp:
04/29/2014 08:17:30 PM (12 years ago)
Author:
prettyboymp
Message:

releasing 0.3.0

Location:
voce-seo/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • voce-seo/trunk/admin/admin.php

    r886992 r905029  
    22
    33class VSEO_Admin {
     4
    45    public static function init() {
    56        require_once(__DIR__ . '/field-callbacks.php');
    67        VSEO_Metabox::init();
    7     }
     8        VSEO_Taxonomy::init();
     9    }
     10
    811}
    912
    1013class VSEO_Metabox {
     14
    1115    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            }
    1720        }, 99 );
    1821
    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 );
    2629        ?>
    2730        <div class="vseo-metabox-tabs-div">
    2831            <ul class="vseo-metabox-tabs" id="vseo-metabox-tabs">
    2932                <?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'] ) );
    3335                }
    3436                ?>
    3537            </ul>
    36             <?php foreach($tabs as $tab_id => $tab) : ?>
     38            <?php foreach ( $tabs as $tab_id => $tab ) : ?>
    3739                <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>
    4751                    <?php endforeach; ?>
    4852                </div>
     
    5054        </div>
    5155        <?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 ) ) {
    5761            return $post_id;
    5862        }
    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,
    6973                            $field['args']
    70                             ));
     74                                ) );
    7175                    }
    7276                }
    7377            }
    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 ) {
    7983        $metabox_tabs = array(
    8084            'general' => array(
     
    8892            )
    8993        );
    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 ) {
    9498        $tab_fields = array(
    9599            'general' => array(
     
    154158                    'title' => '301 Redirect URL',
    155159                ),
    156 
    157160            ),
    158161            '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                ),
    159170                'og_description' => array(
    160171                    'display_callback' => 'vseo_field_textarea',
    161172                    'sanitize_callback' => 'vseo_sanitize_meta_text',
    162173                    '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                ),                             
    167186                'twitter_description' => array(
    168187                    'display_callback' => 'vseo_field_textarea',
    169188                    'sanitize_callback' => 'vseo_sanitize_meta_text',
    170189                    'args' => array(
    171                         'description' => '<span class="description">If you don\'t want to use the meta description for Twitter card but want another description there, 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>',
    172191                    ),
    173192                    'title' => 'Twitter Description',
    174193                ),
    175 
    176194            ),
    177195        );
    178196
    179         if ( !apply_filters( 'vseo_use_facebook_meta', true ) ){
     197        if ( !apply_filters( 'vseo_use_facebook_meta', true ) ) {
    180198            unset( $tab_fields['social']['og_description'] );
    181199        }
    182200
    183         if ( !apply_filters( 'vseo_use_twitter_meta', true ) ){
     201        if ( !apply_filters( 'vseo_use_twitter_meta', true ) ) {
    184202            unset( $tab_fields['social']['twitter_description'] );
    185203        }
    186204
    187205
    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    }
    193209
    194210}
     211
     212class 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  
    33Tags: SEO
    44Requires at least: 3.7.0
    5 Tested up to: 3.8.1
    6 Stable tag: 0.2.8
     5Tested up to: 3.9
     6Stable tag: 0.3.0
    77License: GPLv2 or later
    88
     
    1515
    1616== 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
    1723
    1824= Version 0.2.8 =
  • voce-seo/trunk/vendor/autoload.php

    r888812 r905029  
    55require_once __DIR__ . '/composer' . '/autoload_real.php';
    66
    7 return ComposerAutoloaderInit459250e25a8c6d6781ca5f7b5a361fd0::getLoader();
     7return ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92::getLoader();
  • voce-seo/trunk/vendor/composer/autoload_real.php

    r888812 r905029  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit459250e25a8c6d6781ca5f7b5a361fd0
     5class ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92
    66{
    77    private static $loader;
     
    2020        }
    2121
    22         spl_autoload_register(array('ComposerAutoloaderInit459250e25a8c6d6781ca5f7b5a361fd0', 'loadClassLoader'), true, true);
     22        spl_autoload_register(array('ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92', 'loadClassLoader'), true, true);
    2323        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
    24         spl_autoload_unregister(array('ComposerAutoloaderInit459250e25a8c6d6781ca5f7b5a361fd0', 'loadClassLoader'));
     24        spl_autoload_unregister(array('ComposerAutoloaderInit45346c1a6487f4809dbca4cfc1532f92', 'loadClassLoader'));
    2525
    2626        $vendorDir = dirname(__DIR__);
     
    4646        $includeFiles = require __DIR__ . '/autoload_files.php';
    4747        foreach ($includeFiles as $file) {
    48             composerRequire459250e25a8c6d6781ca5f7b5a361fd0($file);
     48            composerRequire45346c1a6487f4809dbca4cfc1532f92($file);
    4949        }
    5050
     
    5353}
    5454
    55 function composerRequire459250e25a8c6d6781ca5f7b5a361fd0($file)
     55function composerRequire45346c1a6487f4809dbca4cfc1532f92($file)
    5656{
    5757    require $file;
  • voce-seo/trunk/voce-seo.php

    r888812 r905029  
    22/*
    33  Plugin Name: Voce SEO
    4   Version: 0.2.8
     4  Version: 0.3.0
    55  Plugin URI: http://voceconnect.com/
    66  Description: An SEO plugin taking things from both WP SEO and All in One SEO but leaving out the VIP incompatible pieces.
     
    9090            }
    9191
    92         }
     92        } elseif ( is_tax() || is_category() || is_tag() ) {
     93                    $new_title = self::get_term_seo_title();
     94                }
    9395
    9496        if ( !empty( $new_title ) ) {
     
    111113        return $title;
    112114    }
     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    }
    113135
    114136    private static function upgrade_check() {
     
    132154        $description    = self::get_meta_description();
    133155        $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() ) ) {
    135157            $og_description = self::get_seo_meta( 'og_description', get_queried_object_id() );
    136158            if ( ! $og_description )
    137159                $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 );
    142164
    143165        $meta_objects = self::create_meta_object( 'og:type', 'meta', array( 'property' => 'og:type', 'content' => apply_filters( 'vseo_ogtype', 'article' ) ), $meta_objects );
     
    157179        $description    = self::get_meta_description();
    158180        $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() ) ) {
    160182            $twitter_description = self::get_seo_meta( 'twitter_description', get_queried_object_id() );
    161183            if ( ! $twitter_description )
     
    164186        }
    165187
    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 );
    167189
    168190        $meta_objects = self::create_meta_object( 'twitter:card', 'meta', array( 'name' => 'twitter:card', 'content' => apply_filters( 'vseo_twittercard', 'summary' ) ), $meta_objects );
     
    232254    }
    233255
    234     public static function get_ogtitle() {
     256    public static function get_social_title( $meta_key ) {
    235257        if ( is_home() || is_front_page() ) {
    236258            $title = get_bloginfo( 'name' );
     
    240262        } else if ( is_singular() ) {
    241263            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();
    243274        } else {
    244275            $title = '';
     
    283314            }
    284315        } 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                    }
    290327        }
    291328
Note: See TracChangeset for help on using the changeset viewer.