Skip to content

Instantly share code, notes, and snippets.

View theandystratton's full-sized avatar

Andy Stratton theandystratton

View GitHub Profile
@theandystratton
theandystratton / wpdb-remove-like-placeholders.php
Created April 24, 2019 18:14
Remove $wpdb LIKE placeholders/tokens!
<?php
// Sample code for reference
global $wpdb;
$year = (int) ( $_GET['year'] ?? date_i18n( 'Y' ) );
$sql = "SELECT * FROM transactions WHERE DATE( datetime_created ) LIKE %s";
$sql = $wpdb->prepare( $sql, $year . '-01-%' );
<?php
/*
Place in theme's functions.php or /wp-content/mu-plugins folder
Assumes:
- PHP 7
- WP 5.2
- Gravity Forms
- Edit this file for the appropriate invite code => gform_id relationships (lines 32-37)
- Edit this file for the appropriate invite code user meta key (line 41)
*/
location ~* ^/wp-content/.*\.(png|jpe?g)$ {
add_header Vary Accept;
if ($http_accept !~* "webp"){
break;
}
if ( !-f $request_filename ) {
return 404;
}
@theandystratton
theandystratton / git-checkout-revision.sh
Created June 7, 2019 15:00
git checkout revision for file
git checkout $revision-hash file-name.php
<?php
foreach ( [ 'Andy', 'Drew', 'Rob', 'Shane', 'Chris' ] as $name )
{
switch ( $name )
{
case 'Rob' :
case 'Drew' :
case 'Shane' :
// continue; // acts as break within switch(); needs arg "2"
continue 2;
<!-- Typical builds -->
<style>
.heading { color: blue; }
.list-red { color: red; }
p.intro { font-size: 1.2em; }
p.intro span { font-weight: bold;}
</style>
<section class="section section__prices">
mysqldump -u root -p --all-databases > alldb.sql
mysqldump -u root -p --opt --all-databases > alldb.sql
mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql
mysqldump -u root -p --all-databases --single-transaction --skip-lock-tables > all-your-db.sql
<?php
//
// Add the following code to your functions.php or
// save this file to your /wp-content/mu-plugins/ folder.
//
\add_filter( 'pr_message_content', function( $content ){
return \do_shortcode( $content );
});
UPDATE wp_options
SET option_value = 'https://dev.website.com'
WHERE option_name IN ( 'home', 'siteurl' );