File "acf-code-field-v4.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/acf-code-field/acf-code-field-v4.php
File
size: 7.95 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
class acf_code_field_v4 extends acf_field
{
var $settings, $defaults;
function __construct()
{
$this->name = 'acf_code_field';
$this->label = __('ACF Code Field');
$this->category = __("Code Tools", 'acf');
$this->defaults = array('default_value' => '', 'formatting' => 'br', 'maxlength' => '', 'placeholder' => '', 'rows' => '', 'mode' => 'htmlmixed', 'theme' => 'monokai');
parent::__construct();
$this->settings = array('path' => apply_filters('acf/helpers/get_path', __FILE__), 'dir' => apply_filters('acf/helpers/get_dir', __FILE__), 'version' => '1.0.0');
}
function create_options($field)
{
$key = $field['name'];
?>
<tr class="field_option field_option_<?php
echo $this->name;
?>">
<td class="label">
<label><?php
_e("Default Value", 'acf');
?></label>
<p><?php
_e("Appears when creating a new post", 'acf');
?></p>
</td>
<td>
<?php
do_action('acf/create_field', array('type' => 'textarea', 'name' => 'fields[' . $key . '][default_value]', 'value' => $field['default_value']));
?>
</td>
</tr>
<tr class="field_option field_option_<?php
echo $this->name;
?>">
<td class="label">
<label><?php
_e("Placeholder Text", 'acf');
?></label>
<p><?php
_e("Appears within the input", 'acf');
?></p>
</td>
<td>
<?php
do_action('acf/create_field', array('type' => 'text', 'name' => 'fields[' . $key . '][placeholder]', 'value' => $field['placeholder']));
?>
</td>
</tr>
<tr class="field_option field_option_<?php
echo $this->name;
?>">
<td class="label">
<label><?php
_e("Editor mode", 'acf');
?></label>
</td>
<td>
<?php
do_action('acf/create_field', array('type' => 'select', 'name' => 'fields[' . $key . '][mode]', 'value' => $field['mode'], 'choices' => array('htmlmixed' => __("HTML Mixed", 'acf'), 'javascript' => __("JavaScript", 'acf'), 'text/html' => __("HTML", 'acf'), 'css' => __("CSS", 'acf'), 'application/x-httpd-php' => __("PHP", 'acf')), 'layout' => 'horizontal'));
?>
</td>
</tr>
<tr class="field_option field_option_<?php
echo $this->name;
?>">
<td class="label">
<label><?php
_e("Theme", 'acf');
?></label>
</td>
<td>
<?php
$util = new ACF_Code_Field_Util();
do_action('acf/create_field', array('type' => 'select', 'name' => 'fields[' . $key . '][theme]', 'value' => $field['theme'], 'choices' => $util->get_codemirror_themes(), 'layout' => 'horizontal'));
?>
</td>
</tr>
<?php
}
function create_field($field)
{
$o = array('id', 'class', 'name', 'placeholder', 'rows', 'mode', 'theme');
$e = '';
$field_id = $field['id'];
$safe_slug = str_replace("-", "_", $field_id);
$e .= '<textarea';
foreach ($o as $k) {
$e .= ' ' . $k . '="' . esc_attr($field[$k]) . '"';
}
$e .= '>';
$e .= esc_textarea($field['value']);
$e .= '</textarea>';
echo $e;
$dir = trailingslashit(plugin_dir_url(__FILE__));
wp_enqueue_style('codemirror-curr-style-' . $field['theme'], "{$dir}js/" . ACFCF_CODEMIRROR_VERSION . "/theme/{$field['theme']}.css");
?>
<script>
var code_field_<?php
echo $safe_slug;
?> = document.getElementById( '<?php
echo $field['id'];
?>' );
var editor = CodeMirror.fromTextArea( code_field_<?php
echo $safe_slug;
?>, {
lineNumbers: true,
mode: '<?php
echo esc_js($field['mode']);
?>',
theme: '<?php
echo $field['theme'];
?>',
extraKeys: { "Ctrl-Space": "autocomplete" },
value: document.documentElement.innerHTML
} );
</script>
<?php
}
function input_admin_enqueue_scripts()
{
$dir = trailingslashit(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'));
}
function input_admin_head()
{
}
function field_group_admin_enqueue_scripts()
{
}
function field_group_admin_head()
{
}
function load_value($value, $post_id, $field)
{
return $value;
}
function update_value($value, $post_id, $field)
{
return $value;
}
function format_value($value, $post_id, $field)
{
return $value;
}
function format_value_for_api($value, $post_id, $field)
{
return $value;
}
function load_field($field)
{
return $field;
}
function update_field($field, $post_id)
{
return $field;
}
}
new acf_code_field_v4();