Skip to content

Instantly share code, notes, and snippets.

View coulterpeterson's full-sized avatar
🤓
Always learning

Coulter Peterson coulterpeterson

🤓
Always learning
View GitHub Profile
@coulterpeterson
coulterpeterson / functions.php
Created November 21, 2019 21:18
Increase #wordpress memory limit with functions.php #php
add_filter('upload_size_limit', 'mups_upload_max_increase_upload');
function mups_upload_max_increase_upload() {
// Only enter the numeric value in bytes (eg. 104857600)
// 1024 bytes = 1KB
// 1048576 bytes = 1MB
// (Formula: 1048576 * number of MB required = number of Bytes to enter in above form)
return '3145728000';
}
@coulterpeterson
coulterpeterson / snippet.php
Created November 21, 2019 23:01
#PHP only run on my IP address
<?php
if($_SERVER["REMOTE_ADDR"]=='111.111.111.111')
{
//run only my ip
}
?>
@coulterpeterson
coulterpeterson / functions.php
Created November 21, 2019 23:11
#WordPress Debugging Enable and Logging Function
// Source: https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-log
// Usage example: write_log('The variable value is: ' . $myVariable);
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
@coulterpeterson
coulterpeterson / snippet.sql
Last active October 24, 2023 20:32
Update domain in #mysql DB after #WordPress migration to new server
-- Shoutout to https://blog.templatetoaster.com/update-old-urls-in-database/
UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'Existing URL','New URL');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Existing URL','New URL');
UPDATE wp_links SET link_url = replace(link_url, 'Existing URL','New URL');
@coulterpeterson
coulterpeterson / controller.php
Last active November 22, 2019 00:18
#Laravel connect to SMTP using Flysystem #PHP
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Flysystem;
use League\Flysystem\Filesystem;
use League\Flysystem\Sftp\SftpAdapter;
class PagesController extends Controller
@coulterpeterson
coulterpeterson / .htaccess
Created November 23, 2019 00:17
#htaccess 301 redirects in a #wordpress multisite for a single subdomain
RewriteEngine On
RewriteBase /
# Test domain rewrite rules
RewriteCond %{HTTP_HOST} ^(www\.)?testdomain.ca [NC]
RewriteRule ^about-us/core-values$ partnership/ [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^(www\.)?testdomain.ca [NC]
RewriteRule ^about-us/core-values/$ partnership/ [R=301,NC,L]
@coulterpeterson
coulterpeterson / functions.php
Last active August 20, 2020 18:00
Enqueue Scripts and Files in #WordPress #PHP
function add_theme_scripts() {
clearstatcache();
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), filemtime( get_template_directory() . '/css/slider.css'), 'all');
wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), filemtime( get_template_directory() . '/js/script.js'), true);
}
@coulterpeterson
coulterpeterson / functions.php
Last active November 26, 2019 20:22
Get single #blog post by custom meta value and pull lots of #post data #WordPress #PHP
$featuredPostOneArgs = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'homepage_featured_article_1',
'value' => '1',
'compare' => '=='
)
)
@coulterpeterson
coulterpeterson / snippet.php
Created December 4, 2019 20:29
Write to and read from quick #json data store with #PHP
/*
* Takes in a new element to be saved, grabs the data array, appends to it, and re-saves it
*/
function saveData( $dataItem ) {
$dataArray = summonData();
array_push($dataArray, $dataItem);
file_put_contents('./records.json', json_encode($dataArray)); // Overwrites the JSON file
chmod('./records.json', 0664);
}
@coulterpeterson
coulterpeterson / snippet.php
Created December 4, 2019 21:11
Dump variable contents to file and chmod it with #PHP
function writeLog($item){
ob_flush();
ob_start();
var_dump($item);
file_put_contents('debuglog.txt', ob_get_flush());
chmod('debuglog.txt', 0664);
}