Skip to content

Instantly share code, notes, and snippets.

View shaunpalmer's full-sized avatar

shaun palmer shaunpalmer

View GitHub Profile
// Initialize the class.
// Array of class names to instantiate
$classes = [
'Ays_CPT_FAQ',
'Ays_CPT_Location',
'Ays_CPT_Review',
'Ays_CPT_Service',
'Ays_CPT_Team',
];
#This is required if remove fatal error will occur
if ( ! defined( 'AYS_PLUGIN_PATH' ) ) {
define( 'AYS_PLUGIN_PATH', wp_normalize_path( plugin_dir_path( __FILE__ ) ) );
}
spl_autoload_register( function ( $class_name ) {
// Log the class name being attempted to load
error_log( "Autoloader: Attempting to load class $class_name" );
// Only autoload classes that start with 'Ays_'
if ( strpos( $class_name, 'Ays_' ) !== 0 ) {
@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
*/
<?php
/**
* Plugin Name: Your Plugin Name
* Description: Your plugin description.
* Version: 1.0.0
* Author: Your Name
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* @package YourPluginNamespace
👸🏻: Let's break down your ideas based on the **"Register and add settings page"** file you shared and explore ways to incorporate licensing, custom post types, and toggles on the settings page.
### Key Points from the File:
1. **Settings Page Structure**:
- You have a clear framework to add settings, which includes registering options, adding fields, and sanitizing input.
- This is an excellent base for further expansion.
2. **What You Want**:
- **Licensing/Key Registration**: You want a licensing system where you can store and validate a key.
- **Custom Post Types**: A section to manage custom post types.
<?php
/*
Plugin Name: Site Plugin
Description: Site-specific code with support for Gutenberg blocks
Author: Shaun Palmer
Author URI: https://yourwebsite.com/
*/
class SP_SitePlugin {
@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
*/