Skip to content

Instantly share code, notes, and snippets.

@broskees
broskees / debugger.js
Last active September 5, 2022 04:03
A short and sweet javascript debugger function that tells you the variable name and the function it was called in
const debuggerFn = variable => console.log({[debuggerFn.caller]: {variable}});
@broskees
broskees / is-descendent-of.php
Last active September 2, 2022 19:01 — forked from stephenharris/is-descendent-of.php
Check if current page is a descendant of the specified one.
<?php
/**
* Is the current page a descendent of page identified by the path (not slug).
* A page is not a descendent of itself!
*
* @link http://wordpress.stackexchange.com/questions/101213/does-is-child-exist-in-wp-3-5-1
* @link https://gist.github.com/broskees/8fd20d3167c4e7dd2941aaef5e7068cc
* @param string $page_path The path of the page, e.g. mypage/mysubpage
* @return boolean True if current page is a descednent of specified $page_path. False otherwise.
*/
@broskees
broskees / plugin-disabler.php
Created August 16, 2022 15:20
plugin disabler per environment WordPress (slightly modified)
<?php
/*
Plugin Name: Simple Environment plugin disabler
Description: Disables plugins based on environment settings.
Original Author: Kamil Grzegorczyk
Related blog post: https://roots.io/guides/how-to-disable-plugins-on-certain-environments/
Version: 0.1
*/
class DisablePlugins
@broskees
broskees / change_vagrant_version_brew.sh
Last active August 14, 2022 16:46 — forked from jonashackt/downgrade_brew_package.sh
Downgrade homebrew (cask) package
# Uninstall current version you want to change
brew uninstall --cask vagrant
# e.g. Vagrant
brew edit --cask vagrant
# replace the contents of that file with the version of the file found in github history:
# https://github.com/Homebrew/homebrew-cask/commits/master/Casks/vagrant.rb
# or change version and SHA256, you can find on https://releases.hashicorp.com/vagrant/
```
@broskees
broskees / acf-missing.php
Last active June 2, 2022 20:18 — forked from freezvd/acf-missing.php
WordPress mu plugins to check if "Advanced Custom Fields Pro" is active.
<?php
add_action('plugins_loaded', function() {
if ( !function_exists('is_plugin_active') ) {
/** WordPress Plugin Administration API */
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
return;
@broskees
broskees / Zettlekasten ID
Created January 7, 2022 23:42
Readwise to obsidian template - zettlekasten 12 digit id (based on date & time) (Jinja)
{{date|date("Ymd")}}{% for char in time|replace(":", "")|replace("am", "")|replace("pm", "")|list %}{% if loop.index == 1 and time[1] == ":" and "am" in time %}0{{char}}{% elif loop.index < 3 and time[2] == ":" and time[1] == "2" and "am" in time %}0{% elif loop.index == 1 and time[1] == ":" and "pm" in time %}{{char|int() + 12}}{% elif loop.index < 3 and time[2] == ":" and "pm" in time %}{{char|int() + loop.index}}{% else %}{{char}}{% endif %}{% endfor %}
@broskees
broskees / page-template-column.php
Created December 20, 2021 16:18
Add a Page Template column to the WordPress admin "Pages" page
<?php
/**
* Introduces a new column to the 'Page' dashboard that will be used to render the page template
* for the given page.
*
* @param array $page_columns The array of columns rendering page meta data.
*
* @return array $page_columns The update array of page columns.
*/
@broskees
broskees / filters.php
Last active December 9, 2021 20:19
Sage 9 Conditional Sidebars
<?php
add_filter('sage/display_sidebar', function ($display) {
static $display;
isset($display) || $display = in_array(true, [
// The sidebar will be displayed if any of the following return true
is_single(),
is_404(),
is_page_template('views/template-custom.blade.php')
@broskees
broskees / shortcodes.php
Created December 9, 2021 20:00
Year shortcode that shows the next year after december
<?php
add_shortcode('year', function() {
$current_year = date('Y');
$thanksgiving = strtotime("December 1st $current_year");
return $thanksgiving < time() ? $current_year + 1 : $current_year;
});
@broskees
broskees / assets.php
Last active December 7, 2021 20:03
WordPress CSS & JS enqueue router
<?php
/**
* Routes specific js & css files to enqueue if they exist.
*
* (The idea is to use default.css & default.js for all your global styles,
* then simply include default.css & default.js into your $template.css & template.js files
* so that you can easily keep filesizes small and minimize the number of resources requested.)
*/
add_action( 'wp_enqueue_scripts', function() {