File "acf-code-field-v5.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/acf-code-field/acf-code-field-v5.php
File size: 5.62 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!defined('ABSPATH')) {
    exit;
}
if (!class_exists('acf_code_field')) {
    class acf_code_field extends acf_field
    {
        function __construct()
        {
            $this->name = 'acf_code_field';
            $this->label = __('Code area field', 'acf-code-field');
            $this->category = 'Code tools';
            $this->defaults = array('mode' => 'htmlmixed', 'theme' => 'monokai');
            $this->l10n = array('error' => __('Error! Please enter a higher value', 'acf-code-field'));
            parent::__construct();
        }
        function render_field_settings($field)
        {
            acf_render_field_setting($field, array('label' => __('Default Value', 'acf'), 'instructions' => __('Appears when creating a new post', 'acf'), 'type' => 'textarea', 'name' => 'default_value'));
            acf_render_field_setting($field, array('label' => __('Placeholder Text', 'acf'), 'instructions' => __('Appears within the input', 'acf'), 'type' => 'text', 'name' => 'placeholder'));
            acf_render_field_setting($field, array('label' => __('Editor mode', 'acf'), 'instructions' => __('', 'acf'), 'type' => 'select', 'name' => 'mode', 'choices' => array('htmlmixed' => __("HTML Mixed", 'acf'), 'javascript' => __("JavaScript", 'acf'), 'text/html' => __("HTML", 'acf'), 'css' => __("CSS", 'acf'), 'application/x-httpd-php' => __("PHP", 'acf'))));
            $util = new ACF_Code_Field_Util();
            acf_render_field_setting($field, array('label' => __('Editor theme', 'acf'), 'instructions' => __('Themes can be previewed on the <a href="https://codemirror.net/demo/theme.html#default" target="_blank">codemirror website</a>', 'acf'), 'type' => 'select', 'name' => 'theme', 'choices' => $util->get_codemirror_themes()));
        }
        function render_field($field)
        {
            $dir = plugin_dir_url(__FILE__);
            $safe_slug = str_replace("-", "_", $field['id']);
            $o = array('id', 'class', 'name', 'placeholder', 'mode', 'theme');
            $e = '';
            $atts = array();
            foreach ($o as $k) {
                $atts[$k] = $field[$k];
            }
            $atts['class'] = 'acf-code-field-box';
            $e .= '<textarea ' . acf_esc_attr($atts) . ' >';
            $e .= esc_textarea($field['value']);
            $e .= '</textarea>';
            echo $e;
            wp_enqueue_style("codemirror-curr-style-{$field['theme']}", "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/theme/{$field['theme']}.css");
        }
        function input_admin_enqueue_scripts()
        {
            $dir = plugin_dir_url(__FILE__);
            if (version_compare($GLOBALS['wp_version'], '4.9', '>=')) {
                wp_enqueue_script('wp-codemirror');
                wp_enqueue_style('wp-codemirror');
                wp_enqueue_script('csslint');
                wp_enqueue_script('jshint');
                wp_enqueue_script('jsonlint');
                wp_enqueue_script('htmlhint');
                wp_enqueue_script('htmlhint-kses');
                wp_add_inline_script('wp-codemirror', 'window.CodeMirror = wp.CodeMirror;');
            } else {
                wp_enqueue_script('acf-input-code-field-codemirror', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/lib/codemirror.js");
                wp_enqueue_script('acf-input-code-field-codemirror-showhint', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/addon/hint/show-hint.js");
                wp_enqueue_script('acf-input-code-field-codemirror-xmlhint', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/addon/hint/xml-hint.js");
                wp_enqueue_script('acf-input-code-field-codemirror-htmlhint', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/addon/hint/html-hint.js");
                wp_enqueue_style('acf-input-code-field', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/lib/codemirror.css");
            }
            wp_enqueue_script('acf-input-code-field-codemirror-css', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/mode/css/css.js");
            wp_enqueue_script('acf-input-code-field-codemirror-js', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/mode/javascript/javascript.js");
            wp_enqueue_script('acf-input-code-field-codemirror-xml', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/mode/xml/xml.js");
            wp_enqueue_script('acf-input-code-field-codemirror-clike', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/mode/clike/clike.js");
            wp_enqueue_script('acf-input-code-field-codemirror-php', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/mode/php/php.js");
            wp_enqueue_script('acf-input-code-field-codemirror-htmlmixed', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/mode/htmlmixed/htmlmixed.js");
            wp_enqueue_script('acf-input-code-field-codemirror-selection', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/addon/selection/mark-selection.js", array('wp-codemirror'));
            wp_enqueue_script('acf-input-code-field-codemirror-matchbrackets', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/addon/edit/matchbrackets.js", array('wp-codemirror'));
            wp_enqueue_script('acf-input-code-field-codemirror-autorefresh', "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/addon/display/autorefresh.js", array('wp-codemirror'));
            wp_enqueue_style('acf-input-code-field-css', "{$dir}css/input.css");
            wp_register_script('acf-input-code-field-input', "{$dir}js/input.js");
            $localized_values = array('plugins_url' => plugins_url('acf-code-field'), 'codemirror_version' => ACFCF_CODEMIRROR_VERSION);
            wp_localize_script('acf-input-code-field-input', 'acf_code_field_obj', $localized_values);
            wp_enqueue_script('acf-input-code-field-input', '', array('wp-codemirror'));
        }
    }
    new acf_code_field();
}