| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* WP Editor Control |
| 5 |
* |
| 6 |
* Main options: |
| 7 |
* name => a name of the control |
| 8 |
* value => a value to show in the control |
| 9 |
* default => a default value of the control if the "value" option is not specified |
| 10 |
* tinymce => an array of options for tinymce |
| 11 |
* @link http://codex.wordpress.org/Function_Reference/wp_editor |
| 12 |
* |
| 13 |
* @author Alex Kovalev <alex.kovalevv@gmail.com> |
| 14 |
* @copyright (c) 2018, Webcraftic Ltd |
| 15 |
* |
| 16 |
* @package factory-forms |
| 17 |
* @since 1.0.0 |
| 18 |
*/ |
| 19 |
|
| 20 |
// Exit if accessed directly |
| 21 |
if( !defined('ABSPATH') ) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
if( !class_exists('Wbcr_FactoryForms420_WpEditorControl') ) { |
| 26 |
|
| 27 |
class Wbcr_FactoryForms420_WpEditorControl extends Wbcr_FactoryForms420_Control { |
| 28 |
|
| 29 |
public $type = 'wp-editor'; |
| 30 |
|
| 31 |
/** |
| 32 |
* Preparing html attributes and options for tinymce. |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
protected function beforeHtml() |
| 38 |
{ |
| 39 |
|
| 40 |
if( empty($this->options['tinymce']) ) { |
| 41 |
$this->options['tinymce'] = array(); |
| 42 |
} |
| 43 |
|
| 44 |
if( !isset($this->options['tinymce']['content_css']) ) { |
| 45 |
$this->options['tinymce']['content_css'] = FACTORY_FORMS_420_URL . '/assets/css/editor.css'; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Shows the html markup of the control. |
| 51 |
* |
| 52 |
* @since 1.0.0 |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public function html() |
| 56 |
{ |
| 57 |
$name_on_form = $this->getNameOnForm(); |
| 58 |
|
| 59 |
$value = $this->getValue(); |
| 60 |
|
| 61 |
?> |
| 62 |
<div class='factory-form-wp-editor'> |
| 63 |
<?php wp_editor($value, $name_on_form, array( |
| 64 |
'textarea_name' => $name_on_form, |
| 65 |
'wpautop' => false, |
| 66 |
'teeny' => true, |
| 67 |
'tinymce' => $this->getOption('tinymce', array()) |
| 68 |
)); ?> |
| 69 |
</div> |
| 70 |
<?php |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Returns a submit value of the control by a given name. |
| 75 |
* |
| 76 |
* @since 1.0.0 |
| 77 |
* @return mixed |
| 78 |
*/ |
| 79 |
public function getSubmitValue($name, $subName) |
| 80 |
{ |
| 81 |
$name_on_form = $this->getNameOnForm($name); |
| 82 |
|
| 83 |
$value = isset($_POST[$name_on_form]) |
| 84 |
? $_POST[$name_on_form] |
| 85 |
: null; |
| 86 |
|
| 87 |
if( is_array($value) ) { |
| 88 |
$value = implode(',', $value); |
| 89 |
} |
| 90 |
|
| 91 |
return wp_kses_post($value); |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|