Skip to content

Instantly share code, notes, and snippets.

View rogerlos's full-sized avatar

Roger Los rogerlos

View GitHub Profile
@rogerlos
rogerlos / add_template_to_gutenberg_editor.js
Last active May 10, 2019 17:10
Simple script that will add a way to change WordPress Gutenberg editor styles based on template chosen for the post or page.
/**
* License: GPLv2
* Created by Roger Los (rogerlos.com)
* https://github.com/rogerlos
*/
jQuery( function ( $ ) {
/**
* Some values needed for this to work. The actual select is not set in this constant as jQuery won't
* catch its value changing, in my experience...
@rogerlos
rogerlos / Dynamic-SelectControl.js
Last active October 20, 2022 12:21
Allows Gutenberg SelectControl to have its options dynamically populated.
/*
* This is an abbreviated "ES5" script (though it has some ES6 language, just not JSX, or dependencies on npm)
* demonstrating how to get the WordPress "Gutenberg" SelectControl to allow dynamic options.
*
* It probably isn't elegant, but neither am I...I included more context than may be necessary.
*
* (SelectControl pukes on dynamic options because it completely dies, never to be seen again, if it
* is sent an empty options array. This prevents that with a placeholder until your results come back.)
*/
@rogerlos
rogerlos / Puc_Factory.php
Created July 8, 2018 04:16
Untested factory idea
<?php
class Puc_Factory {
/**
* Current version entered by default, but can be changed by ::version()
*/
protected static $major = 4;
protected static $minor = 3;
@rogerlos
rogerlos / proof_of_error.php
Last active January 25, 2018 09:09
Proof of GF errors in form widget
<?php
/*
* You need to run this within a WP environment, with Gravity Forms installed, for the called functions to register.
*/
// make sure you have PHP error reporting on
error_reporting( E_ALL );
// wordpress widget args array; these are always sent by WP
$args = array(
@rogerlos
rogerlos / improved_widget_function.php
Last active January 24, 2018 22:28
Improved Gravity Forms widget function
<?php
/*
* At line 56 of widget.php.
*
* - Adds default values for $instance to prevent PHP warnings
* - Gets rid of extract statement (using it does not make code any more readable)
*/
function widget( $args, $instance ) {
@rogerlos
rogerlos / facetwp-done.js
Created May 3, 2017 21:48
Fires a new FacetWP trigger, 'facetwp-done', when FacetWP is finished rendering content; FacetWP's own triggers are called before rendering is complete.
/**
* Procedural JS that ensures FacetWP has fully rendered all of its various pieces;
* triggers 'facetwp-done' when everything is rendered.
*
* Useful if you need to change the HTML within '.facetwp-selections', for example.
*
* 'waitlimit' : number of times to allow wait_for_facetwp() to be called
* 'waitime' : miliseconds between calls
*/
jQuery( document ).ready( function ( $ ) {
@rogerlos
rogerlos / searchwp_results_substitute_post_for_attachment.php
Created November 11, 2014 23:49
Wordpress SearchWP: Substitute Post for Attachment in Search Results
<?php
/**
* This function will see if a PDF or other "attachment" post-type returned by SearchWP
* is present in a custom field in a regular post, and will return that post instead. Note
* this will only process documents which are referenced via the "attachment" post type.
*
* For example, you may have a product specification PDF and would like it in the search
* results, but would rather people got to it by visiting the product page itself.
*