wpfulcrum/shortcode 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wpfulcrum/shortcode

Composer 安装命令:

composer require wpfulcrum/shortcode

包简介

Fulcrum Shortcode Module - WordPress shortcodes made easy.

README 文档

README

Build Status Latest Stable Version License

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:

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 using shortcode_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 returns id="the-id".
  • $this->getClass() which escapes and returns the class attribute, e.g. foobar. You can pass a true to it to add a space in front of the class attribute, e.g. $this->getClass() returns foobar.

Making It Work

There are 2 ways to utilize this module:

  1. With the full Fulcrum plugin.
  2. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 wpfulcrum/shortcode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-22