Skip to content
Justin Sternberg edited this page Mar 21, 2016 · 7 revisions

Getting Started

If you're using our WordPress Plugin Generator you're halfway there! So let's get started shall we?

Setting up your shortcodes

With WDS-Shortcodes, each shortcode is comprised of two files; one for the front-end, and one to handle the admin stuffs. What you name them is totally up to you, but we like to keep it logical, so we tend to use {shortcode}-shortcode.php and for the admin - {shortcode}-shortcode-admin.php

If you're using the plugin generator, you'll need to prefix your file with class- and drop hem into your includes/ folder of the plugin.

Now, setting up the files takes a bit and warrants their own respective pages on the wiki, so here ya go:

Initializing the Classes

Once you've set those two files up ( per-shortcode ) you'll want to include them in your setup and initialize the classes individually, below is an example:

/**
 * Attach other plugin classes to the base plugin class.
 *
 * @since  0.1.0
 * @return void
 */
public function initalize_shortcode_button() {
	// Attach other plugin classes to the base plugin class.
	// $this->plugin_class = new WDSCPN_Plugin_Class( $this );

	$this->test_shortcode = new WDSCPN_Test_Shortcode();
	$this->test_shortcode_admin = new WDSCPN_Test_Shortcode_Admin(
		$this->test_shortcode->shortcode,
		self::VERSION,
		$this->test_shortcode->atts_defaults
	);
}

NOTE: If you are using the plugin generator you'll want to initialize these in the hooks() method, not in the plugin_classes() method.

The Hooks

Each parent class has a hooks method, without firing these, the plugin simply won't work. To do this, you will need to fire them, example below:

/**
 * Add hooks and filters
 *
 * @since  0.1.0
 * @return void
 */
public function hooks() {
	register_activation_hook( __FILE__, array( $this, '_activate' ) );
	register_deactivation_hook( __FILE__, array( $this, '_deactivate' ) );

	add_action( 'init', array( $this, 'init' ) );

	$this->initalize_shortcode_button();

	$this->test_shortcode->hooks();
	$this->test_shortcode_admin->hooks();
}

Hint: If you're looking to get a head start, check out the demo plugin, "Cool Shortcode".

Clone this wiki locally