WordPress Plugin Starter Comments

, , ,

Here is the minimum comment that you need for a plugin to be recognized.

<?php /* Plugin Name: Example Plugin */

 

Here is the a sample of a plugin with more of the information that is recommended along with some of the default activation calls.


<?php

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

/**
 * @package Some-Plugin-Name
 */

/*
  Plugin Name: Some Plugin
  Plugin URI: https://wpcms.ninja
  Description: Some Plugin Description
  Version: 1
  Author: WP CMS Ninja
  Author URI: https://wpcms.ninja
  License: GPLv2 or later
  Text Domain: some_plugin
 */

define("SOME_PLUGIN_PATH", plugin_dir_path( __FILE__ ));
define('SOME_PLUGIN_BASENAME',   plugin_basename( __FILE__ ));

 /* Runs on Plugin activation */
 register_activation_hook(__FILE__,'some_plugin_install'); 
 function some_plugin_install() {
  some_plugin_db_sync();
  update_option( "some_plugin_Version", "1");
  set_transient( 'some_plugin_activated', 1 );
 }
 
 /* Runs on plugin deactivation */
 register_deactivation_hook( __FILE__, 'some_plugin_deactivate' );
 function some_plugin_deactivate() {
  set_transient( 'some_plugin_deactivated', 1 );
  
 }
 
 /* Runs on plugin uninstall */
 register_uninstall_hook( __FILE__,  'some_plugin_uninstall');
 function some_plugin_uninstall() {
  some_plugin_db_removal(); //can see this function in another one of my code snippets
  delete_option("some_plugin_Version");
 
  delete_transient( 'some_plugin_updated' );
  delete_transient( 'some_plugin_activated' );
 }

 

Skills

Posted on

April 24, 2017

Submit a Comment

Your email address will not be published. Required fields are marked *