Skip to content

Instantly share code, notes, and snippets.

@matheuswd
matheuswd / custom-post-type-value.php
Created November 15, 2015 13:19
How to get a custom value from a Custom Post Type
<?php $get_custom_value = new WP_Query( array( 'post_type' => 'yourposttypehere', 'posts_per_page' => -1 ) ); ?>
<?php while ( $get_custom_value->have_posts() ) : $get_custom_value->the_post(); ?>
<!-- The stuff you want to loop goes in here -->
<?php endwhile; wp_reset_query(); ?>
@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;
}
<?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 / 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},
@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) {
<?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>
<?php
function my_give_limit_comment_length() { ?>
<script>
let comments = document.querySelectorAll('textarea#give-comment');
comments.forEach(comment => comment.setAttribute('maxlength', 255));
</script>
<?php }
@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' );
@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' );