2017 © Pedro Peláez
 

library component-shortcode

Shortcode helper for WordPress

image

flexpress/component-shortcode

Shortcode helper for WordPress

  • Wednesday, August 20, 2014
  • by timperry
  • Repository
  • 1 Watchers
  • 0 Stars
  • 75 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FlexPress shortcode component

Install with Pimple

The Shortcode component uses two classes: - AbstractShortcode, which you extend to create a Shortcode. - ShortcodeHelper, which hooks into everything for you and registers the shortcodes., (*1)

Lets create a pimple config for both of these, (*2)

$pimple["documentLinkShortcode"] = function () {
  return new DocumentLink();
};

$pimple['ShortcodeHelper'] = function ($c) {
    return new ShortcodeHelper($c['objectStorage'], array(
        $c["documentLinkShortcode"]
    ));
};
  • Note the dependency $c['objectStorage'] is a SPLObjectStorage

Creating a concreate shortcode class

Create a concreate class that implements the AbstractShortcode class and implements the getName() and getCallback() methods., (*3)

class DocumentLink extends AbstractShortcode {

    public function getName()
    {
      return "document_link";
    }

    public function getCallback()
    {
      $link = func_get_arg(0);
      return '<a href="' . $link . '">Download document</a>';
    }

}

Public Methods

  • getName() - returns the name of the shortcode that will be used in the editor.
  • getCallback() - returns the markup of the shortcode.

ShortcodeHelper usage

Once you have setup the pimple config you are use the ShortcodeHelper like this, (*4)

$helper = $pimple['ShortcodeHelper'];
$helper->registerShortcodes();

That's it, the helper will then add all the needed hooks and register all the shortcodes you have provided it., (*5)

Public methods

  • registerShortcodes() - Registers the shortcodes provided.

The Versions

20/08 2014

dev-master

9999999-dev

Shortcode helper for WordPress

  Sources   Download

13/08 2014

v1.0.0

1.0.0.0

Shortcode helper for WordPress

  Sources   Download