Add filter for moderated checks
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 27 Feb 2017 19:33:41 +0000 (14:33 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 27 Feb 2017 19:33:41 +0000 (14:33 -0500)
Adding filter to tell if the member is moderated and also call the
contact filter to see if the contact is moderated.

classes/glmPluginSupport.php
setup/adminHooks.php

index 01a6138..873022f 100644 (file)
@@ -571,3 +571,30 @@ function glmMembersFilterPhone( $config, $phone )
 
     return $filteredNumber;
 }
+/**
+ * glmIsMemberModerated
+ *
+ * Checks the Member Record to see if changes should be moderated.
+ *
+ * @param mixed $config   Config Array
+ * @param mixed $wpdb     Word Press DB Object
+ * @param mixed $memberID Members Id
+ *
+ * @access public
+ * @return boolean
+ */
+function glmIsMemberModerated( $config, $wpdb, $memberID )
+{
+    // Check the members access. If it is moderated then return true.
+    $access = $wpdb->get_var(
+        $wpdb->prepare(
+            "SELECT access FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members WHERE id = %d",
+            $memberID
+        )
+    );
+    if ( $access && !in_array( $access, array( $config['access_numb']['Full'], $config['access_numb']['NotDisplayedNotModerated'] ) ) ) {
+        return true;
+    } else {
+        return false;
+    }
+}
index 85dbbaf..c8d1bb6 100644 (file)
@@ -266,3 +266,18 @@ add_filter('glm_associate_phone_filter', function( $phone ){
     return glmMembersFilterPhone( $this->config, $phone );
 });
 
+add_filter( 'glm_user_is_moderated', function( $memberID ){
+    // check to see if the contact is moderated first.
+    $contactIsModerated = apply_filters( 'glm_contact_is_moderated', $this->config['loggedInUser'] );
+    if ( $contactIsModerated ) {
+        return true;
+    }
+    // check to see if the Member is moderated.
+    if ( glmIsMemberModerated( $this->config, $this->wpdb, $memberID ) ) {
+        return true;
+    } else {
+        // if you reach here then not moderated
+        return false;
+    }
+} );
+