Skip to content

secondsky/claude-skills / plugins/wordpress-plugin-core/skills/wordpress-plugin-core

wordpress-plugin-core

Flagged

WordPress plugin development with hooks, security, REST API, custom post types. Use for plugin creation, $wpdb queries, Settings API, or encountering SQL injection, XSS, CSRF, nonce errors.

FileKindSize
SKILL.mdskill md17.9 KB
assets/example-template.txtmarkdown416 B
examples/github-updater.phpscript15.3 KB
references/advanced-topics.mdmarkdown16.6 KB
references/common-hooks.mdmarkdown2.7 KB
references/common-patterns.mdmarkdown13.1 KB
references/error-catalog.mdmarkdown16.3 KB
references/example-reference.mdmarkdown760 B
references/github-auto-updates.mdmarkdown30.3 KB
references/plugin-architectures.mdmarkdown21.0 KB
references/security-checklist.mdmarkdown11.7 KB
scripts/example-script.shexecutablescript302 B
scripts/scaffold-plugin.shexecutablescript9.0 KB
templates/examples/ajax-handler.phpscript8.0 KB
templates/examples/custom-post-type.phpscript9.5 KB
templates/examples/meta-box.phpscript6.3 KB
templates/examples/rest-endpoint.phpscript8.7 KB
templates/examples/settings-page.phpscript7.9 KB
templates/plugin-oop/README.mdmarkdown7.4 KB
templates/plugin-oop/my-oop-plugin.phpscript12.5 KB
templates/plugin-oop/uninstall.phpscript929 B
templates/plugin-oop/views/admin-settings.phpscript2.1 KB
templates/plugin-psr4/README.mdmarkdown9.7 KB
templates/plugin-psr4/composer.jsonconfig706 B
templates/plugin-psr4/my-psr4-plugin.phpscript1.7 KB
templates/plugin-psr4/src/API/BookEndpoints.phpscript5.3 KB
templates/plugin-psr4/src/Admin/Settings.phpscript5.1 KB
templates/plugin-psr4/src/Frontend/Assets.phpscript2.0 KB
templates/plugin-psr4/src/Plugin.phpscript2.4 KB
templates/plugin-psr4/src/PostTypes/Book.phpscript4.9 KB
templates/plugin-psr4/src/Taxonomies/Genre.phpscript1.9 KB
templates/plugin-psr4/uninstall.phpscript929 B
templates/plugin-simple/README.mdmarkdown4.6 KB
templates/plugin-simple/my-simple-plugin.phpscript7.4 KB
templates/plugin-simple/uninstall.phpscript1.3 KB

templates/plugin-psr4/src/Admin/Settings.php

View on GitHub
<?php
/**
 * Admin Settings
 *
 * @package MyPSR4Plugin\Admin
 */

namespace MyPSR4Plugin\Admin;

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Settings class
 */
class Settings {

	/**
	 * Single instance
	 *
	 * @var Settings
	 */
	private static $instance = null;

	/**
	 * Option name
	 *
	 * @var string
	 */
	const OPTION_NAME = 'mypp_settings';

