-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacf-enhanced-message-v4.php
executable file
·184 lines (137 loc) · 3.57 KB
/
acf-enhanced-message-v4.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/*
* ACF - Enhanced Message Field Class
*
*/
// exit if accessed directly
if ( ! defined( 'ABSPATH' ) )
exit;
// check if class already exists
if ( ! class_exists('ACF_Field_Enhanced_Message') ) :
class ACF_Field_Enhanced_Message extends acf_field {
// Field vars
var $settings;
/*
* __construct
*
* Set name / label needed for actions / filters
*/
function __construct( $settings )
{
// vars
$this->name = 'enhanced_message';
$this->label = __('Enhanced Message');
$this->category = __("Layout",'acf');
$this->defaults = array(
'enhanced_message' => '',
'hide_label' => 'no',
);
// settings
$this->settings = $settings;
// do not delete!
parent::__construct();
}
/*
* create_options()
*/
function create_options( $field )
{
// key is needed in the field names to correctly save the data
$key = $field['name'];
// Create Field Options HTML
?>
<!-- Message -->
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php _e("Message",'acf'); ?></label>
<p class="description"><?php echo __('Works like the default Message field but supports PHP and without','acf') . ' <a href="http://codex.wordpress.org/Function_Reference/wpautop" target="_blank">wpautop()</a>'; ?></p>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'textarea',
'value' => $field['enhanced_message'],
'name' => 'fields['.$key.'][enhanced_message]',
));
?>
</td>
</tr>
<!-- Hide Label? -->
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php _e("Hide Label?",'acf'); ?></label>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'radio',
'value' => $field['hide_label'],
'name' => 'fields['.$key.'][hide_label]',
'layout' => 'horizontal',
'choices' => array(
'yes' => __('Yes'),
'no' => __('No'),
)
));
?>
</td>
</tr>
<?php
}
/*
* field_group_admin_head()
*/
function field_group_admin_head()
{
?>
<style>
#acf_fields .fields .field_type-enhanced_message tr.field_name,
#acf_fields .fields .field_type-enhanced_message tr.field_instructions,
#acf_fields .fields .field_type-enhanced_message tr.required { display: none; }
</style>
<script>
</script>
<?php
}
/*
* load_field()
*
*/
function load_field( $field )
{
if ( ! is_admin() || ! function_exists( 'get_current_screen' ) ) {
return $field;
}
$current_screen = get_current_screen();
if ( null !== $current_screen && 'acf' !== $current_screen->post_type && 'yes' === $field['hide_label'] ) {
$field['label'] = '';
echo '<style>body:not(.post-type-acf) div[data-field_key="'.$field['key'].'"] .label {display:none;}</style>';
}
return $field;
}
/*
* field_group_admin_enqueue_scripts()
*/
function field_group_admin_enqueue_scripts() {
$dir = plugin_dir_url( __FILE__ );
// register & include JS
wp_register_script( 'acf-input-enhanced_message', "{$dir}js/input-v4.js", array(), false, true );
wp_enqueue_script('acf-input-enhanced_message');
}
/*
* create_field()
*/
function create_field( $field )
{
$stringVal = $field['enhanced_message'];
ob_start();
eval( '?>' . $stringVal );
$stringVal = ob_get_contents();
ob_end_clean();
echo $stringVal;
}
}
// Initialize field
new ACF_Field_Enhanced_Message( $this->settings );
// class_exists check
endif;