PHPackages                             abuyoyo/cmb2-switch-button - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. abuyoyo/cmb2-switch-button

ActiveWordpress-plugin

abuyoyo/cmb2-switch-button
==========================

CMB2 Switch Button

1.2.2(5y ago)09731

Since Nov 19Pushed 5y agoCompare

[ Source](https://github.com/abuyoyo/CMB2-Switch-Button)[ Packagist](https://packagist.org/packages/abuyoyo/cmb2-switch-button)[ RSS](/packages/abuyoyo-cmb2-switch-button/feed)WikiDiscussions abuyoyo Synced today

READMEChangelog (3)DependenciesVersions (2)Used By (1)

CMB2 Switch Button Field Type
=============================

[](#cmb2-switch-button-field-type)

Custom Switch Button field type for CMB2 Metabox for WordPress.

Installation
------------

[](#installation)

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

Usage:
------

[](#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:
-----------

[](#screenshot)

[![](https://github.com/themevan/CMB2-Switch-Button/raw/master/example_screenshot.gif)](https://github.com/themevan/CMB2-Switch-Button/blob/master/example_screenshot.gif)

Follow us:
----------

[](#follow-us)

- Website:
- Facebook:
- Twitter:

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1999d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/973642e65a5584b10d7285df904ea7e52994714dab348eef12ec3bc9b5ad6cc5?d=identicon)[abuyoyo](/maintainers/abuyoyo)

---

Top Contributors

[![abuyoyo](https://avatars.githubusercontent.com/u/24979061?v=4)](https://github.com/abuyoyo "abuyoyo (6 commits)")[![IanDelMar](https://avatars.githubusercontent.com/u/42134098?v=4)](https://github.com/IanDelMar "IanDelMar (2 commits)")[![davelavoie](https://avatars.githubusercontent.com/u/3408028?v=4)](https://github.com/davelavoie "davelavoie (1 commits)")

### Embed Badge

![Health badge](/badges/abuyoyo-cmb2-switch-button/health.svg)

```
[![Health](https://phpackages.com/badges/abuyoyo-cmb2-switch-button/health.svg)](https://phpackages.com/packages/abuyoyo-cmb2-switch-button)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
