Skip to content

Instantly share code, notes, and snippets.

View shaunpalmer's full-sized avatar

shaun palmer shaunpalmer

View GitHub Profile

In this article I'm going to walk you through process of creating Wordpress plugins. First I'm going to talk about some of the basic concepts in Wordpress plugin development like the actions, hooks, and API's that makes up Wordpress. Then were going to build a plugin where we apply some of the concepts and best practices in developing Wordpress plugins.

###Prerequisites

In order to fully benefit from this tutorial you should have a basic knowledge on PHP. As Wordpress is running on PHP and most of the code that we will be writing will be on PHP. A little bit of knowledge on HTML, CSS and JavaScript is also helpful but not required for this tutorial.

@shaunpalmer
shaunpalmer / How to detect if a WordPress plugin is active.php
Created September 15, 2024 01:17 — forked from mlbd/How to detect if a WordPress plugin is active.php
A function you can use to check if plugin is active/loaded for your plugins/themes
<?php
/**
* Detect if a WordPress plugin is active
* A function you can use to check if plugin is active/loaded for your plugins/themes
* @link //gist.github.com/llgruff/c5666bfeded5de69b1aa424aa80cc14f
*/
// When coding plugins that rely on another one, like Private Content for bbPress or Visual Attributes for WooCommerce, you need to make if the WordPress Plugin is active to initialize your plugin routines or display a notice saying that the required plugin must be activated. In this tutorial we’ll see how to detect whether a certain plugin is active in a couple of ways.
## 1. Check whether a certain class or function or constant exists
@shaunpalmer
shaunpalmer / MyPlugin.php
Created September 15, 2024 02:04 — forked from rheinardkorf/MyPlugin.php
One approach to implement a class autoloader for WordPress plugin development. This file will for the most part be untouched once the structure is in place. The real development starts in the library folder.
<?php
/**
* @package MyPlugin
*/
//Before playing with this file, see the other file in the gist. Read the comments.
if( ! class_exists( 'MyPlugin' ) ) {
class MyPlugin {
@shaunpalmer
shaunpalmer / WordPress-Plugin-Template-Extra-Post-Info.php
Created September 15, 2024 02:08 — forked from rveitch/WordPress-Plugin-Template-Extra-Post-Info.php
A simple plugin starter template to add extra info to posts excerpt previews, after the excerpt-content.
<?php
/*
Plugin name: WordPress Plugin Template - Extra Post Info
Plugin URI: http://veitchdigital.com/
Description: A simple plugin starter template to add extra info to posts excerpt previews, after the excerpt-content.
Author: Ryan Veitch
Author http://veitchdigital.com/
Version: 0.1
*/
@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
* ====
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 / 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
}
@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 / 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 / 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
*/