Wordpress Plugin Standards:
Header Requirements
Define Basic Constant value
/** * Plugin Name: Example Plugin * Plugin URI: https://example.com/plugins/the-basics/ * Description: Basic WordPress Plugin Header Comment * Version: 1.0.0 * Author: Chirag Prajapati * Author URI: https://chrgprajapati.blogspot.com * License: GPL2 * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Text Domain: example * Domain Path: /languages */
Define Basic Constant value
define( 'EX_VERSION', '1.0' ); define( 'EX_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); define( 'EX_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); define( 'EX_PLUGIN_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) ); define( 'EX_CONTENT_URL', content_url( ));Above five is basic but you can define the extra variable as you want. like,
define( 'EX_LOG_DIR', WP_CONTENT_DIR.'/uploads/ex_logs/'); define( 'EX_LOG_file', EX_LOG_DIR.'/ex_log.txt' );Call Required files
require_once EX_PLUGIN_DIR. '/ex_function.php';Activation / Deactivation Hooks
if ( !function_exists( 'ex_setup_post_type' ) ) { function ex_setup_post_type() { // register the "book" custom post type register_post_type( 'book', ['public' => 'true'] ); } } add_action( 'init', 'ex_setup_post_type' ); if ( !function_exists( 'ex_install' ) ) { function ex_install() { // trigger our function that registers the custom post type ex_setup_post_type(); // clear the permalinks after the post type has been registered flush_rewrite_rules(); } } register_activation_hook( EX_PLUGIN_BASENAME, 'ex_install' ); if ( !function_exists( 'ex_deactivation' ) ) { function ex_deactivation() { // unregister the post type, so the rules are no longer in memory unregister_post_type( 'book' ); // clear the permalinks to remove our post type's rules from the database flush_rewrite_rules(); } } register_deactivation_hook( EX_PLUGIN_BASENAME, 'ex_deactivation' );Folder Structure
/plugin-name plugin-name.php uninstall.php /languages /includes /admin /js /css /images /public /js /css /images
Thanks for sharing this information.
ReplyDeleteWhat is WordPress
"Thank you for breaking this down so well! This post is truly valuable."
ReplyDelete