如何给你的主题集成小宇宙插件

如果你需要给你的主题集成小宇宙插件,那么你可以参照一下以下这两个步骤。

1.再functions.php头部引用我封装好的小宇宙安装文件,点击下载

include 'PATH_TO_XYZ_INSTALL/xyz-install.php';

2.用定义好的$xyz_status变量来判断小宇宙插件的状态。

if($xyz_status) {

// 原functions.php的内容

}

下面我们再举个例子,这是叶神UIGREAT主题的functions.php里面原有的代码

 if ( ! function_exists( '_ug' ) ) {
        function _ug( $option = '', $default = null ) {
            $options = get_option( 'ug' ); // Attention: Set your unique id of the framework
            return ( isset( $options[$option] ) ) ? $options[$option] : $default;
        }
    }
    /*
     * --------------------------------------------------------------------
     * 加载功能
     * --------------------------------------------------------------------
     */
    require_once(dirname(__FILE__) . '/inc/functions/enqueue.php');
    require_once(dirname(__FILE__) . '/inc/functions/optimization.php');
    require_once(dirname(__FILE__) . '/inc/functions/article.php');
    require_once(dirname(__FILE__) . '/inc/functions/category.php');
    require_once(dirname(__FILE__) . '/inc/functions/user.php');
    require_once(dirname(__FILE__) . '/inc/functions/other.php');
    require_once(dirname(__FILE__) . '/inc/functions/login-options.php');
    require_once(dirname(__FILE__) . '/inc/functions/comment.php');
    require_once(dirname(__FILE__) . '/inc/functions/setting.php');

我们把xyz-install.php放在了主题的inc目录下,然后将functions.php改为了

include 'inc/xyz-install.php';

if($xyz_status) {

    if ( ! function_exists( '_ug' ) ) {
        function _ug( $option = '', $default = null ) {
            $options = get_option( 'ug' ); // Attention: Set your unique id of the framework
            return ( isset( $options[$option] ) ) ? $options[$option] : $default;
        }
    }
    /*
     * ------------------------------------------------------------------------------
     * 加载功能
     * ------------------------------------------------------------------------------
     */
    require_once(dirname(__FILE__) . '/inc/functions/enqueue.php');
    require_once(dirname(__FILE__) . '/inc/functions/optimization.php');
    require_once(dirname(__FILE__) . '/inc/functions/article.php');
    require_once(dirname(__FILE__) . '/inc/functions/category.php');
    require_once(dirname(__FILE__) . '/inc/functions/user.php');
    require_once(dirname(__FILE__) . '/inc/functions/other.php');
    require_once(dirname(__FILE__) . '/inc/functions/login-options.php');
    require_once(dirname(__FILE__) . '/inc/functions/comment.php');
    require_once(dirname(__FILE__) . '/inc/functions/setting.php');

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注