Skip to content

Instantly share code, notes, and snippets.

@thadallender
Last active March 1, 2016 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thadallender/f6af34205c3be1161dc8 to your computer and use it in GitHub Desktop.
Save thadallender/f6af34205c3be1161dc8 to your computer and use it in GitHub Desktop.
Remove default Sell Media shortcode [sell_media_item] and replace with a custom version
<?php
/**
* Plugin Name: My Sell Media Shortcode
* Plugin URI: http://graphpaperpress.com/plugins/sell-media/
* Description: An example shortcode plugin for Sell Media.
* Version: 1.0
* Author: Graph Paper Press
* Author URI: http://graphpaperpress.com
* Author Email: support@graphpaperpress.com
* Text Domain: sell_media
* Domain Path: languages
* License: GPL2
*
* Copyright 2015 GRAPH PAPER PRESS (email: support@graphpaperpress.com)
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License or license.txt for more details.
*
* @package SellMedia
* @category Core
* @author Thad Allender
* @version 1.0
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* Remove core Sell Media shortcode [sell_media_item]
* and replace with custom [sell_media_item] shortcode
*
* @since 1.0
*/
function my_sell_media_init() {
remove_shortcode( 'sell_media_item' );
add_shortcode( 'sell_media_item', 'my_sell_media_item_shortcode' );
}
add_action( 'init', 'my_sell_media_init' );
/**
* Adds the new 'sell_media_item' short code to the editor. [sell_media_item]
*
* @since 1.0
*/
function my_sell_media_item_shortcode( $atts ) {
extract( shortcode_atts( array(
'style' => 'default',
'color' => 'blue',
'id' => '',
'attachment' => '',
'text' => 'BUY',
'size' => 'large',
'align' => 'center'
), $atts )
);
$html = '';
if ( sell_media_has_multiple_attachments( $id ) ) {
$html .= sell_media_gallery( $id );
} else {
$html .= '<div class="sell-media-item-container sell-media-align' . $align . ' ">';
$html .= sell_media_item_icon( $id, $size, false );
$html .= '<p class="collection">' . sell_media_get_taxonomy_terms( 'collection' ) . '</p>';
$html .= '<div class="sell-media-quick-view sell-media-button" data-product-id="' . esc_attr( $id ) . '" data-attachment-id="' . esc_attr( $attachment ) . '">' . $text . '</div>';
$html .= '</div>';
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment