Skip to content

Instantly share code, notes, and snippets.

View maddisondesigns's full-sized avatar

Anthony Hortin maddisondesigns

View GitHub Profile
@maddisondesigns
maddisondesigns / functions.php
Created September 29, 2014 08:20
Custom Gravity Forms Dropdown Validation
<?php
/**
* Custom Gravity Forms validation. Make sure the form isn't submitted with the default dropdown values
* Useful for when your Gravity Form is displaying default values instead of the field labels.
*
* Tie our validation function to the 'gform_validation' hook. Since we've appended _1 to the filter name (gform_validation_1)
* it will only trigger on form ID 1. Change this number if you want it to trigger on some other form ID.
* There's no sense in running this function on every form submission, now is there!
*
@maddisondesigns
maddisondesigns / gist:653c8ba193e9f31c2120
Last active August 29, 2015 14:18
Publicly Verifying Myself on GitHub
Verifying that +anthonyhortin is my openname (Bitcoin username). https://onename.com/anthonyhortin
@maddisondesigns
maddisondesigns / functions.php
Last active January 1, 2019 11:07
Remove Yoast SEO nag after update
<?php
/*
* Remove the annoying Yoast SEO nag for all Admin Users. Tested with v3.4.2
*/
class ahRemoveYoastNag_Remove_Yoast_SEO_Nag {
private $yoastPluginFile;
public function __construct() {
$this->yoastPluginFile = "wordpress-seo/wp-seo.php";
register_activation_hook( $this->yoastPluginFile, array( $this, 'ryn_remove_yoast_nag_on_activation' ) );
@maddisondesigns
maddisondesigns / cookie-policy.md
Last active June 19, 2022 17:59
eCommerce Terms & Conditions and Privacy Templates
@maddisondesigns
maddisondesigns / common.js
Last active April 6, 2019 19:01
Close all the Divi accordions on page load. Works with Divi 2.5 and above
/**
* Toggle the class on the accordion so that they're all closesd on page load
*/
jQuery( document ).ready( function( $ ) {
$(function() {
$(".et_pb_accordion .et_pb_toggle_open").addClass("et_pb_toggle_close").removeClass("et_pb_toggle_open");
$(".et_pb_accordion .et_pb_toggle").click(function() {
$this = $(this);
setTimeout(function() {
@maddisondesigns
maddisondesigns / functions.php
Last active December 21, 2015 03:51
Filter the Gravity Forms button type to change it to a proper button
<?php
/*
* mytheme_form_submit_button
*
* Filter the Gravity Forms button type to change it to a proper button
*/
function mytheme_form_submit_button( $button, $form ) {
$button = str_replace( "input", "button", $button );
$button = str_replace( "/", "", $button );
$button .= "{$form['button']['text']}</button>";
@maddisondesigns
maddisondesigns / functions.php
Created August 2, 2016 05:59
WordPress Child Theme Example
<?php
function mytheme_scripts_styles() {
// Enqueue the parent theme stylesheet
wp_enqueue_style( 'parent-style', trailingslashit( get_template_directory_uri() ) . 'style.css' );
// Ensure the default WordPress stylesheet is enqueued after the parent stylesheet
wp_enqueue_style( 'style', get_stylesheet_uri(), array( 'parent-style' ) );
}
add_action( 'wp_enqueue_scripts', 'mytheme_scripts_styles' );
@maddisondesigns
maddisondesigns / functions.php
Last active April 12, 2023 06:20
Display the name of the current WordPress template being used
<?php
/**
* Debug function to show the name of the current template being used
*/
function mytheme_show_template() {
global $template;
if ( is_user_logged_in() ) {
echo '<div style="background-color:#000;color:#fff;z-index:9999;position:absolute;top:0;">';
print_r( $template );
if ( is_single() ) {
@maddisondesigns
maddisondesigns / functions.php
Last active March 25, 2019 19:38
Remove the WP REST API JSON Endpoints for non-logged in users
<?php
/*
* Remove the WP REST API JSON Endpoints for logged out users
*/
function mytheme_only_allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@maddisondesigns
maddisondesigns / functions.php
Last active March 25, 2019 19:38
Remove the WP REST API JSON Endpoints for everyone except Administrators
<?php
/*
* Only allow Admin users to view WP REST API JSON Endpoints
*/
function mytheme_only_allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}