Skip to content

Instantly share code, notes, and snippets.

View codearachnid's full-sized avatar
🎯
Focusing

Timothy Wood codearachnid

🎯
Focusing
View GitHub Profile
@codearachnid
codearachnid / ninjatable-rest-api.php
Created March 10, 2023 00:45
Expose Ninja Table data as JSON via REST API.
<?php
/*
* Code snippet to expose ninja table data as JSON via REST API
* Example URL: https://yourdomain.com/wp-json/ninjatable/v1/table/#
* In this working example you should enable authentication to protect your data
* example is contained in `get_items_permissions_check`
* Route logic sourced from https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
*/
add_action('rest_api_init', function () {
@codearachnid
codearachnid / ninja_table_raw_sql_placeholders.php
Created March 10, 2023 04:07
Improve the Ninja Tables admin experience by hooking into `ninja_table_raw_sql_placeholders` filter to add additional placeholders while in admin to allow queries to run in psuedo-mode.
<?php
/**
* hook into `ninja_table_raw_sql_placeholders` filter to add additional placeholders
* while in admin to allow queries to run in psuedo-mode
* @param array $filter
*/
add_filter('ninja_table_raw_sql_placeholders', function($filter){
if( is_admin() ){
/**
* these should already be set passing into this filter
@codearachnid
codearachnid / _notes.md
Last active March 8, 2023 21:56
Gravity Forms: Add "other" option to checkboxes

This is a hacked in way of enabling "other" options to the Gravity Forms Checkbox Field https://docs.gravityforms.com/checkboxes/. Instead of creating a new field as a clone of checkbox or leveraging the built in class hooks to filter the processing I felt it would be better performance to directly modify the core GF logic in hopes they will adopt this in a future release. An example of this is seen like this !Screenshot

The status of these changes will affect the following areas

  • Changes were made against GF Version: 2.7.2
  • I have marked changed areas in these files with a comment Code4OtherChoice it's kludgy but worked for me to update the files as needed during update comparisons.
  • Validation works if the user has not changed the default value when selecting other
  • Validation works if no fields on form are selected
  • "Other" value saves successfull
@codearachnid
codearachnid / .htaccess
Created March 8, 2023 02:20
Convert WordPress /wp-admin/admin-ajax.php to /api
RewriteRule ^api$ /wp-admin/admin-ajax.php [L]
@codearachnid
codearachnid / wp-custom-post-status.php
Created March 8, 2023 01:48
WordPress Custom Post Status OOP
<?php
// sourced from https://www.ibenic.com/create-custom-wordpress-post-status/ and https://stackoverflow.com/a/49569592
class WordPress_Custom_Post_Status {
/**
* Post Types for this status
* @var array
*/
@codearachnid
codearachnid / array_keys_exists.php
Created February 13, 2023 18:16
Because PHP is lacking an array diff for keys within array check
<?php
if(!function_exists('array_keys_exists')){
function array_keys_exists(array $keys, array $arr) {
return !array_diff_key(array_flip($keys), $arr);
}
}
<?php
/**
Adding support for ACF Extended (https://www.acf-extended.com/)
* Multiple New Field Groups
* 30+ New Field Types
update the following files for includes:
* inc/wpbakery/wpbakery_grid_element.php : 61 `include_once(ACFVC_PATH.'inc/acf_vc_helper_extended.php');`
@codearachnid
codearachnid / tribe-organizer-email-clickable.js
Created November 15, 2022 15:35
Turn the WordPress: The Events Calendar plugin obfuscated organizer's email address into a clickable mailto link
jQuery(document).ready(function($){
$('.tribe-organizer-email').each(function(i){
$email = $.trim( $(this).text() );
if( !$(this).has( "a" ).length ){
$(this).html('<a href="mailto:' + $email + '">' + $email + '</a>');
}
})
});
@codearachnid
codearachnid / bottom-jquery-load.html
Created November 2, 2022 15:45
Make sure jquery can run inline before lib is loaded in footer of the page
<script>
window.addEventListener("load", function () {
$(function () {
$("body").append("<p>jQuery is available now!</p>");
// Run my big jQuery function
});
}, false);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
@codearachnid
codearachnid / tribe_remove_venue_links.php
Created July 26, 2013 16:41
Tribe Events Calendar remove venue links from event meta display