Plugin Directory

Changeset 1186627


Ignore:
Timestamp:
06/24/2015 06:04:04 AM (11 years ago)
Author:
mikeleeorg
Message:

Fixed some bugs with backwards compatibility of legacy shortcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • edshelf-widget/trunk/edshelf-widgets.php

    r1186621 r1186627  
    7373 * Returns the Shelf widget itself
    7474 */
    75 function edshelf_shelf_widget_embed( $id = EDSHELF_DEFAULT_SHELF_ID, $height = EDSHELF_DEFAULT_SHELF_HEIGHT, $format = EDSHELF_DEFAULT_SHELF_FORMAT ) {
     75function edshelf_shelf_widget_embed( $id = EDSHELF_DEFAULT_SHELF_ID, $height = EDSHELF_DEFAULT_SHELF_HEIGHT, $format = EDSHELF_DEFAULT_SHELF_FORMAT, $which = 's' ) {
    7676    $id     = esc_attr( $id );
    7777    $height = esc_attr( $height );
    7878    $format = esc_attr( $format );
    79     return "<div id='edshelf-widget-shelf-{$id}'></div><script src='https://edshelf.com/widgets/shelf/?id={$id}&height={$height}&format={$format}&type=shelf'></script>";
     79    $which  = ( $which == 'c' ) ? 'collection' : 'shelf';
     80    return "<div id='edshelf-widget-shelf-{$id}'></div><script src='https://edshelf.com/widgets/{$which}/?id={$id}&height={$height}&format={$format}&type=shelf'></script>";
    8081}
    8182
     
    9596 *
    9697 * [edshelf-shelf-widget id="33080" height="550" format="grid"]
    97  * [edshelf-shelf-widget id="33080" height="550" format="grid"] // Legacy shortcode
    9898 */
    9999add_shortcode( 'edshelf-shelf-widget', 'edshelf_shelf_widget_function' );
    100 add_shortcode( 'edshelf-collection-widget', 'edshelf_shelf_widget_function' ); // Legacy shortcode
    101100function edshelf_shelf_widget_function( $atts ) {
    102101    extract( shortcode_atts( array(
     
    107106
    108107    return edshelf_shelf_widget_embed( $id, $height, $format );
     108}
     109
     110
     111/**
     112 * Creates a legacy shortcode for the Shelf widget
     113 *
     114 * [edshelf-collection-widget id="33080" height="550" format="grid"]
     115 */
     116add_shortcode( 'edshelf-collection-widget', 'edshelf_collection_widget_function' );
     117function edshelf_collection_widget_function( $atts ) {
     118    extract( shortcode_atts( array(
     119        'id'     => EDSHELF_DEFAULT_SHELF_ID,
     120        'height' => EDSHELF_DEFAULT_SHELF_HEIGHT,
     121        'format' => EDSHELF_DEFAULT_SHELF_FORMAT
     122    ), $atts ) );
     123
     124    return edshelf_shelf_widget_embed( $id, $height, $format, 'c' );
    109125}
    110126
Note: See TracChangeset for help on using the changeset viewer.