承接 innocode-digital/wp-assets-version 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

innocode-digital/wp-assets-version

最新稳定版本:1.1.0

Composer 安装命令:

composer require innocode-digital/wp-assets-version

包简介

Helps with versioning of CSS and JS files.

README 文档

README

Description

Helps with versioning of CSS and JS files. Plugin adds flush buttons to admin area for version upgrading. Requires Flush Cache Buttons plugin.

Install

  • Preferable way is to use Composer:

    composer require innocode-digital/wp-assets-version
    

    By default, it will be installed as Must Use Plugin. It's possible to control with extra.installer-paths in composer.json.

  • Alternate way is to clone this repo to wp-content/mu-plugins/ or wp-content/plugins/:

    cd wp-content/plugins/
    git clone git@github.com:innocode-digital/wp-assets-version.git
    cd wp-assets-version/
    composer install
    

If plugin was installed as regular plugin then activate Assets Version from Plugins page or WP-CLI: wp plugin activate wp-assets-version.

Usage

There are known functions wp_enqueue_script and wp_enqueue_style in WordPress core to register and enqueue scripts and styles. In both of them 4th parameter is for version number and in ideal case it should be version of build or theme or null with some version hash in filename ... but sometimes it's hard to implement or there are could be particular issues in caching, and it's where this plugin becomes as a good hotfix. There are few ways to add version with this plugin:

  • Retrieve version through function innocode_assets_version() and set as 4th parameter in enqueue functions, e.g.:

    $ver = function_exists( 'innocode_assets_version' ) ? innocode_assets_version() : false;
    
    wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
    
  • Force using of version where null set as 4th parameter:

    add_filter( 'innocode_assets_version_allow_default', '__return_true' );
    
  • Force using of version but with own logic per dependency (requires previous hook to be set), e.g.:

    /**
     * @param bool $allow
     * @param string $type - One of [ 'script', 'style' ].
     * @param _WP_Dependency $dependency
     */
    add_filter( 'innocode_assets_version_allow_dependency', function ( bool $allow, string $type, _WP_Dependency $dependency ) {
        // @TODO: implement logic
    
        return $allow;
    }, 20, 3 );
    

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2021-08-12