Skip to content

Instantly share code, notes, and snippets.

<?php
function hide_recurring_option_for_offline_payment() { ?>
<script>
let paymentMethodOff = jQuery('input[value="offline"]');
let recurringOption = jQuery('div.give-recurring-donors-choice');
let recurringData = jQuery('input[name="_give_is_donation_recurring"]');
if(true === paymentMethodOff.prop('checked')) {
recurringOption.prop('checked', false);
recurringData.prop('value', 0);
@matheuswd
matheuswd / default-mailchimp-to-yes.php
Created August 31, 2020 15:30
Default the Mailchimp selection to subscribe
<?php
function my_mailchimp_tribute_by_default() { ?>
<script>
jQuery("input[name=give_mailchimp_signup]").prop("checked", true);
</script>
<?php }
add_action( 'give_donation_form_after_submit', 'my_mailchimp_tribute_by_default' );
@matheuswd
matheuswd / blank-amount-focus.php
Created August 6, 2020 17:11
Makes the amount field blank and focused
<?php
function change_amount_focus() { ?>
<script>
jQuery("#give-amount").val("").focus();
</script>
<?php }
add_action( 'give_payment_mode_top', 'change_amount_focus' );
<?php
function my_give_limit_comment_length() { ?>
<script>
let comments = document.querySelectorAll('textarea#give-comment');
comments.forEach(comment => comment.setAttribute('maxlength', 255));
</script>
<?php }
<?php
function my_give_tribute_by_default() { ?>
<script>
let searchParams = new URLSearchParams(window.location.search);
// Change the parameter name here
let referrer = searchParams.has('referrer') ? searchParams.get('referrer') : '';
// Change the target variable here
jQuery("input#ffm-referrer").prop("value", referrer);
</script>
@matheuswd
matheuswd / hide-donate-button-for-offline-donation.php
Created July 2, 2020 23:17
Hides the donate button for offline donations
<?php
/**
Hides the donate button for offline donation
*/
function my_give_hide_button() { ?>
<script>
let gatewayOfflineChecked = jQuery(".give-gateway-option-selected input[value='offline']").prop("value");
if(gatewayOfflineChecked) {
@matheuswd
matheuswd / reduce.js
Created November 30, 2019 14:29
Reduce Exercise
/** 6) Given an array of potential voters, return an object representing the results of the vote
Include how many of the potential voters were in the ages 18-25, how many from 26-35, how many from 36-55, and how many of each of those age ranges actually voted. The resulting object containing this data should have 6 properties. See the example output at the bottom.
*/
var voters = [
{name:'Bob' , age: 30, voted: true},
{name:'Jake' , age: 32, voted: true},
{name:'Kate' , age: 25, voted: false},
{name:'Sam' , age: 20, voted: false},
{name:'Phil' , age: 21, voted: true},
{name:'Ed' , age:55, voted:true},
<?php
function isMultisite() {
if (function_exists('is_multisite'))
return is_multisite();
return false;
}
function isMainSite() {
if (!function_exists('is_main_site' ) || !$this->isMultisite())
@matheuswd
matheuswd / blocking-plugin-updates.php
Last active February 23, 2016 17:42
Block the plugin update
<?php
function disable_plugin_updates( $value ) {
$plugin_path = 'default-featured-image/set-default-featured-image.php';
if ( (isset($value) ) && (is_object($value) ) ) {
if (isset( $value->response[$plugin_path] )) {
unset( $value->response[$plugin_path] );
}
}
return $value;
}