customs
5 months ago
holders
5 months ago
checkbox.php
5 months ago
color-and-opacity.php
5 months ago
color.php
5 months ago
datepicker-range.php
5 months ago
dropdown-and-colors.php
5 months ago
dropdown.php
5 months ago
font.php
5 months ago
google-font.php
5 months ago
gradient.php
5 months ago
hidden.php
5 months ago
index.php
5 months ago
integer.php
5 months ago
list.php
5 months ago
multiple-textbox.php
5 months ago
paddings-editor.php
5 months ago
pattern.php
5 months ago
radio-colors.php
5 months ago
radio.php
5 months ago
textarea.php
5 months ago
textbox.php
5 months ago
url.php
5 months ago
wp-editor.php
5 months ago
wp-editor.php
99 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 | * |
| 12 | * @link http://codex.wordpress.org/Function_Reference/wp_editor |
| 13 | * |
| 14 | * @package factory-forms |
| 15 | * @since 1.0.0 |
| 16 | */ |
| 17 | |
| 18 | // Exit if accessed directly |
| 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | exit; |
| 21 | } |
| 22 | |
| 23 | if ( ! class_exists( 'Wbcr_FactoryForms600_WpEditorControl' ) ) { |
| 24 | |
| 25 | class Wbcr_FactoryForms600_WpEditorControl extends Wbcr_FactoryForms600_Control { |
| 26 | |
| 27 | public $type = 'wp-editor'; |
| 28 | |
| 29 | /** |
| 30 | * Preparing html attributes and options for tinymce. |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * @return void |
| 34 | */ |
| 35 | protected function beforeHtml() { |
| 36 | |
| 37 | if ( empty( $this->options['tinymce'] ) ) { |
| 38 | $this->options['tinymce'] = []; |
| 39 | } |
| 40 | |
| 41 | if ( ! isset( $this->options['tinymce']['content_css'] ) ) { |
| 42 | $this->options['tinymce']['content_css'] = FACTORY_FORMS_600_URL . '/assets/css/editor.css'; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Shows the html markup of the control. |
| 48 | * |
| 49 | * @since 1.0.0 |
| 50 | * @return void |
| 51 | */ |
| 52 | public function html() { |
| 53 | $name_on_form = $this->getNameOnForm(); |
| 54 | |
| 55 | $value = $this->getValue(); |
| 56 | |
| 57 | ?> |
| 58 | <div class='factory-form-wp-editor'> |
| 59 | <?php |
| 60 | wp_editor( |
| 61 | $value, |
| 62 | $name_on_form, |
| 63 | [ |
| 64 | 'textarea_name' => $name_on_form, |
| 65 | 'wpautop' => false, |
| 66 | 'teeny' => true, |
| 67 | 'tinymce' => $this->getOption( 'tinymce', [] ), |
| 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 | ); |
| 72 | ?> |
| 73 | </div> |
| 74 | <?php |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns a submit value of the control by a given name. |
| 79 | * |
| 80 | * @since 1.0.0 |
| 81 | * @return mixed |
| 82 | */ |
| 83 | public function getSubmitValue( $name, $subName ) { |
| 84 | $name_on_form = $this->getNameOnForm( $name ); |
| 85 | |
| 86 | $value = isset( $_POST[ $name_on_form ] ) |
| 87 | ? $_POST[ $name_on_form ] |
| 88 | : null; |
| 89 | |
| 90 | if ( is_array( $value ) ) { |
| 91 | $value = implode( ',', $value ); |
| 92 | } |
| 93 | |
| 94 | return wp_kses_post( $value ); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 |