RWMB_Checkbox_Field

The Evolved RWMB Checkbox Field class.

Defined (1)

The class is defined in the following location(s).

/meta-box/inc/fields/checkbox.php  
  1. class RWMB_Checkbox_Field  
  2. /** 
  3. * Get field HTML 
  4. * @param string $html 
  5. * @param mixed $meta 
  6. * @param array $field 
  7. * @return string 
  8. */ 
  9. static function html( $html, $meta, $field ) 
  10. $checked = checked( ! empty( $meta ), true, false ); 
  11. $name = "name='{$field['field_name']}'"; 
  12. $id = " id='{$field['id']}'"; 
  13. $html = "<input type='checkbox' class='rwmb-checkbox'{$name}{$id}{$checked} />"; 
  14.  
  15. return $html; 
  16.  
  17. /** 
  18. * Set the value of checkbox to 1 or 0 instead of 'checked' and empty string 
  19. * This prevents using default value once the checkbox has been unchecked 
  20. * @link https://github.com/rilwis/meta-box/issues/6 
  21. * @param mixed $new 
  22. * @param mixed $old 
  23. * @param int $post_id 
  24. * @param array $field 
  25. * @return int 
  26. */ 
  27. static function value( $new, $old, $post_id, $field )  
  28. return empty( $new ) ? 0 : 1;