| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.2.6 |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Helpers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class HTML |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Generates a FPToggle input |
| 23 |
* |
| 24 |
* @param string $atts |
| 25 |
* |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
public static function renderFPToggle($atts) |
| 29 |
{ |
| 30 |
if (!$atts && !is_array($atts)) |
| 31 |
{ |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$class = '\FPFramework\Base\Fields\FPToggle'; |
| 36 |
|
| 37 |
$options = [ |
| 38 |
'type' => 'FPToggle', |
| 39 |
'render_group' => false |
| 40 |
]; |
| 41 |
|
| 42 |
$options = array_merge($options, $atts); |
| 43 |
|
| 44 |
$field = new $class($options); |
| 45 |
|
| 46 |
ob_start(); |
| 47 |
$field->render(); |
| 48 |
$html = ob_get_contents(); |
| 49 |
ob_end_clean(); |
| 50 |
|
| 51 |
return $html; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Renders a heading |
| 56 |
* |
| 57 |
* @param array $atts |
| 58 |
* |
| 59 |
* @return string |
| 60 |
*/ |
| 61 |
public static function renderHeading($atts) |
| 62 |
{ |
| 63 |
if (!$atts && !is_array($atts)) |
| 64 |
{ |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
$class = '\FPFramework\Base\Fields\Heading'; |
| 69 |
|
| 70 |
$options = [ |
| 71 |
'type' => 'Heading', |
| 72 |
'render_group' => false |
| 73 |
]; |
| 74 |
|
| 75 |
$options = array_merge($options, $atts); |
| 76 |
|
| 77 |
$field = new $class($options); |
| 78 |
|
| 79 |
ob_start(); |
| 80 |
$field->render(); |
| 81 |
$html = ob_get_contents(); |
| 82 |
ob_end_clean(); |
| 83 |
|
| 84 |
return $html; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Renders the opening of a div |
| 89 |
* |
| 90 |
* @param array $atts |
| 91 |
* |
| 92 |
* @return string |
| 93 |
*/ |
| 94 |
public static function renderStartDiv($atts) |
| 95 |
{ |
| 96 |
if (!$atts && !is_array($atts)) |
| 97 |
{ |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
$class = '\\FPFramework\\Base\\Fields\\CustomDiv'; |
| 102 |
|
| 103 |
$options = ['type' => 'CustomDiv']; |
| 104 |
$options = array_merge($options, $atts); |
| 105 |
|
| 106 |
$field = new $class($options); |
| 107 |
|
| 108 |
ob_start(); |
| 109 |
$field->render(); |
| 110 |
$html = ob_get_contents(); |
| 111 |
ob_end_clean(); |
| 112 |
|
| 113 |
return $html; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Renders the closing of a div |
| 118 |
* |
| 119 |
* @return string |
| 120 |
*/ |
| 121 |
public static function renderEndDiv() |
| 122 |
{ |
| 123 |
$class = '\\FPFramework\\Base\\Fields\\CustomDiv'; |
| 124 |
|
| 125 |
$options = [ |
| 126 |
'type' => 'CustomDiv', |
| 127 |
'position' => 'end' |
| 128 |
]; |
| 129 |
|
| 130 |
$field = new $class($options); |
| 131 |
|
| 132 |
ob_start(); |
| 133 |
$field->render(); |
| 134 |
$html = ob_get_contents(); |
| 135 |
ob_end_clean(); |
| 136 |
|
| 137 |
return $html; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Renders a modal. |
| 142 |
* |
| 143 |
* @param array $payload |
| 144 |
* @param boolean $return |
| 145 |
* |
| 146 |
* @return mixed |
| 147 |
*/ |
| 148 |
public static function renderModal($payload = [], $return = false) |
| 149 |
{ |
| 150 |
if (!$payload && !is_array($payload)) |
| 151 |
{ |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
if (!is_bool($return)) |
| 156 |
{ |
| 157 |
return; |
| 158 |
} |
| 159 |
|
| 160 |
// JS |
| 161 |
wp_register_script( |
| 162 |
'fpframework-modal', |
| 163 |
FPF_MEDIA_URL . 'admin/js/fpf_modal.js', |
| 164 |
[], |
| 165 |
FPF_VERSION, |
| 166 |
true |
| 167 |
); |
| 168 |
wp_enqueue_script('fpframework-modal'); |
| 169 |
|
| 170 |
if ($return) |
| 171 |
{ |
| 172 |
return fpframework()->renderer->admin->render('modal', $payload, $return); |
| 173 |
} |
| 174 |
|
| 175 |
fpframework()->renderer->admin->render('modal', $payload); |
| 176 |
} |
| 177 |
} |