abuyoyo/cmb2-switch-button 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

abuyoyo/cmb2-switch-button

Composer 安装命令:

composer require abuyoyo/cmb2-switch-button

包简介

CMB2 Switch Button

README 文档

README

Custom Switch Button field type for CMB2 Metabox for WordPress.

Installation

You can install it as a plugin, or include the main file into your theme or plugin folder.

Usage:

add_action( 'cmb2_admin_init', 'create_your_metabox' );
if(!function_exists('create_your_metabox')){
  function create_your_metabox(){
    $prefix = '_slug_';

    $cmb2_metabox = new_cmb2_box( array(
        'id'            => $prefix . 'test_metabox',
        'title'         => esc_html__( 'Test Metabox', 'tmv' ),
        'object_types'  => array( 'page'), // Post type
        'priority'   => 'high',
        'context'    => 'normal',
    ) );

    $cmb2_metabox->add_field( array(
        'name'             => esc_html__( 'Dynamically Load', 'text-domain' ),
        'id'               => $prefix . 'metabox_id',
        'desc'             => esc_html__('','text-domain'),
        'type'	           => 'switch',
        'default'          => true, //If it's checked by default 
        'active_value'     => true,
        'inactive_value'   => false
    ) );
  }
}
  • If you set the active_value and inactive_value to a boolean value such as 1/0, true/false, just use it as below
$test_meta = get_post_meta($post->ID, '_slug_metabox_id', true);

if($test_meta){
  //Do something when it's checked;
}
  • If you set the active_value and inactive_value to the specific value other than the boolean value, let's say enable/disable, you can use it as:
$test_meta = get_post_meta($post->ID, '_slug_metabox_id', true);

if($test_meta === 'enable'){
  //Do something when it's checked;
}else{
  //Do something when it's unchecked;
}

Screenshot:

Follow us:

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-11-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固