Skip to content

Instantly share code, notes, and snippets.

View rxnlabs's full-sized avatar

De'Yonte W. rxnlabs

View GitHub Profile
@rxnlabs
rxnlabs / git-check-changed-files
Created February 14, 2015 20:09
Git - figure out if any files have changed on the production/live server. Great for figuring out which files to download to your local environment
#http://stevegrunwell.github.io/wordpress-git/#/20
git ls-files -dmo --exclude-standard
@rxnlabs
rxnlabs / php-mysql-add-insert-multiple-rows-single-query.php
Last active September 19, 2022 18:49
PHP - Insert multiple rows into MySQL table using a single query statement. Example based on code from https://phpacademy.org/topics/how-to-insert-multiple-rows-in-mysql-in-one-query-using-pdo-from-a-form/34096
<?php
// https://phpacademy.org/topics/how-to-insert-multiple-rows-in-mysql-in-one-query-using-pdo-from-a-form/34096
function placeholder( $text, $count = 0, $separator = ',' ) {
$result = array();
if ($count > 0) {
for ($x = 0; $x < $count; $x++) {
$result[] = $text;
}
}
@rxnlabs
rxnlabs / mac-create-add-environment-variable
Last active August 29, 2015 14:13
Mac - set an environment variable. Set an environment variable using Mac
#set an environment variable for closure compiler
export CLOSURE_PATH=/usr/local/opt/closure-compiler/libexec
source ~/.bash_profile
@rxnlabs
rxnlabs / php-wp-swiftype-bulk-delete-add.php
Created December 17, 2014 14:25
PHP WP - Verify that all FAQs are in Swiftype and add all FAQs to Swiftype
<?php
// change the DB_HOST constant to the localhost IP address so it works on a Mac. "Localhost" means something different in a Mac environment
define('DB_HOST','127.0.0.1');
// load the wp-load.php file to use WordPress functions. File path is assumming this is being run from the current theme folder (any theme folder would work)
require 'wp-load.php';
require 'wp-admin/includes/plugin.php';
// check if PHP is being executed from the command line
if( php_sapi_name() === 'cli' && defined('SWIFTYPE_AUTH_TOKEN') ){
@rxnlabs
rxnlabs / php-wordpress-autoload-template-code.php
Created November 7, 2014 14:43
PHP - autoload extra code based on the WordPress template being used. Useful when separating your template functionality into multiple files.
<?php
add_filter( 'template_include', array( $this, 'template_additional_code') );
/**
* Load page specific code for each template.
*
* Load additional code on a per template basis. Code in files are only useful for the particular template.
*
* @author De'Yonte W.<https://github.com/rxnlabs>
@rxnlabs
rxnlabs / js-call-javascript-function-by-string.js
Last active August 11, 2020 16:16
JS - Call and execute javascript functions by names by passing the function name as a string. Use case: Pass an event to ALL Google analytics properties on a page.
//http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string
// http://www.sitepoint.com/call-javascript-function-string-without-using-eval/
function executeFunctionByName(functionName, context, args) {
var args = [].slice.call(arguments).splice(2);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func].apply(this, args);
@rxnlabs
rxnlabs / git-clone-submodule-to-path-track-branch
Last active June 23, 2016 16:13
Git - resetting changed submodules, updating submodules to the latest commit from the master branch. Easy way to work with Git submodules after changing files or when something goes wrong with trying to update submodules.
git submodule add -b master link_to_git_repo_here_ssh_or_https path_to_clone_git_submodule_to_here
@rxnlabs
rxnlabs / php-move-element-to-beggining-of-array.php
Last active August 29, 2015 14:07
PHP - Move element to beginning of array. Shift an array's element position
<?php
/**
* Move array element by index. Only works with zero-based,
* contiguously-indexed arrays
*
* @param array $array
* @param integer $from Use NULL when you want to move the last element
* @param integer $to New index for moved element. Use NULL to push
*
* @throws Exception
@rxnlabs
rxnlabs / php-get-first-value-serailized-multidimensional-array.php
Last active August 29, 2015 14:06
PHP - Get the first value from a multidimensional array where the first value may be a serialized array.
<?php
/**
Get first value from multidimensional serialized array
*/
function get_value_from_multidimensional_array( $possible_array ){
if( is_array($possible_array) ){
$maybe_serialized = @unserialize($possible_array[0]);
if( $maybe_serialized !== false ){
$possible_array[0] = $maybe_serialized;
@rxnlabs
rxnlabs / wordpress-php-upgrade-database-command-line
Created September 8, 2014 17:55
WP - PHP upgrade WordPress database from the command line. Useful if upgrading a large database or upgrading multiple sites and you don't want to visit each sites dashboard.
#initialize PHP interactive shell
php -a
require 'wp-load.php';ini_set('memory_limit',-1);require 'wp-admin/includes/admin.php';require 'wp-admin/includes/upgrade.php';wp_upgrade();