| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.1.146 |
| 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\Base\Fields; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use FPFramework\Base\Field; |
| 20 |
use FPFramework\Libs\Registry; |
| 21 |
|
| 22 |
class Textarea extends Field |
| 23 |
{ |
| 24 |
/** |
| 25 |
* Set specific field options |
| 26 |
* |
| 27 |
* @param array $options |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
protected function setFieldOptions($options) |
| 32 |
{ |
| 33 |
$options = new Registry($options); |
| 34 |
|
| 35 |
$this->field_options = [ |
| 36 |
'mode' => $options->get('mode', null), |
| 37 |
'rows' => $options->get('rows'), |
| 38 |
'filter' => $options->get('filter', 'textarea') |
| 39 |
]; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Runs before field renders. |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function onBeforeRender() |
| 48 |
{ |
| 49 |
// Run only if a textarea mode is given |
| 50 |
if (!$mode = $this->options['mode']) |
| 51 |
{ |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
$mode = 'text/html'; |
| 56 |
|
| 57 |
if ($mode == 'php') |
| 58 |
{ |
| 59 |
$mode = 'application/x-httpd-php'; |
| 60 |
} |
| 61 |
else if ($mode == 'javascript') |
| 62 |
{ |
| 63 |
$mode = 'text/javascript'; |
| 64 |
} |
| 65 |
else if ($mode == 'css') |
| 66 |
{ |
| 67 |
$mode = 'text/css'; |
| 68 |
} |
| 69 |
|
| 70 |
// load code editor |
| 71 |
$settings = wp_enqueue_code_editor([ 'type' => 'text/html' ]); |
| 72 |
|
| 73 |
// Bail if user disabled CodeMirror |
| 74 |
if ( false === $settings ) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
// JS |
| 79 |
wp_register_script( |
| 80 |
'fpframework-textarea-field', |
| 81 |
FPF_MEDIA_URL . 'admin/js/fpf_textarea.js', |
| 82 |
[], |
| 83 |
FPF_VERSION, |
| 84 |
false |
| 85 |
); |
| 86 |
wp_enqueue_script('fpframework-textarea-field'); |
| 87 |
} |
| 88 |
} |