Filters for shortcode tags

This commit is contained in:
Mike Jolley 2013-10-23 14:55:18 +01:00
parent 1b1332d278
commit 8ce3b8dd57
8 changed files with 45 additions and 46 deletions

View File

@ -19,7 +19,7 @@
var a=this;d.onRenderMenu.add(function(c,b){ var a=this;d.onRenderMenu.add(function(c,b){
a.addImmediate(b, ed.getLang('woocommerce.order_tracking'),"[woocommerce_order_tracking]" ); a.addImmediate(b, ed.getLang('woocommerce.order_tracking'), '[' + ed.getLang('woocommerce.order_tracking_shortcode') + ']' );
a.addImmediate(b, ed.getLang('woocommerce.price_button'), '[add_to_cart id="" sku=""]'); a.addImmediate(b, ed.getLang('woocommerce.price_button'), '[add_to_cart id="" sku=""]');
a.addImmediate(b, ed.getLang('woocommerce.product_by_sku'), '[product id="" sku=""]'); a.addImmediate(b, ed.getLang('woocommerce.product_by_sku'), '[product id="" sku=""]');
a.addImmediate(b, ed.getLang('woocommerce.products_by_sku'), '[products ids="" skus=""]'); a.addImmediate(b, ed.getLang('woocommerce.products_by_sku'), '[products ids="" skus=""]');
@ -33,15 +33,7 @@
b.addSeparator(); b.addSeparator();
a.addImmediate(b, ed.getLang('woocommerce.shop_messages'), '[woocommerce_messages]'); a.addImmediate(b, ed.getLang('woocommerce.shop_messages'), '[' + ed.getLang('woocommerce.shop_messages_shortcode') + ']');
b.addSeparator();
c=b.addMenu({title:ed.getLang('woocommerce.pages')});
a.addImmediate(c, ed.getLang('woocommerce.cart'),"[woocommerce_cart]" );
a.addImmediate(c, ed.getLang('woocommerce.checkout'),"[woocommerce_checkout]" );
a.addImmediate(c, ed.getLang('woocommerce.my_account'),"[woocommerce_my_account]" );
}); });
return d return d

View File

