From: Steve Sutton Date: Wed, 22 Feb 2017 16:39:11 +0000 (-0500) Subject: Updating the phone filter. X-Git-Tag: v2.9.7^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=33c015355153ba3451a263d1bd94d675d6133644;p=WP-Plugins%2Fglm-member-db.git Updating the phone filter. 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. --- diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 03f2b44e..01a6138e 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -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; +} diff --git a/index.php b/index.php index 55c71aaf..206f68c6 100644 --- 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 * @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 diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 040bc11c..85dbbaf8 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 ); +}); diff --git a/setup/frontHooks.php b/setup/frontHooks.php index dc44c007..af79d651 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -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 ) {