Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
LinzardMac / gist:4aca565b35aec5e78109a561f50d4380
Created August 29, 2021 19:57
change the html output of the radio field option text in ninja forms (ugly)
jQuery( document ).ready( function( $ ) {
// Instantiate our custom field's controller, defined above.
new myCustomFieldController();
});
var myCustomFieldController = Marionette.Object.extend( {
initialize: function() {
// Listen for render:view event only for listradio field type
this.listenTo( nfRadio.channel( 'listradio' ), 'render:view', this.renderView );
@LinzardMac
LinzardMac / Readme.MD
Created March 6, 2019 02:08
Anonymize facebook post w/ comments to protect identity when screensharing

Paste this in to your web inspector's CSS editor when viewing a post on facebook and it will block out the names and hide the avatars to hide the identity of individuals when taking a screenshot to share.


For Chrome

  • Press Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, Chrome OS) to open Chrome Developer Tools and jump straight into the Console panel.
  • Paste the contents of chrome-console-inspector.css file into the console and hit enter

For Safari

  • Press Command+Option+i (Mac) to open the Safari Web Inspector
  • Click the "console" tab across the top
@LinzardMac
LinzardMac / 1-wp-config.php
Last active October 8, 2021 20:26
Stupid simple conditional config for local and production w/ constants.
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
@LinzardMac
LinzardMac / google-maps-api-poi-events.md
Last active August 28, 2017 20:10
GOOGLE MAPS JAVASCRIPT API PROBLEMS WITH POINTS-OF-INTEREST / CLICKABLE ICONS

GOOGLE MAPS JAVASCRIPT API PROBLEMS WITH POINTS-OF-INTEREST / CLICKABLE ICONS

See the example code working on JSFiddle.net and follow along using this document to discover the wonderful world of WHAT THE F&%^K!(https://jsfiddle.net/t3jt3szr/)


Goal: To allow a user to add a new marker to a google map and utilize the "drag and drop" 1 marker feature to reposition the marker after adding it to the map.

<?php
/** see attached meta.php for usage sample **/
function is_valid_id( $id ) {
// added for a fallback if filter_var is disabled for php build
if ( function_exists( 'filter_var' ) ) {
$default_opts = array(
'options' => array(
'default' => false, // value to return if the filter fails
'min_range' => 1,
'max_range' => PHP_INT_MAX
<?php
// near line 347
// build the attributes for the <script> tag
// including the type and src attrs.
$tag_attributes = [];
/** defaults always set **/
$tag_attributes['type'] = "text/javascript";
$tag_attributes['src'] = $src;
@LinzardMac
LinzardMac / absint.md
Created May 19, 2017 23:45
Pros/Cons of absint()

absint() - WordPress attempt at standardization?

absint() is a WordPress function that passes a string through abs() to turn any negative number into a positive and then intval() which will typecast it as an integer with the above listed “cons” for (int)/inval().

Cons:

  1. Currently there is no way to filter the results before passing the value to the function that queries the database
  2. Does not check for or return a falsey response in case of a malformed ID being passed.
  3. See list for (int)/intval()*

Pros:

@LinzardMac
LinzardMac / is_numeric.md
Created May 19, 2017 23:43
Pros/Cons of is_numeric()

is_numeric()

is_numeric() is a conditional that tests if the value passed is numeric and returns false if not.

Cons:

  • Does not do any sanitization of the input value
  • Will return true for values that could never or would never be a ID of a WordPress core object such as decimals (see truthy values below).
  • WordPress does not consistently create false cases for testing the results of any is_numeric condition tests thus no feedback upon failure.

Values is_numeric() considered valid:

  • +0123.45e6
@LinzardMac
LinzardMac / int-intval.md
Created May 19, 2017 23:38
Explaination of (int)/intval()

(int) Typecast / intval()

Typecasting in PHP is a way to force a value into a format such as an integer without condition or recourse. This means that typecasting with (int) is a form of sanitization but not validation and thus does not provide a message when the value passed is not the proper type.

Cons:

  1. It does not validate the input as an integer, it only typecasts it to an integer regardless of passed type.
  2. Malformed IDs are “allowed” in that they are converted to 0 (int) value and the script continues as if you requested an object with an ID of 0. (see php docs warnings below).
  3. Only time (int) typecasting throws an exception is when a class is typecast as an (int) and since WordPress does not inherently catch exceptions for validating it is relatively useless.
  4. The program does not know that a malformed ID was passed to the request until after the database query fails or returns an unexpected result. **early detection was cited as a reason for doing this early and throughout the codebas
@LinzardMac
LinzardMac / 1-is_valid_id.php
Last active May 30, 2017 01:29
Standardizing the validation of BIGINT integers used in the ID column of wp_posts & adding filters
<?php
/** see attached meta.php for usage sample **/
function is_valid_id( $id ) {
// added for a fallback if filter_var is disabled for php build
if ( function_exists( 'filter_var' ) ) {
$default_opts = array(
'options' => array(
'default' => false, // value to return if the filter fails