| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 6.0 |
| 8 |
*/ |
| 9 |
class FrmHtmlHelper { |
| 10 |
|
| 11 |
/** |
| 12 |
* Create a toggle and either echo or return the string. |
| 13 |
* This is intended for use on admin pages only. The CSS is included in frm_admin.css. |
| 14 |
* |
| 15 |
* @since 6.0 |
| 16 |
* |
| 17 |
* @param string $id |
| 18 |
* @param string $name |
| 19 |
* @param array $args { |
| 20 |
* Any extra arguments. |
| 21 |
* |
| 22 |
* @type bool|null $echo True if you want the toggle to echo. False if you want it to return an HTML string. |
| 23 |
* } |
| 24 |
* |
| 25 |
* @return string|void |
| 26 |
*/ |
| 27 |
public static function toggle( $id, $name, $args ) { |
| 28 |
wp_enqueue_script( 'formidable_settings' ); |
| 29 |
return FrmAppHelper::clip( |
| 30 |
// @phpstan-ignore-next-line |
| 31 |
function () use ( $id, $name, $args ) { |
| 32 |
require FrmAppHelper::plugin_path() . '/classes/views/shared/toggle.php'; |
| 33 |
}, |
| 34 |
isset( $args['echo'] ) ? $args['echo'] : false |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Echo a dropdown option. |
| 40 |
* This is useful to avoid closing and opening PHP to echo <option> tags which leads to extra whitespace. |
| 41 |
* Avoiding whitespace saves 5KB of HTML for an international address field with a country dropdown with 252 options. |
| 42 |
* |
| 43 |
* @since 6.3.1 |
| 44 |
* |
| 45 |
* @param string $option The string used as the option label. |
| 46 |
* @param bool $selected True if the option should be selected. |
| 47 |
* @param array $params Other HTML params for the option. |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public static function echo_dropdown_option( $option, $selected, $params = array() ) { |
| 51 |
echo '<option '; |
| 52 |
FrmAppHelper::array_to_html_params( $params, true ); |
| 53 |
selected( $selected ); |
| 54 |
echo '>'; |
| 55 |
echo esc_html( $option === '' ? ' ' : $option ); |
| 56 |
echo '</option>'; |
| 57 |
} |
| 58 |
} |
| 59 |
|