Skip to content

Instantly share code, notes, and snippets.

@shadyvb
shadyvb / i18n.php
Created February 11, 2021 23:29
Support for single-file JS translation files in loco-translate plugin, includes a patch of the plugin to allow hijacking the file generation process.
<?php
/**
* Register actions and filters
*/
function bootstrap() : void {
// Setup script translations
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\setup_script_translations' );
// Filter the script translation lookup process to avoid linking to relative path names
add_action( 'init', function() {
add_filter( 'wpsimplesaml_force', function( $force ) {
if ( YOUR_CONDITION_HERE ) {
return false; // Do not force redirection
}
return $force;
}, 11 ); // Priority at 11 to override the admin setting
} );
@shadyvb
shadyvb / vscode-phpcs-ext-basepath-fix.patch
Last active July 23, 2021 14:59
Fix VSCode PHPCS issue with basepath arg in ruleset files
175,176c175,177
< const fileRealPath = extfs.realpathSync(filePath);
< if (!data.files[fileRealPath]) {
---
> const { files, totals } = data;
>
> if ( !totals.errors && !totals.warnings) {
179c180,184
< ({ messages } = data.files[fileRealPath]);
---
@shadyvb
shadyvb / reusable-effects.diff
Last active August 2, 2019 09:21
Reusable React effects
diff --git a/content/themes/siemens-ingenuity/verbose/js/app/components/header-search.js b/content/themes/siemens-ingenuity/verbose/js/app/components/header-search.js
index fcbe02b7..bf12822a 100644
--- a/content/themes/siemens-ingenuity/verbose/js/app/components/header-search.js
+++ b/content/themes/siemens-ingenuity/verbose/js/app/components/header-search.js
@@ -1,6 +1,7 @@
-import PropTypes from 'prop-types';
-import React from 'react';
-import { __ } from '@wordpress/i18n';
+import PropTypes from 'prop-types';
+import React, { useEffect, useRef, useState } from 'react';
@shadyvb
shadyvb / VagrantFile
Last active March 31, 2024 17:07
VagrantFile hack to auto-create ssh-config entries for vagrant machines
Vagrant.configure("2") do |config|
config.trigger.after :up,
name: "Caching vagrant ssh-config for '#{CONF['hosts'].join('\' and \'')}'",
ruby: proc{|env,machine| puts `mkdir ~/.ssh/config.d &>/dev/null; vagrant ssh-config | sed 's/Host default/Host #{CONF['hosts'].join(" ")}/' | tee ~/.ssh/config.d/vagrant-#{CONF['hosts'][0]} >/dev/null; bash -c "if ! grep -q 'Include ~/.ssh/config.d/*' ~/.ssh/config; then echo '> Please add the following line to your ~/.ssh/config file: Include ~/.ssh/config.d/*'; fi"`}
end
@shadyvb
shadyvb / remove-uncategorised-from-categorised-posts.sql
Created April 27, 2018 13:21
SQL Query to remove uncategorised category from categorised articles
DELETE
FROM `{PREFIX}_term_relationships`
WHERE `term_taxonomy_id` = 1 AND `object_id` IN
( SELECT * FROM
(
SELECT object_id
FROM `{PREFIX}_term_relationships`
WHERE `term_taxonomy_id`
IN ( SELECT `term_taxonomy_id`
FROM `{PREFIX}_term_taxonomy`
@shadyvb
shadyvb / ninja-forms-export-all-the-things.php
Created December 19, 2017 18:19
Override Ninja Forms Submission download link to download all the things without writing to filesystem
<?php
namespace MY_R_KEY_DOESNT_WORRRRK_PROPERLY;
/**
* Download all submissions of a form, between a specific range if provided.
*
* @action wp_ajax_ninja_forms_export_all_subs
*/
function download_all_subs() {
$form_id = filter_input( INPUT_GET, 'form_id', FILTER_SANITIZE_NUMBER_INT );
@shadyvb
shadyvb / wp-api-easily.php
Last active June 20, 2017 13:59
WP API Node Client in a WP Plugin
<?php
/**
* Plugin name: API easily
* Author: Human Made, K.Adam White
* Description: Enables easy use of WP API Node.js client ( node-wpapi by @kadamwhite ) within WordPress interfaces
*/
function wp_api_easily() {
defined( 'WP_API_EASILY_VERSION' ) || define( 'WP_API_EASILY_VERSION', '1.1.1' );
@shadyvb
shadyvb / scoped-cache.php
Last active September 19, 2016 13:13
WordPress Scoped Cache helper
<?php
/**
* WordPress Scoped Cache Helper
*
* This addresses the problem of obsolete cached data for an object after it is updated.
*
* Sometimes we need to cache specific bits of data related to a certain object, and keep the cached data in sync
* with the object's state. This helper makes it easier to tap into object update process to clear ( and optionally
* rebuild ) the cache.
*
@shadyvb
shadyvb / .gitconfig
Created May 24, 2016 15:13
Git Aliases
[alias]
# Merge the current branch to another one, created back when I needed to merge into three branches before issuing a PR
merge-to = "!f() { git checkout $1 && git merge $2 && git checkout $2; }; f"
# Commit shorthand family:
c = commit
cm = commit -m
cam = commit -am
camp = "!f() { git commit -am \"$1\"; git push; }; f"
ca = commit -a