Now capable of finding ajax models in all plugins
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 30 Mar 2016 16:57:01 +0000 (12:57 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 30 Mar 2016 16:57:01 +0000 (12:57 -0400)
controllers/admin.php
models/admin/ajax/pdfOutput.php [deleted file]
setup/validActions.php

index 9b5ba5c..6504bd4 100644 (file)
@@ -319,32 +319,41 @@ class glmMembersAdmin extends GlmPluginSupport
             trigger_error ( 'ERROR: No "glm_action" itme in POST array.', E_USER_ERROR);
         }
 
-        // Check for a valid action. This only looks in the main plugin. Might have to change this later.
-        if (!isset($this->config['addOns'][GLM_MEMBERS_PLUGIN_SLUG]['actions']['adminActions']['ajax'][$glmAction])) {
-            // Menu item/Action not in valid actions array
-            trigger_error ( 'ERROR: The specified action is not valid - '.$glmAction, E_USER_ERROR);
-        }
+        // Scan through the plugins to find the specified action
+        $actionFound = false;
+        foreach ($this->config['addOns'] as $a) {
 
-        // Build model and path and class names
-        $modelName = GLM_MEMBERS_PLUGIN_PATH . '/models/admin/ajax/'.$glmAction.'.php';
-        $className = 'GlmMembersAdmin_ajax_'.$glmAction;
+            // Check for a valid action in this plugin
+            if (isset($a['actions']['adminActions']['ajax'][$glmAction])) {
 
-        // If model file doesn't exist - we have an error
-        if (!file_exists($modelName)) {
-            trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR);
-        }
+                // Build model and path and class names
+                $modelName = $a['dir'].'/models/admin/ajax/'.$glmAction.'.php';
+                $className = 'GlmMembersAdmin_ajax_'.$glmAction;
 
-        // Load the model file
-        require_once ($modelName);
+                // If model file doesn't exist - we have an error
+                if (!file_exists($modelName)) {
+                    trigger_error ( "ERROR: The specified model file doesn't exist. ($modelName)", E_USER_ERROR);
+                }
+
+                // Load the model file
+                require_once ($modelName);
 
-        // check for an invalid model class name
-        if (!class_exists($className)) {
-            trigger_error ( "ERROR: The specified class naeme doesn't exist. ($className)", E_USER_ERROR);
+                // check for an invalid model class name
+                if (!class_exists($className)) {
+                    trigger_error ( "ERROR: The specified class naeme doesn't exist. ($className)", E_USER_ERROR);
+                }
+
+                // Instantiate the model and ask it to perform the work
+                $model = new $className($this->wpdb, $this->config);
+                $model->modelAction();
+
+            }
         }
 
-        // Instantiate the model and ask it to perform the work
-        $model = new $className($this->wpdb, $this->config);
-        $model->modelAction();
+        // Check if no matching action found
+        if (!$actionFound) {
+            trigger_error ( 'ERROR: The specified action is not valid - '.$glmAction, E_USER_ERROR);
+        }
 
         wp_die();
 
diff --git a/models/admin/ajax/pdfOutput.php b/models/admin/ajax/pdfOutput.php
deleted file mode 100644 (file)
index 95ac50c..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-
-/**
- * Gaslight Media Members Database
- * PDF Output by admin-ajax
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @license  http://www.gaslightmedia.com Gaslightmedia
- * @version  0.1
- */
-
-/*
- * Steve Note...
- *
- * You can get to this using the following URL.
- *
- *  {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=pdfOutput&mystuff=THIS
- *
- * You should be able to do this as POST or GET and should be able to add and read additional parameters.
- * I added a "mystuff" parameter to the URL above and it does output from the code in the
- * modelAction() function below.
- *
- * To add another model under models/admin/ajax all you need to do is create it and add it to the
- * setup/validActions.php file.
- *
- */
-
-// Load Members data abstract
-// require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php');
-
-/*
- * This class performs the work of handling images passed to it via
- * an AJAX call that goes through the WorPress AJAX Handler.
- *
- */
-class GlmMembersAdmin_ajax_pdfOutput // extends GlmDataImages
-{
-
-    /**
-     * WordPress Database Object
-     *
-     * @var $wpdb
-     * @access public
-     */
-    public $wpdb;
-    /**
-     * Plugin Configuration Data
-     *
-     * @var $config
-     * @access public
-     */
-    public $config;
-
-    /*
-     * 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;
-
-        // Run constructor for members data class
-//        parent::__construct(false, false);
-
-    }
-
-    /*
-     * Perform Model Action
-     *
-     * This modelAction takes an AJAX image upload and stores the image in the
-     * media/images directory of the plugin.
-     *
-     * This model action does not return, it simply does it's work then calls die();
-     *
-     * @param $actionData
-     *
-     * Echos JSON string as response and does not return
-     */
-    public function modelAction ($actionData = false)
-    {
-        echo "Stuff = ".$_REQUEST['mystuff']."<br>";
-        die();
-    }
-
-
-}
index 8a3d354..f3b9208 100644 (file)
@@ -33,8 +33,7 @@
 $glmMembersValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-                'imageUpload' => 'glm-member-db',
-                'pdfOutput' => 'glm-member-db'
+                'imageUpload' => 'glm-member-db'
         ),
         'dashboardWidget' => array(
                 'index' => 'glm-member-db'