kunoichi / theme-customizer
A handy class for WordPress customizer settings.
Installs: 9 143
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.6
- hametuha/singleton-pattern: ^1.2
- hametuha/string-utility: ^1.2
- symfony/finder: ^5.4.0
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.0
- phpunit/phpunit: >=5.7
- squizlabs/php_codesniffer: ^3.3
- wp-coding-standards/wpcs: ^2.0
- yoast/phpunit-polyfills: ^1.0
README
A handy PHP class to integrate WordPress Theme Customizer.
Installation
composer require kunoichi/theme-customizer
In your theme's functions.php
:
require __DIR__ . '/vendor/autoload.php';
How to Implement
This library is an abstract class, so you have to implement it.
<?php namespace YourNameSpace\Customizer; use Kunoichi\ThemeCustomizer\CustomizerSetting; class YourClass extends CustomizerSetting { protected $section_id = 'your_custom_setting'; /** * Override this function to register a new section. */ protected function section_setting() { return [ 'title' => __( 'My Theme Setting', 'domain' ), 'priority' => 100, ]; } /** * Return associative array for each fields. * * @return array */ protected function get_fields(): array { return [ 'yoru_serrint_id' => [ 'label' => __( 'Ad after title', 'domain' ), 'stored' => 'option', // 'option' or 'theme_mod'(default) 'type' => 'textarea' // Type of UI. ], ]; } }
And you can call them in your theme's functions.php
.
YourNameSpace\Customizer\YourClass::get_instance();
Or, simply scan directory for convenience. Let's suppose that your theme is my-theme
and directory is PSR-0 ready like below:
my-theme
└src
└ MyBrand
└ MyTheme
└ Customizers
├ ColorSetting
└ AdSetting
You should call like this:
Kunoichi\ThemeCustomizer::register( 'YourBrand\YourTheme\Customizers' );
Arguments
$namespace
Your PSR-0 name space. Directory will be scan recursively.
$direcotry
If not set, default is get_template_directory() . '/src
, which seem to be a common location in theme development.
Predefined Classes
Some customizers are predefined for convenience.
See src/Kunoichi\ThemeCustomizer\Pattern
.
1. Meta and SEO
Kunoichi\ThemeCutomizer\Pattern\Seo
adds HTML meta information like meta-description, OGP, etc.
This customizer is userful to provide basic SEO features. For more advanced features, you should recommmend some plugins.
- Google Analytics or Google Tag Manager scirpt.
- Default and Site top OGP image.
- Top page description.
- Option to stop all feature(in plugins' favor).
2. Sharing
Kunoichi\ThemeCutomizer\Pattern\Share
adds share buttons for SNS. The only codes you should implement:
- Write code to display share buttons via
Kunoichi\ThemeCutomizer\Pattern\Share::render( $position )
Available services are listed in src/Kunoithi/ThemeCustomizer/Models/Brand
Development
wp-env is supported for instant development. You need node, npm, and docker installed.
# Install libraries. npm install # Start Container npm start # wp-env commands are available via npm. npm run env stop
License
GPL 3.0 or later.