Move the add_filter for employees into commonHooks.php
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 29 Mar 2018 14:40:49 +0000 (10:40 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 29 Mar 2018 14:40:49 +0000 (10:40 -0400)
This allows access to this hook on the front end.

setup/adminHooks.php
setup/commonHooks.php [new file with mode: 0644]

index fb75a5f..7c43eed 100644 (file)
@@ -127,42 +127,4 @@ add_filter( 'glm_contact_is_moderated', function( $user ) {
     }
 } );
 
-/**
- * Filter to get the user meta for a contact.
- */
-add_filter( 'glm_contact_has_employees', function( $content, $member_id ){
-    global $wpdb;
-    if ( isset( $member_id ) && !$member_id ) {
-        return $content;
-    }
-    // First will have to see if this member a member contact.
-    $contact = $wpdb->get_row(
-        $wpdb->prepare(
-            "SELECT id,email,username
-               FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
-              WHERE ref_dest = %d
-                AND primary_contact",
-            $member_id
-        ),
-        ARRAY_A
-    );
-    if ( !$contact ) {
-        return $content;
-    }
-    // Get the members wordpress user.
-    if ( $contact['email'] ) {
-        $wp_user = get_user_by( 'email', $contact['email'] );
-    } else if ( $contact['username'] ) {
-        $wp_user = get_user_by( 'login', $contact['username'] );
-    }
-    $employees = array();
-    // Get the users meta data.
-    $user_meta = get_user_meta( $wp_user->ID, 'glmMembersContactMembers', true );
-    if ( $user_meta ) {
-        $employees = explode( ',', $user_meta );
-        // Remove the $member_id from this array if it's in there.
-        $employees = array_filter( $employees, function( $input ) use( $member_id ) { return $input != $member_id; } );
-    }
-    return $employees;
-}, 10, 2 );
 ?>
diff --git a/setup/commonHooks.php b/setup/commonHooks.php
new file mode 100644 (file)
index 0000000..2907290
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Misc Admin Hooks and Filters
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+/*
+ * Place Misc Hooks and Filters here. If this file exists, it will be included
+ * by the add-on main plugin script.
+ *
+ * Note that filter and hook callback functions must be included in-line as shown below...
+ *
+ *  add_filter( 'filter_title', function( $parameter ) {
+ *     // Function code
+ *  });
+ *
+ *  Also note that parameters will be in the context of the main admin controller constructor.
+  */
+
+/**
+ * Filter to get the user meta for a contact.
+ */
+add_filter( 'glm_contact_has_employees', function( $content, $member_id ){
+    global $wpdb;
+    if ( isset( $member_id ) && !$member_id ) {
+        return $content;
+    }
+    // First will have to see if this member a member contact.
+    $contact = $wpdb->get_row(
+        $wpdb->prepare(
+            "SELECT id,email,username
+               FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+              WHERE ref_dest = %d
+                AND primary_contact",
+            $member_id
+        ),
+        ARRAY_A
+    );
+    if ( !$contact ) {
+        return $content;
+    }
+    // Get the members wordpress user.
+    if ( $contact['email'] ) {
+        $wp_user = get_user_by( 'email', $contact['email'] );
+    } else if ( $contact['username'] ) {
+        $wp_user = get_user_by( 'login', $contact['username'] );
+    }
+    $employees = array();
+    // Get the users meta data.
+    $user_meta = get_user_meta( $wp_user->ID, 'glmMembersContactMembers', true );
+    if ( $user_meta ) {
+        $employees = explode( ',', $user_meta );
+        // Remove the $member_id from this array if it's in there.
+        $employees = array_filter( $employees, function( $input ) use( $member_id ) { return $input != $member_id; } );
+    }
+    return $employees;
+}, 10, 2 );
+?>