@ -1 +1 @@
(function(){tinymce.create("tinymce.plugins.WooCommerceShortcodes",{init:function(e,t){},createControl:function(e,t){var n=tinymce.activeEditor;if(e=="woocommerce_shortcodes_button"){e=t.createMenuButton("woocommerce_shortcodes_button",{title:n.getLang("woocommerce.insert"),icons:!1});var r=this;e.onRenderMenu.add(function(e,t){r.addImmediate(t,n.getLang("woocommerce.order_tracking"),"[woocommerce_order_tracking]");r.addImmediate(t,n.getLang("woocommerce.price_button"),'[add_to_cart id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.product_by_sku"),'[product id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_sku"),'[products ids="" skus=""]');r.addImmediate(t,n.getLang("woocommerce.product_categories"),'[product_categories number=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_cat_slug"),'[product_category category="" per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.recent_products"),'[recent_products per_page="12" columns="4" orderby="date" order="desc"]');r.addImmediate(t,n.getLang("woocommerce.featured_products"),'[featured_products per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.shop_messages"),"[woocommerce_messages]");t.addSeparator();e=t.addMenu({title:n.getLang("woocommerce.pages")});r.addImmediate(e,n.getLang("woocommerce.cart"),"[woocommerce_cart]");r.addImmediate(e,n.getLang("woocommerce.checkout"),"[woocommerce_checkout]");r.addImmediate(e,n.getLang("woocommerce.my_account"),"[woocommerce_my_account]")});return e}return null},addImmediate:function(e,t,n){e.add({title:t,onclick:function(){tinyMCE.activeEditor.execCommand("mceInsertContent",!1,n)}})}});tinymce.PluginManager.add("WooCommerceShortcodes",tinymce.plugins.WooCommerceShortcodes)})(); (function(){tinymce.create("tinymce.plugins.WooCommerceShortcodes",{init:function(e,t){},createControl:function(e,t){var n=tinymce.activeEditor;if(e=="woocommerce_shortcodes_button"){e=t.createMenuButton("woocommerce_shortcodes_button",{title:n.getLang("woocommerce.insert"),icons:!1});var r=this;e.onRenderMenu.add(function(e,t){r.addImmediate(t,n.getLang("woocommerce.order_tracking"),"["+n.getLang("woocommerce.order_tracking_shortcode")+"]");r.addImmediate(t,n.getLang("woocommerce.price_button"),'[add_to_cart id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.product_by_sku"),'[product id="" sku=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_sku"),'[products ids="" skus=""]');r.addImmediate(t,n.getLang("woocommerce.product_categories"),'[product_categories number=""]');r.addImmediate(t,n.getLang("woocommerce.products_by_cat_slug"),'[product_category category="" per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.recent_products"),'[recent_products per_page="12" columns="4" orderby="date" order="desc"]');r.addImmediate(t,n.getLang("woocommerce.featured_products"),'[featured_products per_page="12" columns="4" orderby="date" order="desc"]');t.addSeparator();r.addImmediate(t,n.getLang("woocommerce.shop_messages"),"["+n.getLang("woocommerce.shop_messages_shortcode")+"]")});return e}return null},addImmediate:function(e,t,n){e.add({title:t,onclick:function(){tinyMCE.activeEditor.execCommand("mceInsertContent",!1,n)}})}});tinymce.PluginManager.add("WooCommerceShortcodes",tinymce.plugins.WooCommerceShortcodes)})();

View File

@ -11,11 +11,9 @@ $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
recent_products: "' . esc_js( __( 'Recent products', 'woocommerce' ) ) . '", recent_products: "' . esc_js( __( 'Recent products', 'woocommerce' ) ) . '",
featured_products: "' . esc_js( __( 'Featured products', 'woocommerce' ) ) . '", featured_products: "' . esc_js( __( 'Featured products', 'woocommerce' ) ) . '",
shop_messages: "' . esc_js( __( 'Shop Messages', 'woocommerce' ) ) . '", shop_messages: "' . esc_js( __( 'Shop Messages', 'woocommerce' ) ) . '",
pages: "' . esc_js( __( 'Pages', 'woocommerce' ) ) . '",
cart: "' . esc_js( __( 'Cart', 'woocommerce' ) ) . '",
checkout: "' . esc_js( __( 'Checkout', 'woocommerce' ) ) . '",
order_tracking: "' . esc_js( __( 'Order tracking', 'woocommerce' ) ) . '", order_tracking: "' . esc_js( __( 'Order tracking', 'woocommerce' ) ) . '",
my_account: "' . esc_js( __( 'My Account', 'woocommerce' ) ) . '", my_account: "' . esc_js( __( 'My Account', 'woocommerce' ) ) . '",
edit_address: "' . esc_js( __( 'Edit Address', 'woocommerce' ) ) . '", shop_messages_shortcode: "' . esc_js( apply_filters( "shop_messages_shortcode_tag", 'woocommerce_shop_messages' ) ) . '",
order_tracking_shortcode: "' . esc_js( apply_filters( "woocommerce_order_tracking_shortcode_tag", 'woocommerce_order_tracking' ) ) . '"
} }
}})'; }})';

View File

@ -42,7 +42,7 @@ class WC_Settings_Accounts extends WC_Settings_Page {
array( array(
'title' => __( 'My Account Page', 'woocommerce' ), 'title' => __( 'My Account Page', 'woocommerce' ),
'desc' => __( 'Page contents: [woocommerce_my_account]', 'woocommerce' ), 'desc' => __( 'Page contents:', 'woocommerce' ) . ' [' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']',
'id' => 'woocommerce_myaccount_page_id', 'id' => 'woocommerce_myaccount_page_id',
'type' => 'single_select_page', 'type' => 'single_select_page',
'default' => '', 'default' => '',

View File

@ -110,7 +110,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
array( array(
'title' => __( 'Cart Page', 'woocommerce' ), 'title' => __( 'Cart Page', 'woocommerce' ),
'desc' => __( 'Page contents: [woocommerce_cart]', 'woocommerce' ), 'desc' => __( 'Page contents:', 'woocommerce' ) . ' [' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']',
'id' => 'woocommerce_cart_page_id', 'id' => 'woocommerce_cart_page_id',
'type' => 'single_select_page', 'type' => 'single_select_page',
'default' => '', 'default' => '',
@ -121,7 +121,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
array( array(
'title' => __( 'Checkout Page', 'woocommerce' ), 'title' => __( 'Checkout Page', 'woocommerce' ),
'desc' => __( 'Page contents: [woocommerce_checkout]', 'woocommerce' ), 'desc' => __( 'Page contents:', 'woocommerce' ) . ' [' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']',
'id' => 'woocommerce_checkout_page_id', 'id' => 'woocommerce_checkout_page_id',
'type' => 'single_select_page', 'type' => 'single_select_page',
'default' => '', 'default' => '',

View File

@ -287,15 +287,15 @@
), ),
__( 'Cart', 'woocommerce' ) => array( __( 'Cart', 'woocommerce' ) => array(
'option' => 'woocommerce_cart_page_id', 'option' => 'woocommerce_cart_page_id',
'shortcode' => '[woocommerce_cart]' 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']'
), ),
__( 'Checkout', 'woocommerce' ) => array( __( 'Checkout', 'woocommerce' ) => array(
'option' => 'woocommerce_checkout_page_id', 'option' => 'woocommerce_checkout_page_id',
'shortcode' => '[woocommerce_checkout]' 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']'
), ),
__( 'My Account', 'woocommerce' ) => array( __( 'My Account', 'woocommerce' ) => array(
'option' => 'woocommerce_myaccount_page_id', 'option' => 'woocommerce_myaccount_page_id',
'shortcode' => '[woocommerce_my_account]' 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']'
) )
); );

View File

@ -213,17 +213,17 @@ class WC_Install {
'cart' => array( 'cart' => array(
'name' => _x( 'cart', 'page_slug', 'woocommerce' ), 'name' => _x( 'cart', 'page_slug', 'woocommerce' ),
'title' => __( 'Cart', 'woocommerce' ), 'title' => __( 'Cart', 'woocommerce' ),
'content' => '[woocommerce_cart]' 'content' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']'
), ),
'checkout' => array( 'checkout' => array(
'name' => _x( 'checkout', 'page_slug', 'woocommerce' ), 'name' => _x( 'checkout', 'page_slug', 'woocommerce' ),
'title' => __( 'Checkout', 'woocommerce' ), 'title' => __( 'Checkout', 'woocommerce' ),
'content' => '[woocommerce_checkout]' 'content' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']'
), ),
'myaccount' => array( 'myaccount' => array(
'name' => _x( 'my-account', 'page_slug', 'woocommerce' ), 'name' => _x( 'my-account', 'page_slug', 'woocommerce' ),
'title' => __( 'My Account', 'woocommerce' ), 'title' => __( 'My Account', 'woocommerce' ),
'content' => '[woocommerce_my_account]' 'content' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']'
) )
) ); ) );

View File

@ -14,25 +14,34 @@ class WC_Shortcodes {
* Init shortcodes * Init shortcodes
*/ */
public function init() { public function init() {
add_shortcode( 'product', __CLASS__ . '::product' ); // Define shortcodes
add_shortcode( 'product_page', __CLASS__ . '::product_page_shortcode' ); $shortcodes = array(
add_shortcode( 'product_category', __CLASS__ . '::product_category' ); 'product' => __CLASS__ . '::product',
add_shortcode( 'product_categories', __CLASS__ . '::product_categories' ); 'product_page' => __CLASS__ . '::product_page',
add_shortcode( 'add_to_cart', __CLASS__ . '::product_add_to_cart' ); 'product_category' => __CLASS__ . '::product_category',
add_shortcode( 'add_to_cart_url', __CLASS__ . '::product_add_to_cart_url' ); 'product_categories' => __CLASS__ . '::product_categories',
add_shortcode( 'products', __CLASS__ . '::products' ); 'add_to_cart' => __CLASS__ . '::product_add_to_cart',
add_shortcode( 'recent_products', __CLASS__ . '::recent_products' ); 'add_to_cart_url' => __CLASS__ . '::product_add_to_cart_url',
add_shortcode( 'sale_products', __CLASS__ . '::sale_products' ); 'products' => __CLASS__ . '::products',
add_shortcode( 'best_selling_products', __CLASS__ . '::best_selling_products' ); 'recent_products' => __CLASS__ . '::recent_products',
add_shortcode( 'top_rated_products', __CLASS__ . '::top_rated_products' ); 'sale_products' => __CLASS__ . '::sale_products',
add_shortcode( 'featured_products', __CLASS__ . '::featured_products' ); 'best_selling_products' => __CLASS__ . '::best_selling_products',
add_shortcode( 'product_attribute', __CLASS__ . '::product_attribute' ); 'top_rated_products' => __CLASS__ . '::top_rated_products',
add_shortcode( 'related_products', __CLASS__ . '::related_products_shortcode' ); 'featured_products' => __CLASS__ . '::featured_products',
add_shortcode( 'woocommerce_messages', __CLASS__ . '::messages_shortcode' ); 'product_attribute' => __CLASS__ . '::product_attribute',
add_shortcode( 'woocommerce_cart', __CLASS__ . '::cart' ); 'related_products' => __CLASS__ . '::related_products',
add_shortcode( 'woocommerce_checkout', __CLASS__ . '::checkout' ); 'shop_messages' => __CLASS__ . '::shop_messages',
add_shortcode( 'woocommerce_order_tracking', __CLASS__ . '::order_tracking' ); 'woocommerce_order_tracking' => __CLASS__ . '::order_tracking',
add_shortcode( 'woocommerce_my_account', __CLASS__ . '::my_account' ); 'woocommerce_cart' => __CLASS__ . '::cart',
'woocommerce_checkout' => __CLASS__ . '::checkout',
'woocommerce_my_account' => __CLASS__ . '::my_account',
);
foreach ( $shortcodes as $shortcode => $function )
add_shortcode( apply_filters( "{$shortcode}_shortcode_tag", $shortcode ), $function );
// Alias for pre 2.1 compatibility
add_shortcode( 'woocommerce_messages', __CLASS__ . '::shop_messages' );
} }
/** /**
@ -772,7 +781,7 @@ class WC_Shortcodes {
* @param array $atts * @param array $atts
* @return string * @return string
*/ */
public static function product_page_shortcode( $atts ) { public static function product_page( $atts ) {
if ( empty( $atts ) ) return; if ( empty( $atts ) ) return;
if ( ! isset( $atts['id'] ) && ! isset( $atts['sku'] ) ) return; if ( ! isset( $atts['id'] ) && ! isset( $atts['sku'] ) ) return;
@ -824,7 +833,7 @@ class WC_Shortcodes {
* @param array $atts * @param array $atts
* @return string * @return string
*/ */
public static function messages_shortcode() { public static function shop_messages() {
ob_start(); ob_start();
wc_print_messages(); wc_print_messages();
@ -927,7 +936,7 @@ class WC_Shortcodes {
return '<div class="woocommerce">' . ob_get_clean() . '</div>'; return '<div class="woocommerce">' . ob_get_clean() . '</div>';
} }
public static function related_products_shortcode( $atts ) { public static function related_products( $atts ) {
$atts = shortcode_atts( array( $atts = shortcode_atts( array(
'posts_per_page' => '2', 'posts_per_page' => '2',