Download the PHP package wpfulcrum/shortcode without Composer
On this page you can find all versions of the php package wpfulcrum/shortcode. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wpfulcrum/shortcode
More information about wpfulcrum/shortcode
Files in wpfulcrum/shortcode
Package shortcode
Short Description Fulcrum Shortcode Module - WordPress shortcodes made easy.
License MIT
Homepage https://github.com/wpfulcrum/shortcode
Informations about the package shortcode
Shortcode Module
The Fulcrum Custom Shortcode Module makes your job easier for adding shortcodes to your project. Pass it a configuration, build your view file, and it handles the rest for you.
Features
- Registration is handled for you.
- Merges the user-defined atts with the defaults you specify, i.e. handles
shortcode_atts
for you. - Renders the view file you specify in the configuration.
- Use the built-in
Shortcode
class or specify a custom one within your configuration file. - Stores in Fulcrum's Container - when added, automatically stores it in the Container for global usage.
Installation
The best way to use this component is through Composer:
Dependencies
This module requires:
- at least PHP 5.6
- WordPress 4.8+
Configuring a Shortcode
This module, as with all Fulcrum modules, is configuration driven as part of the ModularConfig design pattern. In your theme/plugin's configuration folder, you will want to create a configuration file. Here is the basic structure of that file:
The View File
Shortcodes create HTML that is returned back for inclusion into the content that sent out to the browser. Create a view file for your shortcode.
Example: View File
Properties Available
The following properties are available for you to use within your view file:
$this->attributes
- Array of attributes after merging the user-defined with the defaults usingshortcode_atts
.$this->content
- The content passed into the shortcode, e.g.[foo]This is the content[/foo]
.
Methods Available
Some common shortcode attributes are id
and class
attributes. You can use the following methods to get either of these for your view:
$this->getId()
which escapes and returnsid="the-id"
.$this->getClass()
which escapes and returns the class attribute, e.g.foobar
. You can pass atrue
to it to add a space in front of the class attribute, e.g.$this->getClass()
returnsfoobar
.
Making It Work
There are 2 ways to utilize this module:
- With the full Fulcrum plugin.
- Or on its own without Fulcrum.
With Fulcrum
In Fulcrum, your plugin is an Add-on. In your plugin's configuration file, you will have a parameter for the serviceProviders
, where you list each of the service providers you want to use. In this case, you'll use the provider.post_type
.
For example, using our Book configuration above, this would be the configuration:
Without Fulcrum
Without Fulcrum, you'll need to instantiate each of the dependencies and Shortcode
. For example, you would do:
Contributing
All feedback, bug reports, and pull requests are welcome.