	/**
	 * Get instance
	 *
	 * @return Settings
	 */
	public static function get_instance() {
		if ( null === self::$instance ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * Constructor
	 */
	private function __construct() {
		add_action( 'admin_menu', array( $this, 'add_menu_page' ) );
		add_action( 'admin_init', array( $this, 'register_settings' ) );
	}

	/**
	 * Add menu page
	 */
	public function add_menu_page() {
		add_options_page(
			__( 'My PSR-4 Plugin Settings', 'my-psr4-plugin' ),
			__( 'PSR-4 Plugin', 'my-psr4-plugin' ),
			'manage_options',
			'my-psr4-plugin',
			array( $this, 'render_settings_page' )
		);
	}

	/**
	 * Register settings
	 */
	public function register_settings() {
		register_setting(
			'mypp_settings_group',
			self::OPTION_NAME,
			array( $this, 'sanitize_settings' )
		);

		add_settings_section(
			'mypp_general_section',
			__( 'General Settings', 'my-psr4-plugin' ),
			array( $this, 'render_section_description' ),
			'my-psr4-plugin'
		);

		add_settings_field(
			'mypp_option1',
			__( 'Text Option', 'my-psr4-plugin' ),
			array( $this, 'render_text_field' ),
			'my-psr4-plugin',
			'mypp_general_section',
			array( 'field_id' => 'option1' )
		);

		add_settings_field(
			'mypp_option2',
			__( 'Number Option', 'my-psr4-plugin' ),
			array( $this, 'render_number_field' ),
			'my-psr4-plugin',
			'mypp_general_section',
			array( 'field_id' => 'option2' )
		);

		add_settings_field(
			'mypp_option3',
			__( 'Checkbox Option', 'my-psr4-plugin' ),
			array( $this, 'render_checkbox_field' ),
			'my-psr4-plugin',
			'mypp_general_section',
			array( 'field_id' => 'option3' )
		);
	}

	/**
	 * Render settings page
	 */
	public function render_settings_page() {
		if ( ! current_user_can( 'manage_options' ) ) {
			return;
		}

		?>
		<div class="wrap">
			<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
			<form method="post" action="options.php">
				<?php
				settings_fields( 'mypp_settings_group' );
				do_settings_sections( 'my-psr4-plugin' );
				submit_button( __( 'Save Settings', 'my-psr4-plugin' ) );
				?>
			</form>
		</div>
		<?php
	}

	/**
	 * Render section description
	 */
	public function render_section_description() {
		echo '<p>' . esc_html__( 'Configure your plugin settings below.', 'my-psr4-plugin' ) . '</p>';
	}

	/**
	 * Render text field
	 *
	 * @param array $args Field arguments.
	 */
	public function render_text_field( $args ) {
		$settings = $this->get_settings();
		$field_id = $args['field_id'];
		$value    = isset( $settings[ $field_id ] ) ? $settings[ $field_id ] : '';

		printf(
			'<input type="text" id="mypp_%1$s" name="%2$s[%1$s]" value="%3$s" class="regular-text" />',
			esc_attr( $field_id ),
			esc_attr( self::OPTION_NAME ),
			esc_attr( $value )
		);
	}

	/**
	 * Render number field
	 *
	 * @param array $args Field arguments.
	 */
	public function render_number_field( $args ) {
		$settings = $this->get_settings();
		$field_id = $args['field_id'];
		$value    = isset( $settings[ $field_id ] ) ? $settings[ $field_id ] : 0;

		printf(
			'<input type="number" id="mypp_%1$s" name="%2$s[%1$s]" value="%3$s" min="0" max="100" class="small-text" />',
			esc_attr( $field_id ),
			esc_attr( self::OPTION_NAME ),
			esc_attr( $value )
		);
	}

	/**
	 * Render checkbox field
	 *
	 * @param array $args Field arguments.
	 */
	public function render_checkbox_field( $args ) {
		$settings = $this->get_settings();
		$field_id = $args['field_id'];
		$value    = isset( $settings[ $field_id ] ) ? $settings[ $field_id ] : false;

		printf(
			'<input type="checkbox" id="mypp_%1$s" name="%2$s[%1$s]" value="1" %3$s />',
			esc_attr( $field_id ),
			esc_attr( self::OPTION_NAME ),
			checked( $value, true, false )
		);
	}

	/**
	 * Sanitize settings
	 *
	 * @param array $input Input array.
	 * @return array
	 */
	public function sanitize_settings( $input ) {
		$sanitized = array();

		if ( isset( $input['option1'] ) ) {
			$sanitized['option1'] = sanitize_text_field( $input['option1'] );
		}

		if ( isset( $input['option2'] ) ) {
			$sanitized['option2'] = absint( $input['option2'] );
		}

		if ( isset( $input['option3'] ) ) {
			$sanitized['option3'] = (bool) $input['option3'];
		}

		return $sanitized;
	}

	/**
	 * Get settings
	 *
	 * @return array
	 */
	public function get_settings() {
		$defaults = array(
			'option1' => '',
			'option2' => 0,
			'option3' => false,
		);

		$settings = get_option( self::OPTION_NAME, $defaults );

		return wp_parse_args( $settings, $defaults );
	}

	/**
	 * Set default settings on activation
	 */
	public function set_defaults() {
		if ( false === get_option( self::OPTION_NAME ) ) {
			add_option( self::OPTION_NAME, array(
				'option1' => '',
				'option2' => 0,
				'option3' => false,
			) );
		}
	}
}
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 468kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 468kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 468kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall