PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.3
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.3
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / libraries / size-field-type.php

size-field-type.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 8.0.3, at libraries/size-field-type.php

85 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CMB2 Size Field Type
4 *
5 * @package GamiPress|CMB2_Size_Field_Type
6 */
7
8 if( ! function_exists( 'cmb2_render_size_field_type' ) ) :
9
10 /**
11 * Adds a custom field type for dimension sizes.
12 *
13 * @param object $field The CMB2_Field type object.
14 * @param string $value The saved (and escaped) value.
15 * @param int $object_id The current post ID.
16 * @param string $object_type The current object type.
17 * @param CMB2_Types $field_type The CMB2_Types object.
18 *
19 * @return void
20 */
21 function cmb2_render_size_field_type( $field, $value, $object_id, $object_type, $field_type ) {
22
23 // Make sure we specify each part of the value we need.
24 $value = wp_parse_args( $value, array(
25 'width' => 100,
26 'height' => 100,
27 ) ); ?>
28
29 <div class="cmb-inline">
30 <ul>
31 <li>
32 <label for="<?php echo $field_type->_id( '_width' ); ?>"><?php _e( 'Width:', 'gamipress' ); ?> </label>
33 <?php echo $field_type->input( array(
34 'name' => $field_type->_name( '[width]' ),
35 'id' => $field_type->_id( '_width' ),
36 'value' => $value['width'],
37 'desc' => '',
38 'type' => 'number',
39 'step' => 1,
40 'min' => 0,
41 'class' => 'small-text',
42 ) ); ?>
43 </li>
44 <li>
45 <label for="<?php echo $field_type->_id( '_height' ); ?>"><?php _e( 'Height:', 'gamipress' ); ?> </label>
46 <?php echo $field_type->input( array(
47 'name' => $field_type->_name( '[height]' ),
48 'id' => $field_type->_id( '_height' ),
49 'value' => $value['height'],
50 'desc' => '',
51 'type' => 'number',
52 'step' => 1,
53 'min' => 0,
54 'class' => 'small-text',
55 ) ); ?>
56 </li>
57 </ul>
58 </div>
59 <?php
60
61 echo $field_type->_desc( true );
62 }
63 add_action( 'cmb2_render_size', 'cmb2_render_size_field_type', 10, 5 );
64
65
66 /**
67 * Sanitize the selected value.
68 */
69 function cmb2_sanitize_size_callback( $override_value, $value ) {
70
71 if ( is_array( $value ) ) {
72
73 foreach ( $value as $key => $saved_value ) {
74 $value[$key] = sanitize_text_field( $saved_value );
75 }
76
77 return $value;
78 }
79
80 return $override_value;
81 }
82 add_filter( 'cmb2_sanitize_size', 'cmb2_sanitize_size_callback', 10, 2 );
83
84 endif;
85