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-wp-change-template-page.php
Last active August 29, 2015 14:06
WP - PHP WordPress chage page template at run time
<?php
add_filter( 'template_include', 'my_callback' );
function my_callback( $original_template ) {
if ( some_condition() ) {
return SOME_PATH . '/some-custom-file.php';
} else {
return $original_template;
}
@rxnlabs
rxnlabs / command-line-zip-folder-cli
Last active October 23, 2017 12:33
Command Line - Zip folder and all files (gzip, bz2)
tar -cvzf filename.tar.gz folder
tar -cvjf filename.tar.bz2 folder # even more compression
@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 / sublime-text-example-project-file-1920.json
Last active August 29, 2015 14:04
Sublime Text - SublimeText 3 example project file. One I personally use
{
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
"settings":
{
@rxnlabs
rxnlabs / xampp-enable-ssl
Created July 30, 2014 14:13
XAMPP - enable ssl on Mac
sudo ./Applications/XAMPP/xamppfiles/xampp enablessl
@rxnlabs
rxnlabs / regex-select-between-parentheses
Created July 25, 2014 12:40
Regex - Select characters between two parentheses. PHP based
// http://www.regexr.com/397dr
/\((.*?)\)/s
@rxnlabs
rxnlabs / css-center-align-menu.css
Last active October 23, 2017 12:32
CSS - Center align navigation menu. Navigation menu for navs whose elements are center align in their container. File for CSS and SCSS
/*******************************TOP NAVIGATION MENU*************************************/
div.navigation {
margin-bottom:30px;
border:0 solid #E7E7E7;
border-width:1px 0
}
/* Main menu settings */
nav#main {
clear:both;
@rxnlabs
rxnlabs / wp-add-admin-user-mysql.sql
Last active May 21, 2020 14:55
WP - WordPress add new admin user to MySQL table using raw SQL queries. Use in case you don't have access to WordPress dashboard since you may not be a user yet.
# MariaDB is throwing an error when attempting to use variables. You will have to hardcode the database tables
SET @username = 'YOUR_USER_NAME';
SET @password = 'YOUR_PASSWORD';
SET @nicename = 'YOUR_NICENAME';
SET @email_address = 'YOUR_EMAIL_ADDRESS';
SET @fullname = 'YOUR_FULL_NAME';
SET @wpdb_prefix = 'wp_';
SET @wpdb_users_table = CONCAT(@wpdb_prefix,'', 'users');
SET @wpdb_usermeta_table = CONCAT(@wpdb_prefix,'', 'usermeta');
@rxnlabs
rxnlabs / php-find-replace-string-cli.php
Last active July 5, 2024 16:31
PHP - find and replace string from MySQL database. Look in all tables and replace text, even in serialized strings. Best to use from the PHP CLI (Command Line Interface) when working with large databases.
<?php
ini_set('memory_limit','3200M');
// This script is to solve the problem of doing database search and replace
// when developers have only gone and used the non-relational concept of
// serializing PHP arrays into single database columns. It will search for all
// matching data on the database and change it, even if it's within a serialized
// PHP array.
// The big problem with serialised arrays is that if you do a normal DB
// style search and replace the lengths get mucked up. This search deals with
@rxnlabs
rxnlabs / php-curl-get-headers.php
Last active August 29, 2015 14:04
PHP - get headers from cURL request
<?php
function get_headers_curl($response){
$headers = array();
$header_text = substr($response, 0, strpos($response, "\r\n\r\n"));
foreach (explode("\r\n", $header_text) as $i => $line){
if ($i === 0)
$headers['http_code'] = $line;