wptrt / customize-section-button
WordPress自定义器的按钮部分。
1.0.1
2019-07-01 16:39 UTC
Requires
- php: >=5.6
- dev-master
- 1.0.x-dev
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-and-express-6.11.0
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-and-loader-utils-and-webpack-cli-1.4.2
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/ajv-6.12.6
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/ws-6.2.2
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/ssri-6.0.2
- dev-dependabot/npm_and_yarn/y18n-4.0.1
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.7
This package is auto-updated.
Last update: 2024-09-04 05:00:29 UTC
README
这是一个WordPress自定义器的自定义部分类,允许主题作者创建一个具有“按钮”的部分。其主要目的是提供一个在自定义器中创建“专业”或“升级销售”部分的标准方法。然而,从技术上讲,它也可以用来链接到任何地方。
用法
以下代码应集成到您主题现有的自定义器代码中。
// Use statements must come after the `namespace` statement at the top of the // file but before any other code. use WPTRT\Customize\Section\Button; // Register the "button" section. add_action( 'customize_register', function( $manager ) { $manager->register_section_type( Button::class ); $manager->add_section( new Button( $manager, 'themeslug_pro', [ 'title' => __( 'ThemeName Pro', 'themeslug' ), 'button_text' => __( 'Go Pro', 'themeslug' ), 'button_url' => 'http://example.com' ] ) ); } );
参数
“按钮”部分接受与正常“WP_Customize_Section”相同的所有参数。但是,增加了两个额外的参数。
'button_text'
- 显示在部分按钮中的文本。默认为活动主题名称。'button_url'
- 用于部分按钮的URL。回退到“主题URI”或“作者URI”。
加载所需的CSS和JS
CSS和JS文件的开发版本和生产版本都可用。
为了避免加载额外的资源,我们鼓励主题作者将以下文件导入他们的自定义CSS和JS构建过程中
/path/to/customize-section-button/resources/js/customize-controls.js
/path/to/customize-section-button/resources/scss/customize-controls.scss
.
但是,如果您决定直接排入生产资源,请将以下内容集成到您的自定义器代码中。
// Load the JS and CSS. add_action( 'customize_controls_enqueue_scripts', function() { $version = wp_get_theme()->get( 'Version' ); wp_enqueue_script( 'wptrt-customize-section-button', get_theme_file_uri( 'path/to/customize-section-button/public/js/customize-controls.js' ), [ 'customize-controls' ], $version, true ); wp_enqueue_style( 'wptrt-customize-section-button', get_theme_file_uri( 'path/to/customize-section-button/public/css/customize-controls.css' ), [ 'customize-controls' ], $version ); } );
自动加载
您需要使用自动加载器。理想情况下,这将是一个Composer。但是,我们有一个基本的自动加载器可用于与主题一起使用,如果需要的话。
Composer
从命令行
composer require wptrt/customize-section-button
WPTRT自动加载器
如果您使用WPTRT自动加载器,请使用以下代码
include get_theme_file_path( 'path/to/autoload/src/Loader.php' ); $loader = new \WPTRT\Autoload\Loader(); $loader->add( 'WPTRT\\Customize\\Section', get_theme_file_path( 'path/to/customize-section-button/src' ) ); $loader->register();