Started using Script Registry for enqueing script and style files
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 19 Mar 2019 16:39:36 +0000 (12:39 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 19 Mar 2019 16:39:36 +0000 (12:39 -0400)
Added registry lists for admin and front-end in setup dir
Added a number of scripts and styles to using registry.

defines.php
index.php
models/admin/registrations/events.php
models/admin/registrations/requests.php
models/front/registrations/checkout.php
models/front/registrations/registration.php
readme.txt
setup/registerAdminScriptStyle.php [new file with mode: 0644]
setup/registerFrontScriptStyle.php [new file with mode: 0644]
views/front/registrations/registration.html

index 8d34438..d8f52c0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * {DescrName}
+ * Gaslight Media Event Registrations
  *
  * Set standard defined parameters
  */
index 7d951b6..54ae9a4 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -40,6 +40,13 @@ if (!defined('ABSPATH')) {
  *  We check the plugin version stored in the WordPress option below
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
+ *
+ *  NOTE: When doing development add another position to the plugin
+ *  version number below (i.e. '1.3.1.20'). Since when scripts are
+ *  enqueued using the glmScripRegistry the plugin version is used
+ *  in the wp_register_script() and wp_register_style() calls, adding
+ *  or updating that last position will result in cache-busting. Be
+ *  sure to remove that 4th postion when doing a hotfix or release!
  */
 define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION', '1.3.1');
 define('GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_VERSION', '1.0.4');
index f58ed87..41e3205 100755 (executable)
@@ -92,7 +92,7 @@ class GlmMembersAdmin_registrations_events extends GlmDataRegistrationsRegEvent
             array(
                 'jquery'
             ),
-            GLM_MEMBERS_PLUGIN_VERSION
+            GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION
             );
         wp_enqueue_script('glm-members-reg-admin-mask');
 
index f66d5de..655ef51 100755 (executable)
@@ -114,13 +114,6 @@ class GlmMembersAdmin_registrations_requests extends GlmDataRegistrationsRegRequ
         require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/regCartSupport.php';
         $regCartSupport = new GlmRegCartSupport($this->wpdb, $this->config);
 
-        wp_enqueue_style(
-            'foundation',
-            GLM_MEMBERS_REGISTRATIONS_PLUGIN_BASE_URL . '/css/foundation.css',
-            null,
-            '1.0'
-        );
-
         // Check for option submitted
         if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') {
             $option = $_REQUEST['option'];
index dd13273..469a79a 100755 (executable)
@@ -72,7 +72,7 @@ class GlmMembersFront_registrations_checkout extends GlmRegCartSupport
             array(
                 'jquery'
             ),
-            GLM_MEMBERS_PLUGIN_VERSION
+            GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION
             );
         wp_enqueue_script('glm-members-reg-front-mask');
 
index 14fe2d8..bca56df 100755 (executable)
         $Misc = new GlmDataRegistrationsMisc($this->wpdb, $this->config);
         $misc = $Misc->getEntry(1);
 
