author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Post Administration API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Rename $_POST data from form names to DB post columns. |
|
11 |
* |
|
12 |
* Manipulates $_POST directly. |
|
13 |
* |
|
14 |
* @package WordPress |
|
15 |
* @since 2.6.0 |
|
16 |
* |
|
17 |
* @param bool $update Are we updating a pre-existing post? |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
18 |
* @param array $post_data Array of post data. Defaults to the contents of $_POST. |
136 | 19 |
* @return object|bool WP_Error on failure, true on success. |
20 |
*/ |
|
21 |
function _wp_translate_postdata( $update = false, $post_data = null ) { |
|
22 |
||
23 |
if ( empty($post_data) ) |
|
24 |
$post_data = &$_POST; |
|
25 |
||
26 |
if ( $update ) |
|
27 |
$post_data['ID'] = (int) $post_data['post_ID']; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
29 |
$ptype = get_post_type_object( $post_data['post_type'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
30 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
31 |
if ( $update && ! current_user_can( $ptype->cap->edit_post, $post_data['ID'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
32 |
if ( 'page' == $post_data['post_type'] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
33 |
return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
34 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
35 |
return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
36 |
} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
37 |
if ( 'page' == $post_data['post_type'] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
38 |
return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
39 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
40 |
return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
41 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
42 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
43 |
if ( isset( $post_data['content'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
$post_data['post_content'] = $post_data['content']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
45 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
46 |
if ( isset( $post_data['excerpt'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
47 |
$post_data['post_excerpt'] = $post_data['excerpt']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
48 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
49 |
if ( isset( $post_data['parent_id'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
50 |
$post_data['post_parent'] = (int) $post_data['parent_id']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
51 |
|
136 | 52 |
if ( isset($post_data['trackback_url']) ) |
53 |
$post_data['to_ping'] = $post_data['trackback_url']; |
|
54 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
if ( !isset($post_data['user_ID']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
$post_data['user_ID'] = $GLOBALS['user_ID']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
57 |
|
136 | 58 |
if (!empty ( $post_data['post_author_override'] ) ) { |
59 |
$post_data['post_author'] = (int) $post_data['post_author_override']; |
|
60 |
} else { |
|
61 |
if (!empty ( $post_data['post_author'] ) ) { |
|
62 |
$post_data['post_author'] = (int) $post_data['post_author']; |
|
63 |
} else { |
|
64 |
$post_data['post_author'] = (int) $post_data['user_ID']; |
|
65 |
} |
|
66 |
} |
|
67 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
68 |
if ( ! $update && isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
69 |
&& ! current_user_can( $ptype->cap->edit_others_posts ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
70 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
71 |
if ( 'page' == $post_data['post_type'] ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
72 |
return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
73 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
74 |
return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) ); |
136 | 75 |
} |
76 |
||
77 |
// What to do based on which button they pressed |
|
78 |
if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] ) |
|
79 |
$post_data['post_status'] = 'draft'; |
|
80 |
if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] ) |
|
81 |
$post_data['post_status'] = 'private'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
82 |
if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( !isset($post_data['post_status']) || $post_data['post_status'] != 'private' ) ) |
136 | 83 |
$post_data['post_status'] = 'publish'; |
84 |
if ( isset($post_data['advanced']) && '' != $post_data['advanced'] ) |
|
85 |
$post_data['post_status'] = 'draft'; |
|
86 |
if ( isset($post_data['pending']) && '' != $post_data['pending'] ) |
|
87 |
$post_data['post_status'] = 'pending'; |
|
88 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
89 |
if ( isset( $post_data['ID'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
90 |
$post_id = $post_data['ID']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
91 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
92 |
$post_id = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
93 |
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; |
136 | 94 |
|
95 |
// Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published. |
|
96 |
// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
97 |
if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
98 |
if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) ) |
136 | 99 |
$post_data['post_status'] = 'pending'; |
100 |
||
101 |
if ( ! isset($post_data['post_status']) ) |
|
102 |
$post_data['post_status'] = $previous_status; |
|
103 |
||
104 |
if (!isset( $post_data['comment_status'] )) |
|
105 |
$post_data['comment_status'] = 'closed'; |
|
106 |
||
107 |
if (!isset( $post_data['ping_status'] )) |
|
108 |
$post_data['ping_status'] = 'closed'; |
|
109 |
||
110 |
foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { |
|
111 |
if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) { |
|
112 |
$post_data['edit_date'] = '1'; |
|
113 |
break; |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
if ( !empty( $post_data['edit_date'] ) ) { |
|
118 |
$aa = $post_data['aa']; |
|
119 |
$mm = $post_data['mm']; |
|
120 |
$jj = $post_data['jj']; |
|
121 |
$hh = $post_data['hh']; |
|
122 |
$mn = $post_data['mn']; |
|
123 |
$ss = $post_data['ss']; |
|
124 |
$aa = ($aa <= 0 ) ? date('Y') : $aa; |
|
125 |
$mm = ($mm <= 0 ) ? date('n') : $mm; |
|
126 |
$jj = ($jj > 31 ) ? 31 : $jj; |
|
127 |
$jj = ($jj <= 0 ) ? date('j') : $jj; |
|
128 |
$hh = ($hh > 23 ) ? $hh -24 : $hh; |
|
129 |
$mn = ($mn > 59 ) ? $mn -60 : $mn; |
|
130 |
$ss = ($ss > 59 ) ? $ss -60 : $ss; |
|
131 |
$post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
132 |
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
133 |
if ( !$valid_date ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
134 |
return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
135 |
} |
136 | 136 |
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); |
137 |
} |
|
138 |
||
139 |
return $post_data; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Update an existing post with values provided in $_POST. |
|
144 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
145 |
* @since 1.5.0 |
136 | 146 |
* |
147 |
* @param array $post_data Optional. |
|
148 |
* @return int Post ID. |
|
149 |
*/ |
|
150 |
function edit_post( $post_data = null ) { |
|
151 |
||
152 |
if ( empty($post_data) ) |
|
153 |
$post_data = &$_POST; |
|
154 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
// Clear out any data in internal vars. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
unset( $post_data['filter'] ); |
136 | 157 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
158 |
$post_ID = (int) $post_data['post_ID']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
159 |
$post = get_post( $post_ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
160 |
$post_data['post_type'] = $post->post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
161 |
$post_data['post_mime_type'] = $post->post_mime_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
162 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
163 |
$ptype = get_post_type_object($post_data['post_type']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
164 |
if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
165 |
if ( 'page' == $post_data['post_type'] ) |
136 | 166 |
wp_die( __('You are not allowed to edit this page.' )); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
167 |
else |
136 | 168 |
wp_die( __('You are not allowed to edit this post.' )); |
169 |
} |
|
170 |
||
171 |
$post_data = _wp_translate_postdata( true, $post_data ); |
|
172 |
if ( is_wp_error($post_data) ) |
|
173 |
wp_die( $post_data->get_error_message() ); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
174 |
if ( ( empty( $post_data['action'] ) || 'autosave' != $post_data['action'] ) && 'auto-draft' == $post_data['post_status'] ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
175 |
$post_data['post_status'] = 'draft'; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
176 |
} |
136 | 177 |
|
178 |
if ( isset($post_data['visibility']) ) { |
|
179 |
switch ( $post_data['visibility'] ) { |
|
180 |
case 'public' : |
|
181 |
$post_data['post_password'] = ''; |
|
182 |
break; |
|
183 |
case 'password' : |
|
184 |
unset( $post_data['sticky'] ); |
|
185 |
break; |
|
186 |
case 'private' : |
|
187 |
$post_data['post_status'] = 'private'; |
|
188 |
$post_data['post_password'] = ''; |
|
189 |
unset( $post_data['sticky'] ); |
|
190 |
break; |
|
191 |
} |
|
192 |
} |
|
193 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
194 |
// Post Formats |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
195 |
if ( isset( $post_data['post_format'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
if ( current_theme_supports( 'post-formats', $post_data['post_format'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
set_post_format( $post_ID, $post_data['post_format'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
elseif ( '0' == $post_data['post_format'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
set_post_format( $post_ID, false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
200 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
201 |
|
136 | 202 |
// Meta Stuff |
203 |
if ( isset($post_data['meta']) && $post_data['meta'] ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
204 |
foreach ( $post_data['meta'] as $key => $value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
205 |
if ( !$meta = get_post_meta_by_id( $key ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
206 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
if ( $meta->post_id != $post_ID ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
208 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
209 |
if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
210 |
continue; |
136 | 211 |
update_meta( $key, $value['key'], $value['value'] ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
212 |
} |
136 | 213 |
} |
214 |
||
215 |
if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
216 |
foreach ( $post_data['deletemeta'] as $key => $value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
217 |
if ( !$meta = get_post_meta_by_id( $key ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
if ( $meta->post_id != $post_ID ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
221 |
if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
222 |
continue; |
136 | 223 |
delete_meta( $key ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
224 |
} |
136 | 225 |
} |
226 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
227 |
// Attachment stuff |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
228 |
if ( 'attachment' == $post_data['post_type'] ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
229 |
if ( isset( $post_data[ '_wp_attachment_image_alt' ] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
230 |
$image_alt = get_post_meta( $post_ID, '_wp_attachment_image_alt', true ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
231 |
if ( $image_alt != stripslashes( $post_data['_wp_attachment_image_alt'] ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
232 |
$image_alt = wp_strip_all_tags( stripslashes( $post_data['_wp_attachment_image_alt'] ), true ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
233 |
// update_meta expects slashed |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
234 |
update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
235 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
236 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
237 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
238 |
$attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
239 |
$post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
240 |
} |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
241 |
|
136 | 242 |
add_meta( $post_ID ); |
243 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
244 |
update_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); |
136 | 245 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
wp_update_post( $post_data ); |
136 | 247 |
|
248 |
// Now that we have an ID we can fix any attachment anchor hrefs |
|
249 |
_fix_attachment_links( $post_ID ); |
|
250 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
251 |
wp_set_post_lock( $post_ID ); |
136 | 252 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
253 |
if ( current_user_can( $ptype->cap->edit_others_posts ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
254 |
if ( ! empty( $post_data['sticky'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
255 |
stick_post( $post_ID ); |
136 | 256 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
257 |
unstick_post( $post_ID ); |
136 | 258 |
} |
259 |
||
260 |
return $post_ID; |
|
261 |
} |
|
262 |
||
263 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
* Process the post data for the bulk editing of posts. |
136 | 265 |
* |
266 |
* Updates all bulk edited posts/pages, adding (but not removing) tags and |
|
267 |
* categories. Skips pages when they would be their own parent or child. |
|
268 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
* @since 2.7.0 |
136 | 270 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
271 |
* @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal. |
136 | 272 |
* @return array |
273 |
*/ |
|
274 |
function bulk_edit_posts( $post_data = null ) { |
|
275 |
global $wpdb; |
|
276 |
||
277 |
if ( empty($post_data) ) |
|
278 |
$post_data = &$_POST; |
|
279 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
280 |
if ( isset($post_data['post_type']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
281 |
$ptype = get_post_type_object($post_data['post_type']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
283 |
$ptype = get_post_type_object('post'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
284 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
285 |
if ( !current_user_can( $ptype->cap->edit_posts ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
286 |
if ( 'page' == $ptype->name ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
287 |
wp_die( __('You are not allowed to edit pages.')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
288 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
289 |
wp_die( __('You are not allowed to edit posts.')); |
136 | 290 |
} |
291 |
||
292 |
if ( -1 == $post_data['_status'] ) { |
|
293 |
$post_data['post_status'] = null; |
|
294 |
unset($post_data['post_status']); |
|
295 |
} else { |
|
296 |
$post_data['post_status'] = $post_data['_status']; |
|
297 |
} |
|
298 |
unset($post_data['_status']); |
|
299 |
||
300 |
$post_IDs = array_map( 'intval', (array) $post_data['post'] ); |
|
301 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
302 |
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky' ); |
136 | 303 |
foreach ( $reset as $field ) { |
304 |
if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) ) |
|
305 |
unset($post_data[$field]); |
|
306 |
} |
|
307 |
||
308 |
if ( isset($post_data['post_category']) ) { |
|
309 |
if ( is_array($post_data['post_category']) && ! empty($post_data['post_category']) ) |
|
310 |
$new_cats = array_map( 'absint', $post_data['post_category'] ); |
|
311 |
else |
|
312 |
unset($post_data['post_category']); |
|
313 |
} |
|
314 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
315 |
$tax_input = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
316 |
if ( isset($post_data['tax_input'])) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
317 |
foreach ( $post_data['tax_input'] as $tax_name => $terms ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
318 |
if ( empty($terms) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
319 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
320 |
if ( is_taxonomy_hierarchical( $tax_name ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
321 |
$tax_input[ $tax_name ] = array_map( 'absint', $terms ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
322 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
323 |
$comma = _x( ',', 'tag delimiter' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
324 |
if ( ',' !== $comma ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
325 |
$terms = str_replace( $comma, ',', $terms ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
326 |
$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
327 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
328 |
} |
136 | 329 |
} |
330 |
||
331 |
if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) { |
|
332 |
$pages = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'"); |
|
333 |
$children = array(); |
|
334 |
||
335 |
for ( $i = 0; $i < 50 && $parent > 0; $i++ ) { |
|
336 |
$children[] = $parent; |
|
337 |
||
338 |
foreach ( $pages as $page ) { |
|
339 |
if ( $page->ID == $parent ) { |
|
340 |
$parent = $page->post_parent; |
|
341 |
break; |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
} |
|
346 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
347 |
if ( isset( $post_data['post_format'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
348 |
if ( '0' == $post_data['post_format'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
349 |
$post_data['post_format'] = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
350 |
// don't change the post format if it's not supported or not '0' (standard) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
351 |
elseif ( ! current_theme_supports( 'post-formats', $post_data['post_format'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
352 |
unset( $post_data['post_format'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
353 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
354 |
|
136 | 355 |
$updated = $skipped = $locked = array(); |
356 |
foreach ( $post_IDs as $post_ID ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
357 |
$post_type_object = get_post_type_object( get_post_type( $post_ID ) ); |
136 | 358 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
359 |
if ( !isset( $post_type_object ) || ( isset($children) && in_array($post_ID, $children) ) || !current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) { |
136 | 360 |
$skipped[] = $post_ID; |
361 |
continue; |
|
362 |
} |
|
363 |
||
364 |
if ( wp_check_post_lock( $post_ID ) ) { |
|
365 |
$locked[] = $post_ID; |
|
366 |
continue; |
|
367 |
} |
|
368 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
369 |
$post = get_post( $post_ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
370 |
$tax_names = get_object_taxonomies( $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
371 |
foreach ( $tax_names as $tax_name ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
372 |
$taxonomy_obj = get_taxonomy($tax_name); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
373 |
if ( isset( $tax_input[$tax_name]) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
374 |
$new_terms = $tax_input[$tax_name]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
375 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
376 |
$new_terms = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
377 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
378 |
if ( $taxonomy_obj->hierarchical ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
379 |
$current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'ids') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
380 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
381 |
$current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'names') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
382 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
383 |
$post_data['tax_input'][$tax_name] = array_merge( $current_terms, $new_terms ); |
136 | 384 |
} |
385 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
386 |
if ( isset($new_cats) && in_array( 'category', $tax_names ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
387 |
$cats = (array) wp_get_post_categories($post_ID); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
388 |
$post_data['post_category'] = array_unique( array_merge($cats, $new_cats) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
389 |
unset( $post_data['tax_input']['category'] ); |
136 | 390 |
} |
391 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
392 |
$post_data['post_mime_type'] = $post->post_mime_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
393 |
$post_data['guid'] = $post->guid; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
394 |
|
136 | 395 |
$post_data['ID'] = $post_ID; |
396 |
$updated[] = wp_update_post( $post_data ); |
|
397 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
398 |
if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { |
136 | 399 |
if ( 'sticky' == $post_data['sticky'] ) |
400 |
stick_post( $post_ID ); |
|
401 |
else |
|
402 |
unstick_post( $post_ID ); |
|
403 |
} |
|
404 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
405 |
if ( isset( $post_data['post_format'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
406 |
set_post_format( $post_ID, $post_data['post_format'] ); |
136 | 407 |
} |
408 |
||
409 |
return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked ); |
|
410 |
} |
|
411 |
||
412 |
/** |
|
413 |
* Default post information to use when populating the "Write Post" form. |
|
414 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
415 |
* @since 2.0.0 |
136 | 416 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
417 |
* @param string $post_type A post type string, defaults to 'post'. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
418 |
* @return WP_Post Post object containing all the default post data as attributes |
136 | 419 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
420 |
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
421 |
global $wpdb; |
136 | 422 |
|
423 |
$post_title = ''; |
|
424 |
if ( !empty( $_REQUEST['post_title'] ) ) |
|
425 |
$post_title = esc_html( stripslashes( $_REQUEST['post_title'] )); |
|
426 |
||
427 |
$post_content = ''; |
|
428 |
if ( !empty( $_REQUEST['content'] ) ) |
|
429 |
$post_content = esc_html( stripslashes( $_REQUEST['content'] )); |
|
430 |
||
431 |
$post_excerpt = ''; |
|
432 |
if ( !empty( $_REQUEST['excerpt'] ) ) |
|
433 |
$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] )); |
|
434 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
435 |
if ( $create_in_db ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
436 |
$post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
437 |
$post = get_post( $post_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
438 |
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
439 |
set_post_format( $post, get_option( 'default_post_format' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
440 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
441 |
$post = new stdClass; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
442 |
$post->ID = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
443 |
$post->post_author = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
444 |
$post->post_date = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
445 |
$post->post_date_gmt = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
446 |
$post->post_password = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
447 |
$post->post_type = $post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
448 |
$post->post_status = 'draft'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
449 |
$post->to_ping = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
450 |
$post->pinged = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
451 |
$post->comment_status = get_option( 'default_comment_status' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
452 |
$post->ping_status = get_option( 'default_ping_status' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
453 |
$post->post_pingback = get_option( 'default_pingback_flag' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
454 |
$post->post_category = get_option( 'default_category' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
455 |
$post->page_template = 'default'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
456 |
$post->post_parent = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
457 |
$post->menu_order = 0; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
458 |
$post = new WP_Post( $post ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
459 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
460 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
461 |
$post->post_content = apply_filters( 'default_content', $post_content, $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
462 |
$post->post_title = apply_filters( 'default_title', $post_title, $post ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
463 |
$post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post ); |
136 | 464 |
$post->post_name = ''; |
465 |
||
466 |
return $post; |
|
467 |
} |
|
468 |
||
469 |
/** |
|
470 |
* Determine if a post exists based on title, content, and date |
|
471 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
472 |
* @since 2.0.0 |
136 | 473 |
* |
474 |
* @param string $title Post title |
|
475 |
* @param string $content Optional post content |
|
476 |
* @param string $date Optional post date |
|
477 |
* @return int Post ID if post exists, 0 otherwise. |
|
478 |
*/ |
|
479 |
function post_exists($title, $content = '', $date = '') { |
|
480 |
global $wpdb; |
|
481 |
||
482 |
$post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); |
|
483 |
$post_content = stripslashes( sanitize_post_field( 'post_content', $content, 0, 'db' ) ); |
|
484 |
$post_date = stripslashes( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); |
|
485 |
||
486 |
$query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; |
|
487 |
$args = array(); |
|
488 |
||
489 |
if ( !empty ( $date ) ) { |
|
490 |
$query .= ' AND post_date = %s'; |
|
491 |
$args[] = $post_date; |
|
492 |
} |
|
493 |
||
494 |
if ( !empty ( $title ) ) { |
|
495 |
$query .= ' AND post_title = %s'; |
|
496 |
$args[] = $post_title; |
|
497 |
} |
|
498 |
||
499 |
if ( !empty ( $content ) ) { |
|
500 |
$query .= 'AND post_content = %s'; |
|
501 |
$args[] = $post_content; |
|
502 |
} |
|
503 |
||
504 |
if ( !empty ( $args ) ) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
505 |
return (int) $wpdb->get_var( $wpdb->prepare($query, $args) ); |
136 | 506 |
|
507 |
return 0; |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Creates a new post from the "Write Post" form using $_POST information. |
|
512 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
513 |
* @since 2.1.0 |
136 | 514 |
* |
515 |
* @return unknown |
|
516 |
*/ |
|
517 |
function wp_write_post() { |
|
518 |
global $user_ID; |
|
519 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
520 |
if ( isset($_POST['post_type']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
521 |
$ptype = get_post_type_object($_POST['post_type']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
522 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
523 |
$ptype = get_post_type_object('post'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
524 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
525 |
if ( !current_user_can( $ptype->cap->edit_posts ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
526 |
if ( 'page' == $ptype->name ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
527 |
return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
528 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
529 |
return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) ); |
136 | 530 |
} |
531 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
532 |
$_POST['post_mime_type'] = ''; |
136 | 533 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
534 |
// Clear out any data in internal vars. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
535 |
unset( $_POST['filter'] ); |
136 | 536 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
537 |
// Edit don't write if we have a post id. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
538 |
if ( isset( $_POST['post_ID'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
539 |
return edit_post(); |
136 | 540 |
|
541 |
$translated = _wp_translate_postdata( false ); |
|
542 |
if ( is_wp_error($translated) ) |
|
543 |
return $translated; |
|
544 |
||
545 |
if ( isset($_POST['visibility']) ) { |
|
546 |
switch ( $_POST['visibility'] ) { |
|
547 |
case 'public' : |
|
548 |
$_POST['post_password'] = ''; |
|
549 |
break; |
|
550 |
case 'password' : |
|
551 |
unset( $_POST['sticky'] ); |
|
552 |
break; |
|
553 |
case 'private' : |
|
554 |
$_POST['post_status'] = 'private'; |
|
555 |
$_POST['post_password'] = ''; |
|
556 |
unset( $_POST['sticky'] ); |
|
557 |
break; |
|
558 |
} |
|
559 |
} |
|
560 |
||
561 |
// Create the post. |
|
562 |
$post_ID = wp_insert_post( $_POST ); |
|
563 |
if ( is_wp_error( $post_ID ) ) |
|
564 |
return $post_ID; |
|
565 |
||
566 |
if ( empty($post_ID) ) |
|
567 |
return 0; |
|
568 |
||
569 |
add_meta( $post_ID ); |
|
570 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
571 |
add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); |
136 | 572 |
|
573 |
// Now that we have an ID we can fix any attachment anchor hrefs |
|
574 |
_fix_attachment_links( $post_ID ); |
|
575 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
576 |
wp_set_post_lock( $post_ID ); |
136 | 577 |
|
578 |
return $post_ID; |
|
579 |
} |
|
580 |
||
581 |
/** |
|
582 |
* Calls wp_write_post() and handles the errors. |
|
583 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
584 |
* @since 2.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
585 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
586 |
* @uses wp_write_post() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
587 |
* @uses is_wp_error() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
588 |
* @uses wp_die() |
136 | 589 |
* @return unknown |
590 |
*/ |
|
591 |
function write_post() { |
|
592 |
$result = wp_write_post(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
593 |
if ( is_wp_error( $result ) ) |
136 | 594 |
wp_die( $result->get_error_message() ); |
595 |
else |
|
596 |
return $result; |
|
597 |
} |
|
598 |
||
599 |
// |
|
600 |
// Post Meta |
|
601 |
// |
|
602 |
||
603 |
/** |
|
604 |
* {@internal Missing Short Description}} |
|
605 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
606 |
* @since 1.2.0 |
136 | 607 |
* |
608 |
* @param unknown_type $post_ID |
|
609 |
* @return unknown |
|
610 |
*/ |
|
611 |
function add_meta( $post_ID ) { |
|
612 |
global $wpdb; |
|
613 |
$post_ID = (int) $post_ID; |
|
614 |
||
615 |
$metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : ''; |
|
616 |
$metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : ''; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
617 |
$metavalue = isset($_POST['metavalue']) ? $_POST['metavalue'] : ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
618 |
if ( is_string( $metavalue ) ) |
136 | 619 |
$metavalue = trim( $metavalue ); |
620 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
621 |
if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ( ( ( '#NONE#' != $metakeyselect ) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput ) ) ) { |
136 | 622 |
// We have a key/value pair. If both the select and the |
623 |
// input for the key have data, the input takes precedence: |
|
624 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
625 |
if ( '#NONE#' != $metakeyselect ) |
136 | 626 |
$metakey = $metakeyselect; |
627 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
628 |
if ( $metakeyinput ) |
136 | 629 |
$metakey = $metakeyinput; // default |
630 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
631 |
if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) |
136 | 632 |
return false; |
633 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
634 |
$metakey = esc_sql( $metakey ); |
136 | 635 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
636 |
return add_post_meta( $post_ID, $metakey, $metavalue ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
637 |
} |
136 | 638 |
|
639 |
return false; |
|
640 |
} // add_meta |
|
641 |
||
642 |
/** |
|
643 |
* {@internal Missing Short Description}} |
|
644 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
645 |
* @since 1.2.0 |
136 | 646 |
* |
647 |
* @param unknown_type $mid |
|
648 |
* @return unknown |
|
649 |
*/ |
|
650 |
function delete_meta( $mid ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
651 |
return delete_metadata_by_mid( 'post' , $mid ); |
136 | 652 |
} |
653 |
||
654 |
/** |
|
655 |
* Get a list of previously defined keys. |
|
656 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
657 |
* @since 1.2.0 |
136 | 658 |
* |
659 |
* @return unknown |
|
660 |
*/ |
|
661 |
function get_meta_keys() { |
|
662 |
global $wpdb; |
|
663 |
||
664 |
$keys = $wpdb->get_col( " |
|
665 |
SELECT meta_key |
|
666 |
FROM $wpdb->postmeta |
|
667 |
GROUP BY meta_key |
|
668 |
ORDER BY meta_key" ); |
|
669 |
||
670 |
return $keys; |
|
671 |
} |
|
672 |
||
673 |
/** |
|
674 |
* {@internal Missing Short Description}} |
|
675 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
676 |
* @since 2.1.0 |
136 | 677 |
* |
678 |
* @param unknown_type $mid |
|
679 |
* @return unknown |
|
680 |
*/ |
|
681 |
function get_post_meta_by_id( $mid ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
682 |
return get_metadata_by_mid( 'post', $mid ); |
136 | 683 |
} |
684 |
||
685 |
/** |
|
686 |
* {@internal Missing Short Description}} |
|
687 |
* |
|
688 |
* Some postmeta stuff. |
|
689 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
690 |
* @since 1.2.0 |
136 | 691 |
* |
692 |
* @param unknown_type $postid |
|
693 |
* @return unknown |
|
694 |
*/ |
|
695 |
function has_meta( $postid ) { |
|
696 |
global $wpdb; |
|
697 |
||
698 |
return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id |
|
699 |
FROM $wpdb->postmeta WHERE post_id = %d |
|
700 |
ORDER BY meta_key,meta_id", $postid), ARRAY_A ); |
|
701 |
} |
|
702 |
||
703 |
/** |
|
704 |
* {@internal Missing Short Description}} |
|
705 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
706 |
* @since 1.2.0 |
136 | 707 |
* |
708 |
* @param unknown_type $meta_id |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
709 |
* @param unknown_type $meta_key Expect Slashed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
710 |
* @param unknown_type $meta_value Expect Slashed |
136 | 711 |
* @return unknown |
712 |
*/ |
|
713 |
function update_meta( $meta_id, $meta_key, $meta_value ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
714 |
$meta_key = stripslashes( $meta_key ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
715 |
$meta_value = stripslashes_deep( $meta_value ); |
136 | 716 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
717 |
return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key ); |
136 | 718 |
} |
719 |
||
720 |
// |
|
721 |
// Private |
|
722 |
// |
|
723 |
||
724 |
/** |
|
725 |
* Replace hrefs of attachment anchors with up-to-date permalinks. |
|
726 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
727 |
* @since 2.3.0 |
136 | 728 |
* @access private |
729 |
* |
|
730 |
* @param unknown_type $post_ID |
|
731 |
* @return unknown |
|
732 |
*/ |
|
733 |
function _fix_attachment_links( $post_ID ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
734 |
$post = get_post( $post_ID, ARRAY_A ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
735 |
$content = $post['post_content']; |
136 | 736 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
737 |
// quick sanity check, don't run if no pretty permalinks or post is not published |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
738 |
if ( !get_option('permalink_structure') || $post['post_status'] != 'publish' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
739 |
return; |
136 | 740 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
741 |
// Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
742 |
if ( !strpos($content, '?attachment_id=') || !preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) |
136 | 743 |
return; |
744 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
745 |
$site_url = get_bloginfo('url'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
746 |
$site_url = substr( $site_url, (int) strpos($site_url, '://') ); // remove the http(s) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
747 |
$replace = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
748 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
749 |
foreach ( $link_matches[1] as $key => $value ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
750 |
if ( !strpos($value, '?attachment_id=') || !strpos($value, 'wp-att-') |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
751 |
|| !preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
752 |
|| !preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
753 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
754 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
755 |
$quote = $url_match[1]; // the quote (single or double) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
756 |
$url_id = (int) $url_match[2]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
757 |
$rel_id = (int) $rel_match[1]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
758 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
759 |
if ( !$url_id || !$rel_id || $url_id != $rel_id || strpos($url_match[0], $site_url) === false ) |
136 | 760 |
continue; |
761 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
762 |
$link = $link_matches[0][$key]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
763 |
$replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link ); |
136 | 764 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
765 |
$content = str_replace( $link, $replace, $content ); |
136 | 766 |
} |
767 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
768 |
if ( $replace ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
769 |
$post['post_content'] = $content; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
770 |
// Escape data pulled from DB. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
771 |
$post = add_magic_quotes($post); |
136 | 772 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
773 |
return wp_update_post($post); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
774 |
} |
136 | 775 |
} |
776 |
||
777 |
/** |
|
778 |
* Move child posts to a new parent. |
|
779 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
780 |
* @since 2.3.0 |
136 | 781 |
* @access private |
782 |
* |
|
783 |
* @param unknown_type $old_ID |
|
784 |
* @param unknown_type $new_ID |
|
785 |
* @return unknown |
|
786 |
*/ |
|
787 |
function _relocate_children( $old_ID, $new_ID ) { |
|
788 |
global $wpdb; |
|
789 |
$old_ID = (int) $old_ID; |
|
790 |
$new_ID = (int) $new_ID; |
|
791 |
||
792 |
$children = $wpdb->get_col( $wpdb->prepare(" |
|
793 |
SELECT post_id |
|
794 |
FROM $wpdb->postmeta |
|
795 |
WHERE meta_key = '_wp_attachment_temp_parent' |
|
796 |
AND meta_value = %d", $old_ID) ); |
|
797 |
||
798 |
foreach ( $children as $child_id ) { |
|
799 |
$wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('ID' => $child_id) ); |
|
800 |
delete_post_meta($child_id, '_wp_attachment_temp_parent'); |
|
801 |
} |
|
802 |
} |
|
803 |
||
804 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
805 |
* Get all the possible statuses for a post_type |
136 | 806 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
807 |
* @since 2.5.0 |
136 | 808 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
809 |
* @param string $type The post_type you want the statuses for |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
810 |
* @return array As array of all the statuses for the supplied post type |
136 | 811 |
*/ |
812 |
function get_available_post_statuses($type = 'post') { |
|
813 |
$stati = wp_count_posts($type); |
|
814 |
||
815 |
return array_keys(get_object_vars($stati)); |
|
816 |
} |
|
817 |
||
818 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
819 |
* Run the wp query to fetch the posts for listing on the edit posts page |
136 | 820 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
821 |
* @since 2.5.0 |
136 | 822 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
823 |
* @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
824 |
* @return array |
136 | 825 |
*/ |
826 |
function wp_edit_posts_query( $q = false ) { |
|
827 |
if ( false === $q ) |
|
828 |
$q = $_GET; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
829 |
$q['m'] = isset($q['m']) ? (int) $q['m'] : 0; |
136 | 830 |
$q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
831 |
$post_stati = get_post_stati(); |
136 | 832 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
833 |
if ( isset($q['post_type']) && in_array( $q['post_type'], get_post_types() ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
834 |
$post_type = $q['post_type']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
835 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
836 |
$post_type = 'post'; |
136 | 837 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
838 |
$avail_post_stati = get_available_post_statuses($post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
839 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
840 |
if ( isset($q['post_status']) && in_array( $q['post_status'], $post_stati ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
841 |
$post_status = $q['post_status']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
842 |
$perm = 'readable'; |
136 | 843 |
} |
844 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
845 |
if ( isset($q['orderby']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
846 |
$orderby = $q['orderby']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
847 |
elseif ( isset($q['post_status']) && in_array($q['post_status'], array('pending', 'draft')) ) |
136 | 848 |
$orderby = 'modified'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
849 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
850 |
if ( isset($q['order']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
851 |
$order = $q['order']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
852 |
elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
853 |
$order = 'ASC'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
854 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
855 |
$per_page = 'edit_' . $post_type . '_per_page'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
856 |
$posts_per_page = (int) get_user_option( $per_page ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
857 |
if ( empty( $posts_per_page ) || $posts_per_page < 1 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
858 |
$posts_per_page = 20; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
859 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
860 |
$posts_per_page = apply_filters( $per_page, $posts_per_page ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
861 |
$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
862 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
863 |
$query = compact('post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
864 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
865 |
// Hierarchical types require special args. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
866 |
if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
867 |
$query['orderby'] = 'menu_order title'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
868 |
$query['order'] = 'asc'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
869 |
$query['posts_per_page'] = -1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
870 |
$query['posts_per_archive_page'] = -1; |
136 | 871 |
} |
872 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
873 |
if ( ! empty( $q['show_sticky'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
874 |
$query['post__in'] = (array) get_option( 'sticky_posts' ); |
136 | 875 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
876 |
wp( $query ); |
136 | 877 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
878 |
return $avail_post_stati; |
136 | 879 |
} |
880 |
||
881 |
/** |
|
882 |
* {@internal Missing Short Description}} |
|
883 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
884 |
* @since 2.5.0 |
136 | 885 |
* |
886 |
* @param unknown_type $type |
|
887 |
* @return unknown |
|
888 |
*/ |
|
889 |
function get_available_post_mime_types($type = 'attachment') { |
|
890 |
global $wpdb; |
|
891 |
||
892 |
$types = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type)); |
|
893 |
return $types; |
|
894 |
} |
|
895 |
||
896 |
/** |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
897 |
* Executes a query for attachments. An array of WP_Query arguments |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
898 |
* can be passed in, which will override the arguments set by this function. |
136 | 899 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
900 |
* @since 2.5.0 |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
901 |
* @uses apply_filters() Calls 'upload_per_page' on posts_per_page argument |
136 | 902 |
* |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
903 |
* @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
904 |
* @return array |
136 | 905 |
*/ |
906 |
function wp_edit_attachments_query( $q = false ) { |
|
907 |
if ( false === $q ) |
|
908 |
$q = $_GET; |
|
909 |
||
910 |
$q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; |
|
911 |
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; |
|
912 |
$q['post_type'] = 'attachment'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
913 |
$post_type = get_post_type_object( 'attachment' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
914 |
$states = 'inherit'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
915 |
if ( current_user_can( $post_type->cap->read_private_posts ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
916 |
$states .= ',private'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
917 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
918 |
$q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
919 |
$media_per_page = (int) get_user_option( 'upload_per_page' ); |
136 | 920 |
if ( empty( $media_per_page ) || $media_per_page < 1 ) |
921 |
$media_per_page = 20; |
|
922 |
$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page ); |
|
923 |
||
924 |
$post_mime_types = get_post_mime_types(); |
|
925 |
$avail_post_mime_types = get_available_post_mime_types('attachment'); |
|
926 |
||
927 |
if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) ) |
|
928 |
unset($q['post_mime_type']); |
|
929 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
930 |
if ( isset($q['detached']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
931 |
add_filter('posts_where', '_edit_attachments_query_helper'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
932 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
933 |
wp( $q ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
934 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
935 |
if ( isset($q['detached']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
936 |
remove_filter('posts_where', '_edit_attachments_query_helper'); |
136 | 937 |
|
938 |
return array($post_mime_types, $avail_post_mime_types); |
|
939 |
} |
|
940 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
941 |
function _edit_attachments_query_helper($where) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
942 |
global $wpdb; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
943 |
return $where .= " AND {$wpdb->posts}.post_parent < 1"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
944 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
945 |
|
136 | 946 |
/** |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
947 |
* Returns the list of classes to be used by a metabox |
136 | 948 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
949 |
* @uses get_user_option() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
950 |
* @since 2.5.0 |
136 | 951 |
* |
952 |
* @param unknown_type $id |
|
953 |
* @param unknown_type $page |
|
954 |
* @return unknown |
|
955 |
*/ |
|
956 |
function postbox_classes( $id, $page ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
957 |
if ( isset( $_GET['edit'] ) && $_GET['edit'] == $id ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
958 |
$classes = array( '' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
959 |
} elseif ( $closed = get_user_option('closedpostboxes_'.$page ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
960 |
if ( !is_array( $closed ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
961 |
$classes = array( '' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
962 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
963 |
$classes = in_array( $id, $closed ) ? array( 'closed' ) : array( '' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
964 |
} |
136 | 965 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
966 |
$classes = array( '' ); |
136 | 967 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
968 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
969 |
$classes = apply_filters( "postbox_classes_{$page}_{$id}", $classes ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
970 |
return implode( ' ', $classes ); |
136 | 971 |
} |
972 |
||
973 |
/** |
|
974 |
* {@internal Missing Short Description}} |
|
975 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
976 |
* @since 2.5.0 |
136 | 977 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
978 |
* @param int|object $id Post ID or post object. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
979 |
* @param string $title (optional) Title |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
980 |
* @param string $name (optional) Name |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
981 |
* @return array With two entries of type string |
136 | 982 |
*/ |
983 |
function get_sample_permalink($id, $title = null, $name = null) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
984 |
$post = get_post($id); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
985 |
if ( !$post->ID ) |
136 | 986 |
return array('', ''); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
987 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
988 |
$ptype = get_post_type_object($post->post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
989 |
|
136 | 990 |
$original_status = $post->post_status; |
991 |
$original_date = $post->post_date; |
|
992 |
$original_name = $post->post_name; |
|
993 |
||
994 |
// Hack: get_permalink would return ugly permalink for |
|
995 |
// drafts, so we will fake, that our post is published |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
996 |
if ( in_array($post->post_status, array('draft', 'pending')) ) { |
136 | 997 |
$post->post_status = 'publish'; |
998 |
$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); |
|
999 |
} |
|
1000 |
||
1001 |
// If the user wants to set a new name -- override the current one |
|
1002 |
// Note: if empty name is supplied -- use the title instead, see #6072 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1003 |
if ( !is_null($name) ) |
136 | 1004 |
$post->post_name = sanitize_title($name ? $name : $title, $post->ID); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1005 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1006 |
$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); |
136 | 1007 |
|
1008 |
$post->filter = 'sample'; |
|
1009 |
||
1010 |
$permalink = get_permalink($post, true); |
|
1011 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1012 |
// Replace custom post_type Token with generic pagename token for ease of use. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1013 |
$permalink = str_replace("%$post->post_type%", '%pagename%', $permalink); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1014 |
|
136 | 1015 |
// Handle page hierarchy |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1016 |
if ( $ptype->hierarchical ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1017 |
$uri = get_page_uri($post); |
136 | 1018 |
$uri = untrailingslashit($uri); |
1019 |
$uri = strrev( stristr( strrev( $uri ), '/' ) ); |
|
1020 |
$uri = untrailingslashit($uri); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1021 |
$uri = apply_filters( 'editable_slug', $uri ); |
136 | 1022 |
if ( !empty($uri) ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1023 |
$uri .= '/'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1024 |
$permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink); |
136 | 1025 |
} |
1026 |
||
1027 |
$permalink = array($permalink, apply_filters('editable_slug', $post->post_name)); |
|
1028 |
$post->post_status = $original_status; |
|
1029 |
$post->post_date = $original_date; |
|
1030 |
$post->post_name = $original_name; |
|
1031 |
unset($post->filter); |
|
1032 |
||
1033 |
return $permalink; |
|
1034 |
} |
|
1035 |
||
1036 |
/** |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1037 |
* Returns the HTML of the sample permalink slug editor. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1038 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1039 |
* @since 2.5.0 |
136 | 1040 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1041 |
* @param int|object $id Post ID or post object. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1042 |
* @param string $new_title Optional. New title. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1043 |
* @param string $new_slug Optional. New slug. |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1044 |
* @return string The HTML of the sample permalink slug editor. |
136 | 1045 |
*/ |
1046 |
function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1047 |
global $wpdb; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1048 |
$post = get_post($id); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1049 |
|
136 | 1050 |
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); |
1051 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1052 |
if ( 'publish' == get_post_status( $post ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1053 |
$ptype = get_post_type_object($post->post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1054 |
$view_post = $ptype->labels->view_item; |
136 | 1055 |
$title = __('Click to edit this part of the permalink'); |
1056 |
} else { |
|
1057 |
$title = __('Temporary permalink. Click to edit this part.'); |
|
1058 |
} |
|
1059 |
||
1060 |
if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1061 |
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n"; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1062 |
if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1063 |
$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1064 |
if ( isset( $view_post ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1065 |
$return .= "<span id='view-post-btn'><a href='$permalink' class='button button-small'>$view_post</a></span>\n"; |
136 | 1066 |
|
1067 |
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); |
|
1068 |
||
1069 |
return $return; |
|
1070 |
} |
|
1071 |
||
1072 |
if ( function_exists('mb_strlen') ) { |
|
1073 |
if ( mb_strlen($post_name) > 30 ) { |
|
1074 |
$post_name_abridged = mb_substr($post_name, 0, 14). '…' . mb_substr($post_name, -14); |
|
1075 |
} else { |
|
1076 |
$post_name_abridged = $post_name; |
|
1077 |
} |
|
1078 |
} else { |
|
1079 |
if ( strlen($post_name) > 30 ) { |
|
1080 |
$post_name_abridged = substr($post_name, 0, 14). '…' . substr($post_name, -14); |
|
1081 |
} else { |
|
1082 |
$post_name_abridged = $post_name; |
|
1083 |
} |
|
1084 |
} |
|
1085 |
||
1086 |
$post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>'; |
|
1087 |
$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink); |
|
1088 |
$view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1089 |
$return = '<strong>' . __('Permalink:') . "</strong>\n"; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1090 |
$return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1091 |
$return .= '‎'; // Fix bi-directional text display defect in RTL languages. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1092 |
$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n"; |
136 | 1093 |
$return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n"; |
1094 |
if ( isset($view_post) ) |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1095 |
$return .= "<span id='view-post-btn'><a href='$view_link' class='button button-small'>$view_post</a></span>\n"; |
136 | 1096 |
|
1097 |
$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug); |
|
1098 |
||
1099 |
return $return; |
|
1100 |
} |
|
1101 |
||
1102 |
/** |
|
1103 |
* Output HTML for the post thumbnail meta-box. |
|
1104 |
* |
|
1105 |
* @since 2.9.0 |
|
1106 |
* |
|
1107 |
* @param int $thumbnail_id ID of the attachment used for thumbnail |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1108 |
* @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post. |
136 | 1109 |
* @return string html |
1110 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1111 |
function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1112 |
global $content_width, $_wp_additional_image_sizes; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1113 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1114 |
$post = get_post( $post ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1115 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1116 |
$upload_iframe_src = esc_url( get_upload_iframe_src('image', $post->ID ) ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1117 |
$set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1118 |
$content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) ); |
136 | 1119 |
|
1120 |
if ( $thumbnail_id && get_post( $thumbnail_id ) ) { |
|
1121 |
$old_content_width = $content_width; |
|
1122 |
$content_width = 266; |
|
1123 |
if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) ) |
|
1124 |
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) ); |
|
1125 |
else |
|
1126 |
$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' ); |
|
1127 |
if ( !empty( $thumbnail_html ) ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1128 |
$ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1129 |
$content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1130 |
$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__( 'Remove featured image' ) . '</a></p>'; |
136 | 1131 |
} |
1132 |
$content_width = $old_content_width; |
|
1133 |
} |
|
1134 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1135 |
return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID ); |
136 | 1136 |
} |
1137 |
||
1138 |
/** |
|
1139 |
* Check to see if the post is currently being edited by another user. |
|
1140 |
* |
|
1141 |
* @since 2.5.0 |
|
1142 |
* |
|
1143 |
* @param int $post_id ID of the post to check for editing |
|
1144 |
* @return bool|int False: not locked or locked by current user. Int: user ID of user with lock. |
|
1145 |
*/ |
|
1146 |
function wp_check_post_lock( $post_id ) { |
|
1147 |
if ( !$post = get_post( $post_id ) ) |
|
1148 |
return false; |
|
1149 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1150 |
if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1151 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1152 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1153 |
$lock = explode( ':', $lock ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1154 |
$time = $lock[0]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1155 |
$user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); |
136 | 1156 |
|
1157 |
$time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ); |
|
1158 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1159 |
if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1160 |
return $user; |
136 | 1161 |
return false; |
1162 |
} |
|
1163 |
||
1164 |
/** |
|
1165 |
* Mark the post as currently being edited by the current user |
|
1166 |
* |
|
1167 |
* @since 2.5.0 |
|
1168 |
* |
|
1169 |
* @param int $post_id ID of the post to being edited |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1170 |
* @return bool|array Returns false if the post doesn't exist of there is no current user, or |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1171 |
* an array of the lock time and the user ID. |
136 | 1172 |
*/ |
1173 |
function wp_set_post_lock( $post_id ) { |
|
1174 |
if ( !$post = get_post( $post_id ) ) |
|
1175 |
return false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1176 |
if ( 0 == ($user_id = get_current_user_id()) ) |
136 | 1177 |
return false; |
1178 |
||
1179 |
$now = time(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1180 |
$lock = "$now:$user_id"; |
136 | 1181 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1182 |
update_post_meta( $post->ID, '_edit_lock', $lock ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1183 |
return array( $now, $user_id ); |
136 | 1184 |
} |
1185 |
||
1186 |
/** |
|
1187 |
* Outputs the notice message to say that someone else is editing this post at the moment. |
|
1188 |
* |
|
1189 |
* @since 2.8.5 |
|
1190 |
* @return none |
|
1191 |
*/ |
|
1192 |
function _admin_notice_post_locked() { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1193 |
$post = get_post(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1194 |
$lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1195 |
$user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1196 |
$last_user = get_userdata( $user ); |
136 | 1197 |
$last_user_name = $last_user ? $last_user->display_name : __('Somebody'); |
1198 |
||
1199 |
switch ($post->post_type) { |
|
1200 |
case 'post': |
|
1201 |
$message = __( 'Warning: %s is currently editing this post' ); |
|
1202 |
break; |
|
1203 |
case 'page': |
|
1204 |
$message = __( 'Warning: %s is currently editing this page' ); |
|
1205 |
break; |
|
1206 |
default: |
|
1207 |
$message = __( 'Warning: %s is currently editing this.' ); |
|
1208 |
} |
|
1209 |
||
1210 |
$message = sprintf( $message, esc_html( $last_user_name ) ); |
|
1211 |
echo "<div class='error'><p>$message</p></div>"; |
|
1212 |
} |
|
1213 |
||
1214 |
/** |
|
1215 |
* Creates autosave data for the specified post from $_POST data. |
|
1216 |
* |
|
1217 |
* @package WordPress |
|
1218 |
* @subpackage Post_Revisions |
|
1219 |
* @since 2.6.0 |
|
1220 |
* |
|
1221 |
* @uses _wp_translate_postdata() |
|
1222 |
* @uses _wp_post_revision_fields() |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1223 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1224 |
* @return unknown |
136 | 1225 |
*/ |
1226 |
function wp_create_post_autosave( $post_id ) { |
|
1227 |
$translated = _wp_translate_postdata( true ); |
|
1228 |
if ( is_wp_error( $translated ) ) |
|
1229 |
return $translated; |
|
1230 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1231 |
// Only store one autosave. If there is already an autosave, overwrite it. |
136 | 1232 |
if ( $old_autosave = wp_get_post_autosave( $post_id ) ) { |
1233 |
$new_autosave = _wp_post_revision_fields( $_POST, true ); |
|
1234 |
$new_autosave['ID'] = $old_autosave->ID; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1235 |
$new_autosave['post_author'] = get_current_user_id(); |
136 | 1236 |
return wp_update_post( $new_autosave ); |
1237 |
} |
|
1238 |
||
1239 |
// _wp_put_post_revision() expects unescaped. |
|
1240 |
$_POST = stripslashes_deep($_POST); |
|
1241 |
||
1242 |
// Otherwise create the new autosave as a special post revision |
|
1243 |
return _wp_put_post_revision( $_POST, true ); |
|
1244 |
} |
|
1245 |
||
1246 |
/** |
|
1247 |
* Save draft or manually autosave for showing preview. |
|
1248 |
* |
|
1249 |
* @package WordPress |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1250 |
* @since 2.7.0 |
136 | 1251 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1252 |
* @uses get_post_status() |
136 | 1253 |
* @uses edit_post() |
1254 |
* @uses get_post() |
|
1255 |
* @uses current_user_can() |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1256 |
* @uses wp_die() |
136 | 1257 |
* @uses wp_create_post_autosave() |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1258 |
* @uses add_query_arg() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1259 |
* @uses wp_create_nonce() |
136 | 1260 |
* |
1261 |
* @return str URL to redirect to show the preview |
|
1262 |
*/ |
|
1263 |
function post_preview() { |
|
1264 |
||
1265 |
$post_ID = (int) $_POST['post_ID']; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1266 |
$status = get_post_status( $post_ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1267 |
if ( 'auto-draft' == $status ) |
136 | 1268 |
wp_die( __('Preview not available. Please save as a draft first.') ); |
1269 |
||
1270 |
if ( isset($_POST['catslist']) ) |
|
1271 |
$_POST['post_category'] = explode(",", $_POST['catslist']); |
|
1272 |
||
1273 |
if ( isset($_POST['tags_input']) ) |
|
1274 |
$_POST['tags_input'] = explode(",", $_POST['tags_input']); |
|
1275 |
||
1276 |
if ( $_POST['post_type'] == 'page' || empty($_POST['post_category']) ) |
|
1277 |
unset($_POST['post_category']); |
|
1278 |
||
1279 |
$_POST['ID'] = $post_ID; |
|
1280 |
$post = get_post($post_ID); |
|
1281 |
||
1282 |
if ( 'page' == $post->post_type ) { |
|
1283 |
if ( !current_user_can('edit_page', $post_ID) ) |
|
1284 |
wp_die(__('You are not allowed to edit this page.')); |
|
1285 |
} else { |
|
1286 |
if ( !current_user_can('edit_post', $post_ID) ) |
|
1287 |
wp_die(__('You are not allowed to edit this post.')); |
|
1288 |
} |
|
1289 |
||
1290 |
if ( 'draft' == $post->post_status ) { |
|
1291 |
$id = edit_post(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1292 |
} else { // Non drafts are not overwritten. The autosave is stored in a special post revision. |
136 | 1293 |
$id = wp_create_post_autosave( $post->ID ); |
1294 |
if ( ! is_wp_error($id) ) |
|
1295 |
$id = $post->ID; |
|
1296 |
} |
|
1297 |
||
1298 |
if ( is_wp_error($id) ) |
|
1299 |
wp_die( $id->get_error_message() ); |
|
1300 |
||
1301 |
if ( $_POST['post_status'] == 'draft' ) { |
|
1302 |
$url = add_query_arg( 'preview', 'true', get_permalink($id) ); |
|
1303 |
} else { |
|
1304 |
$nonce = wp_create_nonce('post_preview_' . $id); |
|
1305 |
$url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) ); |
|
1306 |
} |
|
1307 |
||
1308 |
return $url; |
|
1309 |
} |