Skip to content

Instantly share code, notes, and snippets.

View sebastianmoran-mainwp's full-sized avatar
🚀
Fast Lane Strategies: Turbocharging Your WordPress Website for Optimal Speed.

Sebastian Moran sebastianmoran-mainwp

🚀
Fast Lane Strategies: Turbocharging Your WordPress Website for Optimal Speed.
View GitHub Profile
@bahia0019
bahia0019 / hex-to-rgba.php
Created September 20, 2018 21:23
Convert Hex string to RGBA
<?php
/**
* Take Accent color, and convert it to RGBA, and add an opacity of .75.
*/
$accent = get_theme_mod( 'site_accent_color' );
$accent_string = ltrim( $accent, '#' );
$arr = str_split( $accent_string, '2' );
foreach ( $arr as $value ) {
$new_value = hexdec( $value ) . ', ';
@spicecadet
spicecadet / gist:71d65fab0480812bc66b09b69d056253
Created November 17, 2018 10:10
WP-CLI Get Production DB
#!/bin/bash
#get siteurl option from prod and dev
PROD_SITEURL=$(wp @prod option get siteurl);
DEV_SITEURL=$(wp @dev option get siteurl);
#Export database from prod and import to dev
wp @prod db export - > prod.sql
wp @dev db import /srv/www/edmund/prod.sql
@bogdan-mainwp
bogdan-mainwp / disable-get-site-size.php
Last active December 6, 2018 13:59
Custom snippet that will disable site size calculation. In case of inability to connect a child site, it is good to try to use this on the child site.
<?php
// Add the following code snippet to the functions.php file of the active theme of your Child Site site.
add_filter( 'mainwp-child-get-total-size', 'mycustom_mainwp_child_get_total_size', 10 , 1 );
function mycustom_mainwp_child_get_total_size( $value ) {
return false;
}
?>
@bogdan-mainwp
bogdan-mainwp / custom-mainwp-menu-header.php
Last active December 6, 2018 14:00
Custom snippet for renaming the MainWP Dashboard WP Admin menu header
<?php
// Add the following code snippet to the functions.php file of the MainWP Customisations plugin
// Download MainWP Customisations here: https://github.com/mainwp/mainwp-customisations
// More about the plugin: https://mainwp.com/mainwp-customisations/
add_action( 'admin_head', 'mycustom_menu_admin_head' );
function mycustom_menu_admin_head() {
global $menu;
foreach( $menu as &$item ) {
@bogdan-mainwp
bogdan-mainwp / mainwp-wp-version.php
Last active December 6, 2018 14:02
Custom code snippet for creating a custom WP Version column in the Manage Sites table and displaying Child Site WP version for each child site.
<?php
// Add the following code snippet to the functions.php file of the MainWP Customisations plugin
// Download MainWP Customisations here: https://github.com/mainwp/mainwp-customisations
// More about the plugin: https://mainwp.com/mainwp-customisations/
// WP Version example
add_filter( 'mainwp-sitestable-getcolumns', 'mycustom_sites_table_column', 10 );
add_filter( 'mainwp-sitestable-item', 'mycustom_sitestable_item', 10 );
@corsonr
corsonr / disable-woocommerce-3-zoom.php
Created April 5, 2017 08:48
Disable WooCommerce 3.+ Zoom
<?php
remove_theme_support( 'wc-product-gallery-zoom' );
@mathetos
mathetos / site-health-curl-test.php
Last active May 9, 2019 18:53
Add cURL test to WP 5.2 Site Health tests
<?php
/**
* Adds a cURL version test to Site Health
*
* Info here: https://make.wordpress.org/core/2019/04/25/site-health-check-in-5-2/
* NOTE: Requires version 5.2+ of WordPress
*
**/
@davekiss
davekiss / gist:2639184ac066c53416b23c5a66f42d1e
Created February 2, 2019 17:44
EDD Weekly Domain Report via Email
/**
* Add a weekly email report that summarizes which domains that
* your products are being used on.
*/
add_filter( 'cron_schedules', function( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800,
'display' => __('Once Weekly')
);
@psorensen
psorensen / edd-recurring-create.php
Created January 20, 2017 19:28
EDD Recurring Creation
$args = array(
'expiration' => date( 'Y-m-d 23:59:59', strtotime( 'January 3, 2018', current_time( 'timestamp' ) ) ),
'created' => date( 'Y-m-d 23:59:59', strtotime( current_time( 'timestamp' ) ) ),
'status' => 'pending',
'profile_id' => 0,
'transaction_id' => 0,
'initial_amount' => 1,
'recurring_amount' => 700,
'bill_times' => '1',
'period' => 'yearly',

Generate Search & Replace Script For All Applicable http-to-https Image Assets.

  1. run wp --allow-root db query "select post_content from wp_posts where post_content like '%<img src%';" --skip-column-names --silent | grep -oP "<img\s+.*?src=['\"](.*?)['\"].*?>" | grep -oP "https?://[^\"]*" | sort | uniq
  2. using parse_url(), create a PHP function* to find unique hosts and add first occurence of each to an array of links.
  3. Itterate through new list of links and run through a CURL function** to determine
  4. Add links with 200-300 status to an array
  5. Produce Search & Replace script based of returned values

Function Reference