-        // Setup scripts array for needed js files.
-        $scripts = array(
-            'regApp' => 'js/frontRegApp.js',
-        );
-
-        // Loop through our scripts array and register them.
-        foreach ( $scripts as $scriptName => $scriptPath ) {
-            wp_register_script(
-                $scriptName,
-                GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . $scriptPath,
-                array( 'jquery', 'backbone', 'underscore' ),
-                '1.0',
-                true
-            );
+        /*
+         * Enqueue required scripts
+         */
+        // Select frontRegApp.js script to be enqueued
+        glmScriptRegistry::select( glmScriptType::Script, 'RegApp' );
+
+        // If we're using Leaflet - Enqueue Leaflet scripts and styles
+        if ( $this->config['settings']['selected_map_interface'] == 1 ) {
+            glmScriptRegistry::select( glmScriptType::Style, 'Leaflet' );
+            glmScriptRegistry::select( glmScriptType::Script, 'Leaflet' );
+            glmScriptRegistry::select( glmScriptType::Style, 'LeafletControlLoading' );
+            glmScriptRegistry::select( glmScriptType::Script, 'LeafletControlLoading' );
         }
-        // Load Backbone.sj and jQuery.
-        wp_enqueue_script( array( 'backbone', 'jquery' ) );
 
-        // Load our scripts.
-        wp_enqueue_script( array_keys( $scripts ) );
-        $regEvent = array();
+        // If we're using Google Maps - Enqueue Google Maps script
+        if ( $this->config['settings']['selected_map_interface'] == 2 ) {
+            glmScriptRegistry::select( glmScriptType::Script, 'GoogleMapsAPI' );
+        }
 
         // Get any provided option
         if (isset($_REQUEST['option'])) {
         );
         $attendeeFieldsJSON = json_encode($attendeeFields, JSON_NUMERIC_CHECK);
 
+        // Select scripts to enqueue
+        if ( $this->config['settings']['selected_map_interface'] ) {
+
+        }
+
+
         // echo "<pre>".print_r($registrants,1)."</pre>";
 
         // Compile template data
             'haveCart'          => $haveCart,
             'haveRegEvent'      => $haveRegEvent,
             'regEvent'          => $regEvent,
-            'standAlone'        => ($regEvent.event == 0),
+            'standAlone'        => ($regEvent['event'] == 0),
             'regEventFirstTime' => $regEventFirstTime,
             'thisJsUrl'         => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js',
             'regEventJSON'      => json_encode( $event, JSON_NUMERIC_CHECK ),
index 645ad0c..74eb78d 100755 (executable)
@@ -25,6 +25,10 @@ e.g.
 1. Activate the plugin through the 'Plugins' menu in WordPress
 
 == Changelog ==
+= (pending) =
+***** NOTE: NEED TO SET REQUIRED MAIN PLUGIN TO NEXT NEW VERSION DUE TO ADDING SCRIPT REGISTRY ******
+* Now enqueueing most scripts and styles through new Script Registry.
+
 = 1.3.1 =
 * Update database to version 1.0.4
 * Added management flags for showing and requiring Organization and Title attendee fields.
diff --git a/setup/registerAdminScriptStyle.php b/setup/registerAdminScriptStyle.php
new file mode 100644 (file)
index 0000000..26ee514
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+/**
+ * registerAdminScriptStyle.php
+ *
+ * PHP version 5.2
+ *
+ * @category  Setup
+ * @package   Script and Style Registration
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @copyright 2019 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: $Id$
+ * @link      <>
+ */
+
+/**
+ * This file registers scripts and styles with the glmScriptRegistry.
+ *
+ * Scripts and Styles are added to the registry to ensure consistancy and avoid duplication.
+ * This process only lists them in the registry. A further step of calling the enqueue()
+ * method in the running model is required to have the needed scripts and styles passed
+ * to WordPress to have them enqueued. The expection to that is when including an "enqueue"
+ * parameter below that indicates that the scirpt should always be enqueued.
+ *
+ * The parameters below are what can be included. For more information on these parameters see
+ * classes/sciptRegistry.php in the main plugin. When these are loaded a check will be made to
+ * make sure there's no duplicate 'handle' or 'src' strings. The exception for 'handle' is that
+ * it may be the same for a matching script and style (the plugin slug and type prefix the
+ * 'handle' provided below to make them actually unique).
+ *
+ * int     type      Required type enumerated (see glmScriptType above)
+ * string  handle    Required handle (name) for this script (no spaces or punctuation)
+ *                      Handles must be unique for a particular type
+ *                      A matching script and style may have the same handle
+ * string  src       Required source URL of script
+ * array   deps      Optional array of handles for scripts this script depends on
+ * boolean in_footer Optional flag for enqueue before </body> tag
+ * string  media     Optional media types for styles (i.e. 'all', 'print', 'screen'...)
+ * array   attrs     Optional tag attribute name/value pairs to be included in tag
+ * string  plugin    Required plugin slug
+ * string  version   Required plugin version for cache-busting
+ * boolean enqueue   Optional flag, if true always enqueue this
+ *
+ * Please identify the file in the comment area using the URL or application.
+ *
+ * NOTE: The $config array is available in the context of this file. You need to refer
+ * to a config item in a way similar to this...
+ *
+ *  $config['settings']['google_maps_api_key']
+ *
+ * Example - Please add multi-line comment above each with script src for reference
+ *
+ *  glmScriptRegistry::add(
+ *      [
+ *          'type' => glmScriptType::Script,
+ *          'handle' => 'RegApp',
+ *          'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js',
+ *          'deps' => array(
+ *              'jquery',
+ *              'backbone',
+ *              'underscore'
+ *          ),
+ *          'in_footer' => true,
+ *          'attrs' => array(
+ *             'integrity' => 'sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q==',
+ *             'crossorigin' => ''
+ *          ),
+ *          'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+ *          'version' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION
+ *      ] );
+ *
+ * NOTE: DO NOT PLACE ANY SCRIPT OR STYLE FILE TAGS INTO VIEW. SELECT THEM IN THE MODEL
+ * USING THIS REGISTRY ONLY.
+ */
+
diff --git a/setup/registerFrontScriptStyle.php b/setup/registerFrontScriptStyle.php
new file mode 100644 (file)
index 0000000..b3189d9
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+/**
+ * registerFrontScriptStyle.php
+ *
+ * PHP version 5.2
+ *
+ * @category  Setup
+ * @package   Script and Style Registration
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @copyright 2019 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: $Id$
+ * @link      <>
+ */
+
+/**
+ * This file registers scripts and styles with the glmScriptRegistry.
+ *
+ * Scripts and Styles are added to the registry to ensure consistancy and avoid duplication.
+ * This process only lists them in the registry. A further step of calling the enqueue()
+ * method in the running model is required to have the needed scripts and styles passed
+ * to WordPress to have them enqueued. The expection to that is when including an "enqueue"
+ * parameter below that indicates that the scirpt should always be enqueued.
+ *
+ * The parameters below are what can be included. For more information on these parameters see
+ * classes/sciptRegistry.php in the main plugin. When these are loaded a check will be made to
+ * make sure there's no duplicate 'handle' or 'src' strings. The exception for 'handle' is that
+ * it may be the same for a matching script and style (the plugin slug and type prefix the
+ * 'handle' provided below to make them actually unique).
+ *
+ * int     type      Required type enumerated (see glmScriptType above)
+ * string  handle    Required handle (name) for this script (no spaces or punctuation)
+ *                      Handles must be unique for a particular type
+ *                      A matching script and style may have the same handle
+ * string  src       Required source URL of script
+ * array   deps      Optional array of handles for scripts this script depends on
+ * boolean in_footer Optional flag for enqueue before </body> tag
+ * string  media     Optional media types for styles (i.e. 'all', 'print', 'screen'...)
+ * array   attrs     Optional tag attribute name/value pairs to be included in tag
+ * string  plugin    Required plugin slug
+ * string  version   Required plugin version for cache-busting
+ * boolean enqueue   Optional flag, if true always enqueue this
+ *
+ * Please identify the file in the comment area using the URL or application.
+ *
+ * NOTE: The $config array is available in the context of this file. You need to refer
+ * to a config item in a way similar to this...
+ *
+ *  $config['settings']['google_maps_api_key']
+ *
+ * Example - Please add multi-line comment above each with script src for reference
+ *
+ *  glmScriptRegistry::add(
+ *      [
+ *          'type' => glmScriptType::Script,
+ *          'handle' => 'RegApp',
+ *          'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js',
+ *          'deps' => array(
+ *              'jquery',
+ *              'backbone',
+ *              'underscore'
+ *          ),
+ *          'in_footer' => true,
+ *          'attrs' => array(
+ *             'integrity' => 'sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q==',
+ *             'crossorigin' => ''
+ *          ),
+ *          'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+ *          'version' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION
+ *      ] );
+ *
+ * NOTE: DO NOT PLACE ANY SCRIPT OR STYLE FILE TAGS INTO VIEW. SELECT THEM IN THE MODEL
+ * USING THIS REGISTRY ONLY.
+ */
+
+/*
+ * {registrations}/js/frontRegApp.js
+ */
+glmScriptRegistry::add(
+    [
+        'type' => glmScriptType::Script,
+        'handle' => 'RegApp',
+        'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js',
+        'deps' => array(
+            'jquery',
+            'backbone',
+            'underscore'
+        ),
+        'in_footer' => true,
+        'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
+        'version' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_VERSION
+    ] );
index 8e54f41..3179a15 100755 (executable)
@@ -2,14 +2,7 @@
 {* Underscore Templates for the Event Registration App *}
 {* Template for Logged in Account *}
 
-{if $settings.selected_map_interface == 1}
-    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
-    <script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js" integrity="sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q==" crossorigin=""></script>
-    <link rel="stylesheet" href="{$jsUrl}/Leaflet.loading/src/Control.Loading.css" />
-    <script src="{$jsUrl}/Leaflet.loading/src/Control.Loading.js"></script>
-{/if}
 {if $settings.selected_map_interface == 2}
-    <script src="//maps.googleapis.com/maps/api/js?sensor=true&key={$settings.google_maps_api_key}"></script>
     <script type="text/javascript">var enableDraggable = true;</script>
 {/if}