Skip to content

Instantly share code, notes, and snippets.

View circlecube's full-sized avatar

Evan Mullins circlecube

View GitHub Profile
@circlecube
circlecube / new functions.php
Created September 17, 2015 17:25
How to fix "The called constructor method for WP_Widget is deprecated since version 4.3.0!"
...
class My_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'my-widget', // Base ID
'My Widget', // Name
array( 'description' => 'My Widget description.' ) // Args
);
}
@circlecube
circlecube / functions.php
Created October 2, 2015 18:01
Add a class to your wordpress comment form submit button
function circlecube_comment_form( $args ) {
$args['class_submit'] = 'button'; // since WP 4.1
return $args;
}
add_filter( 'comment_form_defaults', 'circlecube_comment_form' );
@circlecube
circlecube / functions.php
Created March 10, 2016 12:12
childof2016: An example WordPress child theme
<?php
function theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ) );
}
@circlecube
circlecube / functions.php
Created December 29, 2016 15:48
WillyMelt API Tweaks
// add custom fields query to WP REST API v2
// https://1fix.io/blog/2015/07/20/query-vars-wp-api/
function my_allow_meta_query( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value' ) );
return $valid_vars;
}
add_filter( 'rest_query_vars', 'my_allow_meta_query' );
@circlecube
circlecube / helpers
Created June 17, 2020 18:19
Normalize interpolate and interpret/map
/**
* normalize takes a value within a given range
* and converts it to a number between 0 and 1
* (actually it can be outside that range
* if the original value is outside its range).
*
* @param {*} value number to be normalized
* @param {*} minimum low end of range - mapped to 0
* @param {*} maximum high end of range - mapped to 1
*/
@circlecube
circlecube / fun-with-functions.js
Created November 13, 2020 14:19
Fun with functions
/*
* Fun with functions
*
* Function exercieses from Douglas Crockford
* in his The Good Parts of JavaScript and the Web
* course on Frontendmasters
* https://frontendmasters.com/courses/good-parts-javascript-web/
*/
// function that takes two numbers and return their sum