forked from hunk/Magic-Fields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MF_ManageWritePanels.php
223 lines (181 loc) · 6.1 KB
/
MF_ManageWritePanels.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
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
<?php
//enqueue js file
add_action('admin_init', 'manage_js');
function manage_js(){
wp_enqueue_script('manage_page_js',
MF_URI.'js/manage_page.js',
array('jquery'),
'0.1',
TRUE
);
//load jquery stringToSlug plugin (special chars power convert)
wp_enqueue_script( 'jqueryStringToSlug',
MF_URI.'js/jquery.stringToSlug.min.js'
);
}
session_start();
unset($_SESSION['change_title_manage']);
unset($_SESSION['change_botton_new_in_manage']);
unset($_SESSION['change_number_manage']);
unset($_SESSION['add_input_search_manage']);
unset($_SESSION['change_number_not_write_panel_manage']);
// filter for boton new
add_filter('manage_posts_columns','change_botton_new_in_manage');
add_filter('manage_pages_columns','change_botton_new_in_manage');
function change_botton_new_in_manage($where){
if (isset($_SESSION['change_botton_new_in_manage'])) {
return $where;
}
global $parent_file;
$types = array('edit.php','edit-pages.php','edit.php?post_type=page');
$type_add_new = array('edit.php' => 'post-new.php' ,'edit-pages.php' => 'page-new.php','edit.php?post_type=page' => 'post-new.php?post_type=page');
$contact = '?';
if(strpos($parent_file, '?')) $contact = '&';
if( !in_array($parent_file, $types) ) return $where;
if( isset($_GET['custom-write-panel-id']) ){
printf("
<script type=\"text/javascript\">
//<![CDATA[
jQuery().ready(function() {
change_button_new('%s','%scustom-write-panel-id=%s','%s');
unlink_write_panel('%s');
});
//]]>
</script>",
$type_add_new[$parent_file],
$contact,
(int)$_GET['custom-write-panel-id'],
(int)$_GET['custom-write-panel-id'],
wp_create_nonce('unlink-write-panel')
);
$_SESSION['change_botton_new_in_manage'] = "1";
}
return $where;
}
// filter for numbers in manage
add_filter('manage_posts_columns','change_number_manage');
add_filter('manage_pages_columns','change_number_manage');
function change_number_manage($where){
global $wpdb, $parent_file;
if (isset($_SESSION['change_number_manage'])) {
return $where;
}
$types = array('edit.php','edit-pages.php','edit.php?post_type=page');
if( !in_array($parent_file, $types) ) return $where;
if(isset($_GET['custom-write-panel-id'])){
if(is_wp30()){
$ver = '30';
$post_type = 'post';
if( isset($_GET['post_type']) ) $post_type = filter_var($_GET['post_type'], FILTER_SANITIZE_SPECIAL_CHARS);
}else{
$ver = '29';
$post_type = $parent_file;
}
$num_posts_mf = RCCWP_CustomWritePanel::GetCountPstWritePanel((int)$_GET['custom-write-panel-id']);
printf("
<script type=\"text/javascript\">
//<![CDATA[
jQuery().ready(function() {
change_number_manage_wp%s('(%s)','(%s)','(%s)','(%s)','(%s)','(%s)','(%s)','%s','filter-posts=1&custom-write-panel-id=%s');
});
//]]>
</script>",
$ver,
array_sum( (array) $num_posts_mf ) - $num_posts_mf->trash,
$num_posts_mf->publish,
$num_posts_mf->pending,
$num_posts_mf->draft,
$num_posts_mf->private,
$num_posts_mf->trash,
$num_posts_mf->future,
$post_type ,
(int)$_GET['custom-write-panel-id']
);
$_SESSION['change_number_manage'] = "1";
}
return $where;
}
// change the title manage page
add_filter('manage_posts_columns','change_title_manage');
add_filter('manage_pages_columns','change_title_manage');
function change_title_manage($where){
if (isset($_SESSION['change_title_manage'])) {
return $where;
}
if(isset($_GET['custom-write-panel-id'])){
$write_panel = RCCWP_CustomWritePanel::Get((int)$_GET['custom-write-panel-id']);
printf("
<script type=\"text/javascript\">
//<![CDATA[
jQuery().ready(function() {
change_title_manage('%s');
});
//]]>
</script>",
$write_panel->name
);
$_SESSION['change_title_manage'] = "1";
}
return $where;
}
// add input for search in manage page for write panels
add_filter('manage_posts_columns','add_input_search_manage');
add_filter('manage_pages_columns','add_input_search_manage');
function add_input_search_manage($where){
if (isset($_SESSION['add_input_search_manage'])) {
return $where;
}
if(isset($_GET['custom-write-panel-id'])){
$write_panel = RCCWP_CustomWritePanel::Get((int)$_GET['custom-write-panel-id']);
printf("
<script type=\"text/javascript\">
//<![CDATA[
jQuery().ready(function() {
add_input_search_manage('%s');
});
//]]>
</script>",
(int)$_GET['custom-write-panel-id']
);
$_SESSION['add_input_search_manage'] = "1";
}
return $where;
}
// change the number for edit in post or page when hide post with write panel
add_filter('manage_posts_columns','change_number_not_write_panel_manage');
add_filter('manage_pages_columns','change_number_not_write_panel_manage');
function change_number_not_write_panel_manage($where){
global $parent_file;
if (isset($_SESSION['change_number_not_write_panel_manage'])) {
return $where;
}
$types = array('edit.php','edit-pages.php','edit.php?post_type=page');
if( !in_array($parent_file, $types) ) return $where;
if(isset($_GET['custom-write-panel-id'])) return $where;
if( !RCCWP_Options::Get('hide-non-standart-content') ) return $where;
$type = 'post';
if(is_wp30()){
if($parent_file == 'edit.php?post_type=page') $type = 'page';
}else{
if($parent_file == 'edit-pages.php') $type = 'page';
}
$num_posts_mf = RCCWP_CustomWritePanel::GetCountPostNotWritePanel($type);
printf("
<script type=\"text/javascript\">
//<![CDATA[
jQuery().ready(function() {
change_number_manage_not_write_panel('(%s)','(%s)','(%s)','(%s)','(%s)','(%s)','(%s)');
});
//]]>
</script>",
array_sum( (array) $num_posts_mf ) - $num_posts_mf->trash,
$num_posts_mf->publish,
$num_posts_mf->pending,
$num_posts_mf->draft,
$num_posts_mf->private,
$num_posts_mf->trash,
$num_posts_mf->future
);
$_SESSION['change_number_not_write_panel_manage'] = "1";
return $where;
}