Skip to content

Instantly share code, notes, and snippets.

View rxnlabs's full-sized avatar

De'Yonte W. rxnlabs

View GitHub Profile
@rxnlabs
rxnlabs / php-array-get-all-possibilities-associative.php
Last active July 22, 2019 10:38
PHP - Generate all possible combinations from multidimensional array
// http://www.devnetwork.net/viewtopic.php?f=1&t=133156
function array_cartesian_utm($arrays){
//returned array...
$cartesic = array();
//calculate expected size of cartesian array...
$size=(sizeof($arrays)>0)?1:0;
foreach($arrays as $array){
$size= $size*sizeof($array);
@rxnlabs
rxnlabs / facebook-detect-embed-link-regex.php
Created November 8, 2018 01:17
PHP - Detect if a link text contains Facebook embeddable content using regular Expressions
@rxnlabs
rxnlabs / wordpress-enable-jetpack-dev-mode.php
Created October 3, 2018 13:08
WordPress - Enable Jetpack development mode if WP_DEBUG is true and Jetpack is NOT connected to WordPress.com. Useful if you want to test out Jetpack modules without needing to be connected to WordPress.com or if doing development from a localhost site
<?php
/**
* Enable Jetpack development mode if WP_DEBUG is true and jetpack is not active/connected to WordPress.com
* See: https://jetpack.com/support/development-mode/
*/
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
if ( method_exists( '\\Jetpack', 'is_active' ) && is_callable( array( '\\Jetpack', 'is_active' ) ) ) {
$jetpack_reflection = new \ReflectionMethod( '\\Jetpack', 'is_active' );
@rxnlabs
rxnlabs / wordpress-get-paragraph-excerpt-end-of-sentence.php
Last active June 21, 2018 14:27
WordPress - WP Get the excerpt starting at the end of a sentence. Get an excerpt of a paragraph and show the "Read More" link after the end of a sentence. Can be modified to use in other PHP apps.
<?php
/**
* Get the excerpt of a paragraph or string of long text.
*
* Get the shortened version of text for the wyisiwig. Use with custom wysiwyg (e.g. Advanced Custom Fields). This will print the paragraph and breaks tag but will strip all other tags
*
* @since 2014-11-06
* @version 2016-03-09
* @author De'Yonte W.<rxnlabs@github.com>
@rxnlabs
rxnlabs / wordpress-get-widget-id-name.php
Last active May 30, 2018 12:41
WordPress - Get the name and id of the widget area being used to display a certain widget. This adds the widget ID and widget area name as HTML comments to the frontend of the site
<?php
/**
* Add the widget ID and widget name as HTML comments.
*
* Makes it easiser to identify exactly which widget area a widget is appearing in.
* This helps a lot with themes that have a lot of sidebars and uses a lot of widgets.
*/
function which_dynamic_sidebar( $sidebar_params ) {
$sidebar_params['0']['class'] = empty( $sidebar_params['0']['class'] )?$sidebar_params['0']['id']:$sidebar_params['0']['class'].' '.$sidebar_params['0']['id'];
$sidebar_params['0']['before_widget'] = '<!--Widget-Area:id:'.esc_attr($sidebar_params['0']['id']).';name:'.esc_attr($sidebar_params['0']['name']).'-->'.$sidebar_params['0']['before_widget'];
@rxnlabs
rxnlabs / regex
Created January 6, 2017 21:12
Regular Expression - Find comments in a file /* comments. Found here http://blog.ostermiller.org/find-comment
/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/
@rxnlabs
rxnlabs / wp-php-woocommerce-convert-new-post-type.php
Last active February 28, 2018 15:20
WP - PHP Convert/Update/Migrate WooCommerce data attributes to a new custom post type. Convert WooCommerce products to new custom post type. Should be used from the Command Line. This was used to convert a WooCommerce store to another post type when WooCommerce was no longer needed.
<?php
ini_set('memory_limit','1500M');
/**
* Update/Covert all WooCommerce Products data to a new post type
*
* Moving all WooCommerce custom data to a new custom post type. Should only be executed from CLI since it uses so many processes.
*
* @author De'Yonte W. <admin@rxnlabs.com>
* @return void
*/
@rxnlabs
rxnlabs / solution-1.php
Created July 16, 2015 15:47
Programming interview question
<?php
/*
Output a list of numbers multiple times depending on their value (e.g. output 9 nine times, or 18 eighteen times). Works well if it doesn't matter if you listall the numbers preceding the last number
*/
$array = array(1,2,3,4,5,6,7,8,9,12,18);
foreach ($array as $num) {
$string = '';
$count = 1 * $num;
for ($i=0;$i < $count; $i++) {
@rxnlabs
rxnlabs / additional-wordpress-columns-tables-updtae-after-moving.txt
Last active October 23, 2017 12:40
PHP + Bash - Move plugins from wordpress single install to composer.json file
# Change the upload path of the sites to make sure media files still work
SELECT * FROM wpdb_6_options WHERE option_name IN ('upload_path', 'upload_url_path');
@rxnlabs
rxnlabs / salsascript-storefront-get-items-in-stock.js
Created March 18, 2016 20:02
SalsaScript - Get stock of items in Salsa storefront using SalsaScript
<script type="text/javascript">
var storefront_items_stock = {};
<?
var storefront = DB.getObjects('store_item');
for each (item in storefront) {
print('storefront_items_stock[');
print( item.store_item_KEY );
print( '] = ' );
print( item.Number_in_Stock );
print( ';\n');