Created
April 21, 2016 18:32
-
-
Save sftranna/2dae207cc9912f7b64fec88bacb7066d to your computer and use it in GitHub Desktop.
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
Here is my public file code | |
<?php | |
/** | |
* The public-facing functionality of the plugin. | |
* | |
* @link | |
* @since 1.0.0 | |
* | |
* @package plugin_name | |
* @subpackage plugin_name/public | |
*/ | |
/** | |
* The public-facing functionality of the plugin. | |
* | |
* Defines the plugin name, version, and two examples hooks for how to | |
* enqueue the admin-specific stylesheet and JavaScript. | |
* | |
* @package plugin_name | |
* @subpackage plugin_name/public | |
* @author Shahzeb <[email protected]> | |
*/ | |
class plugin_name_Public { | |
/** | |
* The ID of this plugin. | |
* | |
* @since 1.0.0 | |
* @access private | |
* @var string $plugin_name The ID of this plugin. | |
*/ | |
private $plugin_name; | |
/** | |
* The version of this plugin. | |
* | |
* @since 1.0.0 | |
* @access private | |
* @var string $version The current version of this plugin. | |
*/ | |
private $version; | |
/** | |
* Initialize the class and set its properties. | |
* | |
* @since 1.0.0 | |
* @param string $plugin_name The name of the plugin. | |
* @param string $version The version of this plugin. | |
*/ | |
public function __construct( $plugin_name, $version ) { | |
$this->plugin_name = $plugin_name; | |
$this->version = $version; | |
} | |
/** | |
* Register the stylesheets for the public-facing side of the site. | |
* | |
* @since 1.0.0 | |
*/ | |
public function enqueue_styles() { | |
/** | |
* This function is provided for demonstration purposes only. | |
* | |
* An instance of this class should be passed to the run() function | |
* defined in plugin_name_Loader as all of the hooks are defined | |
* in that particular class. | |
* | |
* The plugin_name_Loader will then create the relationship | |
* between the defined hooks and the functions defined in this | |
* class. | |
*/ | |
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/ec-authorizenet-public.css', array(), $this->version, 'all' ); | |
} | |
/** | |
* Register the JavaScript for the public-facing side of the site. | |
* | |
* @since 1.0.0 | |
*/ | |
public function enqueue_scripts() { | |
/** | |
* This function is provided for demonstration purposes only. | |
* | |
* An instance of this class should be passed to the run() function | |
* defined in plugin_name_Loader as all of the hooks are defined | |
* in that particular class. | |
* | |
* The plugin_name_Loader will then create the relationship | |
* between the defined hooks and the functions defined in this | |
* class. | |
*/ | |
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ec-authorizenet-public.js', array( 'jquery' ), $this->version, false ); | |
} | |
public function define_hooks() { | |
$this->loader->add_shortcode( "testShortcode", $this->plugin_name, "shortcode_function", $priority = 10, $accepted_args = 2 ); | |
} | |
/*public function shortcode_function() { | |
add_shortcode( 'nowhiring', array( $this, 'list_openings' ) ); | |
add_shortcode( 'nowhiring-howtoapply', array( $this, 'how_to_apply' ) ); | |
} // register_shortcodes()*/ | |
public function shortcode_function(){ | |
echo 'Test the plugin'; | |
} | |
} | |
and loader file is | |
<?php | |
/** | |
* Register all actions and filters for the plugin | |
* | |
* @link http://ecarobar.com/ | |
* @since 1.0.0 | |
* | |
* @package plugin_name | |
* @subpackage plugin_name/includes | |
*/ | |
/** | |
* Register all actions and filters for the plugin. | |
* | |
* Maintain a list of all hooks that are registered throughout | |
* the plugin, and register them with the WordPress API. Call the | |
* run function to execute the list of actions and filters. | |
* | |
* @package plugin_name | |
* @subpackage plugin_name/includes | |
* @author Shahzeb <[email protected]> | |
*/ | |
class plugin_name_Loader { | |
/** | |
* The array of actions registered with WordPress. | |
* | |
* @since 1.0.0 | |
* @access protected | |
* @var array $actions The actions registered with WordPress to fire when the plugin loads. | |
*/ | |
protected $actions; | |
/** | |
* The array of filters registered with WordPress. | |
* | |
* @since 1.0.0 | |
* @access protected | |
* @var array $filters The filters registered with WordPress to fire when the plugin loads. | |
*/ | |
protected $filters; | |
/** | |
* The array of shortcodes registered with WordPress. | |
* | |
* @since 1.0.0 | |
* @access protected | |
* @var array $shortcodes The shortcodes registered with WordPress to fire when the plugin loads. | |
*/ | |
protected $shortcodes; | |
/** | |
* Initialize the collections used to maintain the actions and filters. | |
* | |
* @since 1.0.0 | |
*/ | |
public function __construct() { | |
$this->actions = array(); | |
$this->filters = array(); | |
$this->shortcodes = array(); | |
} | |
/** | |
* Add a new action to the collection to be registered with WordPress. | |
* | |
* @since 1.0.0 | |
* @param string $hook The name of the WordPress action that is being registered. | |
* @param object $component A reference to the instance of the object on which the action is defined. | |
* @param string $callback The name of the function definition on the $component. | |
* @param int $priority Optional. he priority at which the function should be fired. Default is 10. | |
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. | |
*/ | |
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { | |
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); | |
} | |
/** | |
* Add a new filter to the collection to be registered with WordPress. | |
* | |
* @since 1.0.0 | |
* @param string $hook The name of the WordPress filter that is being registered. | |
* @param object $component A reference to the instance of the object on which the filter is defined. | |
* @param string $callback The name of the function definition on the $component. | |
* @param int $priority Optional. he priority at which the function should be fired. Default is 10. | |
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 | |
*/ | |
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { | |
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); | |
} | |
/** | |
* Add a new shortcode to the collection to be registered with WordPress | |
* | |
* @since 1.0.0 | |
* @param string $tag The name of the new shortcode. | |
* @param object $component A reference to the instance of the object on which the shortcode is defined. | |
* @param string $callback The name of the function that defines the shortcode. | |
*/ | |
public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 2 ) { | |
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, $priority, $accepted_args ); | |
} | |
/** | |
* A utility function that is used to register the actions and hooks into a single | |
* collection. | |
* | |
* @since 1.0.0 | |
* @access private | |
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters). | |
* @param string $hook The name of the WordPress filter that is being registered. | |
* @param object $component A reference to the instance of the object on which the filter is defined. | |
* @param string $callback The name of the function definition on the $component. | |
* @param int $priority The priority at which the function should be fired. | |
* @param int $accepted_args The number of arguments that should be passed to the $callback. | |
* @return array The collection of actions and filters registered with WordPress. | |
*/ | |
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { | |
$hooks[] = array( | |
'hook' => $hook, | |
'component' => $component, | |
'callback' => $callback, | |
'priority' => $priority, | |
'accepted_args' => $accepted_args | |
); | |
return $hooks; | |
} | |
/** | |
* Register the filters and actions with WordPress. | |
* | |
* @since 1.0.0 | |
*/ | |
public function run() { | |
foreach ( $this->filters as $hook ) { | |
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); | |
} | |
foreach ( $this->actions as $hook ) { | |
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); | |
} | |
foreach ( $this->shortcodes as $hook ) { | |
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
multiple shortcodes wont work