Skip to content

Instantly share code, notes, and snippets.

View rxnlabs's full-sized avatar

De'Yonte W. rxnlabs

View GitHub Profile
@rxnlabs
rxnlabs / redirect-apache-git-folder
Created July 25, 2023 16:15
Apache - .htaccess prevent Git repos .git/ folder from being viewable
# BEGIN Cornershop
# VCS lockdown
# Deny access to version control content
# Will not work if both Alias & Rewrite modules are disabled
# To verify with git content, check these two URLs:
# 1. /.git/HEAD
# 2. /.gitignore
<IfModule mod_alias.c>
# Deny access to VCS content using Alias Module
RedirectMatch 404 ^(.*/)?\.(git|svn|hg|bzr)+
@rxnlabs
rxnlabs / wp-allow-external-ajax-cors.php
Last active June 27, 2023 20:02
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
<?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
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
{
"templateParts": {
"header": {
"area": "header"
},
"footer": {
"area": "footer"
}
},
"settings": {
@rxnlabs
rxnlabs / gf-api-submit-form-bug-example.md
Last active July 14, 2023 09:23
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 2.4.20.5 and in the latest 2.5 beta.

UPDATE ON 07/14/2023: This is a known bug in Gravity Forms and the plugin developers (i.e. Rocket Genius) are aware of it. Since other developers have made custom workaround to get around this issue, patching this bug would break that custom code, so Rocket Genius has not patched it. This code is probably present in the latest version of the plugin and will probably be present in all future versions.

@rxnlabs
rxnlabs / add-blog-to-wordpress-posts-only.md
Last active August 31, 2023 13:41
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
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
$( 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
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
/**
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
rxnlabs / wp-upload-file-post-wp-http.php
Last active July 18, 2023 20:13
WordPress - Upload files to remote API using WP_Http / wp_remote_post + cURL + fsockopen + CurlFile
<?php
$url = 'https://insert-domain-here.com/api-endpoint';
// 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
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
@rxnlabs
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 WordPress.com. Useful if you want to test out Jetpack modules without needing to be connected to WordPress.com or if doing development from a localhost site
<?php
/**
* Enable Jetpack development mode if WP_DEBUG is true and jetpack is not active/connected to WordPress.com
* See: https://jetpack.com/support/development-mode/
*/
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' );