third_party.php
3.8 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/*
* acf_third_party
*
* @description: controller for add-ons sub menu page
* @since: 3.6
* @created: 25/01/13
*/
class acf_third_party
{
/*
* __construct
*
* @description:
* @since 3.1.8
* @created: 23/06/12
*/
function __construct()
{
// Tabify Edit Screen - http://wordpress.org/extend/plugins/tabify-edit-screen/
add_action('admin_head-settings_page_tabify-edit-screen', array($this,'admin_head_tabify'));
// Duplicate Post - http://wordpress.org/extend/plugins/duplicate-post/
add_action('dp_duplicate_page', array($this, 'dp_duplicate_page'), 11, 2);
// Post Type Switcher - http://wordpress.org/extend/plugins/post-type-switcher/
add_filter('pts_post_type_filter', array($this, 'pts_post_type_filter'));
}
/*
* pts_allowed_pages
*
* @description:
* @since 3.5.3
* @created: 19/11/12
*/
function pts_post_type_filter( $args )
{
// global
global $typenow;
if( $typenow == "acf" )
{
$args = array(
'public' => false,
'show_ui' => true
);
}
// return
return $args;
}
/*
* admin_head_tabify
*
* @description:
* @since 3.5.1
* @created: 9/10/12
*/
function admin_head_tabify()
{
// remove ACF from the tabs
add_filter('tabify_posttypes', array($this, 'tabify_posttypes'));
// add acf metaboxes to list
add_action('tabify_add_meta_boxes' , array($this,'tabify_add_meta_boxes'));
}
/*
* tabify_posttypes
*
* @description:
* @since 3.5.1
* @created: 9/10/12
*/
function tabify_posttypes( $posttypes )
{
if( isset($posttypes['acf']) )
{
unset( $posttypes['acf'] );
}
return $posttypes;
}
/*
* tabify_add_meta_boxes
*
* @description:
* @since 3.5.1
* @created: 9/10/12
*/
function tabify_add_meta_boxes( $post_type )
{
// get acf's
$acfs = apply_filters('acf/get_field_groups', array());
if($acfs)
{
foreach($acfs as $acf)
{
// add meta box
add_meta_box(
'acf_' . $acf['id'],
$acf['title'],
array($this, 'dummy'),
$post_type
);
}
// foreach($acfs as $acf)
}
// if($acfs)
}
function dummy(){ /* Do Nothing */ }
/*
* dp_duplicate_page
*
* @description:
* @since 3.5.1
* @created: 9/10/12
*/
function dp_duplicate_page( $new_post_id, $old_post_object )
{
// only for acf
if( $old_post_object->post_type != "acf" )
{
return;
}
// update keys
$metas = get_post_custom( $new_post_id );
if( $metas )
{
foreach( $metas as $field_key => $field )
{
if( strpos($field_key, 'field_') !== false )
{
$field = $field[0];
$field = maybe_unserialize( $field );
$field = maybe_unserialize( $field ); // just to be sure!
// delete old field
delete_post_meta($new_post_id, $field_key);
// set new keys (recursive for sub fields)
$this->create_new_field_keys( $field );
// save it!
update_post_meta($new_post_id, $field['key'], $field);
}
// if( strpos($field_key, 'field_') !== false )
}
// foreach( $metas as $field_key => $field )
}
// if( $metas )
}
/*
* create_new_field_keys
*
* @description:
* @since 3.5.1
* @created: 9/10/12
*/
function create_new_field_keys( &$field )
{
// update key
$field['key'] = 'field_' . uniqid();
if( isset($field['sub_fields']) && is_array($field['sub_fields']) )
{
foreach( $field['sub_fields'] as $f )
{
$this->create_new_field_keys( $f );
}
}
elseif( isset($field['layouts']) && is_array($field['layouts']) )
{
foreach( $field['layouts'] as $layout )
{
if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
{
foreach( $layout['sub_fields'] as $f )
{
$this->create_new_field_keys( $f );
}
}
}
}
}
}
new acf_third_party();
?>