customs
1 year ago
holders
1 year ago
checkbox.php
1 year ago
color-and-opacity.php
1 year ago
color.php
1 year ago
datepicker-range.php
1 year ago
dropdown-and-colors.php
1 year ago
dropdown.php
1 year ago
font.php
1 year ago
google-font.php
1 year ago
gradient.php
1 year ago
hidden.php
1 year ago
index.php
3 years ago
integer.php
1 year ago
list.php
1 year ago
multiple-textbox.php
1 year ago
paddings-editor.php
1 year ago
pattern.php
1 year ago
radio-colors.php
1 year ago
radio.php
1 year ago
textarea.php
1 year ago
textbox.php
1 year ago
url.php
1 year ago
wp-editor.php
1 year ago
wp-editor.php
98 lines
| 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_FactoryForms480_WpEditorControl') ) { |
| 26 | |
| 27 | class Wbcr_FactoryForms480_WpEditorControl extends Wbcr_FactoryForms480_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_480_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 | 'editor_height' => 213, // In pixels, takes precedence and has no default value |
| 69 | 'textarea_rows' => 10, // Has no visible effect if editor_height is set, default is 20 |
| 70 | )); ?> |
| 71 | </div> |
| 72 | <?php |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns a submit value of the control by a given name. |
| 77 | * |
| 78 | * @since 1.0.0 |
| 79 | * @return mixed |
| 80 | */ |
| 81 | public function getSubmitValue($name, $subName) |
| 82 | { |
| 83 | $name_on_form = $this->getNameOnForm($name); |
| 84 | |
| 85 | $value = isset($_POST[$name_on_form]) |
| 86 | ? $_POST[$name_on_form] |
| 87 | : null; |
| 88 | |
| 89 | if( is_array($value) ) { |
| 90 | $value = implode(',', $value); |
| 91 | } |
| 92 | |
| 93 | return wp_kses_post($value); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 |