Created
December 10, 2016 15:20
-
-
Save davisshaver/13225ef27206f4ba1c8be530db229b14 to your computer and use it in GitHub Desktop.
Basic plugin to add Shortcode UI for Simplechart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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