[ 'enabled' => 1, 'toggle_above' => 0, ], 'data' => [ 'title' => 'Expand to read more', 'swaptitle' => 'Collapse to read less', 'icon' => '▼', 'swapicon' => '▲', ], 'style' => [ 'height' => '1px', 'fdheight' => '1px', ], ]; } /** * Get Collapse Magic options with defaults merged. * * Ensures a complete and valid options array is always returned. * Stored database values override defaults where present. * * @since 1.5.0 * * @return array Complete plugin options array. */ function claps_get_options() { $defaults = claps_default_options(); $stored = get_option('claps_options'); if ( ! is_array($stored) ) { return $defaults; } return array_replace_recursive($defaults, $stored); } /** * Check that a character code submitted is a valid html entity * @param $html_entity * @return false|int */ function claps_validate_dec_entity($html_entity) { // Regular expression pattern to match HTML entity values like 'XXXX;' $pattern = '/^[0-9]{1,6};$/i'; return preg_match($pattern, $html_entity); } /** * Validate a CSS height value. * Allows numeric values with common CSS units. * * @since 1.5.0 * * @param string $value Height value (e.g. 100px, 2em, 50%). * @return bool */ function claps_validate_height_value($value) { $pattern = '/^\d{1,5}(px|em|rem|vh|vw|%)$/'; return is_string($value) && preg_match($pattern, $value) === 1; } /** * Fetch the styles defined by the plugin and prepare these for a call from JS * - Not used in this version * @return void */ function claps_fetch_styles(){ $opts = claps_get_options(); $def = [ 'height'=>'200px', 'fdheight'=>'50px', ]; $styles = is_array($opts['style'])? array_merge($def,$opts['style']): $def; echo wp_json_encode($styles); wp_die(); //NB!! to prevent the whitespace error } /** * Create an input field based on the type provided. This has the functionality needed to render Bootstrap * consistent controls. * This is used on the Admin Options page only. * @param array $def * - type input field type (allowed types are 'text','number','range','date','datetime') * - name is the name of the input field * - value default value * - min minimum value * - max maximum value * - label control label to display * - placeholder (not used yet) * - div_class optional class name for the encapsulating div (no div if missing) * - control_class optional class name for the field control * - label_class optional class name for the field label * @param string $display - echo or return the html * @return string - return sting if $display is false */ function claps_input_field($def, $display=true){ $out = ''; $def = array_merge(array( 'type'=>'text', 'name'=>'', 'value'=>'', 'placeholder'=>'', 'min'=>null, 'max'=>null, 'label'=>null, 'div_class'=>'', 'control_class'=>'', 'label_class'=>'' ),$def); $def['type'] = in_array($def['type'],array('text','number','range','date','datetime','password'))? $def['type']: 'text'; if (strlen($def['name'])){ $out .= strlen($def['div_class'])? '
ERROR: Elements not defined for list
'; } } else { $out .= 'ERROR: Control name not specified'; } if ($display) echo wp_kses_post($out); else return $out; }