Skip to content

Instantly share code, notes, and snippets.

View alexwcoleman's full-sized avatar

Alex Coleman alexwcoleman

View GitHub Profile
@alexwcoleman
alexwcoleman / remote-media-loader.php
Last active April 10, 2018 20:46
Remote Media Loader: WordPress
<?php
/**
* Loads media from a remote site when on a local dev environment.
* Eliminates the need to download the uploads directory from the remote site for testing purposes.
* Just make sure to update the obvious URLs below 🤔👏🎉
* Also, throw this in your mu-plugins folder, or create a plugin for yourself.
*/
if ( 'yourbigfatwebsite.local' === $_SERVER['HTTP_HOST'] ):
add_filter( 'upload_dir', function ( $uploads ) {
$uploads['baseurl'] = 'http://yourbigfatwebsite.com/wp-content/uploads';
@alexwcoleman
alexwcoleman / spacing.scss
Created July 24, 2018 18:23
Create Spacing Classes in SASS
$spacing-values: (
1,
2,
3,
4,
5,
);
@each $val in $spacing-values {
// REMS
(function($) {
let pages = [
'Home',
'About',
'Contact'
// whatever....
];
function addPages(pageArray){
// Create a page with the WordPress REST API
@alexwcoleman
alexwcoleman / functions.php
Created October 4, 2018 22:27
Adding Custom Endpoints to The Events Calendar
// this filter adds the custom field values to the json output for The Events Calendar
// https://theeventscalendar.com/support/forums/topic/custom-field-output-for-json-feed/
add_filter( 'tribe_rest_event_data', 'omfg_add_event_customfields' );
function omfg_add_event_customfields($data) {
$event_id = $data['id'];
$some_data = 'some data';
$data = array_merge( $data,
// This is for a single value
@alexwcoleman
alexwcoleman / functions.php
Created November 15, 2018 06:52
WordPress Cleanup
<?php
// ALL OF THIS IS FROM: https://www.linkedin.com/pulse/wp-speed-up-from-ground-alex-knopp
// Post Revisions
// WordPress will simply store every single post revision you create. If your a developer like me then my clients websites change a lot and these post revisions build up. Add the following to your wp-config.php file to stipulate the number of post revisions saved at any one time.
//Define the number of post revisions to be saved
define( 'WP_POST_REVISIONS', 3 );
// WordPress Bloat
@alexwcoleman
alexwcoleman / functions.php
Created October 8, 2019 21:19
Moving WooCommerce Images to ACF Repeater subfields
add_action( 'init', 'test_update_products' );
function test_update_products() {
// You can use offset if needed.
$args = array(
'post_type' => 'my_awesome_cpt',
'numberposts' => 300,
//'offset' => 1000,
);
@alexwcoleman
alexwcoleman / functions.php
Created October 17, 2019 04:46
CMB2 to ACF Repeater
// make sure to comment out add_action when you're done, or working on the data
add_action( 'init', 'cmb2_to_acf' );
function cmb2_to_acf() {
// You can use offset if needed.
$args = array(
'post_type' => 'some_post_type',
'numberposts' => 400, // whatever number.
// 'offset' => 800,
);
@alexwcoleman
alexwcoleman / functions.php
Created October 25, 2019 04:51
CMB2 Image Repeater to ACF Pro Repeater
// PLEASE NOTE!
// I set my ACF Image Repeater to return only the image ID...
// So this may not work if you have it set to return an Object or...?
// I found this helpful: https://support.advancedcustomfields.com/forums/topic/repeater-update_field/
add_action( 'init', 'cmb2_to_acf' );
function cmb2_to_acf() {
// You can use offset if needed.
$args = array(
@alexwcoleman
alexwcoleman / use-remote-media.php
Created June 3, 2020 21:45 — forked from kingkool68/use-remote-media.php
Check if a local file exists in the WordPress media library and if it doesn't exist, replace the URL with a different URL. Helpful when working with a local site that doesn't have all of the media downloaded as the production site. See https://localwp.com/community/t/proxying-requests-to-wp-content-uploads-to-a-production-site/15701
<?php
// Put this in wp-config.php and replace https://example.com/ with the URL of the production site.
define( 'RH_USE_REMOTE_MEDIA_URL', 'https://example.com/' );
// Put the rest of this in functions.php or a custom plugin or somewhere else.
if ( defined( 'RH_USE_REMOTE_MEDIA_URL' ) && ! empty( RH_USE_REMOTE_MEDIA_URL ) ) {
add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src' );
add_filter( 'wp_calculate_image_srcset', 'filter_wp_calculate_image_srcset' );
add_filter( 'wp_get_attachment_url', 'filter_wp_get_attachment_url' );
}
@alexwcoleman
alexwcoleman / change-filename-prefix.php
Last active June 9, 2022 17:31 — forked from rickalday/change-filename-prefix.php
Changes the 'Receipt-' prefix of the pdf receipt filename. You can include additional information from the donation too.
function my_give_pdf_receipt_filename_changer() {
// Define required variables.
$newname = 'Test-';
$get_data = give_clean( filter_input_array( INPUT_GET ) );
$donation_id = give_get_donation_id_by_key( $get_data['_give_hash'] );
$payment_meta = give_get_payment_meta( $donation_id );
/* Possible values
$payment_meta[_give_donation_company];