Added more commentary and documentation to the adminHooks and commonHooks fiels
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 13 Dec 2017 14:33:53 +0000 (09:33 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 13 Dec 2017 14:33:53 +0000 (09:33 -0500)
setup/adminHooks.php
setup/commonHooks.php

index ca1e229..e4ba99d 100644 (file)
@@ -61,159 +61,3 @@ add_filter( 'glm-members-customfields-edit', function( $content, $fid ){
 
 
 
-
-
-
-/**
- * Filter Captured Data Success Status
- *
- * Returns Stored Data
- */
-add_filter( 'glm-members-customfields-capture', function( $content, $uid, $id ){
-
-}, 10, 3 );
-
-/**
- * Filter to Return Stored Data
- */
-add_filter( 'glm-members-customfields-data', function( $content, $uid, $id ){
-
-}, 10, 3 );
-
-/**
- * Filter to Return a tab link for multi-page sub-tabs.
- */
-add_filter( 'glm-member-db-customfields-nav', function( $content, $tableName ){
-    $out .= '<a id="glm-custom-fields" data-show-table="glm-table-custom-fields" class="glm-'.$tableName .'-tab nav-tab">Custom Fields</a>';
-    return $out;
-},10,2);
-
-/**
- *  ?????????
- */
-add_filter( 'glm-member-db-custom-fields-tab', function( $content, $entityID = '' ){
-    unset( $_REQUEST['glm_action'] );
-    $content = $this->controller( 'fields', 'fields', $entityID );
-    return $content;
-},1,2);
-
-/**
- * Admin member list filter for displaying filters for the custom fields
- */
-add_filter( 'glm-member-db-custom-filter-search', function ( $content ) {
-$parts = array();
-    $customFields = $this->wpdb->get_results(
-        "SELECT *
-           FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX .  "custom_fields
-          WHERE admin_search = 1",
-        ARRAY_A
-    );
-    if ( isset( $customFields ) && count( $customFields ) > 0 ) {
-        foreach ( $customFields as $key => $field ) {
-            switch ( $field['field_type'] ) {
-            case 'textarea':
-                break;
-            case 'text':
-                // convert name to lower case and replace spaces with _
-                $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
-                $parts[$field['id']] = '<b>' . $field['field_name'] . ':</b> <input type="text" size="10" name="' . $field_name . '"';
-                if ( isset( $_REQUEST[$field_name] ) && $fieldValue = filter_var( $_REQUEST[$field_name], FILTER_SANITIZE_STRING ) ) {
-                    $parts[$field['id']] .= ' value="' . $fieldValue . '"';
-                }
-                $parts[$field['id']] .= '></b>';
-
-                break;
-            case 'checkbox':
-                // convert name to lower case and replace spaces with _
-                $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
-                $parts[$field['id']] = '<b>' . $field['field_name'] . ':</b> <input type="checkbox" name="' . $field_name . '" value="1"';
-                if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_VALIDATE_BOOLEAN ) ) {
-                    $parts[$field['id']] .= ' checked';
-                }
-                $parts[$field['id']] .= '></b>';
-                break;
-            }
-        }
-    }
-    return implode( ' ', $parts );
-});
-
-/**
- * Front End Query Hook for searching member by custom fields
- */
-add_filter('glm-member-db-admin-search-query', function() {
-    $queryParts = array();
-    // Get all custom fields
-    $customFields = $this->wpdb->get_results(
-        "SELECT *
-           FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX .  "custom_fields
-          WHERE admin_search = 1",
-        ARRAY_A
-    );
-    if ( isset( $customFields ) && count( $customFields ) > 0 ) {
-        foreach ( $customFields as $key => $field ) {
-            switch ( $field['field_type'] ) {
-            case 'textarea':
-                break;
-            case 'text':
-                // convert name to lower case and replace spaces with _
-                $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
-                if ( isset( $_REQUEST[$field_name] ) && $fieldValue = filter_var( $_REQUEST[$field_name], FILTER_SANITIZE_STRING ) ) {
-                    $queryParts[] = " T.id IN (
-                        SELECT mi.member
-                          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info mi, " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data cfd
-                         WHERE cfd.entity_id = mi.id
-                           AND cfd.field_data like '%" .  esc_sql( $fieldValue ) . "%'
-                           AND cfd.field_id = (SELECT id
-                                           FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
-                                          WHERE field_name = '" . esc_sql( $field['field_name'] ) . "'))";
-                }
-
-                break;
-            case 'checkbox':
-                // convert name to lower case and replace spaces with _
-                $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
-                if ( isset( $_REQUEST[$field_name] ) && filter_var( $_REQUEST[$field_name], FILTER_VALIDATE_BOOLEAN ) ) {
-                    $queryParts[] = " T.id IN (
-                        SELECT mi.member
-                          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info mi, " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_field_data cfd
-                         WHERE cfd.entity_id = mi.id
-                           AND cfd.field_data = 'Yes'
-                           AND cfd.field_id = (SELECT id
-                                           FROM " . GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX . "custom_fields
-                                          WHERE field_name = '" . esc_sql( $field['field_name'] ) . "'))";
-                }
-                break;
-            }
-        }
-    }
-    return $queryParts;
-});
-
-/**
- * ????????
- */
-add_filter('glm-member-db-save-custom-fields', function( $entityID) {
-    require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
-    // this will save the member data
-    //echo "uid = $uid";
-    return customFieldsSaveFields( $entityID);
-
-    },
-    10,
-    1
-);
-
-/**
- * ????????
- */
-add_action(
-    'glm-member-db-clone-custom-fields',
-    function( $entityID, $newId ){
-        require_once GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
-        // this will clone the custom fields data
-        customFieldsCloneFields( $entityID, $newId );
-    },
-    1,
-    2
-);
index 72ce77a..593c1d8 100644 (file)
  *  Also note that parameters will be in the context of the main admin controller constructor.
   */
 
