Created
July 8, 2019 16:30
-
-
Save Artistan/26e65e5377d4410d63a53defeb40b3cb to your computer and use it in GitHub Desktop.
wordpress plugin example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://www.skyverge.com/blog/creating-custom-plugin-for-your-woocommerce-shop/ | |
// https://www.skyverge.com/blog/add-custom-code-to-wordpress/ | |
/** | |
* Plugin Name: [Insert Name] | |
* Plugin URI: [Insert Plugin URL] | |
* Description: [Insert Short Description] | |
* Author: [Insert Your Name] | |
* Author URI: [Insert Your URL] | |
* Version: 1.0 | |
* Text Domain: plugin-name | |
* | |
* Copyright: (c) 2012-2014 [Insert Your Name] ([email protected]) | |
* | |
* License: GNU General Public License v3.0 | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
* | |
* @author [Insert Your Name] | |
* @copyright Copyright (c) 2012-2014, [Insert Your Name] | |
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 | |
* | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
//Add your custom code below this line | |
class SkyvergeSamplePlugin { | |
public function __construct() { | |
// called just before the woocommerce template functions are included | |
add_action( 'init', array( $this, 'include_template_functions' ), 20 ); | |
// called only after woocommerce has finished loading | |
add_action( 'woocommerce_init', array( $this, 'woocommerce_loaded' ) ); | |
// called after all plugins have loaded | |
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); | |
// indicates we are running the admin | |
if ( is_admin() ) { | |
// ... | |
} | |
// indicates we are being served over ssl | |
if ( is_ssl() ) { | |
// ... | |
} | |
// take care of anything else that needs to be done immediately upon plugin instantiation, here in the constructor | |
} | |
/** | |
* Override any of the template functions from woocommerce/woocommerce-template.php | |
* with our own template functions file | |
*/ | |
public function include_template_functions() { | |
include( 'woocommerce-template.php' ); | |
} | |
/** | |
* Take care of anything that needs woocommerce to be loaded. | |
* For instance, if you need access to the $woocommerce global | |
*/ | |
public function woocommerce_loaded() { | |
// ... | |
} | |
/** | |
* Take care of anything that needs all plugins to be loaded | |
*/ | |
public function plugins_loaded() { | |
// ... | |
} | |
} | |
// finally instantiate our plugin class and add it to the set of globals | |
$GLOBALS['wc_acme'] = new WC_Acme(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment