wpfulcrum/shortcode
Composer 安装命令:
composer require wpfulcrum/shortcode
包简介
Fulcrum Shortcode Module - WordPress shortcodes made easy.
关键字:
README 文档
README
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_attsfor you. - Renders the view file you specify in the configuration.
- Use the built-in
Shortcodeclass 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:
composer require wpfulcrum/shortcode
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:
<?php return [ /** * Defines whether the shortcode should autoload when registering with Fulcrum. * * Default is true. */ 'autoload' => true, /** * If you'd like to build your own shortcode class, specify the class name here, such as: * * Fulcrum\Custom\Shortcode\Shortcode * * By default, it will use the built-in Shortcode class. */ 'classname' => '', 'config' => [ /** * Specify the name of the shortcode. This is the "tag" which is used in the content as: [foo]. */ 'shortcode' => 'foo', /** * Set this parameter to `true` when no view file is needed for this shortcode. */ 'noView' => false, /** * Specify the absolute path to this shortcode's view file. * The view file contains the HTML that is built for this shortcode. */ 'view' => __DIR__ . '/views/foo.php', /** * Specify the default attributes for this shortcode. */ 'defaults' => [ 'class' => 'foobar', ], ], ];
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
<p class="<?php echo $this->getClass(); ?>"><?php echo $this->content; ?></p>
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 atrueto 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:
'serviceProviders' => [
/****************************
* Custom Post Types
****************************/
'foo.shortcode' => array(
'provider' => 'provider.shortcode', // this is the service provider to be used.
'config' => FOO_PLUGIN_DIR . 'config/shortcode/foo.php', // path to the shortcode's configuration file.
),
],
Without Fulcrum
Without Fulcrum, you'll need to instantiate each of the dependencies and Shortcode. For example, you would do:
new Shortcode(
ConfigFactory::create(FOO_PLUGIN_DIR . 'config/shortcode/foo.php'), // path to the shortcode's configuration file.
);
Contributing
All feedback, bug reports, and pull requests are welcome.
wpfulcrum/shortcode 适用场景与选型建议
wpfulcrum/shortcode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「shortcode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wpfulcrum/shortcode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wpfulcrum/shortcode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wpfulcrum/shortcode 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Use Wordpress like Shortcodes within the Text Editor of Shopware
A WordPress Plugin for adding SalesVu store 'widgets' (iframes) to your website with a simple Shortcode.
Custom shortcodes for Shortcodable module
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
Adds shortcodes for inserting YouTube and Vimeo videos.
Creates a shortcode block to test if a user is logged in or not and render content as desired.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-22