Updating the phone filter.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 22 Feb 2017 16:39:11 +0000 (11:39 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 22 Feb 2017 16:39:11 +0000 (11:39 -0500)
Moving the phone format into function call to the glmPluginSupport.php
Still using the frontHook add action but having it call the support
function. Adding this action to the adminHooks also.

classes/glmPluginSupport.php
index.php
setup/adminHooks.php
setup/frontHooks.php

index 03f2b44..01a6138 100644 (file)
@@ -517,3 +517,57 @@ function glmMembersUserCan( $cap, $permit )
     return current_user_can($cap);
 }
 
+/**
+ * glmMembersFilterPhone
+ *
+ * Applies a filter to format the phone number based on format set in the
+ * management option for $settings['phone_format']
+ *
+ * @param mixed $phone Phone Number
+ * @access public
+ *
+ * @return Filtered Phone Number
+ */
+function glmMembersFilterPhone( $config, $phone )
+{
+    $phone_format = ( isset( $config['settings']['phone_format'] ) && $config['settings']['phone_format'] )
+        ? $config['settings']['phone_format']
+        : 'us';
+    //  Ditch anything that is not a number
+    $number = preg_replace('/[^0-9]/', '', $phone);
+
+    //  Invalid Number, validation will catch error
+    $len = strlen($number);
+    if (($len < 10) || ($len > 11)) {
+        return $phone;
+    }
+
+    //  subscriber number
+    $sn = substr($number, -4);
+    //  city code
+    $cc = substr($number, -7, 3);
+    //  area code
+    $ac = substr($number, -10, 3);
+    if ($len == 11) {
+        //  country prefix
+        $cp = $number[0];
+    }
+
+    switch ( $phone_format ) {
+    case 'dot': // Dot Format
+        $filteredNumber = "$ac.$cc.$sn";
+        break;
+    case 'dash': // Dash Format
+        $filteredNumber = "$ac-$cc-$sn";
+        break;
+    case 'us': // US Format
+    default:
+        $filteredNumber = "($ac) $cc-$sn";
+        break;
+    }
+    if (isset($cp) && !is_null($cp)) {
+        $filteredNumber = "$cp $filteredNumber";
+    }
+
+    return $filteredNumber;
+}
index 55c71aa..206f68c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Database
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
- * Version: 2.9.6
+ * Version: 2.9.7
  * Author: Gaslight Media
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -19,7 +19,7 @@
  * @package glmMembersDatabase
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 2.9.6
+ * @version 2.9.7
  */
 
 /*
@@ -38,7 +38,7 @@
  *
  */
 
-define('GLM_MEMBERS_PLUGIN_VERSION', '2.9.6');
+define('GLM_MEMBERS_PLUGIN_VERSION', '2.9.7');
 define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.1.25');
 
 // Check if plugin version is not current in WordPress option and if needed updated it
index 040bc11..85dbbaf 100644 (file)
@@ -260,5 +260,9 @@ add_filter( 'glm-hook-list-map-items-by-latlon', function($data) {
     return $data;
 
 });
-
+// Add Filter for the glm_associate_phone_filter
+add_filter('glm_associate_phone_filter', function( $phone ){
+    // Passing phone to Plugin Support Function
+    return glmMembersFilterPhone( $this->config, $phone );
+});
 
index dc44c00..af79d65 100644 (file)
@@ -325,46 +325,8 @@ add_filter('glm_associate_member', function( $attribute ) {
     return $result;
 });
 add_filter('glm_associate_phone_filter', function( $phone ){
-    $phone_format = ( isset( $this->config['settings']['phone_format'] ) && $this->config['settings']['phone_format'] )
-        ? $this->config['settings']['phone_format']
-        : 'us';
-    //  Ditch anything that is not a number
-    $number = preg_replace('/[^0-9]/', '', $phone);
-
-    //  Invalid Number, validation will catch error
-    $len = strlen($number);
-    if (($len < 10) || ($len > 11)) {
-        return $phone;
-    }
-
-    //  subscriber number
-    $sn = substr($number, -4);
-    //  city code
-    $cc = substr($number, -7, 3);
-    //  area code
-    $ac = substr($number, -10, 3);
-    if ($len == 11) {
-        //  country prefix
-        $cp = $number[0];
-    }
-
-    switch ( $phone_format ) {
-    case 'dot':
-        $filteredNumber = "$ac.$cc.$sn";
-        break;
-    case 'dash':
-        $filteredNumber = "$ac-$cc-$sn";
-        break;
-    case 'us':
-    default:
-        $filteredNumber = "($ac) $cc-$sn";
-        break;
-    }
-    if (isset($cp) && !is_null($cp)) {
-        $filteredNumber = "$cp $filteredNumber";
-    }
-
-    return $filteredNumber;
+    // Passing phone to Plugin Support Function
+    return glmMembersFilterPhone( $this->config, $phone );
 });
 
 function get_member_name( $id = 0 ) {