项目作者: LayeredStudio

项目描述 :
WordPress plugin for controlling widget visibility
高级语言: PHP
项目地址: git://github.com/LayeredStudio/if-widget.git
创建时间: 2018-08-19T15:38:35Z
项目社区:https://github.com/LayeredStudio/if-widget

开源协议:GNU General Public License v3.0

下载


If Widget

If Widget is a WordPress plugin which adds extra functionality for widgets, making it easy to hide or display them based on visibility rules. Examples:

  • Display a widget only if current User is logged in
  • Hide widget if visiting from mobile device
  • Display widgets only for Admins and Editors

The plugin is easy to use, each widget will have a “Show widget only if” option which will enable the selection of visibility rules.

This repo is used only for development, downloading & installing from here won’t work as expected. Install from WordPress.org plugin page

Features

  • Basic set of visibility rules
    • User state User is logged in
    • User roles Admin Editor Author etc
    • Page type Front page Blog page
    • Post type Post Page Product etc
    • Device Is Mobile
  • Multiple rules - mix multiple rules for a widget visibility
    • show if User is logged in AND Device is mobile
    • show if User is Admin AND Is Front Fage
  • Support for adding custom visibility rules

Adding custom visibility rules in a plugin or theme

Custom visibility rules can be added easily by any plugin or theme.
Example of adding a new rule for displaying/hiding a widget when current page is a custom-post-type.

  1. // theme's functions.php or plugin file
  2. add_filter('if_visibility_rules', 'my_new_visibility_rule');
  3. function my_new_visibility_rule(array $rules) {
  4. $rules['single-my-custom-post-type'] = array(
  5. 'name' => __('Single my-CPT', 'i18n-domain'), // name of the condition
  6. 'callback' => function() { // callback - must return Boolean
  7. return is_singular('my-custom-post-type');
  8. }
  9. );
  10. return $rules;
  11. }

WordPress.org

Head over to plugin’s page on WordPress.org for more info, reviews and support.