Skip to content

Instantly share code, notes, and snippets.

@mayukojpn
Last active March 28, 2017 21:47
Show Gist options
  • Save mayukojpn/3f68f5329ddf301b034ddcdb6069e434 to your computer and use it in GitHub Desktop.
Save mayukojpn/3f68f5329ddf301b034ddcdb6069e434 to your computer and use it in GitHub Desktop.
ShortCake UI Demo Plugin
<?php
/**
* Plugin Name: Shortcake UI Pullquote Demo
* Plugin URI:
* Description: Try Shortcake with pull-quite shortcode
* Version: 1.0.0
* Author: Mte90
* License: GPL2
*/
add_action( 'init', function() {
/**
* Register your shortcode as you would normally.
* This is a simple example for a pullquote with a citation.
*/
add_shortcode( 'pullquote', function( $attr, $content = '' ) {
$attr = wp_parse_args( $attr, array(
'source' => ''
) );
ob_start();
?>
<section class="pullquote">
<?php echo esc_html( $content ); ?><br/>
<?php if ( ! empty( $attr['source'] ) ) : ?>
<cite><em><?php echo esc_html( $attr['source'] ); ?></em></cite>
<?php endif; ?>
</section>
<?php
return ob_get_clean();
} );
/**
* Register a UI for the Shortcode.
* Pass the shortcode tag (string)
* and an array or args.
*/
if ( function_exists( 'shortcode_ui_register_for_shortcode' ) ) :
shortcode_ui_register_for_shortcode(
'pullquote',
array(
// Display label. String. Required.
'label' => 'Pullquote',
// Icon/image for shortcode. Optional. src or dashicons-$icon. Defaults to carrot.
'listItemImage' => 'dashicons-editor-quote',
// Available shortcode attributes and default values. Required. Array.
// Attribute model expects 'attr', 'type' and 'label'
// Supported field types: text, checkbox, textarea, radio, select, email, url, number, and date.
'attrs' => array(
array(
'label' => 'Cite',
'attr' => 'source',
'type' => 'text',
'placeholder' => 'Firstname Lastname',
'description' => 'Optional',
),
),
'inner_content' => array(
'label' => 'Quote',
),
)
);
endif;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment