Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic plugin to add Shortcode UI for Simplechart
<?php
/*
Plugin Name: Simplechart/Shortcake UI Demo
Plugin URI: http://www.alleyinteractive.com/
Description: This plugin exists to demonstrate Simplechart with Shortcake UI
Version: 0.1
Author: Davis Shaver
Author URI: http://www.alleyinteractive.com/
*/
/* This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* If Shortcake isn't active, then add an administration notice.
*
* @since 0.1
*/
function shortcode_ui_detection() {
if ( ! function_exists( 'shortcode_ui_register_for_shortcode' ) ) {
add_action( 'admin_notices', 'simplechart_shortcake_dev_example_notices' );
}
}
add_action( 'init', 'shortcode_ui_detection' );
/**
* Display the administration notice if the user can activate plugins.
*
* @since 0.1
*/
function simplechart_shortcake_dev_example_notices() {
if ( current_user_can( 'activate_plugins' ) ) {
?>
<div class="error message">
<p><?php esc_html_e( 'Shortcode UI plugin must be active for the Simplechart extension.', 'simplechart-shortcake' ); ?></p>
</div>
<?php
}
}
/**
* Register a basic Shortcode UI for Simplechart
*
* @since 0.1
*/
function shortcode_ui_for_simplechart() {
shortcode_ui_register_for_shortcode(
'simplechart',
array(
'label' => esc_html__( 'Simplechart', 'simplechart-shortcake' ),
'listItemImage' => 'dashicons-chart-pie',
'post_type' => array( 'post' ),
'attrs' => array(
array(
'label' => esc_html__( 'Select Chart', 'Simplechart Shortcake' ),
'attr' => 'id',
'type' => 'post_select',
'query' => array( 'post_type' => 'simplechart' ),
),
),
)
);
}
add_action( 'register_shortcode_ui', 'shortcode_ui_for_simplechart' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment