field-advanced-link.php
5 years ago
field-button.php
5 years ago
field-checkbox.php
5 years ago
field-clone.php
5 years ago
field-code-editor.php
5 years ago
field-column.php
5 years ago
field-dynamic-message.php
5 years ago
field-file.php
5 years ago
field-flexible-content-actions.php
5 years ago
field-flexible-content-async.php
5 years ago
field-flexible-content-controls.php
5 years ago
field-flexible-content-edit.php
5 years ago
field-flexible-content-hide.php
5 years ago
field-flexible-content-preview.php
5 years ago
field-flexible-content-select.php
5 years ago
field-flexible-content-settings.php
5 years ago
field-flexible-content-state.php
5 years ago
field-flexible-content-thumbnail.php
5 years ago
field-flexible-content.php
5 years ago
field-forms.php
5 years ago
field-group.php
5 years ago
field-hidden.php
5 years ago
field-image.php
5 years ago
field-post-object.php
5 years ago
field-post-statuses.php
5 years ago
field-post-types.php
5 years ago
field-recaptcha.php
5 years ago
field-repeater.php
5 years ago
field-select.php
5 years ago
field-slug.php
5 years ago
field-taxonomies.php
5 years ago
field-taxonomy-terms.php
5 years ago
field-textarea.php
5 years ago
field-user-roles.php
5 years ago
field-code-editor.php
155 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | if(acf_version_compare($GLOBALS['wp_version'], '<', '4.9')) |
| 7 | return; |
| 8 | |
| 9 | if(!class_exists('acfe_field_code_editor')): |
| 10 | |
| 11 | class acfe_field_code_editor extends acf_field{ |
| 12 | |
| 13 | function __construct(){ |
| 14 | |
| 15 | $this->name = 'acfe_code_editor'; |
| 16 | $this->label = __('Code Editor', 'acfe'); |
| 17 | $this->category = 'content'; |
| 18 | $this->defaults = array( |
| 19 | 'default_value' => '', |
| 20 | 'placeholder' => '', |
| 21 | 'mode' => 'text/html', |
| 22 | 'lines' => true, |
| 23 | 'indent_unit' => 4, |
| 24 | 'maxlength' => '', |
| 25 | 'rows' => '', |
| 26 | 'max_rows' => '' |
| 27 | ); |
| 28 | |
| 29 | $this->textarea = acf_get_field_type('textarea'); |
| 30 | |
| 31 | parent::__construct(); |
| 32 | |
| 33 | } |
| 34 | |
| 35 | function render_field($field){ |
| 36 | |
| 37 | $wrapper = array( |
| 38 | 'class' => 'acf-input-wrap acfe-field-code-editor', |
| 39 | 'data-mode' => $field['mode'], |
| 40 | 'data-lines' => $field['lines'], |
| 41 | 'data-indent-unit' => $field['indent_unit'], |
| 42 | 'data-rows' => $field['rows'], |
| 43 | 'data-max-rows' => $field['max_rows'], |
| 44 | ); |
| 45 | |
| 46 | $field['type'] = 'textarea'; |
| 47 | |
| 48 | ?> |
| 49 | <div <?php acf_esc_attr_e($wrapper); ?>> |
| 50 | <?php $this->textarea->render_field($field); ?> |
| 51 | </div> |
| 52 | <?php |
| 53 | |
| 54 | } |
| 55 | |
| 56 | function render_field_settings($field){ |
| 57 | |
| 58 | // default_value |
| 59 | acf_render_field_setting($field, array( |
| 60 | 'label' => __('Default Value','acf'), |
| 61 | 'instructions' => __('Appears when creating a new post','acf'), |
| 62 | 'type' => 'acfe_code_editor', |
| 63 | 'name' => 'default_value', |
| 64 | 'rows' => 4 |
| 65 | )); |
| 66 | |
| 67 | // placeholder |
| 68 | acf_render_field_setting($field, array( |
| 69 | 'label' => __('Placeholder','acf'), |
| 70 | 'instructions' => __('Appears within the input','acf'), |
| 71 | 'type' => 'acfe_code_editor', |
| 72 | 'name' => 'placeholder', |
| 73 | 'rows' => 4 |
| 74 | )); |
| 75 | |
| 76 | // Mode |
| 77 | acf_render_field_setting($field, array( |
| 78 | 'label' => __('Editor mode','acf'), |
| 79 | 'instructions' => __('Choose the syntax highlight','acf'), |
| 80 | 'type' => 'select', |
| 81 | 'name' => 'mode', |
| 82 | 'choices' => array( |
| 83 | 'text/html' => __('Text/HTML', 'acf'), |
| 84 | 'javascript' => __('JavaScript', 'acf'), |
| 85 | 'css' => __('CSS', 'acf'), |
| 86 | 'application/x-httpd-php' => __('PHP (mixed)', 'acf'), |
| 87 | 'text/x-php' => __('PHP (plain)', 'acf'), |
| 88 | ) |
| 89 | )); |
| 90 | |
| 91 | // Lines |
| 92 | acf_render_field_setting($field, array( |
| 93 | 'label' => __('Show Lines', 'acf'), |
| 94 | 'instructions' => 'Whether to show line numbers to the left of the editor', |
| 95 | 'type' => 'true_false', |
| 96 | 'name' => 'lines', |
| 97 | 'ui' => true, |
| 98 | )); |
| 99 | |
| 100 | // Indent Unit |
| 101 | acf_render_field_setting($field, array( |
| 102 | 'label' => __('Indent Unit', 'acf'), |
| 103 | 'instructions' => 'How many spaces a block (whatever that means in the edited language) should be indented', |
| 104 | 'type' => 'number', |
| 105 | 'min' => 0, |
| 106 | 'name' => 'indent_unit', |
| 107 | )); |
| 108 | |
| 109 | // maxlength |
| 110 | acf_render_field_setting($field, array( |
| 111 | 'label' => __('Character Limit','acf'), |
| 112 | 'instructions' => __('Leave blank for no limit','acf'), |
| 113 | 'type' => 'number', |
| 114 | 'name' => 'maxlength', |
| 115 | )); |
| 116 | |
| 117 | // rows |
| 118 | acf_render_field_setting($field, array( |
| 119 | 'label' => __('Rows','acf'), |
| 120 | 'instructions' => __('Sets the textarea height','acf'), |
| 121 | 'type' => 'number', |
| 122 | 'name' => 'rows', |
| 123 | 'placeholder' => 8 |
| 124 | )); |
| 125 | |
| 126 | // max rows |
| 127 | acf_render_field_setting($field, array( |
| 128 | 'label' => __('Max rows','acf'), |
| 129 | 'instructions' => __('Sets the textarea max height','acf'), |
| 130 | 'type' => 'number', |
| 131 | 'name' => 'max_rows', |
| 132 | 'placeholder' => '' |
| 133 | )); |
| 134 | |
| 135 | } |
| 136 | |
| 137 | function input_admin_enqueue_scripts(){ |
| 138 | |
| 139 | wp_enqueue_script('code-editor'); |
| 140 | wp_enqueue_style('code-editor'); |
| 141 | |
| 142 | } |
| 143 | |
| 144 | function validate_value($valid, $value, $field, $input){ |
| 145 | |
| 146 | return $this->textarea->validate_value($valid, $value, $field, $input); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | // initialize |
| 153 | acf_register_field_type('acfe_field_code_editor'); |
| 154 | |
| 155 | endif; |