Skip to content

Instantly share code, notes, and snippets.

View shaunpalmer's full-sized avatar

shaun palmer shaunpalmer

View GitHub Profile
@shaunpalmer
shaunpalmer / save_wp_error.php
Last active September 16, 2024 05:00 — forked from iwek/save_wp_error.php
Send WordPress Plugin Activation Errors to a File
<?php
# error_log('Red Alert: Shields failing! Code malfunction in sector 42.');
add_action('activated_plugin', 'save_error_to_log');
function save_error_to_log() {
// Get the error message (if any) during plugin activation
$error_message = ob_get_contents();
// Define the log file path (adjust as needed)
@shaunpalmer
shaunpalmer / one-time-hooks.php
Created September 15, 2024 15:21 — forked from stevegrunwell/one-time-hooks.php
Enables action and filter callbacks to be executed exactly once via the WordPress Plugin API. https://engineering.growella.com/one-time-callbacks-wordpress-plugin-api/
<?php
/**
* Registers the "One time hook" functionality.
*
* Note that this file is intentionally in the *global* namespace!
*
* @author Growella
* @license MIT
*/
@shaunpalmer
shaunpalmer / wp-config.php
Created September 15, 2024 06:59 — forked from danielmcclure/wp-config.php
Run WordPress Updates, WordPress Plugin Updates, and WordPress Theme Updates Automatically
<?php
/*
* Select one or more of the options below to your wp-config.php file to have WordPress updates run automatically.
*/
// Apply Major WordPress Updates Automatically
define( 'WP_AUTO_UPDATE_CORE', true );
// Apply Minor WordPress Updates Automatically
@shaunpalmer
shaunpalmer / plugin-settings.php
Created September 15, 2024 06:57 — forked from annalinneajohansson/plugin-settings.php
A base for a WordPress plugin settings page, using the Settings API #add_options_page #add_action #admin_init #register_setting #add_settings_section
<?php
# http://kovshenin.com/2012/the-wordpress-settings-api/
# http://codex.wordpress.org/Settings_API
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_options_page( __('My Plugin Options', 'textdomain' ), __('My Plugin Options', 'textdomain' ), 'manage_options', 'my-plugin', 'my_options_page' );
}
add_action( 'admin_init', 'my_admin_init' );
@shaunpalmer
shaunpalmer / a-cpt.php
Created September 15, 2024 06:51 — forked from neilgee/a-cpt.php
CPT (Custom Post Type) - WordPress Plugin - there are 2 snippets here - the one name - cpt-hide.php hides the single and archive views, the other one is normal
<?php
/*
Plugin Name: Testimonials Custom Post Type
Plugin URI: http://wpbeaches.com/create-custom-post-types-in-genesis-child-theme-in-wordpress/
Description: Testimonials Custom Post Types
Author: Neil Gowran
Version:1.0.0
Author URI:http://wpbeaches.com
*/
@shaunpalmer
shaunpalmer / class.php
Created September 15, 2024 05:54 — forked from hlashbrooke/class.php
A complete, versatile options page class for any WordPress plugin
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class WordPress_Plugin_Template_Settings {
private $dir;
private $file;
private $assets_dir;
private $assets_url;
private $settings_base;
@shaunpalmer
shaunpalmer / frontendDevlopmentBookmarks.md
Created September 15, 2024 03:37 — forked from PEKTOP/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.
@shaunpalmer
shaunpalmer / is_plugin_active.php
Created September 15, 2024 02:23 — forked from wpscholar/is_plugin_active.php
Test if a WordPress plugin is active
<?php
/**
* Test if a WordPress plugin is active
*/
if ( is_plugin_active('plugin-directory/plugin-file.php') ) {
// the plugin is active
}
The below code is plugin codes used for adding new functionality setup
while updating the plugin or activating the plugin.
This is simple plugin code and it will add transient while updating or activating the plugin.
Clear transient once we finished the operation.
=======================================================================================
<?php
/*Plugin Name: Wordpress Update
@shaunpalmer
shaunpalmer / perf-diagnostics.css
Created September 15, 2024 02:11 — forked from wir/perf-diagnostics.css
CSS used to highlight potential performance issues
:root {
--violation-color: red; /* used for clear issues */
--warning-color: orange; /* used for potential issues we should look into */
}
/* IMAGES */
/*
* Lazy-Loaded Images Check
* ====