Plugin Directory

Changeset 1257849


Ignore:
Timestamp:
10/02/2015 12:06:53 AM (10 years ago)
Author:
whatadewitt
Message:

version 2.0.0 easier to use!

Location:
deweys-open-graph-helper
Files:
15 added
3 edited

Legend:

Unmodified
Added
Removed
  • deweys-open-graph-helper/trunk/README.txt

    r1247953 r1257849  
    44Requires at least: 3.5.1
    55Tested up to: 4.0
    6 Stable tag: 1.0.1
     6Stable tag: 2.0.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3939== Changelog ==
    4040
     41= 2.0.0 =
     42* Added a meta box to make it easier to use custom og tag meta
     43
    4144= 1.1.0 =
    4245* Removed the filter from being called on the homepage, as it was causing unwanted overwrites
  • deweys-open-graph-helper/trunk/class-wad_open_graph.php

    r1247953 r1257849  
    2525   * @var     string
    2626   */
    27   protected $version = '1.1.0';
     27  protected $version = '2.0.0';
    2828
    2929  /**
     
    7272    // 200x200 image for facebook...
    7373    add_action( 'init', array( $this, 'add_og_image_size' ) );
     74
     75    // add og meta box
     76    add_action( 'add_meta_boxes', array( $this, 'add_og_meta_box' ) );
     77
     78    // save og meta
     79    add_action( 'save_post', array( $this, 'save_og_data' ) );
    7480  }
    7581
     
    111117   */
    112118  public static function add_og_image_size() {
    113     add_image_size('200x200', 200, 200, true);
     119    add_image_size('200x200', 200, 200, true); // old size
     120    add_image_size('1200x630', 1200, 630, true); // new size
    114121  }
    115122
     
    125132    if ( is_singular() ) {
    126133      if ( post_type_supports( $post->post_type, 'ogtags' ) ) {
     134        // excerpt
     135        $excerpt = get_the_excerpt();
     136        if ( '' == $excerpt ) {
     137          $excerpt = strip_tags($post->post_content);
     138          $excerpt = strip_shortcodes($excerpt);
     139          $excerpt = str_replace(array("\n", "\r", "\t"), ' ', $excerpt);
     140          $excerpt = substr($excerpt, 0, 155);
     141          $excerpt = $excerpt.'...';
     142          $excerpt = addslashes($excerpt);
     143        }
     144
    127145        // define defaults
    128146        $tags['site_name'] = get_bloginfo( 'name' );
     
    130148        $tags['type'] = 'article';
    131149        $tags['url'] = get_permalink();
    132         $tags['description'] = get_the_excerpt();
     150        $tags['description'] = $excerpt;
    133151
    134152        //Check for a post thumbnail.
     
    136154          $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '200x200', false);
    137155          $tags['image'] = $thumbnail[0];
     156        }
     157
     158        if ( $og_title = get_post_meta($post->ID, 'og_title', true) ) {
     159          $tags['title'] = $og_title;
     160        }
     161
     162        if ( $og_desc = get_post_meta($post->ID, 'og_desc', true) ) {
     163          $tags['description'] = $og_desc;
     164        }
     165
     166        if ( $og_type = get_post_meta($post->ID, 'og_type', true) ) {
     167          $tags['type'] = $og_type;
    138168        }
    139169
     
    155185    }
    156186  }
     187
     188  /**
     189   * Add the og overrides meta box to the page
     190   *
     191   * @since    2.0.0
     192   */
     193  public function add_og_meta_box($post_type) {
     194    if ( post_type_supports($post_type, 'ogtags') ) {
     195      add_meta_box(
     196        'og_meta',
     197        'Custom Open Graph Overrides',
     198        array( $this, 'add_og_meta_box_callback' ),
     199        $post_type
     200        );
     201    }
     202  }
     203
     204  /**
     205   * Callback function to display the meta box
     206   *
     207   * @since    2.0.0
     208   */
     209  public function add_og_meta_box_callback() {
     210    wp_enqueue_style( 'wad_og', plugin_dir_url( __FILE__ ) . '/css/admin.css' );
     211
     212    wp_nonce_field( 'wad_og', 'wad_og_nonce' );
     213    include plugin_dir_path( __FILE__ ) . 'templates/ogform.php';
     214  }
     215
     216  /**
     217   * Save the OG data
     218   *
     219   * @since    2.0.0
     220   */
     221  public function save_og_data($post_id) {
     222    if ( !post_type_supports($_POST['post_type'], 'ogtags') ) {
     223      return;
     224    }
     225
     226    // verify nonce
     227    if ( ! wp_verify_nonce( $_POST['wad_og_nonce'], 'wad_og' ) ) {
     228      return;
     229    }
     230
     231    if ( isset($_POST['og_title']) && !empty($_POST['og_title']) ) {
     232      update_post_meta($post_id, 'og_title', $_POST['og_title']);
     233    } else {
     234      delete_post_meta($post_id, 'og_title');
     235    }
     236
     237    if ( isset($_POST['og_desc']) && !empty($_POST['og_desc']) ) {
     238      update_post_meta($post_id, 'og_desc', $_POST['og_desc']);
     239    } else {
     240      delete_post_meta($post_id, 'og_desc');
     241    }
     242
     243    if ( isset($_POST['og_type']) && !empty($_POST['og_type']) ) {
     244      update_post_meta($post_id, 'og_type', $_POST['og_type']);
     245    } else {
     246      delete_post_meta($post_id, 'og_type');
     247    }
     248
     249    return $post_id;
     250  }
    157251}
  • deweys-open-graph-helper/trunk/wad_open_graph.php

    r1247953 r1257849  
    1111 * Plugin URI:  http://www.whatadewitt.ca
    1212 * Description: Simplifies the use of Open Graph.
    13  * Version:     1.1.0
     13 * Version:     2.0.0
    1414 * Author:      Luke DeWitt
    1515 * Author URI:  http://www.whatadewitt.ca
Note: See TracChangeset for help on using the changeset viewer.