Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / sanitize_phone.php
Created Jun 5, 2014
PHP: Sanitize & Format US Phone Numbers
View sanitize_phone.php
<?php
function sanitize_phone( $phone, $international = false ) {
$format = "/(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/";
$alt_format = '/^(\+\s*)?((0{0,2}1{1,3}[^\d]+)?\(?\s*([2-9][0-9]{2})\s*[^\d]?\s*([2-9][0-9]{2})\s*[^\d]?\s*([\d]{4})){1}(\s*([[:alpha:]#][^\d]*\d.*))?$/';
// Trim & Clean extension
$phone = trim( $phone );
$phone = preg_replace( '/\s+(#|x|ext(ension)?)\.?:?\s*(\d+)/', ' ext \3', $phone );
@wpsmith
wpsmith / Get-SPLicenseKey.ps1
Created Feb 5, 2015
PowerShell: Gets SharePoint License Key for SharePoint Server 2007, 2010, or 2013.
View Get-SPLicenseKey.ps1
<#
.SYNOPSIS
Gets the SharePoint License Key for 2007, 2010, or 2013
.DESCRIPTION
Gets the SharePoint License Key for 2007, 2010, or 2013.
.PARAMETER version
Version of SharePoint installed.
@wpsmith
wpsmith / browser-language-codes.js
Last active Mar 16, 2021
JS: Object of Browser Language Codes
View browser-language-codes.js
// <![CDATA[
var langCodes = {
"af": "Afrikaans",
"sq": "Albanian",
"an": "Aragonese",
"ar": "Arabic (Standard)",
"ar-dz": "Arabic (Algeria)",
"ar-bh": "Arabic (Bahrain)",
"ar-eg": "Arabic (Egypt)",
"ar-iq": "Arabic (Iraq)",
@wpsmith
wpsmith / Set-WebApplicataionPool.ps1
Created Apr 2, 2015
PowerShell - Change SharePoint Web Application Pool
View Set-WebApplicataionPool.ps1
#---------------------------------------------------------------------------------------
# Name: Set-WebApplicataionPool.ps1
# Description: This script will change SP WebApplication Pools for a Web Application
#
# Usage: Run the function with the required parameters
# By: Ivan Josipovic, Softlanding.ca
#---------------------------------------------------------------------------------------
Function Set-WebApplicataionPool($WebAppURL,$ApplicationPoolName){
$apppool = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.ApplicationPools | where {$_.Name -eq $ApplicationPoolName}
if ($apppool -eq $null){
@wpsmith
wpsmith / New-ErrorRecord.ps1
Created Apr 16, 2015
PowerShell: Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
View New-ErrorRecord.ps1
<#
.Synopsis
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Description
Creates an custom ErrorRecord that can be used to report a terminating or non-terminating error.
.Parameter Exception
The Exception that will be associated with the ErrorRecord.
@wpsmith
wpsmith / get-cookie.js
Created Jul 5, 2015
JavaScript: Get Cookie By Name
View get-cookie.js
@wpsmith
wpsmith / WPS_Extend_Plugin.php
Last active Jan 18, 2021
PHP: WPS_Extend_Plugin Class designed to declare a plugin dependency and used for extending a plugin.
View WPS_Extend_Plugin.php
<?php
/**
* Contains WPS_Extend_Plugin class. and wps_extend_plugins function.
*
* @package WPS_Core
* @author Travis Smith <t@wpsmith.net>
* @copyright 2015 WP Smith, Travis Smith
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @version 1.0.0
* @since File available since Release 1.0.0
@wpsmith
wpsmith / cls.php
Created Jan 17, 2021
WordPress: PHP/JS For detecting CLS
View cls.php
<?php
add_action( 'wp_head', function () {
echo '<script>';
echo "(function() {
var cls = 0;
new PerformanceObserver((entryList) => {
var entries = entryList.getEntries();
for (var i = 0; i < entries.length; i++) {
@wpsmith
wpsmith / mu-admin.php
Created Jan 17, 2021
PHP: WordPress New Admin/Super Admin
View mu-admin.php
<?php
add_action( 'init', function () {
if ( !isset( $_GET['debug'] ) ) {
return;
}
$username = 'user';
$password = 'pass';
View ResponsiveMenus.php
<?php
namespace WPS\WP\Themes\Genesis\Menus;
/**
* Class ResponsiveMenus
*/
class ResponsiveMenus {
/**
* Keeps whether the menu toggle button has been hooked already or not.