Skip to content

Instantly share code, notes, and snippets.

@brandonjp
brandonjp / Deactivate_Plugins_On_Staging.php
Created January 28, 2024 00:22
Deactivate Specific Plugins on Staging & Non-Production Sites [SnipSnip.pro] - https://snipsnip.pro/s/827
/**
* Deactivate Specific Plugins on Staging & Non-Production Sites [SnipSnip.pro] - https://snipsnip.pro/s/827
*/
if (!class_exists('Deactivate_Plugins_On_Staging')) {
/**
* Selectively deactivates plugins on staging and similar environments.
*/
class Deactivate_Plugins_On_Staging {
private $stagingKeywords = ['staging', 'dev', 'local', 'test', 'sandbox', 'demo'];
private $forceDeactivations = false; // Set to true to deactivate regardless of environment detection.
@brandonjp
brandonjp / Deactivate_Plugins_On_Production.php
Last active January 28, 2024 00:21
Deactivate Specific Plugins on Production Sites [SnipSnip.pro] - https://snipsnip.pro/s/825
/**
* Deactivate Specific Plugins on Production Sites [SnipSnip.pro] - https://snipsnip.pro/s/825
*/
if (!class_exists('Deactivate_Plugins_On_Production')) {
/**
* Selectively deactivates plugins on production environments.
*/
class Deactivate_Plugins_On_Production {
private $stagingKeywords = ['staging', 'dev', 'local', 'test', 'sandbox', 'demo'];
private $forceDeactivations = false; // Set to true to deactivate regardless of environment detection.
@brandonjp
brandonjp / ScreenshotTimer.scpt
Last active December 26, 2023 22:50 — forked from jonobr1/auto-capture.scpt
A small AppleScript to take a screenshot every X minutes and run for Y hours. Saves to an Image with datetime to your specified folder. Great for recording your workday.
set dir to "~/Dropbox/Dropbox2/ScreenshotTimer/"
do shell script ("mkdir -p " & dir)
set intervalMins to 15 -- Change as per your desired frequency (in minutes)
set durationHours to 8 -- Change as per your desired duration (in hours)
-- Convert minutes to seconds for screenshot interval
set intervalSecs to intervalMins * 60
-- Calculate total repetitions within duration
set totalReps to durationHours * 60 / intervalMins
@brandonjp
brandonjp / this-breaks-csp.php
Last active October 16, 2023 16:51
this breaks code snippets pro - if either line 12 or 38 is removed, the snippet will save. But if both lines are present, an error is returned when saving: "Could not update snippet. Request failed with status code 418" - as of code_snippets_version: 3.5.1
if(!class_exists('WPOptionsViewPage')) {
class WPOptionsViewPage {
public function __construct() {
}
public function add_submenu_page() {
}
public function display_options_page() {
@brandonjp
brandonjp / block-editor-auto-expand-advanced-all-sidebar-panels-snipsnip-pro-.code-snippets.json
Created August 8, 2023 16:20
Block Editor: Auto Expand Advanced & All Sidebar Panels [SnipSnip.pro] - When using Gutenberg Block Editor, anytime the content in the sidebar changes, any panels that are closed will open automatically - https://snipsnip.pro/s/751
{
"generator": "Code Snippets v3.4.2.2",
"date_created": "2023-08-08 16:17",
"snippets": [
{
"id": 53,
"name": "Block Editor: Auto Expand Advanced & All Sidebar Panels [SnipSnip.pro]",
"desc": "<p>Block Editor: Auto Expand Advanced &amp; All Sidebar Panels [SnipSnip.pro] - When using Block Editor, anytime the content in the sidebar changes, any panels that are closed will open automatically. <a href=\"https://snipsnip.pro/s/751\">https://snipsnip.pro/s/751</a></p>",
"code": "if (!class_exists('Expand_Sidebar_Panels_On_Mutation')) {\n class Expand_Sidebar_Panels_On_Mutation {\n public function __construct() {\n add_action('admin_footer', array($this, 'add_inline_script'));\n }\n\n public function add_inline_script() {\n if (!function_exists('\\get_current_screen')) {\n return false;\n }\n $screen = \\get_current_screen();\n if (method_exists($screen, 'is_block_editor') && $screen->is_block_editor()) {\n ?>\n <script type=
@brandonjp
brandonjp / Expand_Sidebar_Panels_On_MouseEnter.json
Created August 5, 2023 16:59
WordPress Block Editor: Expand Advanced & All Sidebar Panels on MouseEnter [SnipSnip.pro]
{
"generator": "Code Snippets v3.4.2.2",
"date_created": "2023-08-05 16:54",
"snippets": [
{
"id": 53,
"name": "Block Editor: Expand All Sidebar Panels on MouseEnter [SnipSnip.pro]",
"desc": "<p>Block Editor: Expand All Sidebar Panels on MouseEnter [SnipSnip.pro] - When using Block Editor, move your mouse into the sidebar and any panels that are closed will open automatically. <a href=\"https://snipsnip.pro/s/177\">https://snipsnip.pro/s/177</a></p>",
"code": "if (!class_exists('Expand_Sidebar_Panels_On_MouseEnter')) {\n class Expand_Sidebar_Panels_On_MouseEnter {\n public function __construct() {\n add_action('admin_footer', array($this, 'add_inline_script'));\n }\n\n public function add_inline_script() {\n if (!function_exists('\\get_current_screen')) {\n return false;\n }\n $screen = \\get_current_screen();\n if (method_exists($screen, 'is_block_editor') && $screen->is_block_editor()) {\n ?>\n <script type=\"text/java
@brandonjp
brandonjp / CustomUserRedirect.json
Last active August 3, 2023 19:58
CustomUserRedirect - Redirect Users After Login [SnipSnip.pro] - Redirect users upon login based on user roles. Use custom roles and redirect rules. More info at: https://snipsnip.pro/s/730
{
"generator": "Code Snippets v3.4.2.2",
"date_created": "2023-08-03 19:38",
"snippets": [
{
"id": 63,
"name": "CustomUserRedirect - Redirect Users After Login [SnipSnip.pro]",
"desc": "<p>CustomUserRedirect - Redirect Users After Login [SnipSnip.pro] - Redirect users upon login based on user roles. Easily add/remove/edit the custom roles and redirection rules. Include dynamic data, such as <code>{{username}}</code>, <code>{{user_id}}</code>, and more, including user meta with <code>{{user_meta:META_KEY_HERE}}</code>. *Notes: This class assumes that each user has only one role. If a user has multiple roles, they will be redirected based on the first role found in their role list. Also, be aware of privacy considerations when using tokens like <code>{{user_email}}</code> and <code>{{user_ip}}</code>, as these could potentially expose sensitive user information. <a id=\"sample-permalink\" href=\"https://snipsnip.pro/s/730\">https://snipsnip.pro/s/730</a></p>",
"code": "// Custo
@brandonjp
brandonjp / AddPostAttachmentsMetaBox.php
Created June 16, 2023 21:23
For WordPress, Add a Metabox to List Attachments in the editor. Works on posts, pages & custom post types. - https://snipsnip.pro/s/724
// Add a Metabox to List Attachments in the editor - https://snipsnip.pro/s/724
if (!class_exists('AddPostAttachmentsMetaBox')) {
class AddPostAttachmentsMetaBox {
public function __construct() {
add_action('add_meta_boxes', array($this, 'add_metabox_of_post_attachments'));
}
public function add_metabox_of_post_attachments() {
$post_types = get_post_types(array('public' => true), 'names');
foreach ($post_types as $post_type) {
@brandonjp
brandonjp / SimplePostDuplicator.php
Created June 16, 2023 18:44
For Wordpress, add a Duplicate option to Posts & Pages without using a plugin.
// SimplePostDuplicator - Adds a Duplicate option to Posts & Pages without using a plugin! https://snipsnip.pro/s/701
if (!class_exists('SimplePostDuplicator')) {
class SimplePostDuplicator {
public function __construct() {
add_action('admin_action_simple_post_duplicator_duplicate_post_as_draft', array($this, 'duplicatePostAsDraft'));
add_filter('post_row_actions', array($this, 'addDuplicatePostLink'), 10, 2);
add_filter('page_row_actions', array($this, 'addDuplicatePostLink'), 10, 2);
}
@brandonjp
brandonjp / site-add-env-notice-to-admin-screens.code-snippets.php
Created January 21, 2023 22:13
SITE: Add Env Notice to Admin Screens - WP / Code Snippets Pro
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* SITE: Add Env Notice to Admin Screens
*
* For admins only, display an admin notice with the current domain environment, such as: [STAGING] or [LOCAL] or [PRODUCTION]
* /* Requires Env555 */
*/
/* Requires Env555 */