Skip to content

Instantly share code, notes, and snippets.

View alexwcoleman's full-sized avatar

Alex Coleman alexwcoleman

View GitHub Profile
@alexwcoleman
alexwcoleman / class.cpt.php
Last active September 19, 2017 19:44 — forked from jpurpleman/class.cpt.php
Custom Post Type Class
<?php
class MyCPTs {
public function __construct() {
add_action( 'init', array ( $this, 'load_cpts'), 0 );
}
/**
@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];
@alexwcoleman
alexwcoleman / givewp-add-heart-to-recurring-option.php
Created August 24, 2022 16:04 — forked from jessedmatlock/givewp-add-heart-to-recurring-option.php
GiveWP - add a heart SVG icon to recurring option box that animates when a recurring donation is selected
// Inject an SVG icon (heart) into recurring selection box via JS
function override_givewp_js() {
if( ! is_admin() ) { ?>
<script type="text/javascript">
jQuery(document).ready( function($) {
$('.give-btn.advance-btn').on('click', function(){
if( $('.give-recurring-donors-choice').length ){
$('.give-recurring-donors-choice').append('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 255.96 256" data-inject-url="http://vertex2022.local/wp-content/themes/vertex-ranch-2022/assets/img/icons/solid/love.svg" class="svg-inject icon-svg icon-svg-sm solid-mono text-red me-4 mb-5 mb-md-0"><path class="fill-primary" d="M96 186.67A90.77 90.77 0 01186.63 96a89.82 89.82 0 0138.9 8.9 64.28 64.28 0 00-95.3-86L120 29.15l-10.28-10.27a64.21 64.21 0 00-90.93 0 64.56 64.56 0 000 91.06L96 187.28z"></path><path class="fill-secondary" d="M186.63 117.33A69.34 69.34 0 10256 186.67a69.41 69.41 0 00-69.37-69.34zm30.19 55.73l-30.54 37.32a8.06 8.06 0 01-5.92 3h-.27a8 8 0 01-5.84-2.53l-17.46-18.67a8 8 0 0111.7-10.95l11.2
@alexwcoleman
alexwcoleman / custom_pdf_tag_donor_title.php
Created September 7, 2022 19:05 — forked from matheuswd/custom_pdf_tag_donor_title.php
Creates the {donor_title} tag for the GiveWP PDF Receipt
<?php
function custom_pdf_tag_donor_title( $template_content, $args ) {
$donor_title = isset( $args['buyer_info']['title'] ) && $args['buyer_info']['title'] !== '' ? $args['buyer_info']['title'] : __('', 'give');
$template_content = str_replace( '{donor_title}', $donor_title, $template_content );
return $template_content;
}
add_filter( 'give_pdf_compiled_template_content', 'custom_pdf_tag_donor_title', 999, 2 );
@alexwcoleman
alexwcoleman / stripe-pass-custom-meta-for-payments.php
Created June 30, 2023 21:13 — forked from rickalday/stripe-pass-custom-meta-for-payments.php
Pass custom field data to Stripe when payment is processed.
<?php
function give_stripe_custom_payment_meta( $charge_args ) {
// Sanitize the input posted data to the form.
$posted_data = give_clean( filter_input_array( INPUT_POST ) );
//Uncomment the followign line to print the $posted_data array to the error log
//error_log(print_r($posted_data, TRUE));
//Get form ID