Skip to content

Instantly share code, notes, and snippets.


De'Yonte W. rxnlabs

View GitHub Profile
rxnlabs / wp-allow-external-ajax-cors.php
Last active November 3, 2022 16:16
WordPress - Allow CORS headers for external sites. Allow external site to make an AJAX request against the WP site if you don't have access to the .htaccess file or your site is hosted on an NGINX server
View wp-allow-external-ajax-cors.php
* Add CORS HTTP headers to the page request to allow the MTS curriculm site to make an AJAX request against the site
* Modify the HTTP headers that WordPress outputs before they are sent so we can add CORS headers to the request for things like an AJAX request
* @param array $headers The HTTP headers that WordPress is about to send
* @param WP $wp The current WordPress environment instance
rxnlabs / experimental-theme.json
Last active October 15, 2021 16:09 — forked from thetwopct/experimental-theme.json
An actual working experimental-theme.json as the WordPress documentation is utter shit
View experimental-theme.json
"templateParts": {
"header": {
"area": "header"
"footer": {
"area": "footer"
"settings": {
rxnlabs /
Last active December 12, 2022 07:40
Gravity Forms - GFAPI::submit_form bug when the $_POST variable contains existing data because of array_merge_recursive

Gravity Forms GFAPI::submit_form bug

There is a bug with the Gravity Forms GFAPI::submit_form method when the $_POST variable contains any existing values that match what you pass to GFAPI::submit_form.

Because GFAPI::submit_form internally uses array_merge_recursive, any existing values in the $_POST variable will be added to any values that exist in the second parameter that you pass to GFAPI::submit_form.

This bug appears in the latest version of Gravity Forms and in the latest 2.5 beta


rxnlabs /
Last active July 29, 2020 14:22
WordPress - WP: Add /blog to your Post post type only and remove it from your other custom post types and taxonomies after adding /blog

Add a /blog to your WordPress blog posts only and remove it from the other post types

This is useful if you want to know when a user is viewing a blog post in Google Analytics vs a page. Or if you want to just have an easy way to distinguish your blog content from your other content using the URL.

There may be an easier way to do this but all of my Googling didn't turn up any answers that let you modify the post URLs only.

  1. Add the code from remove-blog-front-from-custom-post-types.php to your theme's functions.php or to a custom plugin or some file where it will get loaded. This code prevents the new blog base from being applied to the URLs of Custom POst types and taxonomy archives.
  2. Log into your WordPress admin
  3. Go to Settings -> Permalinks
  4. Select the Custom Structure field and add /blog to the Permalink structure (add this before the /%postname% part of the URL
rxnlabs / js-fill-height-of-viewport-width-section-minus-header-height.js
Created April 2, 2020 14:31
CSS + JS - Fill height of viewport with section minus the header height
View js-fill-height-of-viewport-width-section-minus-header-height.js
$( window ).on( 'resize', debounce( function () {
var $header = $('.site-header');
$.each($('.content-section.type-hero'), function (index, node) {
var $hero = $(node);
$hero.css('height', 'calc(100vh - ' + $header.height() + 'px)');
} ) );
function debounce( func, wait, immediate ) {
var timeout;
rxnlabs / wp-admin-popup-replace-image.js
Created December 22, 2019 14:53
JS - WP (WordPress) admin replace featured image when we don't have access to SSH
View wp-admin-popup-replace-image.js
Run as a bookmarklet in your browser. Run in the WordPress admin area. Set the WordPress admin posts view number really high from the default 20 posts to something like 500 posts to decrease the number of times we need to run this.
Make sure to disable your browser's popup blocker since this will open a LOT of windows.
Update the featured image of all of the posts that in the WordPress admin on the Posts table page
(function() {
/*Check if a value is a positive, whole number integer*/
function isNormalInteger(str) {
rxnlabs / wp-upload-file-post-wp-http.php
Last active April 30, 2022 12:03
WordPress - Upload files to remote API using WP_Http / wp_remote_post + cURL + fsockopen + CurlFile
View wp-upload-file-post-wp-http.php
$url = '';
// The file is stored on your system/host
$path_to_uploaded_file = '/full-path-to-file/picture.jpg';
$form_fields = [ 'first_name' => 'Foo', 'last_name' => 'Bar' ];
if ( file_exists( $path_to_uploaded_file ) ) {
$form_fields['profile_picture'] = new CurlFile( $path_to_uploaded_file );
rxnlabs / facebook-detect-embed-link-regex.php
Created November 8, 2018 01:17
PHP - Detect if a link text contains Facebook embeddable content using regular Expressions
View facebook-detect-embed-link-regex.php
rxnlabs / wordpress-enable-jetpack-dev-mode.php
Created October 3, 2018 13:08
WordPress - Enable Jetpack development mode if WP_DEBUG is true and Jetpack is NOT connected to Useful if you want to test out Jetpack modules without needing to be connected to or if doing development from a localhost site
View wordpress-enable-jetpack-dev-mode.php
* Enable Jetpack development mode if WP_DEBUG is true and jetpack is not active/connected to
* See:
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
if ( method_exists( '\\Jetpack', 'is_active' ) && is_callable( array( '\\Jetpack', 'is_active' ) ) ) {
$jetpack_reflection = new \ReflectionMethod( '\\Jetpack', 'is_active' );
rxnlabs / wordpress-get-widget-id-name.php
Last active May 30, 2018 12:41
WordPress - Get the name and id of the widget area being used to display a certain widget. This adds the widget ID and widget area name as HTML comments to the frontend of the site
View wordpress-get-widget-id-name.php
* Add the widget ID and widget name as HTML comments.
* Makes it easiser to identify exactly which widget area a widget is appearing in.
* This helps a lot with themes that have a lot of sidebars and uses a lot of widgets.
function which_dynamic_sidebar( $sidebar_params ) {
$sidebar_params['0']['class'] = empty( $sidebar_params['0']['class'] )?$sidebar_params['0']['id']:$sidebar_params['0']['class'].' '.$sidebar_params['0']['id'];
$sidebar_params['0']['before_widget'] = '<!--Widget-Area:id:'.esc_attr($sidebar_params['0']['id']).';name:'.esc_attr($sidebar_params['0']['name']).'-->'.$sidebar_params['0']['before_widget'];