Create a model for the shortcode builder.
models/admin/pages/shortcode.php
and view file
views/admin/pages/shortcode.html
Which deals with the output of the meta box for the shortcode.
Js file moved into the adminHooks.php so it gets setup in time.
echo '<pre>', print_r($array), '</pre>';
}
- /**
- *
- * Shortcode Builder Functions
- *
- */
- private $shortcodeCounter = 0;
- private function get_shortcode_count() {
- return $this->shortcodeCounter;
- }
- private function increase_shortcode_count() {
- $this->shortcodeCounter += 1;
- }
- public function glmMembersShortcode(){
-
- // load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet
- if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){
- wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css');
- wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true);
- }
-
- function custom_js_css() {
-
- wp_enqueue_script('your-meta-box', GLM_MEMBERS_PLUGIN_URL. '/js/shortcodeBuilder.js', array('jquery'), null, true);
- }
- add_action('admin_print_styles-post.php', 'custom_js_css');
- add_action('admin_print_styles-post-new.php', 'custom_js_css');
- reset($this->config['addOns']);
- foreach ($this->config['addOns'] as $a) {
- $cssFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/css/admin.css';
- if (is_file($cssFile)) {
- $cssName = $a['slug'].'-admin-css';
- wp_register_style(
- $cssName,
- GLM_MEMBERS_WORDPRESS_PLUGIN_URL.'/'.$a['slug'].'/css/admin.css',
- false,
- GLM_MEMBERS_PLUGIN_VERSION
- );
- wp_enqueue_style($cssName);
- }
- }
-
- add_meta_box("shortcode_builder",
- "Associate Shortcode Builder",
- array($this,'shortcode_builder_markup'),
- "page", 'normal', 'high'
- );
-
- }
-
- public function shortcode_builder_markup_template($shortCodes, $list) {
- //dropdown for shortcode names
- $this->increase_shortcode_count();
- echo '<div id="shortcode_container" class="'.$this->get_shortcode_count().'" style="overflow: auto">';
- echo '<div id="shortcodeBuilder">';
- echo '<select id="shortcodeDropdown" class="shortcodeDropdown">
- <option value=""> Select Shortcode </option>';
- foreach($shortCodes as $code){
- if (false !== strpos($code, 'members-list') || false !== strpos($code, 'packaging-list')){
- if ( false !== strpos($code, 'members-list' ) ){
- echo '<option value = "' . $code . '">' . 'Display Member List by Category' . '</option>';
- } else if ( false !== strpos($code, 'packaging-list' ) ){
- //echo '<option value = "' . $code . '">' . 'Display Packages' . '</option>';
- }
- }
- }
- echo '</select>';
-
-// echo '<button id="showCategory" class="button" type="button"> Select a Category </button>';
- /*
- * Member DB Shortcode Attributes
- */
-
- //dropdown for categories
- echo '<select id="category-scDropdown" name="category-scDropdown[]" >';
- echo '<option disabled> Select Category </option>';
- foreach ( $list as $key => $value ) {
- if ( ! empty( $value['parent']['name'] ) ) {
- echo '<option value='. $key .'>' . '   '.$value['name'] . '</option>';
- } else {
- echo '<option value='. $key .'>' .' '. $value['name'] . '</option>';
- }
- }
- echo '</select>';
-
- // dropdown for blank start
- echo '<select id="blank-start-scDropdown">';
- echo '<option disabled> Hide List Until Searched</option>
- <option value="False"> No </option>
- <option value="True"> Yes </option>';
- echo '</select>';
-
- // dropdown for views
- echo '<select id="view-scDropdown">';
- echo '<option disabled> View </option>';
- echo '<option selected="selected" value="list"> List View </option>';
- echo '<option value="grid"> Grid View </option>';
- echo '</select>';
-
- // dropdown for Amenity Groups
- $amenGroupSql = "
- SELECT id,name
- FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_groups
- ORDER BY name";
- $amenGroups = $this->wpdb->get_results( $amenGroupSql, ARRAY_A );
- echo '<select id="amenitygroup-scDropdown" name="amenitygroup-scDropdown[]">';
- echo '<option disabled>Select Groups</option>';
- foreach ( $amenGroups as $group ) {
- echo '<option value='. $group['id'] .'>' .' '. $group['name'] . '</option>';
- }
- echo '</select>';
-
- // packaging addOn mark up
- if(file_exists(GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){
- include GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php";
- }
-
- // list and detail buttons to open dialog for member db 'show' attr options
-
-// echo '<button id="detailBtn" class="glm-button" type="button"> Show Detail Options </button>';
-
- echo '<button id="generate" class="right button" type="button"> Insert Shortcode </button>';
- echo '<button id="glmRemoveShortCode" class="right button" type="button"> Delete Shortcode </button>';
- echo '</div>';
-
-
- echo '<div id="activeCategories" class="glm-dynSelect-box scCategories" style="height: auto; overflow: auto;"><div id="categoryTitle">Categories</div></div>';
-
- echo '<div id="activeGroups" class="glm-group-dynSelect-box scGroups" style="height: auto; overflow: auto;"><div id="groupsTitle">Amenity Groups</div></div>';
-
-// echo '<div id="shortcode_preview_box" style="overflow: auto; clear: both;"><div id="shortcodesTitle">Shortcodes</div></div>';
- echo '</div>';
- }
- // metabox content
- public function shortcode_builder_markup(){
-
- require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php');
-
- $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes'];
- $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes'];
- $glmcat = new GlmDataCategories($this->wpdb, $this->config);
- $list = $glmcat->getListSortedParentChild();
-
- // get the each addOn slugs to pass to the config array later
- $addOns = $this->config['addOns'];
- foreach($addOns as $addOn){
- if(!is_array($addOn['slug'])){
- $addOnSlugs[] = $addOn['slug'];
- }
- }
-
- // use the addOn slugs to access each of the shortcodes
- foreach($addOnSlugs as $addOn){
-
- // Check if the add-on has shortcodes
- if (isset($this->config['addOns'][$addOn]['shortcodes'])) {
-
- // It does, so add them to the list
- if ($this->config['addOns'][$addOn]['shortcodes']) {
- $shortCodeList[] = $this->config['addOns'][$addOn]['shortcodes'];
- }
-
- }
- }
-
- // loop through the shortcodes to pull out the shortcode names
- foreach($shortCodeList as $addonInfo) {
- foreach($addonInfo as $shortCode=>$value){
-// echo "<pre>".print_r($value, true)."</pre>";
- if(!is_array($shortCode)){
- $shortCodes[] = $shortCode;
- }
- }
- }
-
- // This function when called will auto-increment the shortcode ID
- $this->shortcode_builder_markup_template($shortCodes, $list);
- ?>
- <script type="text/javascript">
- jQuery(document).ready( function () {
- jQuery("#additionalShortcode").click( function () {
-
- });
- });
- </script>
-
-
- <?php
- // It should be able to be called several times (once every time the
- // additionalShortcode button is clicked), but there are still some
- // issues with that. Nice-print conflict..
-// $this->shortcode_builder_markup_template($shortCodes, $list);
-
- // This button will add another shortcode editor
-
- //echo '<button id="additionalShortcode" class="button" type="button"> Configure Additional Shortcode </button>';
- }
}
/*
);
// add shortcode metabox
+ /*
add_action('add_meta_boxes', array(
$this,
'glmMembersShortcode'
) );
+ */
// Add AJAX image upload action
add_action( 'wp_ajax_glm_members_admin_ajax',
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Shortcode Builder
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+/**
+ * Adding content to the GLM Associate Dashboard Widget from an Add-on.
+ *
+ * There are three filters in the GLM Associate Dashboard Widget view for adding content into the widget.
+ * These include short warnings, lists of pending user actions, and other notices.
+ *
+ * See "Management" -> "Hooks" then scan down to "Main Dashboard Widget Hooks".
+ *
+ * Here's the best method for providing content to the dashboard widget. There is an example of this in the search add-on.
+ *
+ * 1. Create a Model/View to build additional content for the dashboard widget
+ * a. Add a model for generating the warning/notice to the add-on in, for example, "models/admin/dashboardWidget/search/"
+ * b. Add a view for this model to the add-on in, for example, "views/admin/dashboardWidget/search/"
+ * (see Main Dashboard Widget Hooks descriptions for suggested format)
+ * c. Add the model to "setup/validActions.php" in the add-on
+ *
+ * 2. Place an add_filter() function in the add-on's "setup/adminHooks.php" file, for example...
+ *
+ * // Add content to the main dashboard widget
+ * add_filter( 'glm-member-db-dashboard-widget-warnings', function( $content ) {
+ * $content .= $this->controller('dashboardWidget', 'search');
+ * return $content;
+ * });
+ */
+
+/**
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_pages_shortcode
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+ private $shortcodeCounter = 0;
+
+ /**
+ * Constructor
+ *
+ * This contructor sets up this model. At this time that only includes
+ * storing away the WordPress data object.
+ *
+ * @return object Class object
+ *
+ */
+ public function __construct ($wpdb, $config)
+ {
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+ }
+
+ /**
+ * Perform Model Action
+ *
+ * This method does the work for this model and returns any resulting data
+ *
+ * @return array Status and data array
+ *
+ * 'status'
+ *
+ * True if successfull and false if there was a fatal failure.
+ *
+ * 'menuItemRedirect'
+ *
+ * If not false, provides a menu item the controller should
+ * execute after this one. Normally if this is used, there would also be a
+ * modelRedirect value supplied as well.
+ *
+ * 'modelRedirect'
+ *
+ * If not false, provides an action the controller should execute after
+ * this one.
+ *
+ * 'view'
+ *
+ * A suggested view name that the contoller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ */
+ public function modelAction ($actionData = false)
+ {
+ $success = true;
+ $categories = array();
+
+ // load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet
+ if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){
+ wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css');
+ wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true);
+ }
+
+ reset($this->config['addOns']);
+ foreach ($this->config['addOns'] as $a) {
+ $cssFile = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/css/admin.css';
+ if (is_file($cssFile)) {
+ $cssName = $a['slug'].'-admin-css';
+ wp_register_style(
+ $cssName,
+ GLM_MEMBERS_WORDPRESS_PLUGIN_URL.'/'.$a['slug'].'/css/admin.css',
+ false,
+ GLM_MEMBERS_PLUGIN_VERSION
+ );
+ wp_enqueue_style($cssName);
+ }
+ }
+
+ require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php');
+
+ $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes'];
+ $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes'];
+ $glmcat = new GlmDataCategories( $this->wpdb, $this->config );
+ $categories = $glmcat->getListSortedParentChild();
+
+ // get the each addOn slugs to pass to the config array later
+ $addOns = $this->config['addOns'];
+ foreach($addOns as $addOn){
+ if(!is_array($addOn['slug'])){
+ $addOnSlugs[] = $addOn['slug'];
+ }
+ }
+
+ // use the addOn slugs to access each of the shortcodes
+ foreach($addOnSlugs as $addOn){
+
+ // Check if the add-on has shortcodes
+ if (isset($this->config['addOns'][$addOn]['shortcodes'])) {
+
+ // It does, so add them to the list
+ if ($this->config['addOns'][$addOn]['shortcodes']) {
+ $shortCodeList[] = $this->config['addOns'][$addOn]['shortcodes'];
+ }
+
+ }
+ }
+
+ // loop through the shortcodes to pull out the shortcode names
+ foreach($shortCodeList as $addonInfo) {
+ foreach($addonInfo as $shortCode=>$value){
+ if(!is_array($shortCode)){
+ $shortCodes[] = $shortCode;
+ }
+ }
+ }
+
+ // This function when called will auto-increment the shortcode ID
+ $this->increase_shortcode_count();
+ // Amenity Groups.
+ $amenGroupSql = "
+ SELECT id,name
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_groups
+ ORDER BY name";
+ $amenGroups = $this->wpdb->get_results( $amenGroupSql, ARRAY_A );
+
+ // Compile template data
+ $templateData = array(
+ 'categories' => $categories,
+ 'amenGroups' => $amenGroups,
+ 'shortCodes' => $shortCodes,
+ );
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => $success,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => 'admin/pages/shortcode.html',
+ 'data' => $templateData
+ );
+
+ }
+
+ /**
+ * get_shortcode_count
+ *
+ * Return the count of shortcodes.
+ *
+ * @access private
+ * @return void
+ */
+ private function get_shortcode_count() {
+ return $this->shortcodeCounter;
+ }
+ /**
+ * increase_shortcode_count
+ *
+ * Increase the shortcode by one.
+ *
+ * @access private
+ * @return void
+ */
+ private function increase_shortcode_count() {
+ $this->shortcodeCounter += 1;
+ }
+}
10,
2
);
-
+
$menuName = "Members Only Menu";
$menuSlug = "members-only-menu";
// Does the menu exist already?
register_nav_menu($menuSlug, $menuName);
-
+
$menuExists = wp_get_nav_menu_object( $menuName );
// If it doesn't exist, let's create it.
if( !$menuExists){
-
+
$membersOnlyPageID = get_option(GLM_MEMBERS_PLUGIN_MEMBERS_ONLY_ID);
//
$menu_id = wp_create_nav_menu($menuName);
$locations[$menuSlug] = $menu->term_id;
set_theme_mod('nav_menu_locations', $locations);
}
+
+
+add_action( 'add_meta_boxes', function() {
+ function custom_js_css() {
+ wp_enqueue_script('your-meta-box', GLM_MEMBERS_PLUGIN_URL. '/js/shortcodeBuilder.js', array('jquery'), null, true);
+ }
+ add_action('admin_print_styles-post.php', 'custom_js_css' );
+ add_action('admin_print_styles-post-new.php', 'custom_js_css' );
+ add_meta_box("shortcode_builder",
+ "Associate Shortcode Builder",
+ function() {
+ $this->controller( 'pages', 'shortcode' );
+ },
+ "page", 'normal', 'high'
+ );
+} );
+
// This function below needs to be defined in the theme's functions.php
//
//if ( ! function_exists( 'glm_members_only_menu' ) && class_exists('GLM_Members_Only_Walker')) {
// }
//}
-
-?>
\ No newline at end of file
+
+?>
'memberInfo' => 'glm-member-db',
'memberEdit' => 'glm-member-db',
'locations' => 'glm-member-db',
- )
- ,
+ ),
'settings' => array(
'index' => 'glm-member-db', // Member Types
'categories' => 'glm-member-db',
'error' => array(
'index' => 'glm-member-db',
'badAction' => 'glm-member-db',
+ ),
+ 'pages' => array(
+ 'shortcode' => 'glm-member-db'
)
),
'frontActions' => array(
--- /dev/null
+<div id="shortcode_container" class="{$shortcode_count}" style="overflow: auto">
+ <div id="shortcodeBuilder">
+ <select id="shortcodeDropdown" class="shortcodeDropdown">
+ <option value=""> Select Shortcode </option>
+ {foreach $shortCodes as $code}
+ <option value = "{$code}">Display Member List by Category</option>
+ {/foreach}
+ </select>
+ <select id="category-scDropdown" name="category-scDropdown[]">
+ <option disabled> Select Category </option>
+ {foreach $categories as $key => $value}
+ {if !$value.parent.name}
+ <option value="{$key}">   {$value.name}</option>
+ {else}
+ <option value="{$key}"> {$value.name}</option>
+ {/if}
+ {/foreach}
+ </select>
+ <select id="blank-start-scDropdown">
+ <option disabled> Hide List Until Searched</option>
+ <option value="False"> No </option>
+ <option value="True"> Yes </option>
+ </select>
+ <select id="view-scDropdown">
+ <option disabled> View </option>
+ <option selected="selected" value="list"> List View </option>
+ <option value="grid"> Grid View </option>
+ </select>
+ <select id="amenitygroup-scDropdown" name="amenitygroup-scDropdown[]">
+ <option disabled> Select Groups </option>
+ {foreach $amenGroups as $group}
+ <option value="{$group.id}"> {$group.name}</option>
+ {/foreach}
+ </select>
+ <button id="generate" class="right button" type="button"> Insert Shortcode </button>
+ <button id="glmRemoveShortCode" class="right button" type="button"> Delete Shortcode </button>
+ </div>
+ <div id="activeCategories" class="glm-dynSelect-box scCategories" style="height: auto; overflow: auto;"><div id="categoryTitle">Categories</div></div>
+ <div id="activeGroups" class="glm-group-dynSelect-box scGroups" style="height: auto; overflow: auto;"><div id="groupsTitle">Amenity Groups</div></div>
+</div>
+
+