+/*
+ * Overview
+ *
+ * This add-on is used to create, display, edit, submit, store, and recall data for custom fields.
+ * It provides hooks through which other add-ons can implement additional custom fields with minimal
+ * work.
+ *
+ * A group of fields that constitute a custom form segment are identified by a form ID (FID). This
+ * FID needs to be unique for each such group of fields. The current standard is for it to include
+ * some identification of the add-on/plugin that's calling it, the purpose of the form, and an
+ * integer that used to uniquely identify the form if it's created by an entity that is one member
+ * of a list of such entities. For example...
+ *
+ *      glm_reg_customfields_reg_event_{some registration event ID}
+ *
+ * In some cases it may be helpful to add an additional number to the end of the FID. In this
+ * example, there maybe multiple registration levels for the event, each of those levels may have
+ * their own custom fields that need to be collected. By adding the level ID to the end, it's pretty
+ * clear what this FID is for.
+ *
+ * glm_reg_customfields_reg_event_{event id}_level_{level ID}
+ *
+ * Another integer is used when applying a FID to a partucular submission of data. This is the
+ * record ID (recordId) and it's used when storing submitted information for a single use of the
+ * FID. for example, when collecting data for each attendee of an event, each attendee would have
+ * a unique record id that is saved with the form data to identify that it's for that attendee.
+ *
+ * The information submitted data is stored and recalled using a combination of the form field ID
+ * (contained in the form field table) and the recordId. Becuase of this, the record ID only needs
+ * to be unique for use with a specific FID. The same recordId can also be used along with another
+ * FID to reference other data.
+ *
+ * These are the hooks provided in this file. Also look at the adminHooks.php file for the
+ * glm-members-customfields-edit hook used to create and edit groups of custom form fields.
+ *
+ * glm-members-customfields-active            Is the add-on installed and active
+ * glm-members-customfields-have-fields       Does a particular FID exist (has fields)
+ * glm-members-customfields-form-display      Display a particular form by FID
+ * glm-members-customfields-form-submit       Submit data for a particular FID and optionally store it
+ * glm-members-customfields-form-store        Store data returned from the "form-submit" hook above
+ *
+ */
+
+
+
 /**
  * Filter will return true if the plugin is active.
  */