@@ -21,120 +21,120 @@ discard block |
||
21 | 21 | * @param array $request The unsanitized request values. |
22 | 22 | */ |
23 | 23 | function _wp_ajax_menu_quick_search( $request = array() ) { |
24 | - $args = array(); |
|
25 | - $type = isset( $request['type'] ) ? $request['type'] : ''; |
|
26 | - $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; |
|
27 | - $query = isset( $request['q'] ) ? $request['q'] : ''; |
|
28 | - $response_format = isset( $request['response-format'] ) ? $request['response-format'] : ''; |
|
29 | - |
|
30 | - if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) { |
|
31 | - $response_format = 'json'; |
|
32 | - } |
|
33 | - |
|
34 | - if ( 'markup' === $response_format ) { |
|
35 | - $args['walker'] = new Walker_Nav_Menu_Checklist; |
|
36 | - } |
|
37 | - |
|
38 | - if ( 'get-post-item' === $type ) { |
|
39 | - if ( post_type_exists( $object_type ) ) { |
|
40 | - if ( isset( $request['ID'] ) ) { |
|
41 | - $object_id = (int) $request['ID']; |
|
42 | - if ( 'markup' === $response_format ) { |
|
43 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); |
|
44 | - } elseif ( 'json' === $response_format ) { |
|
45 | - echo wp_json_encode( |
|
46 | - array( |
|
47 | - 'ID' => $object_id, |
|
48 | - 'post_title' => get_the_title( $object_id ), |
|
49 | - 'post_type' => get_post_type( $object_id ), |
|
50 | - ) |
|
51 | - ); |
|
52 | - echo "\n"; |
|
53 | - } |
|
54 | - } |
|
55 | - } elseif ( taxonomy_exists( $object_type ) ) { |
|
56 | - if ( isset( $request['ID'] ) ) { |
|
57 | - $object_id = (int) $request['ID']; |
|
58 | - if ( 'markup' === $response_format ) { |
|
59 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); |
|
60 | - } elseif ( 'json' === $response_format ) { |
|
61 | - $post_obj = get_term( $object_id, $object_type ); |
|
62 | - echo wp_json_encode( |
|
63 | - array( |
|
64 | - 'ID' => $object_id, |
|
65 | - 'post_title' => $post_obj->name, |
|
66 | - 'post_type' => $object_type, |
|
67 | - ) |
|
68 | - ); |
|
69 | - echo "\n"; |
|
70 | - } |
|
71 | - } |
|
72 | - } |
|
73 | - } elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) { |
|
74 | - if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) { |
|
75 | - $post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); |
|
76 | - $args = array_merge( |
|
77 | - $args, |
|
78 | - array( |
|
79 | - 'no_found_rows' => true, |
|
80 | - 'update_post_meta_cache' => false, |
|
81 | - 'update_post_term_cache' => false, |
|
82 | - 'posts_per_page' => 10, |
|
83 | - 'post_type' => $matches[2], |
|
84 | - 's' => $query, |
|
85 | - ) |
|
86 | - ); |
|
87 | - if ( isset( $post_type_obj->_default_query ) ) { |
|
88 | - $args = array_merge( $args, (array) $post_type_obj->_default_query ); |
|
89 | - } |
|
90 | - $search_results_query = new WP_Query( $args ); |
|
91 | - if ( ! $search_results_query->have_posts() ) { |
|
92 | - return; |
|
93 | - } |
|
94 | - while ( $search_results_query->have_posts() ) { |
|
95 | - $post = $search_results_query->next_post(); |
|
96 | - if ( 'markup' === $response_format ) { |
|
97 | - $var_by_ref = $post->ID; |
|
98 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); |
|
99 | - } elseif ( 'json' === $response_format ) { |
|
100 | - echo wp_json_encode( |
|
101 | - array( |
|
102 | - 'ID' => $post->ID, |
|
103 | - 'post_title' => get_the_title( $post->ID ), |
|
104 | - 'post_type' => $matches[2], |
|
105 | - ) |
|
106 | - ); |
|
107 | - echo "\n"; |
|
108 | - } |
|
109 | - } |
|
110 | - } elseif ( 'taxonomy' === $matches[1] ) { |
|
111 | - $terms = get_terms( |
|
112 | - array( |
|
113 | - 'taxonomy' => $matches[2], |
|
114 | - 'name__like' => $query, |
|
115 | - 'number' => 10, |
|
116 | - 'hide_empty' => false, |
|
117 | - ) |
|
118 | - ); |
|
119 | - if ( empty( $terms ) || is_wp_error( $terms ) ) { |
|
120 | - return; |
|
121 | - } |
|
122 | - foreach ( (array) $terms as $term ) { |
|
123 | - if ( 'markup' === $response_format ) { |
|
124 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); |
|
125 | - } elseif ( 'json' === $response_format ) { |
|
126 | - echo wp_json_encode( |
|
127 | - array( |
|
128 | - 'ID' => $term->term_id, |
|
129 | - 'post_title' => $term->name, |
|
130 | - 'post_type' => $matches[2], |
|
131 | - ) |
|
132 | - ); |
|
133 | - echo "\n"; |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
24 | + $args = array(); |
|
25 | + $type = isset( $request['type'] ) ? $request['type'] : ''; |
|
26 | + $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; |
|
27 | + $query = isset( $request['q'] ) ? $request['q'] : ''; |
|
28 | + $response_format = isset( $request['response-format'] ) ? $request['response-format'] : ''; |
|
29 | + |
|
30 | + if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) { |
|
31 | + $response_format = 'json'; |
|
32 | + } |
|
33 | + |
|
34 | + if ( 'markup' === $response_format ) { |
|
35 | + $args['walker'] = new Walker_Nav_Menu_Checklist; |
|
36 | + } |
|
37 | + |
|
38 | + if ( 'get-post-item' === $type ) { |
|
39 | + if ( post_type_exists( $object_type ) ) { |
|
40 | + if ( isset( $request['ID'] ) ) { |
|
41 | + $object_id = (int) $request['ID']; |
|
42 | + if ( 'markup' === $response_format ) { |
|
43 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); |
|
44 | + } elseif ( 'json' === $response_format ) { |
|
45 | + echo wp_json_encode( |
|
46 | + array( |
|
47 | + 'ID' => $object_id, |
|
48 | + 'post_title' => get_the_title( $object_id ), |
|
49 | + 'post_type' => get_post_type( $object_id ), |
|
50 | + ) |
|
51 | + ); |
|
52 | + echo "\n"; |
|
53 | + } |
|
54 | + } |
|
55 | + } elseif ( taxonomy_exists( $object_type ) ) { |
|
56 | + if ( isset( $request['ID'] ) ) { |
|
57 | + $object_id = (int) $request['ID']; |
|
58 | + if ( 'markup' === $response_format ) { |
|
59 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); |
|
60 | + } elseif ( 'json' === $response_format ) { |
|
61 | + $post_obj = get_term( $object_id, $object_type ); |
|
62 | + echo wp_json_encode( |
|
63 | + array( |
|
64 | + 'ID' => $object_id, |
|
65 | + 'post_title' => $post_obj->name, |
|
66 | + 'post_type' => $object_type, |
|
67 | + ) |
|
68 | + ); |
|
69 | + echo "\n"; |
|
70 | + } |
|
71 | + } |
|
72 | + } |
|
73 | + } elseif ( preg_match( '/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches ) ) { |
|
74 | + if ( 'posttype' === $matches[1] && get_post_type_object( $matches[2] ) ) { |
|
75 | + $post_type_obj = _wp_nav_menu_meta_box_object( get_post_type_object( $matches[2] ) ); |
|
76 | + $args = array_merge( |
|
77 | + $args, |
|
78 | + array( |
|
79 | + 'no_found_rows' => true, |
|
80 | + 'update_post_meta_cache' => false, |
|
81 | + 'update_post_term_cache' => false, |
|
82 | + 'posts_per_page' => 10, |
|
83 | + 'post_type' => $matches[2], |
|
84 | + 's' => $query, |
|
85 | + ) |
|
86 | + ); |
|
87 | + if ( isset( $post_type_obj->_default_query ) ) { |
|
88 | + $args = array_merge( $args, (array) $post_type_obj->_default_query ); |
|
89 | + } |
|
90 | + $search_results_query = new WP_Query( $args ); |
|
91 | + if ( ! $search_results_query->have_posts() ) { |
|
92 | + return; |
|
93 | + } |
|
94 | + while ( $search_results_query->have_posts() ) { |
|
95 | + $post = $search_results_query->next_post(); |
|
96 | + if ( 'markup' === $response_format ) { |
|
97 | + $var_by_ref = $post->ID; |
|
98 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); |
|
99 | + } elseif ( 'json' === $response_format ) { |
|
100 | + echo wp_json_encode( |
|
101 | + array( |
|
102 | + 'ID' => $post->ID, |
|
103 | + 'post_title' => get_the_title( $post->ID ), |
|
104 | + 'post_type' => $matches[2], |
|
105 | + ) |
|
106 | + ); |
|
107 | + echo "\n"; |
|
108 | + } |
|
109 | + } |
|
110 | + } elseif ( 'taxonomy' === $matches[1] ) { |
|
111 | + $terms = get_terms( |
|
112 | + array( |
|
113 | + 'taxonomy' => $matches[2], |
|
114 | + 'name__like' => $query, |
|
115 | + 'number' => 10, |
|
116 | + 'hide_empty' => false, |
|
117 | + ) |
|
118 | + ); |
|
119 | + if ( empty( $terms ) || is_wp_error( $terms ) ) { |
|
120 | + return; |
|
121 | + } |
|
122 | + foreach ( (array) $terms as $term ) { |
|
123 | + if ( 'markup' === $response_format ) { |
|
124 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); |
|
125 | + } elseif ( 'json' === $response_format ) { |
|
126 | + echo wp_json_encode( |
|
127 | + array( |
|
128 | + 'ID' => $term->term_id, |
|
129 | + 'post_title' => $term->name, |
|
130 | + 'post_type' => $matches[2], |
|
131 | + ) |
|
132 | + ); |
|
133 | + echo "\n"; |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -143,29 +143,29 @@ discard block |
||
143 | 143 | * @since 3.0.0 |
144 | 144 | */ |
145 | 145 | function wp_nav_menu_setup() { |
146 | - // Register meta boxes. |
|
147 | - wp_nav_menu_post_type_meta_boxes(); |
|
148 | - add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); |
|
149 | - wp_nav_menu_taxonomy_meta_boxes(); |
|
150 | - |
|
151 | - // Register advanced menu items (columns). |
|
152 | - add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); |
|
153 | - |
|
154 | - // If first time editing, disable advanced items by default. |
|
155 | - if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { |
|
156 | - $user = wp_get_current_user(); |
|
157 | - update_user_meta( |
|
158 | - $user->ID, |
|
159 | - 'managenav-menuscolumnshidden', |
|
160 | - array( |
|
161 | - 0 => 'link-target', |
|
162 | - 1 => 'css-classes', |
|
163 | - 2 => 'xfn', |
|
164 | - 3 => 'description', |
|
165 | - 4 => 'title-attribute', |
|
166 | - ) |
|
167 | - ); |
|
168 | - } |
|
146 | + // Register meta boxes. |
|
147 | + wp_nav_menu_post_type_meta_boxes(); |
|
148 | + add_meta_box( 'add-custom-links', __( 'Custom Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); |
|
149 | + wp_nav_menu_taxonomy_meta_boxes(); |
|
150 | + |
|
151 | + // Register advanced menu items (columns). |
|
152 | + add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); |
|
153 | + |
|
154 | + // If first time editing, disable advanced items by default. |
|
155 | + if ( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { |
|
156 | + $user = wp_get_current_user(); |
|
157 | + update_user_meta( |
|
158 | + $user->ID, |
|
159 | + 'managenav-menuscolumnshidden', |
|
160 | + array( |
|
161 | + 0 => 'link-target', |
|
162 | + 1 => 'css-classes', |
|
163 | + 2 => 'xfn', |
|
164 | + 3 => 'description', |
|
165 | + 4 => 'title-attribute', |
|
166 | + ) |
|
167 | + ); |
|
168 | + } |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | * @global array $wp_meta_boxes |
177 | 177 | */ |
178 | 178 | function wp_initial_nav_menu_meta_boxes() { |
179 | - global $wp_meta_boxes; |
|
180 | - |
|
181 | - if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) { |
|
182 | - return; |
|
183 | - } |
|
184 | - |
|
185 | - $initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category' ); |
|
186 | - $hidden_meta_boxes = array(); |
|
187 | - |
|
188 | - foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) { |
|
189 | - foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) { |
|
190 | - foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) { |
|
191 | - if ( in_array( $box['id'], $initial_meta_boxes, true ) ) { |
|
192 | - unset( $box['id'] ); |
|
193 | - } else { |
|
194 | - $hidden_meta_boxes[] = $box['id']; |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - $user = wp_get_current_user(); |
|
201 | - update_user_meta( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes ); |
|
179 | + global $wp_meta_boxes; |
|
180 | + |
|
181 | + if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array( $wp_meta_boxes ) ) { |
|
182 | + return; |
|
183 | + } |
|
184 | + |
|
185 | + $initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category' ); |
|
186 | + $hidden_meta_boxes = array(); |
|
187 | + |
|
188 | + foreach ( array_keys( $wp_meta_boxes['nav-menus'] ) as $context ) { |
|
189 | + foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) { |
|
190 | + foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) { |
|
191 | + if ( in_array( $box['id'], $initial_meta_boxes, true ) ) { |
|
192 | + unset( $box['id'] ); |
|
193 | + } else { |
|
194 | + $hidden_meta_boxes[] = $box['id']; |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + $user = wp_get_current_user(); |
|
201 | + update_user_meta( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes ); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -207,33 +207,33 @@ discard block |
||
207 | 207 | * @since 3.0.0 |
208 | 208 | */ |
209 | 209 | function wp_nav_menu_post_type_meta_boxes() { |
210 | - $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); |
|
211 | - |
|
212 | - if ( ! $post_types ) { |
|
213 | - return; |
|
214 | - } |
|
215 | - |
|
216 | - foreach ( $post_types as $post_type ) { |
|
217 | - /** |
|
218 | - * Filters whether a menu items meta box will be added for the current |
|
219 | - * object type. |
|
220 | - * |
|
221 | - * If a falsey value is returned instead of an object, the menu items |
|
222 | - * meta box for the current meta box object will not be added. |
|
223 | - * |
|
224 | - * @since 3.0.0 |
|
225 | - * |
|
226 | - * @param WP_Post_Type|false $post_type The current object to add a menu items |
|
227 | - * meta box for. |
|
228 | - */ |
|
229 | - $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); |
|
230 | - if ( $post_type ) { |
|
231 | - $id = $post_type->name; |
|
232 | - // Give pages a higher priority. |
|
233 | - $priority = ( 'page' === $post_type->name ? 'core' : 'default' ); |
|
234 | - add_meta_box( "add-post-type-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type ); |
|
235 | - } |
|
236 | - } |
|
210 | + $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); |
|
211 | + |
|
212 | + if ( ! $post_types ) { |
|
213 | + return; |
|
214 | + } |
|
215 | + |
|
216 | + foreach ( $post_types as $post_type ) { |
|
217 | + /** |
|
218 | + * Filters whether a menu items meta box will be added for the current |
|
219 | + * object type. |
|
220 | + * |
|
221 | + * If a falsey value is returned instead of an object, the menu items |
|
222 | + * meta box for the current meta box object will not be added. |
|
223 | + * |
|
224 | + * @since 3.0.0 |
|
225 | + * |
|
226 | + * @param WP_Post_Type|false $post_type The current object to add a menu items |
|
227 | + * meta box for. |
|
228 | + */ |
|
229 | + $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); |
|
230 | + if ( $post_type ) { |
|
231 | + $id = $post_type->name; |
|
232 | + // Give pages a higher priority. |
|
233 | + $priority = ( 'page' === $post_type->name ? 'core' : 'default' ); |
|
234 | + add_meta_box( "add-post-type-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type ); |
|
235 | + } |
|
236 | + } |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -242,20 +242,20 @@ discard block |
||
242 | 242 | * @since 3.0.0 |
243 | 243 | */ |
244 | 244 | function wp_nav_menu_taxonomy_meta_boxes() { |
245 | - $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); |
|
246 | - |
|
247 | - if ( ! $taxonomies ) { |
|
248 | - return; |
|
249 | - } |
|
250 | - |
|
251 | - foreach ( $taxonomies as $tax ) { |
|
252 | - /** This filter is documented in wp-admin/includes/nav-menu.php */ |
|
253 | - $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); |
|
254 | - if ( $tax ) { |
|
255 | - $id = $tax->name; |
|
256 | - add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); |
|
257 | - } |
|
258 | - } |
|
245 | + $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); |
|
246 | + |
|
247 | + if ( ! $taxonomies ) { |
|
248 | + return; |
|
249 | + } |
|
250 | + |
|
251 | + foreach ( $taxonomies as $tax ) { |
|
252 | + /** This filter is documented in wp-admin/includes/nav-menu.php */ |
|
253 | + $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); |
|
254 | + if ( $tax ) { |
|
255 | + $id = $tax->name; |
|
256 | + add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); |
|
257 | + } |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -271,13 +271,13 @@ discard block |
||
271 | 271 | * @return string|false Disabled attribute if at least one menu exists, false if not. |
272 | 272 | */ |
273 | 273 | function wp_nav_menu_disabled_check( $nav_menu_selected_id, $display = true ) { |
274 | - global $one_theme_location_no_menus; |
|
274 | + global $one_theme_location_no_menus; |
|
275 | 275 | |
276 | - if ( $one_theme_location_no_menus ) { |
|
277 | - return false; |
|
278 | - } |
|
276 | + if ( $one_theme_location_no_menus ) { |
|
277 | + return false; |
|
278 | + } |
|
279 | 279 | |
280 | - return disabled( $nav_menu_selected_id, 0, $display ); |
|
280 | + return disabled( $nav_menu_selected_id, 0, $display ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | * @global int|string $nav_menu_selected_id |
290 | 290 | */ |
291 | 291 | function wp_nav_menu_item_link_meta_box() { |
292 | - global $_nav_menu_placeholder, $nav_menu_selected_id; |
|
292 | + global $_nav_menu_placeholder, $nav_menu_selected_id; |
|
293 | 293 | |
294 | - $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; |
|
294 | + $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; |
|
295 | 295 | |
296 | - ?> |
|
296 | + ?> |
|
297 | 297 | <div class="customlinkdiv" id="customlinkdiv"> |
298 | 298 | <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> |
299 | 299 | <p id="menu-item-url-wrap" class="wp-clearfix"> |
@@ -336,175 +336,175 @@ discard block |
||
336 | 336 | * } |
337 | 337 | */ |
338 | 338 | function wp_nav_menu_item_post_type_meta_box( $data_object, $box ) { |
339 | - global $_nav_menu_placeholder, $nav_menu_selected_id; |
|
340 | - |
|
341 | - $post_type_name = $box['args']->name; |
|
342 | - $post_type = get_post_type_object( $post_type_name ); |
|
343 | - $tab_name = $post_type_name . '-tab'; |
|
344 | - |
|
345 | - // Paginate browsing for large numbers of post objects. |
|
346 | - $per_page = 50; |
|
347 | - $pagenum = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
|
348 | - $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
|
349 | - |
|
350 | - $args = array( |
|
351 | - 'offset' => $offset, |
|
352 | - 'order' => 'ASC', |
|
353 | - 'orderby' => 'title', |
|
354 | - 'posts_per_page' => $per_page, |
|
355 | - 'post_type' => $post_type_name, |
|
356 | - 'suppress_filters' => true, |
|
357 | - 'update_post_term_cache' => false, |
|
358 | - 'update_post_meta_cache' => false, |
|
359 | - ); |
|
360 | - |
|
361 | - if ( isset( $box['args']->_default_query ) ) { |
|
362 | - $args = array_merge( $args, (array) $box['args']->_default_query ); |
|
363 | - } |
|
364 | - |
|
365 | - /* |
|
339 | + global $_nav_menu_placeholder, $nav_menu_selected_id; |
|
340 | + |
|
341 | + $post_type_name = $box['args']->name; |
|
342 | + $post_type = get_post_type_object( $post_type_name ); |
|
343 | + $tab_name = $post_type_name . '-tab'; |
|
344 | + |
|
345 | + // Paginate browsing for large numbers of post objects. |
|
346 | + $per_page = 50; |
|
347 | + $pagenum = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
|
348 | + $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
|
349 | + |
|
350 | + $args = array( |
|
351 | + 'offset' => $offset, |
|
352 | + 'order' => 'ASC', |
|
353 | + 'orderby' => 'title', |
|
354 | + 'posts_per_page' => $per_page, |
|
355 | + 'post_type' => $post_type_name, |
|
356 | + 'suppress_filters' => true, |
|
357 | + 'update_post_term_cache' => false, |
|
358 | + 'update_post_meta_cache' => false, |
|
359 | + ); |
|
360 | + |
|
361 | + if ( isset( $box['args']->_default_query ) ) { |
|
362 | + $args = array_merge( $args, (array) $box['args']->_default_query ); |
|
363 | + } |
|
364 | + |
|
365 | + /* |
|
366 | 366 | * If we're dealing with pages, let's prioritize the Front Page, |
367 | 367 | * Posts Page and Privacy Policy Page at the top of the list. |
368 | 368 | */ |
369 | - $important_pages = array(); |
|
370 | - if ( 'page' === $post_type_name ) { |
|
371 | - $suppress_page_ids = array(); |
|
372 | - |
|
373 | - // Insert Front Page or custom Home link. |
|
374 | - $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; |
|
375 | - |
|
376 | - $front_page_obj = null; |
|
377 | - if ( ! empty( $front_page ) ) { |
|
378 | - $front_page_obj = get_post( $front_page ); |
|
379 | - $front_page_obj->front_or_home = true; |
|
380 | - |
|
381 | - $important_pages[] = $front_page_obj; |
|
382 | - $suppress_page_ids[] = $front_page_obj->ID; |
|
383 | - } else { |
|
384 | - $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; |
|
385 | - $front_page_obj = (object) array( |
|
386 | - 'front_or_home' => true, |
|
387 | - 'ID' => 0, |
|
388 | - 'object_id' => $_nav_menu_placeholder, |
|
389 | - 'post_content' => '', |
|
390 | - 'post_excerpt' => '', |
|
391 | - 'post_parent' => '', |
|
392 | - 'post_title' => _x( 'Home', 'nav menu home label' ), |
|
393 | - 'post_type' => 'nav_menu_item', |
|
394 | - 'type' => 'custom', |
|
395 | - 'url' => home_url( '/' ), |
|
396 | - ); |
|
397 | - |
|
398 | - $important_pages[] = $front_page_obj; |
|
399 | - } |
|
400 | - |
|
401 | - // Insert Posts Page. |
|
402 | - $posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; |
|
403 | - |
|
404 | - if ( ! empty( $posts_page ) ) { |
|
405 | - $posts_page_obj = get_post( $posts_page ); |
|
406 | - $posts_page_obj->posts_page = true; |
|
407 | - |
|
408 | - $important_pages[] = $posts_page_obj; |
|
409 | - $suppress_page_ids[] = $posts_page_obj->ID; |
|
410 | - } |
|
411 | - |
|
412 | - // Insert Privacy Policy Page. |
|
413 | - $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
414 | - |
|
415 | - if ( ! empty( $privacy_policy_page_id ) ) { |
|
416 | - $privacy_policy_page = get_post( $privacy_policy_page_id ); |
|
417 | - if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { |
|
418 | - $privacy_policy_page->privacy_policy_page = true; |
|
419 | - |
|
420 | - $important_pages[] = $privacy_policy_page; |
|
421 | - $suppress_page_ids[] = $privacy_policy_page->ID; |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - // Add suppression array to arguments for WP_Query. |
|
426 | - if ( ! empty( $suppress_page_ids ) ) { |
|
427 | - $args['post__not_in'] = $suppress_page_ids; |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - // @todo Transient caching of these results with proper invalidation on updating of a post of this type. |
|
432 | - $get_posts = new WP_Query; |
|
433 | - $posts = $get_posts->query( $args ); |
|
434 | - |
|
435 | - // Only suppress and insert when more than just suppression pages available. |
|
436 | - if ( ! $get_posts->post_count ) { |
|
437 | - if ( ! empty( $suppress_page_ids ) ) { |
|
438 | - unset( $args['post__not_in'] ); |
|
439 | - $get_posts = new WP_Query; |
|
440 | - $posts = $get_posts->query( $args ); |
|
441 | - } else { |
|
442 | - echo '<p>' . __( 'No items.' ) . '</p>'; |
|
443 | - return; |
|
444 | - } |
|
445 | - } elseif ( ! empty( $important_pages ) ) { |
|
446 | - $posts = array_merge( $important_pages, $posts ); |
|
447 | - } |
|
448 | - |
|
449 | - $num_pages = $get_posts->max_num_pages; |
|
450 | - |
|
451 | - $page_links = paginate_links( |
|
452 | - array( |
|
453 | - 'base' => add_query_arg( |
|
454 | - array( |
|
455 | - $tab_name => 'all', |
|
456 | - 'paged' => '%#%', |
|
457 | - 'item-type' => 'post_type', |
|
458 | - 'item-object' => $post_type_name, |
|
459 | - ) |
|
460 | - ), |
|
461 | - 'format' => '', |
|
462 | - 'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>', |
|
463 | - 'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>', |
|
464 | - 'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ', |
|
465 | - 'total' => $num_pages, |
|
466 | - 'current' => $pagenum, |
|
467 | - ) |
|
468 | - ); |
|
469 | - |
|
470 | - $db_fields = false; |
|
471 | - if ( is_post_type_hierarchical( $post_type_name ) ) { |
|
472 | - $db_fields = array( |
|
473 | - 'parent' => 'post_parent', |
|
474 | - 'id' => 'ID', |
|
475 | - ); |
|
476 | - } |
|
477 | - |
|
478 | - $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
479 | - |
|
480 | - $current_tab = 'most-recent'; |
|
481 | - |
|
482 | - if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) { |
|
483 | - $current_tab = $_REQUEST[ $tab_name ]; |
|
484 | - } |
|
485 | - |
|
486 | - if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { |
|
487 | - $current_tab = 'search'; |
|
488 | - } |
|
489 | - |
|
490 | - $removed_args = array( |
|
491 | - 'action', |
|
492 | - 'customlink-tab', |
|
493 | - 'edit-menu-item', |
|
494 | - 'menu-item', |
|
495 | - 'page-tab', |
|
496 | - '_wpnonce', |
|
497 | - ); |
|
498 | - |
|
499 | - $most_recent_url = ''; |
|
500 | - $view_all_url = ''; |
|
501 | - $search_url = ''; |
|
502 | - if ( $nav_menu_selected_id ) { |
|
503 | - $most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) ); |
|
504 | - $view_all_url = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); |
|
505 | - $search_url = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) ); |
|
506 | - } |
|
507 | - ?> |
|
369 | + $important_pages = array(); |
|
370 | + if ( 'page' === $post_type_name ) { |
|
371 | + $suppress_page_ids = array(); |
|
372 | + |
|
373 | + // Insert Front Page or custom Home link. |
|
374 | + $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; |
|
375 | + |
|
376 | + $front_page_obj = null; |
|
377 | + if ( ! empty( $front_page ) ) { |
|
378 | + $front_page_obj = get_post( $front_page ); |
|
379 | + $front_page_obj->front_or_home = true; |
|
380 | + |
|
381 | + $important_pages[] = $front_page_obj; |
|
382 | + $suppress_page_ids[] = $front_page_obj->ID; |
|
383 | + } else { |
|
384 | + $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; |
|
385 | + $front_page_obj = (object) array( |
|
386 | + 'front_or_home' => true, |
|
387 | + 'ID' => 0, |
|
388 | + 'object_id' => $_nav_menu_placeholder, |
|
389 | + 'post_content' => '', |
|
390 | + 'post_excerpt' => '', |
|
391 | + 'post_parent' => '', |
|
392 | + 'post_title' => _x( 'Home', 'nav menu home label' ), |
|
393 | + 'post_type' => 'nav_menu_item', |
|
394 | + 'type' => 'custom', |
|
395 | + 'url' => home_url( '/' ), |
|
396 | + ); |
|
397 | + |
|
398 | + $important_pages[] = $front_page_obj; |
|
399 | + } |
|
400 | + |
|
401 | + // Insert Posts Page. |
|
402 | + $posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; |
|
403 | + |
|
404 | + if ( ! empty( $posts_page ) ) { |
|
405 | + $posts_page_obj = get_post( $posts_page ); |
|
406 | + $posts_page_obj->posts_page = true; |
|
407 | + |
|
408 | + $important_pages[] = $posts_page_obj; |
|
409 | + $suppress_page_ids[] = $posts_page_obj->ID; |
|
410 | + } |
|
411 | + |
|
412 | + // Insert Privacy Policy Page. |
|
413 | + $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); |
|
414 | + |
|
415 | + if ( ! empty( $privacy_policy_page_id ) ) { |
|
416 | + $privacy_policy_page = get_post( $privacy_policy_page_id ); |
|
417 | + if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { |
|
418 | + $privacy_policy_page->privacy_policy_page = true; |
|
419 | + |
|
420 | + $important_pages[] = $privacy_policy_page; |
|
421 | + $suppress_page_ids[] = $privacy_policy_page->ID; |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + // Add suppression array to arguments for WP_Query. |
|
426 | + if ( ! empty( $suppress_page_ids ) ) { |
|
427 | + $args['post__not_in'] = $suppress_page_ids; |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + // @todo Transient caching of these results with proper invalidation on updating of a post of this type. |
|
432 | + $get_posts = new WP_Query; |
|
433 | + $posts = $get_posts->query( $args ); |
|
434 | + |
|
435 | + // Only suppress and insert when more than just suppression pages available. |
|
436 | + if ( ! $get_posts->post_count ) { |
|
437 | + if ( ! empty( $suppress_page_ids ) ) { |
|
438 | + unset( $args['post__not_in'] ); |
|
439 | + $get_posts = new WP_Query; |
|
440 | + $posts = $get_posts->query( $args ); |
|
441 | + } else { |
|
442 | + echo '<p>' . __( 'No items.' ) . '</p>'; |
|
443 | + return; |
|
444 | + } |
|
445 | + } elseif ( ! empty( $important_pages ) ) { |
|
446 | + $posts = array_merge( $important_pages, $posts ); |
|
447 | + } |
|
448 | + |
|
449 | + $num_pages = $get_posts->max_num_pages; |
|
450 | + |
|
451 | + $page_links = paginate_links( |
|
452 | + array( |
|
453 | + 'base' => add_query_arg( |
|
454 | + array( |
|
455 | + $tab_name => 'all', |
|
456 | + 'paged' => '%#%', |
|
457 | + 'item-type' => 'post_type', |
|
458 | + 'item-object' => $post_type_name, |
|
459 | + ) |
|
460 | + ), |
|
461 | + 'format' => '', |
|
462 | + 'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>', |
|
463 | + 'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>', |
|
464 | + 'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ', |
|
465 | + 'total' => $num_pages, |
|
466 | + 'current' => $pagenum, |
|
467 | + ) |
|
468 | + ); |
|
469 | + |
|
470 | + $db_fields = false; |
|
471 | + if ( is_post_type_hierarchical( $post_type_name ) ) { |
|
472 | + $db_fields = array( |
|
473 | + 'parent' => 'post_parent', |
|
474 | + 'id' => 'ID', |
|
475 | + ); |
|
476 | + } |
|
477 | + |
|
478 | + $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
479 | + |
|
480 | + $current_tab = 'most-recent'; |
|
481 | + |
|
482 | + if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) { |
|
483 | + $current_tab = $_REQUEST[ $tab_name ]; |
|
484 | + } |
|
485 | + |
|
486 | + if ( ! empty( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { |
|
487 | + $current_tab = 'search'; |
|
488 | + } |
|
489 | + |
|
490 | + $removed_args = array( |
|
491 | + 'action', |
|
492 | + 'customlink-tab', |
|
493 | + 'edit-menu-item', |
|
494 | + 'menu-item', |
|
495 | + 'page-tab', |
|
496 | + '_wpnonce', |
|
497 | + ); |
|
498 | + |
|
499 | + $most_recent_url = ''; |
|
500 | + $view_all_url = ''; |
|
501 | + $search_url = ''; |
|
502 | + if ( $nav_menu_selected_id ) { |
|
503 | + $most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) ); |
|
504 | + $view_all_url = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); |
|
505 | + $search_url = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) ); |
|
506 | + } |
|
507 | + ?> |
|
508 | 508 | <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv"> |
509 | 509 | <ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs"> |
510 | 510 | <li <?php echo ( 'most-recent' === $current_tab ? ' class="tabs"' : '' ); ?>> |
@@ -527,60 +527,60 @@ discard block |
||
527 | 527 | <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php echo ( 'most-recent' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" role="region" aria-label="<?php _e( 'Most Recent' ); ?>" tabindex="0"> |
528 | 528 | <ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear"> |
529 | 529 | <?php |
530 | - $recent_args = array_merge( |
|
531 | - $args, |
|
532 | - array( |
|
533 | - 'orderby' => 'post_date', |
|
534 | - 'order' => 'DESC', |
|
535 | - 'posts_per_page' => 15, |
|
536 | - ) |
|
537 | - ); |
|
538 | - $most_recent = $get_posts->query( $recent_args ); |
|
539 | - $args['walker'] = $walker; |
|
540 | - |
|
541 | - /** |
|
542 | - * Filters the posts displayed in the 'Most Recent' tab of the current |
|
543 | - * post type's menu items meta box. |
|
544 | - * |
|
545 | - * The dynamic portion of the hook name, `$post_type_name`, refers to the post type name. |
|
546 | - * |
|
547 | - * Possible hook names include: |
|
548 | - * |
|
549 | - * - `nav_menu_items_post_recent` |
|
550 | - * - `nav_menu_items_page_recent` |
|
551 | - * |
|
552 | - * @since 4.3.0 |
|
553 | - * @since 4.9.0 Added the `$recent_args` parameter. |
|
554 | - * |
|
555 | - * @param WP_Post[] $most_recent An array of post objects being listed. |
|
556 | - * @param array $args An array of `WP_Query` arguments for the meta box. |
|
557 | - * @param array $box Arguments passed to `wp_nav_menu_item_post_type_meta_box()`. |
|
558 | - * @param array $recent_args An array of `WP_Query` arguments for 'Most Recent' tab. |
|
559 | - */ |
|
560 | - $most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box, $recent_args ); |
|
561 | - |
|
562 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args ); |
|
563 | - ?> |
|
530 | + $recent_args = array_merge( |
|
531 | + $args, |
|
532 | + array( |
|
533 | + 'orderby' => 'post_date', |
|
534 | + 'order' => 'DESC', |
|
535 | + 'posts_per_page' => 15, |
|
536 | + ) |
|
537 | + ); |
|
538 | + $most_recent = $get_posts->query( $recent_args ); |
|
539 | + $args['walker'] = $walker; |
|
540 | + |
|
541 | + /** |
|
542 | + * Filters the posts displayed in the 'Most Recent' tab of the current |
|
543 | + * post type's menu items meta box. |
|
544 | + * |
|
545 | + * The dynamic portion of the hook name, `$post_type_name`, refers to the post type name. |
|
546 | + * |
|
547 | + * Possible hook names include: |
|
548 | + * |
|
549 | + * - `nav_menu_items_post_recent` |
|
550 | + * - `nav_menu_items_page_recent` |
|
551 | + * |
|
552 | + * @since 4.3.0 |
|
553 | + * @since 4.9.0 Added the `$recent_args` parameter. |
|
554 | + * |
|
555 | + * @param WP_Post[] $most_recent An array of post objects being listed. |
|
556 | + * @param array $args An array of `WP_Query` arguments for the meta box. |
|
557 | + * @param array $box Arguments passed to `wp_nav_menu_item_post_type_meta_box()`. |
|
558 | + * @param array $recent_args An array of `WP_Query` arguments for 'Most Recent' tab. |
|
559 | + */ |
|
560 | + $most_recent = apply_filters( "nav_menu_items_{$post_type_name}_recent", $most_recent, $args, $box, $recent_args ); |
|
561 | + |
|
562 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $most_recent ), 0, (object) $args ); |
|
563 | + ?> |
|
564 | 564 | </ul> |
565 | 565 | </div><!-- /.tabs-panel --> |
566 | 566 | |
567 | 567 | <div class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search" role="region" aria-label="<?php echo $post_type->labels->search_items; ?>" tabindex="0"> |
568 | 568 | <?php |
569 | - if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { |
|
570 | - $searched = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ); |
|
571 | - $search_results = get_posts( |
|
572 | - array( |
|
573 | - 's' => $searched, |
|
574 | - 'post_type' => $post_type_name, |
|
575 | - 'fields' => 'all', |
|
576 | - 'order' => 'DESC', |
|
577 | - ) |
|
578 | - ); |
|
579 | - } else { |
|
580 | - $searched = ''; |
|
581 | - $search_results = array(); |
|
582 | - } |
|
583 | - ?> |
|
569 | + if ( isset( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ) ) { |
|
570 | + $searched = esc_attr( $_REQUEST[ 'quick-search-posttype-' . $post_type_name ] ); |
|
571 | + $search_results = get_posts( |
|
572 | + array( |
|
573 | + 's' => $searched, |
|
574 | + 'post_type' => $post_type_name, |
|
575 | + 'fields' => 'all', |
|
576 | + 'order' => 'DESC', |
|
577 | + ) |
|
578 | + ); |
|
579 | + } else { |
|
580 | + $searched = ''; |
|
581 | + $search_results = array(); |
|
582 | + } |
|
583 | + ?> |
|
584 | 584 | <p class="quick-search-wrap"> |
585 | 585 | <label for="quick-search-posttype-<?php echo $post_type_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label> |
586 | 586 | <input type="search"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="quick-search" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" id="quick-search-posttype-<?php echo $post_type_name; ?>" /> |
@@ -591,9 +591,9 @@ discard block |
||
591 | 591 | <ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear"> |
592 | 592 | <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> |
593 | 593 | <?php |
594 | - $args['walker'] = $walker; |
|
595 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args ); |
|
596 | - ?> |
|
594 | + $args['walker'] = $walker; |
|
595 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args ); |
|
596 | + ?> |
|
597 | 597 | <?php elseif ( is_wp_error( $search_results ) ) : ?> |
598 | 598 | <li><?php echo $search_results->get_error_message(); ?></li> |
599 | 599 | <?php elseif ( ! empty( $searched ) ) : ?> |
@@ -610,54 +610,54 @@ discard block |
||
610 | 610 | <?php endif; ?> |
611 | 611 | <ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name; ?>" class="categorychecklist form-no-clear"> |
612 | 612 | <?php |
613 | - $args['walker'] = $walker; |
|
614 | - |
|
615 | - if ( $post_type->has_archive ) { |
|
616 | - $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; |
|
617 | - array_unshift( |
|
618 | - $posts, |
|
619 | - (object) array( |
|
620 | - 'ID' => 0, |
|
621 | - 'object_id' => $_nav_menu_placeholder, |
|
622 | - 'object' => $post_type_name, |
|
623 | - 'post_content' => '', |
|
624 | - 'post_excerpt' => '', |
|
625 | - 'post_title' => $post_type->labels->archives, |
|
626 | - 'post_type' => 'nav_menu_item', |
|
627 | - 'type' => 'post_type_archive', |
|
628 | - 'url' => get_post_type_archive_link( $post_type_name ), |
|
629 | - ) |
|
630 | - ); |
|
631 | - } |
|
632 | - |
|
633 | - /** |
|
634 | - * Filters the posts displayed in the 'View All' tab of the current |
|
635 | - * post type's menu items meta box. |
|
636 | - * |
|
637 | - * The dynamic portion of the hook name, `$post_type_name`, refers |
|
638 | - * to the slug of the current post type. |
|
639 | - * |
|
640 | - * Possible hook names include: |
|
641 | - * |
|
642 | - * - `nav_menu_items_post` |
|
643 | - * - `nav_menu_items_page` |
|
644 | - * |
|
645 | - * @since 3.2.0 |
|
646 | - * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
|
647 | - * |
|
648 | - * @see WP_Query::query() |
|
649 | - * |
|
650 | - * @param object[] $posts The posts for the current post type. Mostly `WP_Post` objects, but |
|
651 | - * can also contain "fake" post objects to represent other menu items. |
|
652 | - * @param array $args An array of `WP_Query` arguments. |
|
653 | - * @param WP_Post_Type $post_type The current post type object for this menu item meta box. |
|
654 | - */ |
|
655 | - $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); |
|
656 | - |
|
657 | - $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); |
|
658 | - |
|
659 | - echo $checkbox_items; |
|
660 | - ?> |
|
613 | + $args['walker'] = $walker; |
|
614 | + |
|
615 | + if ( $post_type->has_archive ) { |
|
616 | + $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; |
|
617 | + array_unshift( |
|
618 | + $posts, |
|
619 | + (object) array( |
|
620 | + 'ID' => 0, |
|
621 | + 'object_id' => $_nav_menu_placeholder, |
|
622 | + 'object' => $post_type_name, |
|
623 | + 'post_content' => '', |
|
624 | + 'post_excerpt' => '', |
|
625 | + 'post_title' => $post_type->labels->archives, |
|
626 | + 'post_type' => 'nav_menu_item', |
|
627 | + 'type' => 'post_type_archive', |
|
628 | + 'url' => get_post_type_archive_link( $post_type_name ), |
|
629 | + ) |
|
630 | + ); |
|
631 | + } |
|
632 | + |
|
633 | + /** |
|
634 | + * Filters the posts displayed in the 'View All' tab of the current |
|
635 | + * post type's menu items meta box. |
|
636 | + * |
|
637 | + * The dynamic portion of the hook name, `$post_type_name`, refers |
|
638 | + * to the slug of the current post type. |
|
639 | + * |
|
640 | + * Possible hook names include: |
|
641 | + * |
|
642 | + * - `nav_menu_items_post` |
|
643 | + * - `nav_menu_items_page` |
|
644 | + * |
|
645 | + * @since 3.2.0 |
|
646 | + * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
|
647 | + * |
|
648 | + * @see WP_Query::query() |
|
649 | + * |
|
650 | + * @param object[] $posts The posts for the current post type. Mostly `WP_Post` objects, but |
|
651 | + * can also contain "fake" post objects to represent other menu items. |
|
652 | + * @param array $args An array of `WP_Query` arguments. |
|
653 | + * @param WP_Post_Type $post_type The current post type object for this menu item meta box. |
|
654 | + */ |
|
655 | + $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); |
|
656 | + |
|
657 | + $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); |
|
658 | + |
|
659 | + echo $checkbox_items; |
|
660 | + ?> |
|
661 | 661 | </ul> |
662 | 662 | <?php if ( ! empty( $page_links ) ) : ?> |
663 | 663 | <div class="add-menu-item-pagelinks"> |
@@ -700,107 +700,107 @@ discard block |
||
700 | 700 | * } |
701 | 701 | */ |
702 | 702 | function wp_nav_menu_item_taxonomy_meta_box( $data_object, $box ) { |
703 | - global $nav_menu_selected_id; |
|
704 | - |
|
705 | - $taxonomy_name = $box['args']->name; |
|
706 | - $taxonomy = get_taxonomy( $taxonomy_name ); |
|
707 | - $tab_name = $taxonomy_name . '-tab'; |
|
708 | - |
|
709 | - // Paginate browsing for large numbers of objects. |
|
710 | - $per_page = 50; |
|
711 | - $pagenum = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
|
712 | - $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
|
713 | - |
|
714 | - $args = array( |
|
715 | - 'taxonomy' => $taxonomy_name, |
|
716 | - 'child_of' => 0, |
|
717 | - 'exclude' => '', |
|
718 | - 'hide_empty' => false, |
|
719 | - 'hierarchical' => 1, |
|
720 | - 'include' => '', |
|
721 | - 'number' => $per_page, |
|
722 | - 'offset' => $offset, |
|
723 | - 'order' => 'ASC', |
|
724 | - 'orderby' => 'name', |
|
725 | - 'pad_counts' => false, |
|
726 | - ); |
|
727 | - |
|
728 | - $terms = get_terms( $args ); |
|
729 | - |
|
730 | - if ( ! $terms || is_wp_error( $terms ) ) { |
|
731 | - echo '<p>' . __( 'No items.' ) . '</p>'; |
|
732 | - return; |
|
733 | - } |
|
734 | - |
|
735 | - $num_pages = ceil( |
|
736 | - wp_count_terms( |
|
737 | - array_merge( |
|
738 | - $args, |
|
739 | - array( |
|
740 | - 'number' => '', |
|
741 | - 'offset' => '', |
|
742 | - ) |
|
743 | - ) |
|
744 | - ) / $per_page |
|
745 | - ); |
|
746 | - |
|
747 | - $page_links = paginate_links( |
|
748 | - array( |
|
749 | - 'base' => add_query_arg( |
|
750 | - array( |
|
751 | - $tab_name => 'all', |
|
752 | - 'paged' => '%#%', |
|
753 | - 'item-type' => 'taxonomy', |
|
754 | - 'item-object' => $taxonomy_name, |
|
755 | - ) |
|
756 | - ), |
|
757 | - 'format' => '', |
|
758 | - 'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>', |
|
759 | - 'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>', |
|
760 | - 'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ', |
|
761 | - 'total' => $num_pages, |
|
762 | - 'current' => $pagenum, |
|
763 | - ) |
|
764 | - ); |
|
765 | - |
|
766 | - $db_fields = false; |
|
767 | - if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { |
|
768 | - $db_fields = array( |
|
769 | - 'parent' => 'parent', |
|
770 | - 'id' => 'term_id', |
|
771 | - ); |
|
772 | - } |
|
773 | - |
|
774 | - $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
775 | - |
|
776 | - $current_tab = 'most-used'; |
|
777 | - |
|
778 | - if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) { |
|
779 | - $current_tab = $_REQUEST[ $tab_name ]; |
|
780 | - } |
|
781 | - |
|
782 | - if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) { |
|
783 | - $current_tab = 'search'; |
|
784 | - } |
|
785 | - |
|
786 | - $removed_args = array( |
|
787 | - 'action', |
|
788 | - 'customlink-tab', |
|
789 | - 'edit-menu-item', |
|
790 | - 'menu-item', |
|
791 | - 'page-tab', |
|
792 | - '_wpnonce', |
|
793 | - ); |
|
794 | - |
|
795 | - $most_used_url = ''; |
|
796 | - $view_all_url = ''; |
|
797 | - $search_url = ''; |
|
798 | - if ( $nav_menu_selected_id ) { |
|
799 | - $most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) ); |
|
800 | - $view_all_url = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); |
|
801 | - $search_url = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) ); |
|
802 | - } |
|
803 | - ?> |
|
703 | + global $nav_menu_selected_id; |
|
704 | + |
|
705 | + $taxonomy_name = $box['args']->name; |
|
706 | + $taxonomy = get_taxonomy( $taxonomy_name ); |
|
707 | + $tab_name = $taxonomy_name . '-tab'; |
|
708 | + |
|
709 | + // Paginate browsing for large numbers of objects. |
|
710 | + $per_page = 50; |
|
711 | + $pagenum = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
|
712 | + $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
|
713 | + |
|
714 | + $args = array( |
|
715 | + 'taxonomy' => $taxonomy_name, |
|
716 | + 'child_of' => 0, |
|
717 | + 'exclude' => '', |
|
718 | + 'hide_empty' => false, |
|
719 | + 'hierarchical' => 1, |
|
720 | + 'include' => '', |
|
721 | + 'number' => $per_page, |
|
722 | + 'offset' => $offset, |
|
723 | + 'order' => 'ASC', |
|
724 | + 'orderby' => 'name', |
|
725 | + 'pad_counts' => false, |
|
726 | + ); |
|
727 | + |
|
728 | + $terms = get_terms( $args ); |
|
729 | + |
|
730 | + if ( ! $terms || is_wp_error( $terms ) ) { |
|
731 | + echo '<p>' . __( 'No items.' ) . '</p>'; |
|
732 | + return; |
|
733 | + } |
|
734 | + |
|
735 | + $num_pages = ceil( |
|
736 | + wp_count_terms( |
|
737 | + array_merge( |
|
738 | + $args, |
|
739 | + array( |
|
740 | + 'number' => '', |
|
741 | + 'offset' => '', |
|
742 | + ) |
|
743 | + ) |
|
744 | + ) / $per_page |
|
745 | + ); |
|
746 | + |
|
747 | + $page_links = paginate_links( |
|
748 | + array( |
|
749 | + 'base' => add_query_arg( |
|
750 | + array( |
|
751 | + $tab_name => 'all', |
|
752 | + 'paged' => '%#%', |
|
753 | + 'item-type' => 'taxonomy', |
|
754 | + 'item-object' => $taxonomy_name, |
|
755 | + ) |
|
756 | + ), |
|
757 | + 'format' => '', |
|
758 | + 'prev_text' => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '«' ) . '</span>', |
|
759 | + 'next_text' => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '»' ) . '</span>', |
|
760 | + 'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ', |
|
761 | + 'total' => $num_pages, |
|
762 | + 'current' => $pagenum, |
|
763 | + ) |
|
764 | + ); |
|
765 | + |
|
766 | + $db_fields = false; |
|
767 | + if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { |
|
768 | + $db_fields = array( |
|
769 | + 'parent' => 'parent', |
|
770 | + 'id' => 'term_id', |
|
771 | + ); |
|
772 | + } |
|
773 | + |
|
774 | + $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
775 | + |
|
776 | + $current_tab = 'most-used'; |
|
777 | + |
|
778 | + if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) { |
|
779 | + $current_tab = $_REQUEST[ $tab_name ]; |
|
780 | + } |
|
781 | + |
|
782 | + if ( ! empty( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) { |
|
783 | + $current_tab = 'search'; |
|
784 | + } |
|
785 | + |
|
786 | + $removed_args = array( |
|
787 | + 'action', |
|
788 | + 'customlink-tab', |
|
789 | + 'edit-menu-item', |
|
790 | + 'menu-item', |
|
791 | + 'page-tab', |
|
792 | + '_wpnonce', |
|
793 | + ); |
|
794 | + |
|
795 | + $most_used_url = ''; |
|
796 | + $view_all_url = ''; |
|
797 | + $search_url = ''; |
|
798 | + if ( $nav_menu_selected_id ) { |
|
799 | + $most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) ); |
|
800 | + $view_all_url = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) ); |
|
801 | + $search_url = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) ); |
|
802 | + } |
|
803 | + ?> |
|
804 | 804 | <div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv"> |
805 | 805 | <ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs"> |
806 | 806 | <li <?php echo ( 'most-used' === $current_tab ? ' class="tabs"' : '' ); ?>> |
@@ -823,18 +823,18 @@ discard block |
||
823 | 823 | <div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php echo ( 'most-used' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" role="region" aria-label="<?php echo $taxonomy->labels->most_used; ?>" tabindex="0"> |
824 | 824 | <ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" > |
825 | 825 | <?php |
826 | - $popular_terms = get_terms( |
|
827 | - array( |
|
828 | - 'taxonomy' => $taxonomy_name, |
|
829 | - 'orderby' => 'count', |
|
830 | - 'order' => 'DESC', |
|
831 | - 'number' => 10, |
|
832 | - 'hierarchical' => false, |
|
833 | - ) |
|
834 | - ); |
|
835 | - $args['walker'] = $walker; |
|
836 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args ); |
|
837 | - ?> |
|
826 | + $popular_terms = get_terms( |
|
827 | + array( |
|
828 | + 'taxonomy' => $taxonomy_name, |
|
829 | + 'orderby' => 'count', |
|
830 | + 'order' => 'DESC', |
|
831 | + 'number' => 10, |
|
832 | + 'hierarchical' => false, |
|
833 | + ) |
|
834 | + ); |
|
835 | + $args['walker'] = $walker; |
|
836 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $popular_terms ), 0, (object) $args ); |
|
837 | + ?> |
|
838 | 838 | </ul> |
839 | 839 | </div><!-- /.tabs-panel --> |
840 | 840 | |
@@ -846,9 +846,9 @@ discard block |
||
846 | 846 | <?php endif; ?> |
847 | 847 | <ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name; ?>" class="categorychecklist form-no-clear"> |
848 | 848 | <?php |
849 | - $args['walker'] = $walker; |
|
850 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args ); |
|
851 | - ?> |
|
849 | + $args['walker'] = $walker; |
|
850 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args ); |
|
851 | + ?> |
|
852 | 852 | </ul> |
853 | 853 | <?php if ( ! empty( $page_links ) ) : ?> |
854 | 854 | <div class="add-menu-item-pagelinks"> |
@@ -859,23 +859,23 @@ discard block |
||
859 | 859 | |
860 | 860 | <div class="tabs-panel <?php echo ( 'search' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>" role="region" aria-label="<?php echo $taxonomy->labels->search_items; ?>" tabindex="0"> |
861 | 861 | <?php |
862 | - if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) { |
|
863 | - $searched = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ); |
|
864 | - $search_results = get_terms( |
|
865 | - array( |
|
866 | - 'taxonomy' => $taxonomy_name, |
|
867 | - 'name__like' => $searched, |
|
868 | - 'fields' => 'all', |
|
869 | - 'orderby' => 'count', |
|
870 | - 'order' => 'DESC', |
|
871 | - 'hierarchical' => false, |
|
872 | - ) |
|
873 | - ); |
|
874 | - } else { |
|
875 | - $searched = ''; |
|
876 | - $search_results = array(); |
|
877 | - } |
|
878 | - ?> |
|
862 | + if ( isset( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ) ) { |
|
863 | + $searched = esc_attr( $_REQUEST[ 'quick-search-taxonomy-' . $taxonomy_name ] ); |
|
864 | + $search_results = get_terms( |
|
865 | + array( |
|
866 | + 'taxonomy' => $taxonomy_name, |
|
867 | + 'name__like' => $searched, |
|
868 | + 'fields' => 'all', |
|
869 | + 'orderby' => 'count', |
|
870 | + 'order' => 'DESC', |
|
871 | + 'hierarchical' => false, |
|
872 | + ) |
|
873 | + ); |
|
874 | + } else { |
|
875 | + $searched = ''; |
|
876 | + $search_results = array(); |
|
877 | + } |
|
878 | + ?> |
|
879 | 879 | <p class="quick-search-wrap"> |
880 | 880 | <label for="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" class="screen-reader-text"><?php _e( 'Search' ); ?></label> |
881 | 881 | <input type="search" class="quick-search" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" id="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" /> |
@@ -886,9 +886,9 @@ discard block |
||
886 | 886 | <ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name; ?>" class="categorychecklist form-no-clear"> |
887 | 887 | <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> |
888 | 888 | <?php |
889 | - $args['walker'] = $walker; |
|
890 | - echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args ); |
|
891 | - ?> |
|
889 | + $args['walker'] = $walker; |
|
890 | + echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $search_results ), 0, (object) $args ); |
|
891 | + ?> |
|
892 | 892 | <?php elseif ( is_wp_error( $search_results ) ) : ?> |
893 | 893 | <li><?php echo $search_results->get_error_message(); ?></li> |
894 | 894 | <?php elseif ( ! empty( $searched ) ) : ?> |
@@ -923,63 +923,63 @@ discard block |
||
923 | 923 | * @return int[] The database IDs of the items saved |
924 | 924 | */ |
925 | 925 | function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { |
926 | - $menu_id = (int) $menu_id; |
|
927 | - $items_saved = array(); |
|
928 | - |
|
929 | - if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { |
|
930 | - |
|
931 | - // Loop through all the menu items' POST values. |
|
932 | - foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) { |
|
933 | - if ( |
|
934 | - // Checkbox is not checked. |
|
935 | - empty( $_item_object_data['menu-item-object-id'] ) && |
|
936 | - ( |
|
937 | - // And item type either isn't set. |
|
938 | - ! isset( $_item_object_data['menu-item-type'] ) || |
|
939 | - // Or URL is the default. |
|
940 | - in_array( $_item_object_data['menu-item-url'], array( 'https://', 'http://', '' ), true ) || |
|
941 | - // Or it's not a custom menu item (but not the custom home page). |
|
942 | - ! ( 'custom' === $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || |
|
943 | - // Or it *is* a custom menu item that already exists. |
|
944 | - ! empty( $_item_object_data['menu-item-db-id'] ) |
|
945 | - ) |
|
946 | - ) { |
|
947 | - // Then this potential menu item is not getting added to this menu. |
|
948 | - continue; |
|
949 | - } |
|
950 | - |
|
951 | - // If this possible menu item doesn't actually have a menu database ID yet. |
|
952 | - if ( |
|
953 | - empty( $_item_object_data['menu-item-db-id'] ) || |
|
954 | - ( 0 > $_possible_db_id ) || |
|
955 | - $_possible_db_id != $_item_object_data['menu-item-db-id'] |
|
956 | - ) { |
|
957 | - $_actual_db_id = 0; |
|
958 | - } else { |
|
959 | - $_actual_db_id = (int) $_item_object_data['menu-item-db-id']; |
|
960 | - } |
|
961 | - |
|
962 | - $args = array( |
|
963 | - 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), |
|
964 | - 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), |
|
965 | - 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), |
|
966 | - 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), |
|
967 | - 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), |
|
968 | - 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), |
|
969 | - 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), |
|
970 | - 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), |
|
971 | - 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), |
|
972 | - 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), |
|
973 | - 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), |
|
974 | - 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), |
|
975 | - 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), |
|
976 | - ); |
|
977 | - |
|
978 | - $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); |
|
979 | - |
|
980 | - } |
|
981 | - } |
|
982 | - return $items_saved; |
|
926 | + $menu_id = (int) $menu_id; |
|
927 | + $items_saved = array(); |
|
928 | + |
|
929 | + if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { |
|
930 | + |
|
931 | + // Loop through all the menu items' POST values. |
|
932 | + foreach ( (array) $menu_data as $_possible_db_id => $_item_object_data ) { |
|
933 | + if ( |
|
934 | + // Checkbox is not checked. |
|
935 | + empty( $_item_object_data['menu-item-object-id'] ) && |
|
936 | + ( |
|
937 | + // And item type either isn't set. |
|
938 | + ! isset( $_item_object_data['menu-item-type'] ) || |
|
939 | + // Or URL is the default. |
|
940 | + in_array( $_item_object_data['menu-item-url'], array( 'https://', 'http://', '' ), true ) || |
|
941 | + // Or it's not a custom menu item (but not the custom home page). |
|
942 | + ! ( 'custom' === $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || |
|
943 | + // Or it *is* a custom menu item that already exists. |
|
944 | + ! empty( $_item_object_data['menu-item-db-id'] ) |
|
945 | + ) |
|
946 | + ) { |
|
947 | + // Then this potential menu item is not getting added to this menu. |
|
948 | + continue; |
|
949 | + } |
|
950 | + |
|
951 | + // If this possible menu item doesn't actually have a menu database ID yet. |
|
952 | + if ( |
|
953 | + empty( $_item_object_data['menu-item-db-id'] ) || |
|
954 | + ( 0 > $_possible_db_id ) || |
|
955 | + $_possible_db_id != $_item_object_data['menu-item-db-id'] |
|
956 | + ) { |
|
957 | + $_actual_db_id = 0; |
|
958 | + } else { |
|
959 | + $_actual_db_id = (int) $_item_object_data['menu-item-db-id']; |
|
960 | + } |
|
961 | + |
|
962 | + $args = array( |
|
963 | + 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), |
|
964 | + 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), |
|
965 | + 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), |
|
966 | + 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), |
|
967 | + 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), |
|
968 | + 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), |
|
969 | + 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), |
|
970 | + 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), |
|
971 | + 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), |
|
972 | + 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), |
|
973 | + 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), |
|
974 | + 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), |
|
975 | + 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), |
|
976 | + ); |
|
977 | + |
|
978 | + $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); |
|
979 | + |
|
980 | + } |
|
981 | + } |
|
982 | + return $items_saved; |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | /** |
@@ -993,36 +993,36 @@ discard block |
||
993 | 993 | * @return object The post type or taxonomy object. |
994 | 994 | */ |
995 | 995 | function _wp_nav_menu_meta_box_object( $data_object = null ) { |
996 | - if ( isset( $data_object->name ) ) { |
|
997 | - |
|
998 | - if ( 'page' === $data_object->name ) { |
|
999 | - $data_object->_default_query = array( |
|
1000 | - 'orderby' => 'menu_order title', |
|
1001 | - 'post_status' => 'publish', |
|
1002 | - ); |
|
1003 | - |
|
1004 | - // Posts should show only published items. |
|
1005 | - } elseif ( 'post' === $data_object->name ) { |
|
1006 | - $data_object->_default_query = array( |
|
1007 | - 'post_status' => 'publish', |
|
1008 | - ); |
|
1009 | - |
|
1010 | - // Categories should be in reverse chronological order. |
|
1011 | - } elseif ( 'category' === $data_object->name ) { |
|
1012 | - $data_object->_default_query = array( |
|
1013 | - 'orderby' => 'id', |
|
1014 | - 'order' => 'DESC', |
|
1015 | - ); |
|
1016 | - |
|
1017 | - // Custom post types should show only published items. |
|
1018 | - } else { |
|
1019 | - $data_object->_default_query = array( |
|
1020 | - 'post_status' => 'publish', |
|
1021 | - ); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - return $data_object; |
|
996 | + if ( isset( $data_object->name ) ) { |
|
997 | + |
|
998 | + if ( 'page' === $data_object->name ) { |
|
999 | + $data_object->_default_query = array( |
|
1000 | + 'orderby' => 'menu_order title', |
|
1001 | + 'post_status' => 'publish', |
|
1002 | + ); |
|
1003 | + |
|
1004 | + // Posts should show only published items. |
|
1005 | + } elseif ( 'post' === $data_object->name ) { |
|
1006 | + $data_object->_default_query = array( |
|
1007 | + 'post_status' => 'publish', |
|
1008 | + ); |
|
1009 | + |
|
1010 | + // Categories should be in reverse chronological order. |
|
1011 | + } elseif ( 'category' === $data_object->name ) { |
|
1012 | + $data_object->_default_query = array( |
|
1013 | + 'orderby' => 'id', |
|
1014 | + 'order' => 'DESC', |
|
1015 | + ); |
|
1016 | + |
|
1017 | + // Custom post types should show only published items. |
|
1018 | + } else { |
|
1019 | + $data_object->_default_query = array( |
|
1020 | + 'post_status' => 'publish', |
|
1021 | + ); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + return $data_object; |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | /** |
@@ -1034,69 +1034,69 @@ discard block |
||
1034 | 1034 | * @return string|WP_Error The menu formatted to edit or error object on failure. |
1035 | 1035 | */ |
1036 | 1036 | function wp_get_nav_menu_to_edit( $menu_id = 0 ) { |
1037 | - $menu = wp_get_nav_menu_object( $menu_id ); |
|
1038 | - |
|
1039 | - // If the menu exists, get its items. |
|
1040 | - if ( is_nav_menu( $menu ) ) { |
|
1041 | - $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_status' => 'any' ) ); |
|
1042 | - $result = '<div id="menu-instructions" class="post-body-plain'; |
|
1043 | - $result .= ( ! empty( $menu_items ) ) ? ' menu-instructions-inactive">' : '">'; |
|
1044 | - $result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>'; |
|
1045 | - $result .= '</div>'; |
|
1046 | - |
|
1047 | - if ( empty( $menu_items ) ) { |
|
1048 | - return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
|
1049 | - } |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * Filters the Walker class used when adding nav menu items. |
|
1053 | - * |
|
1054 | - * @since 3.0.0 |
|
1055 | - * |
|
1056 | - * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. |
|
1057 | - * @param int $menu_id ID of the menu being rendered. |
|
1058 | - */ |
|
1059 | - $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
|
1060 | - |
|
1061 | - if ( class_exists( $walker_class_name ) ) { |
|
1062 | - $walker = new $walker_class_name; |
|
1063 | - } else { |
|
1064 | - return new WP_Error( |
|
1065 | - 'menu_walker_not_exist', |
|
1066 | - sprintf( |
|
1067 | - /* translators: %s: Walker class name. */ |
|
1068 | - __( 'The Walker class named %s does not exist.' ), |
|
1069 | - '<strong>' . $walker_class_name . '</strong>' |
|
1070 | - ) |
|
1071 | - ); |
|
1072 | - } |
|
1073 | - |
|
1074 | - $some_pending_menu_items = false; |
|
1075 | - $some_invalid_menu_items = false; |
|
1076 | - foreach ( (array) $menu_items as $menu_item ) { |
|
1077 | - if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) { |
|
1078 | - $some_pending_menu_items = true; |
|
1079 | - } |
|
1080 | - if ( ! empty( $menu_item->_invalid ) ) { |
|
1081 | - $some_invalid_menu_items = true; |
|
1082 | - } |
|
1083 | - } |
|
1084 | - |
|
1085 | - if ( $some_pending_menu_items ) { |
|
1086 | - $result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>'; |
|
1087 | - } |
|
1088 | - |
|
1089 | - if ( $some_invalid_menu_items ) { |
|
1090 | - $result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>'; |
|
1091 | - } |
|
1092 | - |
|
1093 | - $result .= '<ul class="menu" id="menu-to-edit"> '; |
|
1094 | - $result .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items ), 0, (object) array( 'walker' => $walker ) ); |
|
1095 | - $result .= ' </ul> '; |
|
1096 | - return $result; |
|
1097 | - } elseif ( is_wp_error( $menu ) ) { |
|
1098 | - return $menu; |
|
1099 | - } |
|
1037 | + $menu = wp_get_nav_menu_object( $menu_id ); |
|
1038 | + |
|
1039 | + // If the menu exists, get its items. |
|
1040 | + if ( is_nav_menu( $menu ) ) { |
|
1041 | + $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_status' => 'any' ) ); |
|
1042 | + $result = '<div id="menu-instructions" class="post-body-plain'; |
|
1043 | + $result .= ( ! empty( $menu_items ) ) ? ' menu-instructions-inactive">' : '">'; |
|
1044 | + $result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>'; |
|
1045 | + $result .= '</div>'; |
|
1046 | + |
|
1047 | + if ( empty( $menu_items ) ) { |
|
1048 | + return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; |
|
1049 | + } |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * Filters the Walker class used when adding nav menu items. |
|
1053 | + * |
|
1054 | + * @since 3.0.0 |
|
1055 | + * |
|
1056 | + * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. |
|
1057 | + * @param int $menu_id ID of the menu being rendered. |
|
1058 | + */ |
|
1059 | + $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); |
|
1060 | + |
|
1061 | + if ( class_exists( $walker_class_name ) ) { |
|
1062 | + $walker = new $walker_class_name; |
|
1063 | + } else { |
|
1064 | + return new WP_Error( |
|
1065 | + 'menu_walker_not_exist', |
|
1066 | + sprintf( |
|
1067 | + /* translators: %s: Walker class name. */ |
|
1068 | + __( 'The Walker class named %s does not exist.' ), |
|
1069 | + '<strong>' . $walker_class_name . '</strong>' |
|
1070 | + ) |
|
1071 | + ); |
|
1072 | + } |
|
1073 | + |
|
1074 | + $some_pending_menu_items = false; |
|
1075 | + $some_invalid_menu_items = false; |
|
1076 | + foreach ( (array) $menu_items as $menu_item ) { |
|
1077 | + if ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) { |
|
1078 | + $some_pending_menu_items = true; |
|
1079 | + } |
|
1080 | + if ( ! empty( $menu_item->_invalid ) ) { |
|
1081 | + $some_invalid_menu_items = true; |
|
1082 | + } |
|
1083 | + } |
|
1084 | + |
|
1085 | + if ( $some_pending_menu_items ) { |
|
1086 | + $result .= '<div class="notice notice-info notice-alt inline"><p>' . __( 'Click Save Menu to make pending menu items public.' ) . '</p></div>'; |
|
1087 | + } |
|
1088 | + |
|
1089 | + if ( $some_invalid_menu_items ) { |
|
1090 | + $result .= '<div class="notice notice-error notice-alt inline"><p>' . __( 'There are some invalid menu items. Please check or delete them.' ) . '</p></div>'; |
|
1091 | + } |
|
1092 | + |
|
1093 | + $result .= '<ul class="menu" id="menu-to-edit"> '; |
|
1094 | + $result .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items ), 0, (object) array( 'walker' => $walker ) ); |
|
1095 | + $result .= ' </ul> '; |
|
1096 | + return $result; |
|
1097 | + } elseif ( is_wp_error( $menu ) ) { |
|
1098 | + return $menu; |
|
1099 | + } |
|
1100 | 1100 | |
1101 | 1101 | } |
1102 | 1102 | |
@@ -1108,15 +1108,15 @@ discard block |
||
1108 | 1108 | * @return string[] Array of column titles keyed by their column name. |
1109 | 1109 | */ |
1110 | 1110 | function wp_nav_menu_manage_columns() { |
1111 | - return array( |
|
1112 | - '_title' => __( 'Show advanced menu properties' ), |
|
1113 | - 'cb' => '<input type="checkbox" />', |
|
1114 | - 'link-target' => __( 'Link Target' ), |
|
1115 | - 'title-attribute' => __( 'Title Attribute' ), |
|
1116 | - 'css-classes' => __( 'CSS Classes' ), |
|
1117 | - 'xfn' => __( 'Link Relationship (XFN)' ), |
|
1118 | - 'description' => __( 'Description' ), |
|
1119 | - ); |
|
1111 | + return array( |
|
1112 | + '_title' => __( 'Show advanced menu properties' ), |
|
1113 | + 'cb' => '<input type="checkbox" />', |
|
1114 | + 'link-target' => __( 'Link Target' ), |
|
1115 | + 'title-attribute' => __( 'Title Attribute' ), |
|
1116 | + 'css-classes' => __( 'CSS Classes' ), |
|
1117 | + 'xfn' => __( 'Link Relationship (XFN)' ), |
|
1118 | + 'description' => __( 'Description' ), |
|
1119 | + ); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | /** |
@@ -1128,15 +1128,15 @@ discard block |
||
1128 | 1128 | * @global wpdb $wpdb WordPress database abstraction object. |
1129 | 1129 | */ |
1130 | 1130 | function _wp_delete_orphaned_draft_menu_items() { |
1131 | - global $wpdb; |
|
1132 | - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
1131 | + global $wpdb; |
|
1132 | + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
1133 | 1133 | |
1134 | - // Delete orphaned draft menu items. |
|
1135 | - $menu_items_to_delete = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < %d", $delete_timestamp ) ); |
|
1134 | + // Delete orphaned draft menu items. |
|
1135 | + $menu_items_to_delete = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < %d", $delete_timestamp ) ); |
|
1136 | 1136 | |
1137 | - foreach ( (array) $menu_items_to_delete as $menu_item_id ) { |
|
1138 | - wp_delete_post( $menu_item_id, true ); |
|
1139 | - } |
|
1137 | + foreach ( (array) $menu_items_to_delete as $menu_item_id ) { |
|
1138 | + wp_delete_post( $menu_item_id, true ); |
|
1139 | + } |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |
@@ -1149,113 +1149,113 @@ discard block |
||
1149 | 1149 | * @return array The menu updated message |
1150 | 1150 | */ |
1151 | 1151 | function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) { |
1152 | - $unsorted_menu_items = wp_get_nav_menu_items( |
|
1153 | - $nav_menu_selected_id, |
|
1154 | - array( |
|
1155 | - 'orderby' => 'ID', |
|
1156 | - 'output' => ARRAY_A, |
|
1157 | - 'output_key' => 'ID', |
|
1158 | - 'post_status' => 'draft,publish', |
|
1159 | - ) |
|
1160 | - ); |
|
1161 | - |
|
1162 | - $messages = array(); |
|
1163 | - $menu_items = array(); |
|
1164 | - |
|
1165 | - // Index menu items by DB ID. |
|
1166 | - foreach ( $unsorted_menu_items as $_item ) { |
|
1167 | - $menu_items[ $_item->db_id ] = $_item; |
|
1168 | - } |
|
1169 | - |
|
1170 | - $post_fields = array( |
|
1171 | - 'menu-item-db-id', |
|
1172 | - 'menu-item-object-id', |
|
1173 | - 'menu-item-object', |
|
1174 | - 'menu-item-parent-id', |
|
1175 | - 'menu-item-position', |
|
1176 | - 'menu-item-type', |
|
1177 | - 'menu-item-title', |
|
1178 | - 'menu-item-url', |
|
1179 | - 'menu-item-description', |
|
1180 | - 'menu-item-attr-title', |
|
1181 | - 'menu-item-target', |
|
1182 | - 'menu-item-classes', |
|
1183 | - 'menu-item-xfn', |
|
1184 | - ); |
|
1185 | - |
|
1186 | - wp_defer_term_counting( true ); |
|
1187 | - |
|
1188 | - // Loop through all the menu items' POST variables. |
|
1189 | - if ( ! empty( $_POST['menu-item-db-id'] ) ) { |
|
1190 | - foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) { |
|
1191 | - |
|
1192 | - // Menu item title can't be blank. |
|
1193 | - if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' === $_POST['menu-item-title'][ $_key ] ) { |
|
1194 | - continue; |
|
1195 | - } |
|
1196 | - |
|
1197 | - $args = array(); |
|
1198 | - foreach ( $post_fields as $field ) { |
|
1199 | - $args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : ''; |
|
1200 | - } |
|
1201 | - |
|
1202 | - $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][ $_key ] != $_key ? 0 : $_key ), $args ); |
|
1203 | - |
|
1204 | - if ( is_wp_error( $menu_item_db_id ) ) { |
|
1205 | - $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>'; |
|
1206 | - } else { |
|
1207 | - unset( $menu_items[ $menu_item_db_id ] ); |
|
1208 | - } |
|
1209 | - } |
|
1210 | - } |
|
1211 | - |
|
1212 | - // Remove menu items from the menu that weren't in $_POST. |
|
1213 | - if ( ! empty( $menu_items ) ) { |
|
1214 | - foreach ( array_keys( $menu_items ) as $menu_item_id ) { |
|
1215 | - if ( is_nav_menu_item( $menu_item_id ) ) { |
|
1216 | - wp_delete_post( $menu_item_id ); |
|
1217 | - } |
|
1218 | - } |
|
1219 | - } |
|
1220 | - |
|
1221 | - // Store 'auto-add' pages. |
|
1222 | - $auto_add = ! empty( $_POST['auto-add-pages'] ); |
|
1223 | - $nav_menu_option = (array) get_option( 'nav_menu_options' ); |
|
1224 | - |
|
1225 | - if ( ! isset( $nav_menu_option['auto_add'] ) ) { |
|
1226 | - $nav_menu_option['auto_add'] = array(); |
|
1227 | - } |
|
1228 | - |
|
1229 | - if ( $auto_add ) { |
|
1230 | - if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) { |
|
1231 | - $nav_menu_option['auto_add'][] = $nav_menu_selected_id; |
|
1232 | - } |
|
1233 | - } else { |
|
1234 | - $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ); |
|
1235 | - if ( false !== $key ) { |
|
1236 | - unset( $nav_menu_option['auto_add'][ $key ] ); |
|
1237 | - } |
|
1238 | - } |
|
1239 | - |
|
1240 | - // Remove non-existent/deleted menus. |
|
1241 | - $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); |
|
1242 | - update_option( 'nav_menu_options', $nav_menu_option ); |
|
1243 | - |
|
1244 | - wp_defer_term_counting( false ); |
|
1245 | - |
|
1246 | - /** This action is documented in wp-includes/nav-menu.php */ |
|
1247 | - do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); |
|
1248 | - |
|
1249 | - $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . |
|
1250 | - sprintf( |
|
1251 | - /* translators: %s: Nav menu title. */ |
|
1252 | - __( '%s has been updated.' ), |
|
1253 | - '<strong>' . $nav_menu_selected_title . '</strong>' |
|
1254 | - ) . '</p></div>'; |
|
1255 | - |
|
1256 | - unset( $menu_items, $unsorted_menu_items ); |
|
1257 | - |
|
1258 | - return $messages; |
|
1152 | + $unsorted_menu_items = wp_get_nav_menu_items( |
|
1153 | + $nav_menu_selected_id, |
|
1154 | + array( |
|
1155 | + 'orderby' => 'ID', |
|
1156 | + 'output' => ARRAY_A, |
|
1157 | + 'output_key' => 'ID', |
|
1158 | + 'post_status' => 'draft,publish', |
|
1159 | + ) |
|
1160 | + ); |
|
1161 | + |
|
1162 | + $messages = array(); |
|
1163 | + $menu_items = array(); |
|
1164 | + |
|
1165 | + // Index menu items by DB ID. |
|
1166 | + foreach ( $unsorted_menu_items as $_item ) { |
|
1167 | + $menu_items[ $_item->db_id ] = $_item; |
|
1168 | + } |
|
1169 | + |
|
1170 | + $post_fields = array( |
|
1171 | + 'menu-item-db-id', |
|
1172 | + 'menu-item-object-id', |
|
1173 | + 'menu-item-object', |
|
1174 | + 'menu-item-parent-id', |
|
1175 | + 'menu-item-position', |
|
1176 | + 'menu-item-type', |
|
1177 | + 'menu-item-title', |
|
1178 | + 'menu-item-url', |
|
1179 | + 'menu-item-description', |
|
1180 | + 'menu-item-attr-title', |
|
1181 | + 'menu-item-target', |
|
1182 | + 'menu-item-classes', |
|
1183 | + 'menu-item-xfn', |
|
1184 | + ); |
|
1185 | + |
|
1186 | + wp_defer_term_counting( true ); |
|
1187 | + |
|
1188 | + // Loop through all the menu items' POST variables. |
|
1189 | + if ( ! empty( $_POST['menu-item-db-id'] ) ) { |
|
1190 | + foreach ( (array) $_POST['menu-item-db-id'] as $_key => $k ) { |
|
1191 | + |
|
1192 | + // Menu item title can't be blank. |
|
1193 | + if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' === $_POST['menu-item-title'][ $_key ] ) { |
|
1194 | + continue; |
|
1195 | + } |
|
1196 | + |
|
1197 | + $args = array(); |
|
1198 | + foreach ( $post_fields as $field ) { |
|
1199 | + $args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : ''; |
|
1200 | + } |
|
1201 | + |
|
1202 | + $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][ $_key ] != $_key ? 0 : $_key ), $args ); |
|
1203 | + |
|
1204 | + if ( is_wp_error( $menu_item_db_id ) ) { |
|
1205 | + $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>'; |
|
1206 | + } else { |
|
1207 | + unset( $menu_items[ $menu_item_db_id ] ); |
|
1208 | + } |
|
1209 | + } |
|
1210 | + } |
|
1211 | + |
|
1212 | + // Remove menu items from the menu that weren't in $_POST. |
|
1213 | + if ( ! empty( $menu_items ) ) { |
|
1214 | + foreach ( array_keys( $menu_items ) as $menu_item_id ) { |
|
1215 | + if ( is_nav_menu_item( $menu_item_id ) ) { |
|
1216 | + wp_delete_post( $menu_item_id ); |
|
1217 | + } |
|
1218 | + } |
|
1219 | + } |
|
1220 | + |
|
1221 | + // Store 'auto-add' pages. |
|
1222 | + $auto_add = ! empty( $_POST['auto-add-pages'] ); |
|
1223 | + $nav_menu_option = (array) get_option( 'nav_menu_options' ); |
|
1224 | + |
|
1225 | + if ( ! isset( $nav_menu_option['auto_add'] ) ) { |
|
1226 | + $nav_menu_option['auto_add'] = array(); |
|
1227 | + } |
|
1228 | + |
|
1229 | + if ( $auto_add ) { |
|
1230 | + if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) { |
|
1231 | + $nav_menu_option['auto_add'][] = $nav_menu_selected_id; |
|
1232 | + } |
|
1233 | + } else { |
|
1234 | + $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ); |
|
1235 | + if ( false !== $key ) { |
|
1236 | + unset( $nav_menu_option['auto_add'][ $key ] ); |
|
1237 | + } |
|
1238 | + } |
|
1239 | + |
|
1240 | + // Remove non-existent/deleted menus. |
|
1241 | + $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); |
|
1242 | + update_option( 'nav_menu_options', $nav_menu_option ); |
|
1243 | + |
|
1244 | + wp_defer_term_counting( false ); |
|
1245 | + |
|
1246 | + /** This action is documented in wp-includes/nav-menu.php */ |
|
1247 | + do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); |
|
1248 | + |
|
1249 | + $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . |
|
1250 | + sprintf( |
|
1251 | + /* translators: %s: Nav menu title. */ |
|
1252 | + __( '%s has been updated.' ), |
|
1253 | + '<strong>' . $nav_menu_selected_title . '</strong>' |
|
1254 | + ) . '</p></div>'; |
|
1255 | + |
|
1256 | + unset( $menu_items, $unsorted_menu_items ); |
|
1257 | + |
|
1258 | + return $messages; |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | /** |
@@ -1267,36 +1267,36 @@ discard block |
||
1267 | 1267 | * @access private |
1268 | 1268 | */ |
1269 | 1269 | function _wp_expand_nav_menu_post_data() { |
1270 | - if ( ! isset( $_POST['nav-menu-data'] ) ) { |
|
1271 | - return; |
|
1272 | - } |
|
1273 | - |
|
1274 | - $data = json_decode( stripslashes( $_POST['nav-menu-data'] ) ); |
|
1275 | - |
|
1276 | - if ( ! is_null( $data ) && $data ) { |
|
1277 | - foreach ( $data as $post_input_data ) { |
|
1278 | - // For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`), |
|
1279 | - // derive the array path keys via regex and set the value in $_POST. |
|
1280 | - preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches ); |
|
1281 | - |
|
1282 | - $array_bits = array( $matches[1] ); |
|
1283 | - |
|
1284 | - if ( isset( $matches[3] ) ) { |
|
1285 | - $array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) ); |
|
1286 | - } |
|
1287 | - |
|
1288 | - $new_post_data = array(); |
|
1289 | - |
|
1290 | - // Build the new array value from leaf to trunk. |
|
1291 | - for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) { |
|
1292 | - if ( count( $array_bits ) - 1 == $i ) { |
|
1293 | - $new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value ); |
|
1294 | - } else { |
|
1295 | - $new_post_data = array( $array_bits[ $i ] => $new_post_data ); |
|
1296 | - } |
|
1297 | - } |
|
1298 | - |
|
1299 | - $_POST = array_replace_recursive( $_POST, $new_post_data ); |
|
1300 | - } |
|
1301 | - } |
|
1270 | + if ( ! isset( $_POST['nav-menu-data'] ) ) { |
|
1271 | + return; |
|
1272 | + } |
|
1273 | + |
|
1274 | + $data = json_decode( stripslashes( $_POST['nav-menu-data'] ) ); |
|
1275 | + |
|
1276 | + if ( ! is_null( $data ) && $data ) { |
|
1277 | + foreach ( $data as $post_input_data ) { |
|
1278 | + // For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`), |
|
1279 | + // derive the array path keys via regex and set the value in $_POST. |
|
1280 | + preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches ); |
|
1281 | + |
|
1282 | + $array_bits = array( $matches[1] ); |
|
1283 | + |
|
1284 | + if ( isset( $matches[3] ) ) { |
|
1285 | + $array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) ); |
|
1286 | + } |
|
1287 | + |
|
1288 | + $new_post_data = array(); |
|
1289 | + |
|
1290 | + // Build the new array value from leaf to trunk. |
|
1291 | + for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) { |
|
1292 | + if ( count( $array_bits ) - 1 == $i ) { |
|
1293 | + $new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value ); |
|
1294 | + } else { |
|
1295 | + $new_post_data = array( $array_bits[ $i ] => $new_post_data ); |
|
1296 | + } |
|
1297 | + } |
|
1298 | + |
|
1299 | + $_POST = array_replace_recursive( $_POST, $new_post_data ); |
|
1300 | + } |
|
1301 | + } |
|
1302 | 1302 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! class_exists( 'WP_Privacy_Requests_Table' ) ) { |
11 | - require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-requests-table.php'; |
|
11 | + require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-requests-table.php'; |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,152 +17,152 @@ discard block |
||
17 | 17 | * @since 4.9.6 |
18 | 18 | */ |
19 | 19 | class WP_Privacy_Data_Removal_Requests_List_Table extends WP_Privacy_Requests_Table { |
20 | - /** |
|
21 | - * Action name for the requests this table will work with. |
|
22 | - * |
|
23 | - * @since 4.9.6 |
|
24 | - * |
|
25 | - * @var string $request_type Name of action. |
|
26 | - */ |
|
27 | - protected $request_type = 'remove_personal_data'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Post type for the requests. |
|
31 | - * |
|
32 | - * @since 4.9.6 |
|
33 | - * |
|
34 | - * @var string $post_type The post type. |
|
35 | - */ |
|
36 | - protected $post_type = 'user_request'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Actions column. |
|
40 | - * |
|
41 | - * @since 4.9.6 |
|
42 | - * |
|
43 | - * @param WP_User_Request $item Item being shown. |
|
44 | - * @return string Email column markup. |
|
45 | - */ |
|
46 | - public function column_email( $item ) { |
|
47 | - $row_actions = array(); |
|
48 | - |
|
49 | - // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received. |
|
50 | - $status = $item->status; |
|
51 | - $request_id = $item->ID; |
|
52 | - $row_actions = array(); |
|
53 | - if ( 'request-confirmed' !== $status ) { |
|
54 | - /** This filter is documented in wp-admin/includes/ajax-actions.php */ |
|
55 | - $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); |
|
56 | - $erasers_count = count( $erasers ); |
|
57 | - $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); |
|
58 | - |
|
59 | - $remove_data_markup = '<span class="remove-personal-data force-remove-personal-data" ' . |
|
60 | - 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' . |
|
61 | - 'data-request-id="' . esc_attr( $request_id ) . '" ' . |
|
62 | - 'data-nonce="' . esc_attr( $nonce ) . |
|
63 | - '">'; |
|
64 | - |
|
65 | - $remove_data_markup .= '<span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle">' . __( 'Force erase personal data' ) . '</button></span>' . |
|
66 | - '<span class="remove-personal-data-processing hidden">' . __( 'Erasing data...' ) . ' <span class="erasure-progress"></span></span>' . |
|
67 | - '<span class="remove-personal-data-success hidden">' . __( 'Erasure completed.' ) . '</span>' . |
|
68 | - '<span class="remove-personal-data-failed hidden">' . __( 'Force erasure has failed.' ) . ' <button type="button" class="button-link remove-personal-data-handle">' . __( 'Retry' ) . '</button></span>'; |
|
69 | - |
|
70 | - $remove_data_markup .= '</span>'; |
|
71 | - |
|
72 | - $row_actions['remove-data'] = $remove_data_markup; |
|
73 | - } |
|
74 | - |
|
75 | - if ( 'request-completed' !== $status ) { |
|
76 | - $complete_request_markup = '<span>'; |
|
77 | - $complete_request_markup .= sprintf( |
|
78 | - '<a href="%s" class="complete-request" aria-label="%s">%s</a>', |
|
79 | - esc_url( |
|
80 | - wp_nonce_url( |
|
81 | - add_query_arg( |
|
82 | - array( |
|
83 | - 'action' => 'complete', |
|
84 | - 'request_id' => array( $request_id ), |
|
85 | - ), |
|
86 | - admin_url( 'erase-personal-data.php' ) |
|
87 | - ), |
|
88 | - 'bulk-privacy_requests' |
|
89 | - ) |
|
90 | - ), |
|
91 | - esc_attr( |
|
92 | - sprintf( |
|
93 | - /* translators: %s: Request email. */ |
|
94 | - __( 'Mark export request for “%s” as completed.' ), |
|
95 | - $item->email |
|
96 | - ) |
|
97 | - ), |
|
98 | - __( 'Complete request' ) |
|
99 | - ); |
|
100 | - $complete_request_markup .= '</span>'; |
|
101 | - } |
|
102 | - |
|
103 | - if ( ! empty( $complete_request_markup ) ) { |
|
104 | - $row_actions['complete-request'] = $complete_request_markup; |
|
105 | - } |
|
106 | - |
|
107 | - return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Next steps column. |
|
112 | - * |
|
113 | - * @since 4.9.6 |
|
114 | - * |
|
115 | - * @param WP_User_Request $item Item being shown. |
|
116 | - */ |
|
117 | - public function column_next_steps( $item ) { |
|
118 | - $status = $item->status; |
|
119 | - |
|
120 | - switch ( $status ) { |
|
121 | - case 'request-pending': |
|
122 | - esc_html_e( 'Waiting for confirmation' ); |
|
123 | - break; |
|
124 | - case 'request-confirmed': |
|
125 | - /** This filter is documented in wp-admin/includes/ajax-actions.php */ |
|
126 | - $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); |
|
127 | - $erasers_count = count( $erasers ); |
|
128 | - $request_id = $item->ID; |
|
129 | - $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); |
|
130 | - |
|
131 | - echo '<div class="remove-personal-data" ' . |
|
132 | - 'data-force-erase="1" ' . |
|
133 | - 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' . |
|
134 | - 'data-request-id="' . esc_attr( $request_id ) . '" ' . |
|
135 | - 'data-nonce="' . esc_attr( $nonce ) . |
|
136 | - '">'; |
|
137 | - |
|
138 | - ?> |
|
20 | + /** |
|
21 | + * Action name for the requests this table will work with. |
|
22 | + * |
|
23 | + * @since 4.9.6 |
|
24 | + * |
|
25 | + * @var string $request_type Name of action. |
|
26 | + */ |
|
27 | + protected $request_type = 'remove_personal_data'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Post type for the requests. |
|
31 | + * |
|
32 | + * @since 4.9.6 |
|
33 | + * |
|
34 | + * @var string $post_type The post type. |
|
35 | + */ |
|
36 | + protected $post_type = 'user_request'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Actions column. |
|
40 | + * |
|
41 | + * @since 4.9.6 |
|
42 | + * |
|
43 | + * @param WP_User_Request $item Item being shown. |
|
44 | + * @return string Email column markup. |
|
45 | + */ |
|
46 | + public function column_email( $item ) { |
|
47 | + $row_actions = array(); |
|
48 | + |
|
49 | + // Allow the administrator to "force remove" the personal data even if confirmation has not yet been received. |
|
50 | + $status = $item->status; |
|
51 | + $request_id = $item->ID; |
|
52 | + $row_actions = array(); |
|
53 | + if ( 'request-confirmed' !== $status ) { |
|
54 | + /** This filter is documented in wp-admin/includes/ajax-actions.php */ |
|
55 | + $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); |
|
56 | + $erasers_count = count( $erasers ); |
|
57 | + $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); |
|
58 | + |
|
59 | + $remove_data_markup = '<span class="remove-personal-data force-remove-personal-data" ' . |
|
60 | + 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' . |
|
61 | + 'data-request-id="' . esc_attr( $request_id ) . '" ' . |
|
62 | + 'data-nonce="' . esc_attr( $nonce ) . |
|
63 | + '">'; |
|
64 | + |
|
65 | + $remove_data_markup .= '<span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle">' . __( 'Force erase personal data' ) . '</button></span>' . |
|
66 | + '<span class="remove-personal-data-processing hidden">' . __( 'Erasing data...' ) . ' <span class="erasure-progress"></span></span>' . |
|
67 | + '<span class="remove-personal-data-success hidden">' . __( 'Erasure completed.' ) . '</span>' . |
|
68 | + '<span class="remove-personal-data-failed hidden">' . __( 'Force erasure has failed.' ) . ' <button type="button" class="button-link remove-personal-data-handle">' . __( 'Retry' ) . '</button></span>'; |
|
69 | + |
|
70 | + $remove_data_markup .= '</span>'; |
|
71 | + |
|
72 | + $row_actions['remove-data'] = $remove_data_markup; |
|
73 | + } |
|
74 | + |
|
75 | + if ( 'request-completed' !== $status ) { |
|
76 | + $complete_request_markup = '<span>'; |
|
77 | + $complete_request_markup .= sprintf( |
|
78 | + '<a href="%s" class="complete-request" aria-label="%s">%s</a>', |
|
79 | + esc_url( |
|
80 | + wp_nonce_url( |
|
81 | + add_query_arg( |
|
82 | + array( |
|
83 | + 'action' => 'complete', |
|
84 | + 'request_id' => array( $request_id ), |
|
85 | + ), |
|
86 | + admin_url( 'erase-personal-data.php' ) |
|
87 | + ), |
|
88 | + 'bulk-privacy_requests' |
|
89 | + ) |
|
90 | + ), |
|
91 | + esc_attr( |
|
92 | + sprintf( |
|
93 | + /* translators: %s: Request email. */ |
|
94 | + __( 'Mark export request for “%s” as completed.' ), |
|
95 | + $item->email |
|
96 | + ) |
|
97 | + ), |
|
98 | + __( 'Complete request' ) |
|
99 | + ); |
|
100 | + $complete_request_markup .= '</span>'; |
|
101 | + } |
|
102 | + |
|
103 | + if ( ! empty( $complete_request_markup ) ) { |
|
104 | + $row_actions['complete-request'] = $complete_request_markup; |
|
105 | + } |
|
106 | + |
|
107 | + return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Next steps column. |
|
112 | + * |
|
113 | + * @since 4.9.6 |
|
114 | + * |
|
115 | + * @param WP_User_Request $item Item being shown. |
|
116 | + */ |
|
117 | + public function column_next_steps( $item ) { |
|
118 | + $status = $item->status; |
|
119 | + |
|
120 | + switch ( $status ) { |
|
121 | + case 'request-pending': |
|
122 | + esc_html_e( 'Waiting for confirmation' ); |
|
123 | + break; |
|
124 | + case 'request-confirmed': |
|
125 | + /** This filter is documented in wp-admin/includes/ajax-actions.php */ |
|
126 | + $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() ); |
|
127 | + $erasers_count = count( $erasers ); |
|
128 | + $request_id = $item->ID; |
|
129 | + $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id ); |
|
130 | + |
|
131 | + echo '<div class="remove-personal-data" ' . |
|
132 | + 'data-force-erase="1" ' . |
|
133 | + 'data-erasers-count="' . esc_attr( $erasers_count ) . '" ' . |
|
134 | + 'data-request-id="' . esc_attr( $request_id ) . '" ' . |
|
135 | + 'data-nonce="' . esc_attr( $nonce ) . |
|
136 | + '">'; |
|
137 | + |
|
138 | + ?> |
|
139 | 139 | <span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle"><?php _e( 'Erase personal data' ); ?></button></span> |
140 | 140 | <span class="remove-personal-data-processing hidden"><?php _e( 'Erasing data...' ); ?> <span class="erasure-progress"></span></span> |
141 | 141 | <span class="remove-personal-data-success success-message hidden" ><?php _e( 'Erasure completed.' ); ?></span> |
142 | 142 | <span class="remove-personal-data-failed hidden"><?php _e( 'Data erasure has failed.' ); ?> <button type="button" class="button-link remove-personal-data-handle"><?php _e( 'Retry' ); ?></button></span> |
143 | 143 | <?php |
144 | 144 | |
145 | - echo '</div>'; |
|
146 | - |
|
147 | - break; |
|
148 | - case 'request-failed': |
|
149 | - echo '<button type="submit" class="button-link" name="privacy_action_email_retry[' . $item->ID . ']" id="privacy_action_email_retry[' . $item->ID . ']">' . __( 'Retry' ) . '</button>'; |
|
150 | - break; |
|
151 | - case 'request-completed': |
|
152 | - echo '<a href="' . esc_url( |
|
153 | - wp_nonce_url( |
|
154 | - add_query_arg( |
|
155 | - array( |
|
156 | - 'action' => 'delete', |
|
157 | - 'request_id' => array( $item->ID ), |
|
158 | - ), |
|
159 | - admin_url( 'erase-personal-data.php' ) |
|
160 | - ), |
|
161 | - 'bulk-privacy_requests' |
|
162 | - ) |
|
163 | - ) . '">' . esc_html__( 'Remove request' ) . '</a>'; |
|
164 | - break; |
|
165 | - } |
|
166 | - } |
|
145 | + echo '</div>'; |
|
146 | + |
|
147 | + break; |
|
148 | + case 'request-failed': |
|
149 | + echo '<button type="submit" class="button-link" name="privacy_action_email_retry[' . $item->ID . ']" id="privacy_action_email_retry[' . $item->ID . ']">' . __( 'Retry' ) . '</button>'; |
|
150 | + break; |
|
151 | + case 'request-completed': |
|
152 | + echo '<a href="' . esc_url( |
|
153 | + wp_nonce_url( |
|
154 | + add_query_arg( |
|
155 | + array( |
|
156 | + 'action' => 'delete', |
|
157 | + 'request_id' => array( $item->ID ), |
|
158 | + ), |
|
159 | + admin_url( 'erase-personal-data.php' ) |
|
160 | + ), |
|
161 | + 'bulk-privacy_requests' |
|
162 | + ) |
|
163 | + ) . '">' . esc_html__( 'Remove request' ) . '</a>'; |
|
164 | + break; |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | 168 | } |
@@ -13,360 +13,360 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class Custom_Image_Header { |
15 | 15 | |
16 | - /** |
|
17 | - * Callback for administration header. |
|
18 | - * |
|
19 | - * @var callable |
|
20 | - * @since 2.1.0 |
|
21 | - */ |
|
22 | - public $admin_header_callback; |
|
23 | - |
|
24 | - /** |
|
25 | - * Callback for header div. |
|
26 | - * |
|
27 | - * @var callable |
|
28 | - * @since 3.0.0 |
|
29 | - */ |
|
30 | - public $admin_image_div_callback; |
|
31 | - |
|
32 | - /** |
|
33 | - * Holds default headers. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - * @since 3.0.0 |
|
37 | - */ |
|
38 | - public $default_headers = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Used to trigger a success message when settings updated and set to true. |
|
42 | - * |
|
43 | - * @since 3.0.0 |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - private $updated; |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor - Register administration header callback. |
|
50 | - * |
|
51 | - * @since 2.1.0 |
|
52 | - * @param callable $admin_header_callback |
|
53 | - * @param callable $admin_image_div_callback Optional custom image div output callback. |
|
54 | - */ |
|
55 | - public function __construct( $admin_header_callback, $admin_image_div_callback = '' ) { |
|
56 | - $this->admin_header_callback = $admin_header_callback; |
|
57 | - $this->admin_image_div_callback = $admin_image_div_callback; |
|
58 | - |
|
59 | - add_action( 'admin_menu', array( $this, 'init' ) ); |
|
60 | - |
|
61 | - add_action( 'customize_save_after', array( $this, 'customize_set_last_used' ) ); |
|
62 | - add_action( 'wp_ajax_custom-header-crop', array( $this, 'ajax_header_crop' ) ); |
|
63 | - add_action( 'wp_ajax_custom-header-add', array( $this, 'ajax_header_add' ) ); |
|
64 | - add_action( 'wp_ajax_custom-header-remove', array( $this, 'ajax_header_remove' ) ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Set up the hooks for the Custom Header admin page. |
|
69 | - * |
|
70 | - * @since 2.1.0 |
|
71 | - */ |
|
72 | - public function init() { |
|
73 | - $page = add_theme_page( __( 'Header' ), __( 'Header' ), 'edit_theme_options', 'custom-header', array( $this, 'admin_page' ) ); |
|
74 | - |
|
75 | - if ( ! $page ) { |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - add_action( "admin_print_scripts-{$page}", array( $this, 'js_includes' ) ); |
|
80 | - add_action( "admin_print_styles-{$page}", array( $this, 'css_includes' ) ); |
|
81 | - add_action( "admin_head-{$page}", array( $this, 'help' ) ); |
|
82 | - add_action( "admin_head-{$page}", array( $this, 'take_action' ), 50 ); |
|
83 | - add_action( "admin_head-{$page}", array( $this, 'js' ), 50 ); |
|
84 | - |
|
85 | - if ( $this->admin_header_callback ) { |
|
86 | - add_action( "admin_head-{$page}", $this->admin_header_callback, 51 ); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Adds contextual help. |
|
92 | - * |
|
93 | - * @since 3.0.0 |
|
94 | - */ |
|
95 | - public function help() { |
|
96 | - get_current_screen()->add_help_tab( |
|
97 | - array( |
|
98 | - 'id' => 'overview', |
|
99 | - 'title' => __( 'Overview' ), |
|
100 | - 'content' => |
|
101 | - '<p>' . __( 'This screen is used to customize the header section of your theme.' ) . '</p>' . |
|
102 | - '<p>' . __( 'You can choose from the theme’s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.' ) . '<p>', |
|
103 | - ) |
|
104 | - ); |
|
105 | - |
|
106 | - get_current_screen()->add_help_tab( |
|
107 | - array( |
|
108 | - 'id' => 'set-header-image', |
|
109 | - 'title' => __( 'Header Image' ), |
|
110 | - 'content' => |
|
111 | - '<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the “Choose Image” button.' ) . '</p>' . |
|
112 | - '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you would like and click the “Save Changes” button.' ) . '</p>' . |
|
113 | - '<p>' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the “Random” radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '</p>' . |
|
114 | - '<p>' . __( 'If you do not want a header image to be displayed on your site at all, click the “Remove Header Image” button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click “Save Changes”.' ) . '</p>', |
|
115 | - ) |
|
116 | - ); |
|
117 | - |
|
118 | - get_current_screen()->add_help_tab( |
|
119 | - array( |
|
120 | - 'id' => 'set-header-text', |
|
121 | - 'title' => __( 'Header Text' ), |
|
122 | - 'content' => |
|
123 | - '<p>' . sprintf( |
|
124 | - /* translators: %s: URL to General Settings screen. */ |
|
125 | - __( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%s">General Settings</a> section.' ), |
|
126 | - admin_url( 'options-general.php' ) |
|
127 | - ) . |
|
128 | - '</p>' . |
|
129 | - '<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
|
130 | - '<p>' . __( 'Do not forget to click “Save Changes” when you are done!' ) . '</p>', |
|
131 | - ) |
|
132 | - ); |
|
133 | - |
|
134 | - get_current_screen()->set_help_sidebar( |
|
135 | - '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
|
136 | - '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Header_Screen">Documentation on Custom Header</a>' ) . '</p>' . |
|
137 | - '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Get the current step. |
|
143 | - * |
|
144 | - * @since 2.6.0 |
|
145 | - * |
|
146 | - * @return int Current step. |
|
147 | - */ |
|
148 | - public function step() { |
|
149 | - if ( ! isset( $_GET['step'] ) ) { |
|
150 | - return 1; |
|
151 | - } |
|
152 | - |
|
153 | - $step = (int) $_GET['step']; |
|
154 | - if ( $step < 1 || 3 < $step || |
|
155 | - ( 2 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) || |
|
156 | - ( 3 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) ) |
|
157 | - ) { |
|
158 | - return 1; |
|
159 | - } |
|
160 | - |
|
161 | - return $step; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Set up the enqueue for the JavaScript files. |
|
166 | - * |
|
167 | - * @since 2.1.0 |
|
168 | - */ |
|
169 | - public function js_includes() { |
|
170 | - $step = $this->step(); |
|
171 | - |
|
172 | - if ( ( 1 === $step || 3 === $step ) ) { |
|
173 | - wp_enqueue_media(); |
|
174 | - wp_enqueue_script( 'custom-header' ); |
|
175 | - if ( current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
176 | - wp_enqueue_script( 'wp-color-picker' ); |
|
177 | - } |
|
178 | - } elseif ( 2 === $step ) { |
|
179 | - wp_enqueue_script( 'imgareaselect' ); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Set up the enqueue for the CSS files |
|
185 | - * |
|
186 | - * @since 2.7.0 |
|
187 | - */ |
|
188 | - public function css_includes() { |
|
189 | - $step = $this->step(); |
|
190 | - |
|
191 | - if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
192 | - wp_enqueue_style( 'wp-color-picker' ); |
|
193 | - } elseif ( 2 === $step ) { |
|
194 | - wp_enqueue_style( 'imgareaselect' ); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Execute custom header modification. |
|
200 | - * |
|
201 | - * @since 2.6.0 |
|
202 | - */ |
|
203 | - public function take_action() { |
|
204 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
205 | - return; |
|
206 | - } |
|
207 | - |
|
208 | - if ( empty( $_POST ) ) { |
|
209 | - return; |
|
210 | - } |
|
211 | - |
|
212 | - $this->updated = true; |
|
213 | - |
|
214 | - if ( isset( $_POST['resetheader'] ) ) { |
|
215 | - check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
216 | - |
|
217 | - $this->reset_header_image(); |
|
218 | - |
|
219 | - return; |
|
220 | - } |
|
221 | - |
|
222 | - if ( isset( $_POST['removeheader'] ) ) { |
|
223 | - check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
224 | - |
|
225 | - $this->remove_header_image(); |
|
226 | - |
|
227 | - return; |
|
228 | - } |
|
229 | - |
|
230 | - if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) { |
|
231 | - check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
232 | - |
|
233 | - set_theme_mod( 'header_textcolor', 'blank' ); |
|
234 | - } elseif ( isset( $_POST['text-color'] ) ) { |
|
235 | - check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
236 | - |
|
237 | - $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] ); |
|
238 | - |
|
239 | - $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] ); |
|
240 | - |
|
241 | - if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { |
|
242 | - set_theme_mod( 'header_textcolor', $color ); |
|
243 | - } elseif ( ! $color ) { |
|
244 | - set_theme_mod( 'header_textcolor', 'blank' ); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - if ( isset( $_POST['default-header'] ) ) { |
|
249 | - check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
250 | - |
|
251 | - $this->set_header_image( $_POST['default-header'] ); |
|
252 | - |
|
253 | - return; |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Process the default headers |
|
259 | - * |
|
260 | - * @since 3.0.0 |
|
261 | - * |
|
262 | - * @global array $_wp_default_headers |
|
263 | - */ |
|
264 | - public function process_default_headers() { |
|
265 | - global $_wp_default_headers; |
|
266 | - |
|
267 | - if ( ! isset( $_wp_default_headers ) ) { |
|
268 | - return; |
|
269 | - } |
|
270 | - |
|
271 | - if ( ! empty( $this->default_headers ) ) { |
|
272 | - return; |
|
273 | - } |
|
274 | - |
|
275 | - $this->default_headers = $_wp_default_headers; |
|
276 | - $template_directory_uri = get_template_directory_uri(); |
|
277 | - $stylesheet_directory_uri = get_stylesheet_directory_uri(); |
|
278 | - |
|
279 | - foreach ( array_keys( $this->default_headers ) as $header ) { |
|
280 | - $this->default_headers[ $header ]['url'] = sprintf( |
|
281 | - $this->default_headers[ $header ]['url'], |
|
282 | - $template_directory_uri, |
|
283 | - $stylesheet_directory_uri |
|
284 | - ); |
|
285 | - |
|
286 | - $this->default_headers[ $header ]['thumbnail_url'] = sprintf( |
|
287 | - $this->default_headers[ $header ]['thumbnail_url'], |
|
288 | - $template_directory_uri, |
|
289 | - $stylesheet_directory_uri |
|
290 | - ); |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Display UI for selecting one of several default headers. |
|
296 | - * |
|
297 | - * Show the random image option if this theme has multiple header images. |
|
298 | - * Random image option is on by default if no header has been set. |
|
299 | - * |
|
300 | - * @since 3.0.0 |
|
301 | - * |
|
302 | - * @param string $type The header type. One of 'default' (for the Uploaded Images control) |
|
303 | - * or 'uploaded' (for the Uploaded Images control). |
|
304 | - */ |
|
305 | - public function show_header_selector( $type = 'default' ) { |
|
306 | - if ( 'default' === $type ) { |
|
307 | - $headers = $this->default_headers; |
|
308 | - } else { |
|
309 | - $headers = get_uploaded_header_images(); |
|
310 | - $type = 'uploaded'; |
|
311 | - } |
|
312 | - |
|
313 | - if ( 1 < count( $headers ) ) { |
|
314 | - echo '<div class="random-header">'; |
|
315 | - echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />'; |
|
316 | - _e( '<strong>Random:</strong> Show a different image on each page.' ); |
|
317 | - echo '</label>'; |
|
318 | - echo '</div>'; |
|
319 | - } |
|
320 | - |
|
321 | - echo '<div class="available-headers">'; |
|
322 | - |
|
323 | - foreach ( $headers as $header_key => $header ) { |
|
324 | - $header_thumbnail = $header['thumbnail_url']; |
|
325 | - $header_url = $header['url']; |
|
326 | - $header_alt_text = empty( $header['alt_text'] ) ? '' : $header['alt_text']; |
|
327 | - |
|
328 | - echo '<div class="default-header">'; |
|
329 | - echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />'; |
|
330 | - $width = ''; |
|
331 | - if ( ! empty( $header['attachment_id'] ) ) { |
|
332 | - $width = ' width="230"'; |
|
333 | - } |
|
334 | - echo '<img src="' . set_url_scheme( $header_thumbnail ) . '" alt="' . esc_attr( $header_alt_text ) . '"' . $width . ' /></label>'; |
|
335 | - echo '</div>'; |
|
336 | - } |
|
337 | - |
|
338 | - echo '<div class="clear"></div></div>'; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Execute JavaScript depending on step. |
|
343 | - * |
|
344 | - * @since 2.1.0 |
|
345 | - */ |
|
346 | - public function js() { |
|
347 | - $step = $this->step(); |
|
348 | - |
|
349 | - if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
350 | - $this->js_1(); |
|
351 | - } elseif ( 2 === $step ) { |
|
352 | - $this->js_2(); |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Display JavaScript based on Step 1 and 3. |
|
358 | - * |
|
359 | - * @since 2.6.0 |
|
360 | - */ |
|
361 | - public function js_1() { |
|
362 | - $default_color = ''; |
|
363 | - if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) { |
|
364 | - $default_color = get_theme_support( 'custom-header', 'default-text-color' ); |
|
365 | - if ( $default_color && false === strpos( $default_color, '#' ) ) { |
|
366 | - $default_color = '#' . $default_color; |
|
367 | - } |
|
368 | - } |
|
369 | - ?> |
|
16 | + /** |
|
17 | + * Callback for administration header. |
|
18 | + * |
|
19 | + * @var callable |
|
20 | + * @since 2.1.0 |
|
21 | + */ |
|
22 | + public $admin_header_callback; |
|
23 | + |
|
24 | + /** |
|
25 | + * Callback for header div. |
|
26 | + * |
|
27 | + * @var callable |
|
28 | + * @since 3.0.0 |
|
29 | + */ |
|
30 | + public $admin_image_div_callback; |
|
31 | + |
|
32 | + /** |
|
33 | + * Holds default headers. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + * @since 3.0.0 |
|
37 | + */ |
|
38 | + public $default_headers = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Used to trigger a success message when settings updated and set to true. |
|
42 | + * |
|
43 | + * @since 3.0.0 |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + private $updated; |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor - Register administration header callback. |
|
50 | + * |
|
51 | + * @since 2.1.0 |
|
52 | + * @param callable $admin_header_callback |
|
53 | + * @param callable $admin_image_div_callback Optional custom image div output callback. |
|
54 | + */ |
|
55 | + public function __construct( $admin_header_callback, $admin_image_div_callback = '' ) { |
|
56 | + $this->admin_header_callback = $admin_header_callback; |
|
57 | + $this->admin_image_div_callback = $admin_image_div_callback; |
|
58 | + |
|
59 | + add_action( 'admin_menu', array( $this, 'init' ) ); |
|
60 | + |
|
61 | + add_action( 'customize_save_after', array( $this, 'customize_set_last_used' ) ); |
|
62 | + add_action( 'wp_ajax_custom-header-crop', array( $this, 'ajax_header_crop' ) ); |
|
63 | + add_action( 'wp_ajax_custom-header-add', array( $this, 'ajax_header_add' ) ); |
|
64 | + add_action( 'wp_ajax_custom-header-remove', array( $this, 'ajax_header_remove' ) ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Set up the hooks for the Custom Header admin page. |
|
69 | + * |
|
70 | + * @since 2.1.0 |
|
71 | + */ |
|
72 | + public function init() { |
|
73 | + $page = add_theme_page( __( 'Header' ), __( 'Header' ), 'edit_theme_options', 'custom-header', array( $this, 'admin_page' ) ); |
|
74 | + |
|
75 | + if ( ! $page ) { |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + add_action( "admin_print_scripts-{$page}", array( $this, 'js_includes' ) ); |
|
80 | + add_action( "admin_print_styles-{$page}", array( $this, 'css_includes' ) ); |
|
81 | + add_action( "admin_head-{$page}", array( $this, 'help' ) ); |
|
82 | + add_action( "admin_head-{$page}", array( $this, 'take_action' ), 50 ); |
|
83 | + add_action( "admin_head-{$page}", array( $this, 'js' ), 50 ); |
|
84 | + |
|
85 | + if ( $this->admin_header_callback ) { |
|
86 | + add_action( "admin_head-{$page}", $this->admin_header_callback, 51 ); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Adds contextual help. |
|
92 | + * |
|
93 | + * @since 3.0.0 |
|
94 | + */ |
|
95 | + public function help() { |
|
96 | + get_current_screen()->add_help_tab( |
|
97 | + array( |
|
98 | + 'id' => 'overview', |
|
99 | + 'title' => __( 'Overview' ), |
|
100 | + 'content' => |
|
101 | + '<p>' . __( 'This screen is used to customize the header section of your theme.' ) . '</p>' . |
|
102 | + '<p>' . __( 'You can choose from the theme’s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.' ) . '<p>', |
|
103 | + ) |
|
104 | + ); |
|
105 | + |
|
106 | + get_current_screen()->add_help_tab( |
|
107 | + array( |
|
108 | + 'id' => 'set-header-image', |
|
109 | + 'title' => __( 'Header Image' ), |
|
110 | + 'content' => |
|
111 | + '<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the “Choose Image” button.' ) . '</p>' . |
|
112 | + '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you would like and click the “Save Changes” button.' ) . '</p>' . |
|
113 | + '<p>' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the “Random” radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '</p>' . |
|
114 | + '<p>' . __( 'If you do not want a header image to be displayed on your site at all, click the “Remove Header Image” button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click “Save Changes”.' ) . '</p>', |
|
115 | + ) |
|
116 | + ); |
|
117 | + |
|
118 | + get_current_screen()->add_help_tab( |
|
119 | + array( |
|
120 | + 'id' => 'set-header-text', |
|
121 | + 'title' => __( 'Header Text' ), |
|
122 | + 'content' => |
|
123 | + '<p>' . sprintf( |
|
124 | + /* translators: %s: URL to General Settings screen. */ |
|
125 | + __( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%s">General Settings</a> section.' ), |
|
126 | + admin_url( 'options-general.php' ) |
|
127 | + ) . |
|
128 | + '</p>' . |
|
129 | + '<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
|
130 | + '<p>' . __( 'Do not forget to click “Save Changes” when you are done!' ) . '</p>', |
|
131 | + ) |
|
132 | + ); |
|
133 | + |
|
134 | + get_current_screen()->set_help_sidebar( |
|
135 | + '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
|
136 | + '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Header_Screen">Documentation on Custom Header</a>' ) . '</p>' . |
|
137 | + '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Get the current step. |
|
143 | + * |
|
144 | + * @since 2.6.0 |
|
145 | + * |
|
146 | + * @return int Current step. |
|
147 | + */ |
|
148 | + public function step() { |
|
149 | + if ( ! isset( $_GET['step'] ) ) { |
|
150 | + return 1; |
|
151 | + } |
|
152 | + |
|
153 | + $step = (int) $_GET['step']; |
|
154 | + if ( $step < 1 || 3 < $step || |
|
155 | + ( 2 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) || |
|
156 | + ( 3 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) ) |
|
157 | + ) { |
|
158 | + return 1; |
|
159 | + } |
|
160 | + |
|
161 | + return $step; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Set up the enqueue for the JavaScript files. |
|
166 | + * |
|
167 | + * @since 2.1.0 |
|
168 | + */ |
|
169 | + public function js_includes() { |
|
170 | + $step = $this->step(); |
|
171 | + |
|
172 | + if ( ( 1 === $step || 3 === $step ) ) { |
|
173 | + wp_enqueue_media(); |
|
174 | + wp_enqueue_script( 'custom-header' ); |
|
175 | + if ( current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
176 | + wp_enqueue_script( 'wp-color-picker' ); |
|
177 | + } |
|
178 | + } elseif ( 2 === $step ) { |
|
179 | + wp_enqueue_script( 'imgareaselect' ); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Set up the enqueue for the CSS files |
|
185 | + * |
|
186 | + * @since 2.7.0 |
|
187 | + */ |
|
188 | + public function css_includes() { |
|
189 | + $step = $this->step(); |
|
190 | + |
|
191 | + if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
192 | + wp_enqueue_style( 'wp-color-picker' ); |
|
193 | + } elseif ( 2 === $step ) { |
|
194 | + wp_enqueue_style( 'imgareaselect' ); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Execute custom header modification. |
|
200 | + * |
|
201 | + * @since 2.6.0 |
|
202 | + */ |
|
203 | + public function take_action() { |
|
204 | + if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
205 | + return; |
|
206 | + } |
|
207 | + |
|
208 | + if ( empty( $_POST ) ) { |
|
209 | + return; |
|
210 | + } |
|
211 | + |
|
212 | + $this->updated = true; |
|
213 | + |
|
214 | + if ( isset( $_POST['resetheader'] ) ) { |
|
215 | + check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
216 | + |
|
217 | + $this->reset_header_image(); |
|
218 | + |
|
219 | + return; |
|
220 | + } |
|
221 | + |
|
222 | + if ( isset( $_POST['removeheader'] ) ) { |
|
223 | + check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
224 | + |
|
225 | + $this->remove_header_image(); |
|
226 | + |
|
227 | + return; |
|
228 | + } |
|
229 | + |
|
230 | + if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) { |
|
231 | + check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
232 | + |
|
233 | + set_theme_mod( 'header_textcolor', 'blank' ); |
|
234 | + } elseif ( isset( $_POST['text-color'] ) ) { |
|
235 | + check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
236 | + |
|
237 | + $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] ); |
|
238 | + |
|
239 | + $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] ); |
|
240 | + |
|
241 | + if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { |
|
242 | + set_theme_mod( 'header_textcolor', $color ); |
|
243 | + } elseif ( ! $color ) { |
|
244 | + set_theme_mod( 'header_textcolor', 'blank' ); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + if ( isset( $_POST['default-header'] ) ) { |
|
249 | + check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
250 | + |
|
251 | + $this->set_header_image( $_POST['default-header'] ); |
|
252 | + |
|
253 | + return; |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Process the default headers |
|
259 | + * |
|
260 | + * @since 3.0.0 |
|
261 | + * |
|
262 | + * @global array $_wp_default_headers |
|
263 | + */ |
|
264 | + public function process_default_headers() { |
|
265 | + global $_wp_default_headers; |
|
266 | + |
|
267 | + if ( ! isset( $_wp_default_headers ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | + |
|
271 | + if ( ! empty( $this->default_headers ) ) { |
|
272 | + return; |
|
273 | + } |
|
274 | + |
|
275 | + $this->default_headers = $_wp_default_headers; |
|
276 | + $template_directory_uri = get_template_directory_uri(); |
|
277 | + $stylesheet_directory_uri = get_stylesheet_directory_uri(); |
|
278 | + |
|
279 | + foreach ( array_keys( $this->default_headers ) as $header ) { |
|
280 | + $this->default_headers[ $header ]['url'] = sprintf( |
|
281 | + $this->default_headers[ $header ]['url'], |
|
282 | + $template_directory_uri, |
|
283 | + $stylesheet_directory_uri |
|
284 | + ); |
|
285 | + |
|
286 | + $this->default_headers[ $header ]['thumbnail_url'] = sprintf( |
|
287 | + $this->default_headers[ $header ]['thumbnail_url'], |
|
288 | + $template_directory_uri, |
|
289 | + $stylesheet_directory_uri |
|
290 | + ); |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Display UI for selecting one of several default headers. |
|
296 | + * |
|
297 | + * Show the random image option if this theme has multiple header images. |
|
298 | + * Random image option is on by default if no header has been set. |
|
299 | + * |
|
300 | + * @since 3.0.0 |
|
301 | + * |
|
302 | + * @param string $type The header type. One of 'default' (for the Uploaded Images control) |
|
303 | + * or 'uploaded' (for the Uploaded Images control). |
|
304 | + */ |
|
305 | + public function show_header_selector( $type = 'default' ) { |
|
306 | + if ( 'default' === $type ) { |
|
307 | + $headers = $this->default_headers; |
|
308 | + } else { |
|
309 | + $headers = get_uploaded_header_images(); |
|
310 | + $type = 'uploaded'; |
|
311 | + } |
|
312 | + |
|
313 | + if ( 1 < count( $headers ) ) { |
|
314 | + echo '<div class="random-header">'; |
|
315 | + echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />'; |
|
316 | + _e( '<strong>Random:</strong> Show a different image on each page.' ); |
|
317 | + echo '</label>'; |
|
318 | + echo '</div>'; |
|
319 | + } |
|
320 | + |
|
321 | + echo '<div class="available-headers">'; |
|
322 | + |
|
323 | + foreach ( $headers as $header_key => $header ) { |
|
324 | + $header_thumbnail = $header['thumbnail_url']; |
|
325 | + $header_url = $header['url']; |
|
326 | + $header_alt_text = empty( $header['alt_text'] ) ? '' : $header['alt_text']; |
|
327 | + |
|
328 | + echo '<div class="default-header">'; |
|
329 | + echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />'; |
|
330 | + $width = ''; |
|
331 | + if ( ! empty( $header['attachment_id'] ) ) { |
|
332 | + $width = ' width="230"'; |
|
333 | + } |
|
334 | + echo '<img src="' . set_url_scheme( $header_thumbnail ) . '" alt="' . esc_attr( $header_alt_text ) . '"' . $width . ' /></label>'; |
|
335 | + echo '</div>'; |
|
336 | + } |
|
337 | + |
|
338 | + echo '<div class="clear"></div></div>'; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Execute JavaScript depending on step. |
|
343 | + * |
|
344 | + * @since 2.1.0 |
|
345 | + */ |
|
346 | + public function js() { |
|
347 | + $step = $this->step(); |
|
348 | + |
|
349 | + if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { |
|
350 | + $this->js_1(); |
|
351 | + } elseif ( 2 === $step ) { |
|
352 | + $this->js_2(); |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Display JavaScript based on Step 1 and 3. |
|
358 | + * |
|
359 | + * @since 2.6.0 |
|
360 | + */ |
|
361 | + public function js_1() { |
|
362 | + $default_color = ''; |
|
363 | + if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) { |
|
364 | + $default_color = get_theme_support( 'custom-header', 'default-text-color' ); |
|
365 | + if ( $default_color && false === strpos( $default_color, '#' ) ) { |
|
366 | + $default_color = '#' . $default_color; |
|
367 | + } |
|
368 | + } |
|
369 | + ?> |
|
370 | 370 | <script type="text/javascript"> |
371 | 371 | (function($){ |
372 | 372 | var default_color = '<?php echo esc_js( $default_color ); ?>', |
@@ -412,16 +412,16 @@ discard block |
||
412 | 412 | })(jQuery); |
413 | 413 | </script> |
414 | 414 | <?php |
415 | - } |
|
415 | + } |
|
416 | 416 | |
417 | - /** |
|
418 | - * Display JavaScript based on Step 2. |
|
419 | - * |
|
420 | - * @since 2.6.0 |
|
421 | - */ |
|
422 | - public function js_2() { |
|
417 | + /** |
|
418 | + * Display JavaScript based on Step 2. |
|
419 | + * |
|
420 | + * @since 2.6.0 |
|
421 | + */ |
|
422 | + public function js_2() { |
|
423 | 423 | |
424 | - ?> |
|
424 | + ?> |
|
425 | 425 | <script type="text/javascript"> |
426 | 426 | function onEndCrop( coords ) { |
427 | 427 | jQuery( '#x1' ).val(coords.x); |
@@ -456,24 +456,24 @@ discard block |
||
456 | 456 | x2: xinit, |
457 | 457 | y2: yinit, |
458 | 458 | <?php |
459 | - if ( ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
460 | - && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
461 | - ) { |
|
462 | - ?> |
|
459 | + if ( ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
460 | + && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
461 | + ) { |
|
462 | + ?> |
|
463 | 463 | aspectRatio: xinit + ':' + yinit, |
464 | 464 | <?php |
465 | - } |
|
466 | - if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { |
|
467 | - ?> |
|
465 | + } |
|
466 | + if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { |
|
467 | + ?> |
|
468 | 468 | maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>, |
469 | 469 | <?php |
470 | - } |
|
471 | - if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
472 | - ?> |
|
470 | + } |
|
471 | + if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
472 | + ?> |
|
473 | 473 | maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>, |
474 | 474 | <?php |
475 | - } |
|
476 | - ?> |
|
475 | + } |
|
476 | + ?> |
|
477 | 477 | onInit: function () { |
478 | 478 | jQuery('#width').val(xinit); |
479 | 479 | jQuery('#height').val(yinit); |
@@ -488,16 +488,16 @@ discard block |
||
488 | 488 | } ); |
489 | 489 | </script> |
490 | 490 | <?php |
491 | - } |
|
491 | + } |
|
492 | 492 | |
493 | - /** |
|
494 | - * Display first step of custom header image page. |
|
495 | - * |
|
496 | - * @since 2.1.0 |
|
497 | - */ |
|
498 | - public function step_1() { |
|
499 | - $this->process_default_headers(); |
|
500 | - ?> |
|
493 | + /** |
|
494 | + * Display first step of custom header image page. |
|
495 | + * |
|
496 | + * @since 2.1.0 |
|
497 | + */ |
|
498 | + public function step_1() { |
|
499 | + $this->process_default_headers(); |
|
500 | + ?> |
|
501 | 501 | |
502 | 502 | <div class="wrap"> |
503 | 503 | <h1><?php _e( 'Custom Header' ); ?></h1> |
@@ -506,12 +506,12 @@ discard block |
||
506 | 506 | <div class="notice notice-info hide-if-no-customize"> |
507 | 507 | <p> |
508 | 508 | <?php |
509 | - printf( |
|
510 | - /* translators: %s: URL to header image configuration in Customizer. */ |
|
511 | - __( 'You can now manage and live-preview Custom Header in the <a href="%s">Customizer</a>.' ), |
|
512 | - admin_url( 'customize.php?autofocus[control]=header_image' ) |
|
513 | - ); |
|
514 | - ?> |
|
509 | + printf( |
|
510 | + /* translators: %s: URL to header image configuration in Customizer. */ |
|
511 | + __( 'You can now manage and live-preview Custom Header in the <a href="%s">Customizer</a>.' ), |
|
512 | + admin_url( 'customize.php?autofocus[control]=header_image' ) |
|
513 | + ); |
|
514 | + ?> |
|
515 | 515 | </p> |
516 | 516 | </div> |
517 | 517 | <?php } ?> |
@@ -520,9 +520,9 @@ discard block |
||
520 | 520 | <div id="message" class="updated"> |
521 | 521 | <p> |
522 | 522 | <?php |
523 | - /* translators: %s: Home URL. */ |
|
524 | - printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); |
|
525 | - ?> |
|
523 | + /* translators: %s: Home URL. */ |
|
524 | + printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); |
|
525 | + ?> |
|
526 | 526 | </p> |
527 | 527 | </div> |
528 | 528 | <?php } ?> |
@@ -537,33 +537,33 @@ discard block |
||
537 | 537 | <th scope="row"><?php _e( 'Preview' ); ?></th> |
538 | 538 | <td> |
539 | 539 | <?php |
540 | - if ( $this->admin_image_div_callback ) { |
|
541 | - call_user_func( $this->admin_image_div_callback ); |
|
542 | - } else { |
|
543 | - $custom_header = get_custom_header(); |
|
544 | - $header_image = get_header_image(); |
|
545 | - |
|
546 | - if ( $header_image ) { |
|
547 | - $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');'; |
|
548 | - } else { |
|
549 | - $header_image_style = ''; |
|
550 | - } |
|
551 | - |
|
552 | - if ( $custom_header->width ) { |
|
553 | - $header_image_style .= 'max-width:' . $custom_header->width . 'px;'; |
|
554 | - } |
|
555 | - if ( $custom_header->height ) { |
|
556 | - $header_image_style .= 'height:' . $custom_header->height . 'px;'; |
|
557 | - } |
|
558 | - ?> |
|
540 | + if ( $this->admin_image_div_callback ) { |
|
541 | + call_user_func( $this->admin_image_div_callback ); |
|
542 | + } else { |
|
543 | + $custom_header = get_custom_header(); |
|
544 | + $header_image = get_header_image(); |
|
545 | + |
|
546 | + if ( $header_image ) { |
|
547 | + $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');'; |
|
548 | + } else { |
|
549 | + $header_image_style = ''; |
|
550 | + } |
|
551 | + |
|
552 | + if ( $custom_header->width ) { |
|
553 | + $header_image_style .= 'max-width:' . $custom_header->width . 'px;'; |
|
554 | + } |
|
555 | + if ( $custom_header->height ) { |
|
556 | + $header_image_style .= 'height:' . $custom_header->height . 'px;'; |
|
557 | + } |
|
558 | + ?> |
|
559 | 559 | <div id="headimg" style="<?php echo $header_image_style; ?>"> |
560 | 560 | <?php |
561 | - if ( display_header_text() ) { |
|
562 | - $style = ' style="color:#' . get_header_textcolor() . ';"'; |
|
563 | - } else { |
|
564 | - $style = ' style="display:none;"'; |
|
565 | - } |
|
566 | - ?> |
|
561 | + if ( display_header_text() ) { |
|
562 | + $style = ' style="color:#' . get_header_textcolor() . ';"'; |
|
563 | + } else { |
|
564 | + $style = ' style="display:none;"'; |
|
565 | + } |
|
566 | + ?> |
|
567 | 567 | <h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo( 'url' ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1> |
568 | 568 | <div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> |
569 | 569 | </div> |
@@ -578,69 +578,69 @@ discard block |
||
578 | 578 | <td> |
579 | 579 | <p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br /> |
580 | 580 | <?php |
581 | - if ( ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
582 | - && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
583 | - ) { |
|
584 | - printf( |
|
585 | - /* translators: 1: Image width in pixels, 2: Image height in pixels. */ |
|
586 | - __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', |
|
587 | - get_theme_support( 'custom-header', 'width' ), |
|
588 | - get_theme_support( 'custom-header', 'height' ) |
|
589 | - ); |
|
590 | - } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { |
|
591 | - if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
592 | - printf( |
|
593 | - /* translators: %s: Size in pixels. */ |
|
594 | - __( 'Images should be at least %s wide.' ) . ' ', |
|
595 | - sprintf( |
|
596 | - /* translators: %d: Custom header width. */ |
|
597 | - '<strong>' . __( '%d pixels' ) . '</strong>', |
|
598 | - get_theme_support( 'custom-header', 'width' ) |
|
599 | - ) |
|
600 | - ); |
|
601 | - } |
|
602 | - } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
603 | - if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { |
|
604 | - printf( |
|
605 | - /* translators: %s: Size in pixels. */ |
|
606 | - __( 'Images should be at least %s tall.' ) . ' ', |
|
607 | - sprintf( |
|
608 | - /* translators: %d: Custom header height. */ |
|
609 | - '<strong>' . __( '%d pixels' ) . '</strong>', |
|
610 | - get_theme_support( 'custom-header', 'height' ) |
|
611 | - ) |
|
612 | - ); |
|
613 | - } |
|
614 | - } |
|
615 | - |
|
616 | - if ( current_theme_supports( 'custom-header', 'flex-height' ) |
|
617 | - || current_theme_supports( 'custom-header', 'flex-width' ) |
|
618 | - ) { |
|
619 | - if ( current_theme_supports( 'custom-header', 'width' ) ) { |
|
620 | - printf( |
|
621 | - /* translators: %s: Size in pixels. */ |
|
622 | - __( 'Suggested width is %s.' ) . ' ', |
|
623 | - sprintf( |
|
624 | - /* translators: %d: Custom header width. */ |
|
625 | - '<strong>' . __( '%d pixels' ) . '</strong>', |
|
626 | - get_theme_support( 'custom-header', 'width' ) |
|
627 | - ) |
|
628 | - ); |
|
629 | - } |
|
630 | - |
|
631 | - if ( current_theme_supports( 'custom-header', 'height' ) ) { |
|
632 | - printf( |
|
633 | - /* translators: %s: Size in pixels. */ |
|
634 | - __( 'Suggested height is %s.' ) . ' ', |
|
635 | - sprintf( |
|
636 | - /* translators: %d: Custom header height. */ |
|
637 | - '<strong>' . __( '%d pixels' ) . '</strong>', |
|
638 | - get_theme_support( 'custom-header', 'height' ) |
|
639 | - ) |
|
640 | - ); |
|
641 | - } |
|
642 | - } |
|
643 | - ?> |
|
581 | + if ( ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
582 | + && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
583 | + ) { |
|
584 | + printf( |
|
585 | + /* translators: 1: Image width in pixels, 2: Image height in pixels. */ |
|
586 | + __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', |
|
587 | + get_theme_support( 'custom-header', 'width' ), |
|
588 | + get_theme_support( 'custom-header', 'height' ) |
|
589 | + ); |
|
590 | + } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { |
|
591 | + if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
592 | + printf( |
|
593 | + /* translators: %s: Size in pixels. */ |
|
594 | + __( 'Images should be at least %s wide.' ) . ' ', |
|
595 | + sprintf( |
|
596 | + /* translators: %d: Custom header width. */ |
|
597 | + '<strong>' . __( '%d pixels' ) . '</strong>', |
|
598 | + get_theme_support( 'custom-header', 'width' ) |
|
599 | + ) |
|
600 | + ); |
|
601 | + } |
|
602 | + } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
603 | + if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { |
|
604 | + printf( |
|
605 | + /* translators: %s: Size in pixels. */ |
|
606 | + __( 'Images should be at least %s tall.' ) . ' ', |
|
607 | + sprintf( |
|
608 | + /* translators: %d: Custom header height. */ |
|
609 | + '<strong>' . __( '%d pixels' ) . '</strong>', |
|
610 | + get_theme_support( 'custom-header', 'height' ) |
|
611 | + ) |
|
612 | + ); |
|
613 | + } |
|
614 | + } |
|
615 | + |
|
616 | + if ( current_theme_supports( 'custom-header', 'flex-height' ) |
|
617 | + || current_theme_supports( 'custom-header', 'flex-width' ) |
|
618 | + ) { |
|
619 | + if ( current_theme_supports( 'custom-header', 'width' ) ) { |
|
620 | + printf( |
|
621 | + /* translators: %s: Size in pixels. */ |
|
622 | + __( 'Suggested width is %s.' ) . ' ', |
|
623 | + sprintf( |
|
624 | + /* translators: %d: Custom header width. */ |
|
625 | + '<strong>' . __( '%d pixels' ) . '</strong>', |
|
626 | + get_theme_support( 'custom-header', 'width' ) |
|
627 | + ) |
|
628 | + ); |
|
629 | + } |
|
630 | + |
|
631 | + if ( current_theme_supports( 'custom-header', 'height' ) ) { |
|
632 | + printf( |
|
633 | + /* translators: %s: Size in pixels. */ |
|
634 | + __( 'Suggested height is %s.' ) . ' ', |
|
635 | + sprintf( |
|
636 | + /* translators: %d: Custom header height. */ |
|
637 | + '<strong>' . __( '%d pixels' ) . '</strong>', |
|
638 | + get_theme_support( 'custom-header', 'height' ) |
|
639 | + ) |
|
640 | + ); |
|
641 | + } |
|
642 | + } |
|
643 | + ?> |
|
644 | 644 | </p> |
645 | 645 | <form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ); ?>"> |
646 | 646 | <p> |
@@ -651,15 +651,15 @@ discard block |
||
651 | 651 | <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?> |
652 | 652 | </p> |
653 | 653 | <?php |
654 | - $modal_update_href = add_query_arg( |
|
655 | - array( |
|
656 | - 'page' => 'custom-header', |
|
657 | - 'step' => 2, |
|
658 | - '_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ), |
|
659 | - ), |
|
660 | - admin_url( 'themes.php' ) |
|
661 | - ); |
|
662 | - ?> |
|
654 | + $modal_update_href = add_query_arg( |
|
655 | + array( |
|
656 | + 'page' => 'custom-header', |
|
657 | + 'step' => 2, |
|
658 | + '_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ), |
|
659 | + ), |
|
660 | + admin_url( 'themes.php' ) |
|
661 | + ); |
|
662 | + ?> |
|
663 | 663 | <p> |
664 | 664 | <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
665 | 665 | <button id="choose-from-library-link" class="button" |
@@ -684,14 +684,14 @@ discard block |
||
684 | 684 | <td> |
685 | 685 | <p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ); ?></p> |
686 | 686 | <?php |
687 | - $this->show_header_selector( 'uploaded' ); |
|
688 | - ?> |
|
687 | + $this->show_header_selector( 'uploaded' ); |
|
688 | + ?> |
|
689 | 689 | </td> |
690 | 690 | </tr> |
691 | 691 | <?php |
692 | - endif; |
|
693 | - if ( ! empty( $this->default_headers ) ) : |
|
694 | - ?> |
|
692 | + endif; |
|
693 | + if ( ! empty( $this->default_headers ) ) : |
|
694 | + ?> |
|
695 | 695 | <tr> |
696 | 696 | <th scope="row"><?php _e( 'Default Images' ); ?></th> |
697 | 697 | <td> |
@@ -701,14 +701,14 @@ discard block |
||
701 | 701 | <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ); ?></p> |
702 | 702 | <?php endif; ?> |
703 | 703 | <?php |
704 | - $this->show_header_selector( 'default' ); |
|
705 | - ?> |
|
704 | + $this->show_header_selector( 'default' ); |
|
705 | + ?> |
|
706 | 706 | </td> |
707 | 707 | </tr> |
708 | 708 | <?php |
709 | - endif; |
|
710 | - if ( get_header_image() ) : |
|
711 | - ?> |
|
709 | + endif; |
|
710 | + if ( get_header_image() ) : |
|
711 | + ?> |
|
712 | 712 | <tr> |
713 | 713 | <th scope="row"><?php _e( 'Remove Image' ); ?></th> |
714 | 714 | <td> |
@@ -717,16 +717,16 @@ discard block |
||
717 | 717 | </td> |
718 | 718 | </tr> |
719 | 719 | <?php |
720 | - endif; |
|
720 | + endif; |
|
721 | 721 | |
722 | - $default_image = sprintf( |
|
723 | - get_theme_support( 'custom-header', 'default-image' ), |
|
724 | - get_template_directory_uri(), |
|
725 | - get_stylesheet_directory_uri() |
|
726 | - ); |
|
722 | + $default_image = sprintf( |
|
723 | + get_theme_support( 'custom-header', 'default-image' ), |
|
724 | + get_template_directory_uri(), |
|
725 | + get_stylesheet_directory_uri() |
|
726 | + ); |
|
727 | 727 | |
728 | - if ( $default_image && get_header_image() !== $default_image ) : |
|
729 | - ?> |
|
728 | + if ( $default_image && get_header_image() !== $default_image ) : |
|
729 | + ?> |
|
730 | 730 | <tr> |
731 | 731 | <th scope="row"><?php _e( 'Reset Image' ); ?></th> |
732 | 732 | <td> |
@@ -758,27 +758,27 @@ discard block |
||
758 | 758 | <td> |
759 | 759 | <p> |
760 | 760 | <?php |
761 | - $default_color = ''; |
|
762 | - if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) { |
|
763 | - $default_color = get_theme_support( 'custom-header', 'default-text-color' ); |
|
764 | - if ( $default_color && false === strpos( $default_color, '#' ) ) { |
|
765 | - $default_color = '#' . $default_color; |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - $default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : ''; |
|
770 | - |
|
771 | - $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' ); |
|
772 | - if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) { |
|
773 | - $header_textcolor = '#' . $header_textcolor; |
|
774 | - } |
|
775 | - |
|
776 | - echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />'; |
|
777 | - if ( $default_color ) { |
|
778 | - /* translators: %s: Default text color. */ |
|
779 | - echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>'; |
|
780 | - } |
|
781 | - ?> |
|
761 | + $default_color = ''; |
|
762 | + if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) { |
|
763 | + $default_color = get_theme_support( 'custom-header', 'default-text-color' ); |
|
764 | + if ( $default_color && false === strpos( $default_color, '#' ) ) { |
|
765 | + $default_color = '#' . $default_color; |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + $default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : ''; |
|
770 | + |
|
771 | + $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' ); |
|
772 | + if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) { |
|
773 | + $header_textcolor = '#' . $header_textcolor; |
|
774 | + } |
|
775 | + |
|
776 | + echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />'; |
|
777 | + if ( $default_color ) { |
|
778 | + /* translators: %s: Default text color. */ |
|
779 | + echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>'; |
|
780 | + } |
|
781 | + ?> |
|
782 | 782 | </p> |
783 | 783 | </td> |
784 | 784 | </tr> |
@@ -787,126 +787,126 @@ discard block |
||
787 | 787 | <?php |
788 | 788 | endif; |
789 | 789 | |
790 | - /** |
|
791 | - * Fires just before the submit button in the custom header options form. |
|
792 | - * |
|
793 | - * @since 3.1.0 |
|
794 | - */ |
|
795 | - do_action( 'custom_header_options' ); |
|
790 | + /** |
|
791 | + * Fires just before the submit button in the custom header options form. |
|
792 | + * |
|
793 | + * @since 3.1.0 |
|
794 | + */ |
|
795 | + do_action( 'custom_header_options' ); |
|
796 | 796 | |
797 | - wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
798 | - ?> |
|
797 | + wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); |
|
798 | + ?> |
|
799 | 799 | |
800 | 800 | <?php submit_button( null, 'primary', 'save-header-options' ); ?> |
801 | 801 | </form> |
802 | 802 | </div> |
803 | 803 | |
804 | 804 | <?php |
805 | - } |
|
806 | - |
|
807 | - /** |
|
808 | - * Display second step of custom header image page. |
|
809 | - * |
|
810 | - * @since 2.1.0 |
|
811 | - */ |
|
812 | - public function step_2() { |
|
813 | - check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' ); |
|
814 | - |
|
815 | - if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
|
816 | - wp_die( |
|
817 | - '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
|
818 | - '<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>', |
|
819 | - 403 |
|
820 | - ); |
|
821 | - } |
|
822 | - |
|
823 | - if ( empty( $_POST ) && isset( $_GET['file'] ) ) { |
|
824 | - $attachment_id = absint( $_GET['file'] ); |
|
825 | - $file = get_attached_file( $attachment_id, true ); |
|
826 | - $url = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
827 | - $url = $url[0]; |
|
828 | - } elseif ( isset( $_POST ) ) { |
|
829 | - $data = $this->step_2_manage_upload(); |
|
830 | - $attachment_id = $data['attachment_id']; |
|
831 | - $file = $data['file']; |
|
832 | - $url = $data['url']; |
|
833 | - } |
|
834 | - |
|
835 | - if ( file_exists( $file ) ) { |
|
836 | - list( $width, $height, $type, $attr ) = wp_getimagesize( $file ); |
|
837 | - } else { |
|
838 | - $data = wp_get_attachment_metadata( $attachment_id ); |
|
839 | - $height = isset( $data['height'] ) ? (int) $data['height'] : 0; |
|
840 | - $width = isset( $data['width'] ) ? (int) $data['width'] : 0; |
|
841 | - unset( $data ); |
|
842 | - } |
|
843 | - |
|
844 | - $max_width = 0; |
|
845 | - |
|
846 | - // For flex, limit size of image displayed to 1500px unless theme says otherwise. |
|
847 | - if ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
848 | - $max_width = 1500; |
|
849 | - } |
|
850 | - |
|
851 | - if ( current_theme_supports( 'custom-header', 'max-width' ) ) { |
|
852 | - $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); |
|
853 | - } |
|
854 | - |
|
855 | - $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); |
|
856 | - |
|
857 | - // If flexible height isn't supported and the image is the exact right size. |
|
858 | - if ( ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
859 | - && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
860 | - && (int) get_theme_support( 'custom-header', 'width' ) === $width |
|
861 | - && (int) get_theme_support( 'custom-header', 'height' ) === $height |
|
862 | - ) { |
|
863 | - // Add the metadata. |
|
864 | - if ( file_exists( $file ) ) { |
|
865 | - wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
866 | - } |
|
867 | - |
|
868 | - $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
|
869 | - |
|
870 | - /** |
|
871 | - * Fires after the header image is set or an error is returned. |
|
872 | - * |
|
873 | - * @since 2.1.0 |
|
874 | - * |
|
875 | - * @param string $file Path to the file. |
|
876 | - * @param int $attachment_id Attachment ID. |
|
877 | - */ |
|
878 | - do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication. |
|
879 | - |
|
880 | - return $this->finished(); |
|
881 | - } elseif ( $width > $max_width ) { |
|
882 | - $oitar = $width / $max_width; |
|
883 | - |
|
884 | - $image = wp_crop_image( |
|
885 | - $attachment_id, |
|
886 | - 0, |
|
887 | - 0, |
|
888 | - $width, |
|
889 | - $height, |
|
890 | - $max_width, |
|
891 | - $height / $oitar, |
|
892 | - false, |
|
893 | - str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) |
|
894 | - ); |
|
895 | - |
|
896 | - if ( ! $image || is_wp_error( $image ) ) { |
|
897 | - wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
|
898 | - } |
|
899 | - |
|
900 | - /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
|
901 | - $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication. |
|
902 | - |
|
903 | - $url = str_replace( wp_basename( $url ), wp_basename( $image ), $url ); |
|
904 | - $width = $width / $oitar; |
|
905 | - $height = $height / $oitar; |
|
906 | - } else { |
|
907 | - $oitar = 1; |
|
908 | - } |
|
909 | - ?> |
|
805 | + } |
|
806 | + |
|
807 | + /** |
|
808 | + * Display second step of custom header image page. |
|
809 | + * |
|
810 | + * @since 2.1.0 |
|
811 | + */ |
|
812 | + public function step_2() { |
|
813 | + check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' ); |
|
814 | + |
|
815 | + if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
|
816 | + wp_die( |
|
817 | + '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
|
818 | + '<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>', |
|
819 | + 403 |
|
820 | + ); |
|
821 | + } |
|
822 | + |
|
823 | + if ( empty( $_POST ) && isset( $_GET['file'] ) ) { |
|
824 | + $attachment_id = absint( $_GET['file'] ); |
|
825 | + $file = get_attached_file( $attachment_id, true ); |
|
826 | + $url = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
827 | + $url = $url[0]; |
|
828 | + } elseif ( isset( $_POST ) ) { |
|
829 | + $data = $this->step_2_manage_upload(); |
|
830 | + $attachment_id = $data['attachment_id']; |
|
831 | + $file = $data['file']; |
|
832 | + $url = $data['url']; |
|
833 | + } |
|
834 | + |
|
835 | + if ( file_exists( $file ) ) { |
|
836 | + list( $width, $height, $type, $attr ) = wp_getimagesize( $file ); |
|
837 | + } else { |
|
838 | + $data = wp_get_attachment_metadata( $attachment_id ); |
|
839 | + $height = isset( $data['height'] ) ? (int) $data['height'] : 0; |
|
840 | + $width = isset( $data['width'] ) ? (int) $data['width'] : 0; |
|
841 | + unset( $data ); |
|
842 | + } |
|
843 | + |
|
844 | + $max_width = 0; |
|
845 | + |
|
846 | + // For flex, limit size of image displayed to 1500px unless theme says otherwise. |
|
847 | + if ( current_theme_supports( 'custom-header', 'flex-width' ) ) { |
|
848 | + $max_width = 1500; |
|
849 | + } |
|
850 | + |
|
851 | + if ( current_theme_supports( 'custom-header', 'max-width' ) ) { |
|
852 | + $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); |
|
853 | + } |
|
854 | + |
|
855 | + $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); |
|
856 | + |
|
857 | + // If flexible height isn't supported and the image is the exact right size. |
|
858 | + if ( ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
859 | + && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
860 | + && (int) get_theme_support( 'custom-header', 'width' ) === $width |
|
861 | + && (int) get_theme_support( 'custom-header', 'height' ) === $height |
|
862 | + ) { |
|
863 | + // Add the metadata. |
|
864 | + if ( file_exists( $file ) ) { |
|
865 | + wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); |
|
866 | + } |
|
867 | + |
|
868 | + $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
|
869 | + |
|
870 | + /** |
|
871 | + * Fires after the header image is set or an error is returned. |
|
872 | + * |
|
873 | + * @since 2.1.0 |
|
874 | + * |
|
875 | + * @param string $file Path to the file. |
|
876 | + * @param int $attachment_id Attachment ID. |
|
877 | + */ |
|
878 | + do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication. |
|
879 | + |
|
880 | + return $this->finished(); |
|
881 | + } elseif ( $width > $max_width ) { |
|
882 | + $oitar = $width / $max_width; |
|
883 | + |
|
884 | + $image = wp_crop_image( |
|
885 | + $attachment_id, |
|
886 | + 0, |
|
887 | + 0, |
|
888 | + $width, |
|
889 | + $height, |
|
890 | + $max_width, |
|
891 | + $height / $oitar, |
|
892 | + false, |
|
893 | + str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) |
|
894 | + ); |
|
895 | + |
|
896 | + if ( ! $image || is_wp_error( $image ) ) { |
|
897 | + wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
|
898 | + } |
|
899 | + |
|
900 | + /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
|
901 | + $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication. |
|
902 | + |
|
903 | + $url = str_replace( wp_basename( $url ), wp_basename( $image ), $url ); |
|
904 | + $width = $width / $oitar; |
|
905 | + $height = $height / $oitar; |
|
906 | + } else { |
|
907 | + $oitar = 1; |
|
908 | + } |
|
909 | + ?> |
|
910 | 910 | |
911 | 911 | <div class="wrap"> |
912 | 912 | <h1><?php _e( 'Crop Header Image' ); ?></h1> |
@@ -933,668 +933,668 @@ discard block |
||
933 | 933 | <p class="submit"> |
934 | 934 | <?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?> |
935 | 935 | <?php |
936 | - if ( isset( $oitar ) && 1 === $oitar |
|
937 | - && ( current_theme_supports( 'custom-header', 'flex-height' ) |
|
938 | - || current_theme_supports( 'custom-header', 'flex-width' ) ) |
|
939 | - ) { |
|
940 | - submit_button( __( 'Skip Cropping, Publish Image as Is' ), '', 'skip-cropping', false ); |
|
941 | - } |
|
942 | - ?> |
|
936 | + if ( isset( $oitar ) && 1 === $oitar |
|
937 | + && ( current_theme_supports( 'custom-header', 'flex-height' ) |
|
938 | + || current_theme_supports( 'custom-header', 'flex-width' ) ) |
|
939 | + ) { |
|
940 | + submit_button( __( 'Skip Cropping, Publish Image as Is' ), '', 'skip-cropping', false ); |
|
941 | + } |
|
942 | + ?> |
|
943 | 943 | </p> |
944 | 944 | </form> |
945 | 945 | </div> |
946 | 946 | <?php |
947 | - } |
|
948 | - |
|
949 | - |
|
950 | - /** |
|
951 | - * Upload the file to be cropped in the second step. |
|
952 | - * |
|
953 | - * @since 3.4.0 |
|
954 | - */ |
|
955 | - public function step_2_manage_upload() { |
|
956 | - $overrides = array( 'test_form' => false ); |
|
957 | - |
|
958 | - $uploaded_file = $_FILES['import']; |
|
959 | - $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] ); |
|
960 | - |
|
961 | - if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
|
962 | - wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) ); |
|
963 | - } |
|
964 | - |
|
965 | - $file = wp_handle_upload( $uploaded_file, $overrides ); |
|
966 | - |
|
967 | - if ( isset( $file['error'] ) ) { |
|
968 | - wp_die( $file['error'], __( 'Image Upload Error' ) ); |
|
969 | - } |
|
970 | - |
|
971 | - $url = $file['url']; |
|
972 | - $type = $file['type']; |
|
973 | - $file = $file['file']; |
|
974 | - $filename = wp_basename( $file ); |
|
975 | - |
|
976 | - // Construct the attachment array. |
|
977 | - $attachment = array( |
|
978 | - 'post_title' => $filename, |
|
979 | - 'post_content' => $url, |
|
980 | - 'post_mime_type' => $type, |
|
981 | - 'guid' => $url, |
|
982 | - 'context' => 'custom-header', |
|
983 | - ); |
|
984 | - |
|
985 | - // Save the data. |
|
986 | - $attachment_id = wp_insert_attachment( $attachment, $file ); |
|
987 | - |
|
988 | - return compact( 'attachment_id', 'file', 'filename', 'url', 'type' ); |
|
989 | - } |
|
990 | - |
|
991 | - /** |
|
992 | - * Display third step of custom header image page. |
|
993 | - * |
|
994 | - * @since 2.1.0 |
|
995 | - * @since 4.4.0 Switched to using wp_get_attachment_url() instead of the guid |
|
996 | - * for retrieving the header image URL. |
|
997 | - */ |
|
998 | - public function step_3() { |
|
999 | - check_admin_referer( 'custom-header-crop-image' ); |
|
1000 | - |
|
1001 | - if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
|
1002 | - wp_die( |
|
1003 | - '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
|
1004 | - '<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>', |
|
1005 | - 403 |
|
1006 | - ); |
|
1007 | - } |
|
1008 | - |
|
1009 | - if ( ! empty( $_POST['skip-cropping'] ) |
|
1010 | - && ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
1011 | - && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
1012 | - ) { |
|
1013 | - wp_die( |
|
1014 | - '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
|
1015 | - '<p>' . __( 'The active theme does not support a flexible sized header image.' ) . '</p>', |
|
1016 | - 403 |
|
1017 | - ); |
|
1018 | - } |
|
1019 | - |
|
1020 | - if ( $_POST['oitar'] > 1 ) { |
|
1021 | - $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; |
|
1022 | - $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; |
|
1023 | - $_POST['width'] = $_POST['width'] * $_POST['oitar']; |
|
1024 | - $_POST['height'] = $_POST['height'] * $_POST['oitar']; |
|
1025 | - } |
|
1026 | - |
|
1027 | - $attachment_id = absint( $_POST['attachment_id'] ); |
|
1028 | - $original = get_attached_file( $attachment_id ); |
|
1029 | - |
|
1030 | - $dimensions = $this->get_header_dimensions( |
|
1031 | - array( |
|
1032 | - 'height' => $_POST['height'], |
|
1033 | - 'width' => $_POST['width'], |
|
1034 | - ) |
|
1035 | - ); |
|
1036 | - $height = $dimensions['dst_height']; |
|
1037 | - $width = $dimensions['dst_width']; |
|
1038 | - |
|
1039 | - if ( empty( $_POST['skip-cropping'] ) ) { |
|
1040 | - $cropped = wp_crop_image( |
|
1041 | - $attachment_id, |
|
1042 | - (int) $_POST['x1'], |
|
1043 | - (int) $_POST['y1'], |
|
1044 | - (int) $_POST['width'], |
|
1045 | - (int) $_POST['height'], |
|
1046 | - $width, |
|
1047 | - $height |
|
1048 | - ); |
|
1049 | - } elseif ( ! empty( $_POST['create-new-attachment'] ) ) { |
|
1050 | - $cropped = _copy_image_file( $attachment_id ); |
|
1051 | - } else { |
|
1052 | - $cropped = get_attached_file( $attachment_id ); |
|
1053 | - } |
|
1054 | - |
|
1055 | - if ( ! $cropped || is_wp_error( $cropped ) ) { |
|
1056 | - wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
|
1057 | - } |
|
1058 | - |
|
1059 | - /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
|
1060 | - $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. |
|
1061 | - |
|
1062 | - $attachment = $this->create_attachment_object( $cropped, $attachment_id ); |
|
1063 | - |
|
1064 | - if ( ! empty( $_POST['create-new-attachment'] ) ) { |
|
1065 | - unset( $attachment['ID'] ); |
|
1066 | - } |
|
1067 | - |
|
1068 | - // Update the attachment. |
|
1069 | - $attachment_id = $this->insert_attachment( $attachment, $cropped ); |
|
1070 | - |
|
1071 | - $url = wp_get_attachment_url( $attachment_id ); |
|
1072 | - $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
|
1073 | - |
|
1074 | - // Cleanup. |
|
1075 | - $medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original ); |
|
1076 | - if ( file_exists( $medium ) ) { |
|
1077 | - wp_delete_file( $medium ); |
|
1078 | - } |
|
1079 | - |
|
1080 | - if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) { |
|
1081 | - wp_delete_file( $original ); |
|
1082 | - } |
|
1083 | - |
|
1084 | - return $this->finished(); |
|
1085 | - } |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * Display last step of custom header image page. |
|
1089 | - * |
|
1090 | - * @since 2.1.0 |
|
1091 | - */ |
|
1092 | - public function finished() { |
|
1093 | - $this->updated = true; |
|
1094 | - $this->step_1(); |
|
1095 | - } |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Display the page based on the current step. |
|
1099 | - * |
|
1100 | - * @since 2.1.0 |
|
1101 | - */ |
|
1102 | - public function admin_page() { |
|
1103 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1104 | - wp_die( __( 'Sorry, you are not allowed to customize headers.' ) ); |
|
1105 | - } |
|
1106 | - |
|
1107 | - $step = $this->step(); |
|
1108 | - |
|
1109 | - if ( 2 === $step ) { |
|
1110 | - $this->step_2(); |
|
1111 | - } elseif ( 3 === $step ) { |
|
1112 | - $this->step_3(); |
|
1113 | - } else { |
|
1114 | - $this->step_1(); |
|
1115 | - } |
|
1116 | - } |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * Unused since 3.5.0. |
|
1120 | - * |
|
1121 | - * @since 3.4.0 |
|
1122 | - * |
|
1123 | - * @param array $form_fields |
|
1124 | - * @return array $form_fields |
|
1125 | - */ |
|
1126 | - public function attachment_fields_to_edit( $form_fields ) { |
|
1127 | - return $form_fields; |
|
1128 | - } |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * Unused since 3.5.0. |
|
1132 | - * |
|
1133 | - * @since 3.4.0 |
|
1134 | - * |
|
1135 | - * @param array $tabs |
|
1136 | - * @return array $tabs |
|
1137 | - */ |
|
1138 | - public function filter_upload_tabs( $tabs ) { |
|
1139 | - return $tabs; |
|
1140 | - } |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * Choose a header image, selected from existing uploaded and default headers, |
|
1144 | - * or provide an array of uploaded header data (either new, or from media library). |
|
1145 | - * |
|
1146 | - * @since 3.4.0 |
|
1147 | - * |
|
1148 | - * @param mixed $choice Which header image to select. Allows for values of 'random-default-image', |
|
1149 | - * for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling |
|
1150 | - * among the uploaded images; the key of a default image registered for that theme; and |
|
1151 | - * the key of an image uploaded for that theme (the attachment ID of the image). |
|
1152 | - * Or an array of arguments: attachment_id, url, width, height. All are required. |
|
1153 | - */ |
|
1154 | - final public function set_header_image( $choice ) { |
|
1155 | - if ( is_array( $choice ) || is_object( $choice ) ) { |
|
1156 | - $choice = (array) $choice; |
|
1157 | - |
|
1158 | - if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) { |
|
1159 | - return; |
|
1160 | - } |
|
1161 | - |
|
1162 | - $choice['url'] = esc_url_raw( $choice['url'] ); |
|
1163 | - |
|
1164 | - $header_image_data = (object) array( |
|
1165 | - 'attachment_id' => $choice['attachment_id'], |
|
1166 | - 'url' => $choice['url'], |
|
1167 | - 'thumbnail_url' => $choice['url'], |
|
1168 | - 'height' => $choice['height'], |
|
1169 | - 'width' => $choice['width'], |
|
1170 | - ); |
|
1171 | - |
|
1172 | - update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); |
|
1173 | - |
|
1174 | - set_theme_mod( 'header_image', $choice['url'] ); |
|
1175 | - set_theme_mod( 'header_image_data', $header_image_data ); |
|
1176 | - |
|
1177 | - return; |
|
1178 | - } |
|
1179 | - |
|
1180 | - if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) { |
|
1181 | - set_theme_mod( 'header_image', $choice ); |
|
1182 | - remove_theme_mod( 'header_image_data' ); |
|
1183 | - |
|
1184 | - return; |
|
1185 | - } |
|
1186 | - |
|
1187 | - $uploaded = get_uploaded_header_images(); |
|
1188 | - |
|
1189 | - if ( $uploaded && isset( $uploaded[ $choice ] ) ) { |
|
1190 | - $header_image_data = $uploaded[ $choice ]; |
|
1191 | - } else { |
|
1192 | - $this->process_default_headers(); |
|
1193 | - if ( isset( $this->default_headers[ $choice ] ) ) { |
|
1194 | - $header_image_data = $this->default_headers[ $choice ]; |
|
1195 | - } else { |
|
1196 | - return; |
|
1197 | - } |
|
1198 | - } |
|
1199 | - |
|
1200 | - set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) ); |
|
1201 | - set_theme_mod( 'header_image_data', $header_image_data ); |
|
1202 | - } |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * Remove a header image. |
|
1206 | - * |
|
1207 | - * @since 3.4.0 |
|
1208 | - */ |
|
1209 | - final public function remove_header_image() { |
|
1210 | - $this->set_header_image( 'remove-header' ); |
|
1211 | - } |
|
1212 | - |
|
1213 | - /** |
|
1214 | - * Reset a header image to the default image for the theme. |
|
1215 | - * |
|
1216 | - * This method does not do anything if the theme does not have a default header image. |
|
1217 | - * |
|
1218 | - * @since 3.4.0 |
|
1219 | - */ |
|
1220 | - final public function reset_header_image() { |
|
1221 | - $this->process_default_headers(); |
|
1222 | - $default = get_theme_support( 'custom-header', 'default-image' ); |
|
1223 | - |
|
1224 | - if ( ! $default ) { |
|
1225 | - $this->remove_header_image(); |
|
1226 | - return; |
|
1227 | - } |
|
1228 | - |
|
1229 | - $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1230 | - |
|
1231 | - $default_data = array(); |
|
1232 | - foreach ( $this->default_headers as $header => $details ) { |
|
1233 | - if ( $details['url'] === $default ) { |
|
1234 | - $default_data = $details; |
|
1235 | - break; |
|
1236 | - } |
|
1237 | - } |
|
1238 | - |
|
1239 | - set_theme_mod( 'header_image', $default ); |
|
1240 | - set_theme_mod( 'header_image_data', (object) $default_data ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Calculate width and height based on what the currently selected theme supports. |
|
1245 | - * |
|
1246 | - * @since 3.9.0 |
|
1247 | - * |
|
1248 | - * @param array $dimensions |
|
1249 | - * @return array dst_height and dst_width of header image. |
|
1250 | - */ |
|
1251 | - final public function get_header_dimensions( $dimensions ) { |
|
1252 | - $max_width = 0; |
|
1253 | - $width = absint( $dimensions['width'] ); |
|
1254 | - $height = absint( $dimensions['height'] ); |
|
1255 | - $theme_height = get_theme_support( 'custom-header', 'height' ); |
|
1256 | - $theme_width = get_theme_support( 'custom-header', 'width' ); |
|
1257 | - $has_flex_width = current_theme_supports( 'custom-header', 'flex-width' ); |
|
1258 | - $has_flex_height = current_theme_supports( 'custom-header', 'flex-height' ); |
|
1259 | - $has_max_width = current_theme_supports( 'custom-header', 'max-width' ); |
|
1260 | - $dst = array( |
|
1261 | - 'dst_height' => null, |
|
1262 | - 'dst_width' => null, |
|
1263 | - ); |
|
1264 | - |
|
1265 | - // For flex, limit size of image displayed to 1500px unless theme says otherwise. |
|
1266 | - if ( $has_flex_width ) { |
|
1267 | - $max_width = 1500; |
|
1268 | - } |
|
1269 | - |
|
1270 | - if ( $has_max_width ) { |
|
1271 | - $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); |
|
1272 | - } |
|
1273 | - $max_width = max( $max_width, $theme_width ); |
|
1274 | - |
|
1275 | - if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) { |
|
1276 | - $dst['dst_height'] = absint( $height * ( $max_width / $width ) ); |
|
1277 | - } elseif ( $has_flex_height && $has_flex_width ) { |
|
1278 | - $dst['dst_height'] = $height; |
|
1279 | - } else { |
|
1280 | - $dst['dst_height'] = $theme_height; |
|
1281 | - } |
|
1282 | - |
|
1283 | - if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) { |
|
1284 | - $dst['dst_width'] = absint( $width * ( $max_width / $width ) ); |
|
1285 | - } elseif ( $has_flex_width && $has_flex_height ) { |
|
1286 | - $dst['dst_width'] = $width; |
|
1287 | - } else { |
|
1288 | - $dst['dst_width'] = $theme_width; |
|
1289 | - } |
|
1290 | - |
|
1291 | - return $dst; |
|
1292 | - } |
|
1293 | - |
|
1294 | - /** |
|
1295 | - * Create an attachment 'object'. |
|
1296 | - * |
|
1297 | - * @since 3.9.0 |
|
1298 | - * |
|
1299 | - * @param string $cropped Cropped image URL. |
|
1300 | - * @param int $parent_attachment_id Attachment ID of parent image. |
|
1301 | - * @return array An array with attachment object data. |
|
1302 | - */ |
|
1303 | - final public function create_attachment_object( $cropped, $parent_attachment_id ) { |
|
1304 | - $parent = get_post( $parent_attachment_id ); |
|
1305 | - $parent_url = wp_get_attachment_url( $parent->ID ); |
|
1306 | - $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); |
|
1307 | - |
|
1308 | - $size = wp_getimagesize( $cropped ); |
|
1309 | - $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; |
|
1310 | - |
|
1311 | - $attachment = array( |
|
1312 | - 'ID' => $parent_attachment_id, |
|
1313 | - 'post_title' => wp_basename( $cropped ), |
|
1314 | - 'post_mime_type' => $image_type, |
|
1315 | - 'guid' => $url, |
|
1316 | - 'context' => 'custom-header', |
|
1317 | - 'post_parent' => $parent_attachment_id, |
|
1318 | - ); |
|
1319 | - |
|
1320 | - return $attachment; |
|
1321 | - } |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * Insert an attachment and its metadata. |
|
1325 | - * |
|
1326 | - * @since 3.9.0 |
|
1327 | - * |
|
1328 | - * @param array $attachment An array with attachment object data. |
|
1329 | - * @param string $cropped File path to cropped image. |
|
1330 | - * @return int Attachment ID. |
|
1331 | - */ |
|
1332 | - final public function insert_attachment( $attachment, $cropped ) { |
|
1333 | - $parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null; |
|
1334 | - unset( $attachment['post_parent'] ); |
|
1335 | - |
|
1336 | - $attachment_id = wp_insert_attachment( $attachment, $cropped ); |
|
1337 | - $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); |
|
1338 | - |
|
1339 | - // If this is a crop, save the original attachment ID as metadata. |
|
1340 | - if ( $parent_id ) { |
|
1341 | - $metadata['attachment_parent'] = $parent_id; |
|
1342 | - } |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * Filters the header image attachment metadata. |
|
1346 | - * |
|
1347 | - * @since 3.9.0 |
|
1348 | - * |
|
1349 | - * @see wp_generate_attachment_metadata() |
|
1350 | - * |
|
1351 | - * @param array $metadata Attachment metadata. |
|
1352 | - */ |
|
1353 | - $metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata ); |
|
1354 | - |
|
1355 | - wp_update_attachment_metadata( $attachment_id, $metadata ); |
|
1356 | - |
|
1357 | - return $attachment_id; |
|
1358 | - } |
|
1359 | - |
|
1360 | - /** |
|
1361 | - * Gets attachment uploaded by Media Manager, crops it, then saves it as a |
|
1362 | - * new object. Returns JSON-encoded object details. |
|
1363 | - * |
|
1364 | - * @since 3.9.0 |
|
1365 | - */ |
|
1366 | - public function ajax_header_crop() { |
|
1367 | - check_ajax_referer( 'image_editor-' . $_POST['id'], 'nonce' ); |
|
1368 | - |
|
1369 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1370 | - wp_send_json_error(); |
|
1371 | - } |
|
1372 | - |
|
1373 | - if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
|
1374 | - wp_send_json_error(); |
|
1375 | - } |
|
1376 | - |
|
1377 | - $crop_details = $_POST['cropDetails']; |
|
1378 | - |
|
1379 | - $dimensions = $this->get_header_dimensions( |
|
1380 | - array( |
|
1381 | - 'height' => $crop_details['height'], |
|
1382 | - 'width' => $crop_details['width'], |
|
1383 | - ) |
|
1384 | - ); |
|
1385 | - |
|
1386 | - $attachment_id = absint( $_POST['id'] ); |
|
1387 | - |
|
1388 | - $cropped = wp_crop_image( |
|
1389 | - $attachment_id, |
|
1390 | - (int) $crop_details['x1'], |
|
1391 | - (int) $crop_details['y1'], |
|
1392 | - (int) $crop_details['width'], |
|
1393 | - (int) $crop_details['height'], |
|
1394 | - (int) $dimensions['dst_width'], |
|
1395 | - (int) $dimensions['dst_height'] |
|
1396 | - ); |
|
1397 | - |
|
1398 | - if ( ! $cropped || is_wp_error( $cropped ) ) { |
|
1399 | - wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) ); |
|
1400 | - } |
|
1401 | - |
|
1402 | - /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
|
1403 | - $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. |
|
1404 | - |
|
1405 | - $attachment = $this->create_attachment_object( $cropped, $attachment_id ); |
|
1406 | - |
|
1407 | - $previous = $this->get_previous_crop( $attachment ); |
|
1408 | - |
|
1409 | - if ( $previous ) { |
|
1410 | - $attachment['ID'] = $previous; |
|
1411 | - } else { |
|
1412 | - unset( $attachment['ID'] ); |
|
1413 | - } |
|
1414 | - |
|
1415 | - $new_attachment_id = $this->insert_attachment( $attachment, $cropped ); |
|
1416 | - |
|
1417 | - $attachment['attachment_id'] = $new_attachment_id; |
|
1418 | - $attachment['url'] = wp_get_attachment_url( $new_attachment_id ); |
|
1419 | - |
|
1420 | - $attachment['width'] = $dimensions['dst_width']; |
|
1421 | - $attachment['height'] = $dimensions['dst_height']; |
|
1422 | - |
|
1423 | - wp_send_json_success( $attachment ); |
|
1424 | - } |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * Given an attachment ID for a header image, updates its "last used" |
|
1428 | - * timestamp to now. |
|
1429 | - * |
|
1430 | - * Triggered when the user tries adds a new header image from the |
|
1431 | - * Media Manager, even if s/he doesn't save that change. |
|
1432 | - * |
|
1433 | - * @since 3.9.0 |
|
1434 | - */ |
|
1435 | - public function ajax_header_add() { |
|
1436 | - check_ajax_referer( 'header-add', 'nonce' ); |
|
1437 | - |
|
1438 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1439 | - wp_send_json_error(); |
|
1440 | - } |
|
1441 | - |
|
1442 | - $attachment_id = absint( $_POST['attachment_id'] ); |
|
1443 | - if ( $attachment_id < 1 ) { |
|
1444 | - wp_send_json_error(); |
|
1445 | - } |
|
1446 | - |
|
1447 | - $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1448 | - update_post_meta( $attachment_id, $key, time() ); |
|
1449 | - update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); |
|
1450 | - |
|
1451 | - wp_send_json_success(); |
|
1452 | - } |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * Given an attachment ID for a header image, unsets it as a user-uploaded |
|
1456 | - * header image for the active theme. |
|
1457 | - * |
|
1458 | - * Triggered when the user clicks the overlay "X" button next to each image |
|
1459 | - * choice in the Customizer's Header tool. |
|
1460 | - * |
|
1461 | - * @since 3.9.0 |
|
1462 | - */ |
|
1463 | - public function ajax_header_remove() { |
|
1464 | - check_ajax_referer( 'header-remove', 'nonce' ); |
|
1465 | - |
|
1466 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1467 | - wp_send_json_error(); |
|
1468 | - } |
|
1469 | - |
|
1470 | - $attachment_id = absint( $_POST['attachment_id'] ); |
|
1471 | - if ( $attachment_id < 1 ) { |
|
1472 | - wp_send_json_error(); |
|
1473 | - } |
|
1474 | - |
|
1475 | - $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1476 | - delete_post_meta( $attachment_id, $key ); |
|
1477 | - delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); |
|
1478 | - |
|
1479 | - wp_send_json_success(); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * Updates the last-used postmeta on a header image attachment after saving a new header image via the Customizer. |
|
1484 | - * |
|
1485 | - * @since 3.9.0 |
|
1486 | - * |
|
1487 | - * @param WP_Customize_Manager $wp_customize Customize manager. |
|
1488 | - */ |
|
1489 | - public function customize_set_last_used( $wp_customize ) { |
|
1490 | - |
|
1491 | - $header_image_data_setting = $wp_customize->get_setting( 'header_image_data' ); |
|
1492 | - |
|
1493 | - if ( ! $header_image_data_setting ) { |
|
1494 | - return; |
|
1495 | - } |
|
1496 | - |
|
1497 | - $data = $header_image_data_setting->post_value(); |
|
1498 | - |
|
1499 | - if ( ! isset( $data['attachment_id'] ) ) { |
|
1500 | - return; |
|
1501 | - } |
|
1502 | - |
|
1503 | - $attachment_id = $data['attachment_id']; |
|
1504 | - $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1505 | - update_post_meta( $attachment_id, $key, time() ); |
|
1506 | - } |
|
1507 | - |
|
1508 | - /** |
|
1509 | - * Gets the details of default header images if defined. |
|
1510 | - * |
|
1511 | - * @since 3.9.0 |
|
1512 | - * |
|
1513 | - * @return array Default header images. |
|
1514 | - */ |
|
1515 | - public function get_default_header_images() { |
|
1516 | - $this->process_default_headers(); |
|
1517 | - |
|
1518 | - // Get the default image if there is one. |
|
1519 | - $default = get_theme_support( 'custom-header', 'default-image' ); |
|
1520 | - |
|
1521 | - if ( ! $default ) { // If not, easy peasy. |
|
1522 | - return $this->default_headers; |
|
1523 | - } |
|
1524 | - |
|
1525 | - $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1526 | - |
|
1527 | - $already_has_default = false; |
|
1528 | - |
|
1529 | - foreach ( $this->default_headers as $k => $h ) { |
|
1530 | - if ( $h['url'] === $default ) { |
|
1531 | - $already_has_default = true; |
|
1532 | - break; |
|
1533 | - } |
|
1534 | - } |
|
1535 | - |
|
1536 | - if ( $already_has_default ) { |
|
1537 | - return $this->default_headers; |
|
1538 | - } |
|
1539 | - |
|
1540 | - // If the one true image isn't included in the default set, prepend it. |
|
1541 | - $header_images = array(); |
|
1542 | - $header_images['default'] = array( |
|
1543 | - 'url' => $default, |
|
1544 | - 'thumbnail_url' => $default, |
|
1545 | - 'description' => 'Default', |
|
1546 | - ); |
|
1547 | - |
|
1548 | - // The rest of the set comes after. |
|
1549 | - return array_merge( $header_images, $this->default_headers ); |
|
1550 | - } |
|
1551 | - |
|
1552 | - /** |
|
1553 | - * Gets the previously uploaded header images. |
|
1554 | - * |
|
1555 | - * @since 3.9.0 |
|
1556 | - * |
|
1557 | - * @return array Uploaded header images. |
|
1558 | - */ |
|
1559 | - public function get_uploaded_header_images() { |
|
1560 | - $header_images = get_uploaded_header_images(); |
|
1561 | - $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1562 | - $alt_text_key = '_wp_attachment_image_alt'; |
|
1563 | - |
|
1564 | - foreach ( $header_images as &$header_image ) { |
|
1565 | - $header_meta = get_post_meta( $header_image['attachment_id'] ); |
|
1566 | - $header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : ''; |
|
1567 | - $header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : ''; |
|
1568 | - } |
|
1569 | - |
|
1570 | - return $header_images; |
|
1571 | - } |
|
1572 | - |
|
1573 | - /** |
|
1574 | - * Get the ID of a previous crop from the same base image. |
|
1575 | - * |
|
1576 | - * @since 4.9.0 |
|
1577 | - * |
|
1578 | - * @param array $attachment An array with a cropped attachment object data. |
|
1579 | - * @return int|false An attachment ID if one exists. False if none. |
|
1580 | - */ |
|
1581 | - public function get_previous_crop( $attachment ) { |
|
1582 | - $header_images = $this->get_uploaded_header_images(); |
|
1583 | - |
|
1584 | - // Bail early if there are no header images. |
|
1585 | - if ( empty( $header_images ) ) { |
|
1586 | - return false; |
|
1587 | - } |
|
1588 | - |
|
1589 | - $previous = false; |
|
1590 | - |
|
1591 | - foreach ( $header_images as $image ) { |
|
1592 | - if ( $image['attachment_parent'] === $attachment['post_parent'] ) { |
|
1593 | - $previous = $image['attachment_id']; |
|
1594 | - break; |
|
1595 | - } |
|
1596 | - } |
|
1597 | - |
|
1598 | - return $previous; |
|
1599 | - } |
|
947 | + } |
|
948 | + |
|
949 | + |
|
950 | + /** |
|
951 | + * Upload the file to be cropped in the second step. |
|
952 | + * |
|
953 | + * @since 3.4.0 |
|
954 | + */ |
|
955 | + public function step_2_manage_upload() { |
|
956 | + $overrides = array( 'test_form' => false ); |
|
957 | + |
|
958 | + $uploaded_file = $_FILES['import']; |
|
959 | + $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] ); |
|
960 | + |
|
961 | + if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
|
962 | + wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) ); |
|
963 | + } |
|
964 | + |
|
965 | + $file = wp_handle_upload( $uploaded_file, $overrides ); |
|
966 | + |
|
967 | + if ( isset( $file['error'] ) ) { |
|
968 | + wp_die( $file['error'], __( 'Image Upload Error' ) ); |
|
969 | + } |
|
970 | + |
|
971 | + $url = $file['url']; |
|
972 | + $type = $file['type']; |
|
973 | + $file = $file['file']; |
|
974 | + $filename = wp_basename( $file ); |
|
975 | + |
|
976 | + // Construct the attachment array. |
|
977 | + $attachment = array( |
|
978 | + 'post_title' => $filename, |
|
979 | + 'post_content' => $url, |
|
980 | + 'post_mime_type' => $type, |
|
981 | + 'guid' => $url, |
|
982 | + 'context' => 'custom-header', |
|
983 | + ); |
|
984 | + |
|
985 | + // Save the data. |
|
986 | + $attachment_id = wp_insert_attachment( $attachment, $file ); |
|
987 | + |
|
988 | + return compact( 'attachment_id', 'file', 'filename', 'url', 'type' ); |
|
989 | + } |
|
990 | + |
|
991 | + /** |
|
992 | + * Display third step of custom header image page. |
|
993 | + * |
|
994 | + * @since 2.1.0 |
|
995 | + * @since 4.4.0 Switched to using wp_get_attachment_url() instead of the guid |
|
996 | + * for retrieving the header image URL. |
|
997 | + */ |
|
998 | + public function step_3() { |
|
999 | + check_admin_referer( 'custom-header-crop-image' ); |
|
1000 | + |
|
1001 | + if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
|
1002 | + wp_die( |
|
1003 | + '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
|
1004 | + '<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>', |
|
1005 | + 403 |
|
1006 | + ); |
|
1007 | + } |
|
1008 | + |
|
1009 | + if ( ! empty( $_POST['skip-cropping'] ) |
|
1010 | + && ! current_theme_supports( 'custom-header', 'flex-height' ) |
|
1011 | + && ! current_theme_supports( 'custom-header', 'flex-width' ) |
|
1012 | + ) { |
|
1013 | + wp_die( |
|
1014 | + '<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
|
1015 | + '<p>' . __( 'The active theme does not support a flexible sized header image.' ) . '</p>', |
|
1016 | + 403 |
|
1017 | + ); |
|
1018 | + } |
|
1019 | + |
|
1020 | + if ( $_POST['oitar'] > 1 ) { |
|
1021 | + $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; |
|
1022 | + $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; |
|
1023 | + $_POST['width'] = $_POST['width'] * $_POST['oitar']; |
|
1024 | + $_POST['height'] = $_POST['height'] * $_POST['oitar']; |
|
1025 | + } |
|
1026 | + |
|
1027 | + $attachment_id = absint( $_POST['attachment_id'] ); |
|
1028 | + $original = get_attached_file( $attachment_id ); |
|
1029 | + |
|
1030 | + $dimensions = $this->get_header_dimensions( |
|
1031 | + array( |
|
1032 | + 'height' => $_POST['height'], |
|
1033 | + 'width' => $_POST['width'], |
|
1034 | + ) |
|
1035 | + ); |
|
1036 | + $height = $dimensions['dst_height']; |
|
1037 | + $width = $dimensions['dst_width']; |
|
1038 | + |
|
1039 | + if ( empty( $_POST['skip-cropping'] ) ) { |
|
1040 | + $cropped = wp_crop_image( |
|
1041 | + $attachment_id, |
|
1042 | + (int) $_POST['x1'], |
|
1043 | + (int) $_POST['y1'], |
|
1044 | + (int) $_POST['width'], |
|
1045 | + (int) $_POST['height'], |
|
1046 | + $width, |
|
1047 | + $height |
|
1048 | + ); |
|
1049 | + } elseif ( ! empty( $_POST['create-new-attachment'] ) ) { |
|
1050 | + $cropped = _copy_image_file( $attachment_id ); |
|
1051 | + } else { |
|
1052 | + $cropped = get_attached_file( $attachment_id ); |
|
1053 | + } |
|
1054 | + |
|
1055 | + if ( ! $cropped || is_wp_error( $cropped ) ) { |
|
1056 | + wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); |
|
1057 | + } |
|
1058 | + |
|
1059 | + /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
|
1060 | + $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. |
|
1061 | + |
|
1062 | + $attachment = $this->create_attachment_object( $cropped, $attachment_id ); |
|
1063 | + |
|
1064 | + if ( ! empty( $_POST['create-new-attachment'] ) ) { |
|
1065 | + unset( $attachment['ID'] ); |
|
1066 | + } |
|
1067 | + |
|
1068 | + // Update the attachment. |
|
1069 | + $attachment_id = $this->insert_attachment( $attachment, $cropped ); |
|
1070 | + |
|
1071 | + $url = wp_get_attachment_url( $attachment_id ); |
|
1072 | + $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); |
|
1073 | + |
|
1074 | + // Cleanup. |
|
1075 | + $medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original ); |
|
1076 | + if ( file_exists( $medium ) ) { |
|
1077 | + wp_delete_file( $medium ); |
|
1078 | + } |
|
1079 | + |
|
1080 | + if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) { |
|
1081 | + wp_delete_file( $original ); |
|
1082 | + } |
|
1083 | + |
|
1084 | + return $this->finished(); |
|
1085 | + } |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * Display last step of custom header image page. |
|
1089 | + * |
|
1090 | + * @since 2.1.0 |
|
1091 | + */ |
|
1092 | + public function finished() { |
|
1093 | + $this->updated = true; |
|
1094 | + $this->step_1(); |
|
1095 | + } |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Display the page based on the current step. |
|
1099 | + * |
|
1100 | + * @since 2.1.0 |
|
1101 | + */ |
|
1102 | + public function admin_page() { |
|
1103 | + if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1104 | + wp_die( __( 'Sorry, you are not allowed to customize headers.' ) ); |
|
1105 | + } |
|
1106 | + |
|
1107 | + $step = $this->step(); |
|
1108 | + |
|
1109 | + if ( 2 === $step ) { |
|
1110 | + $this->step_2(); |
|
1111 | + } elseif ( 3 === $step ) { |
|
1112 | + $this->step_3(); |
|
1113 | + } else { |
|
1114 | + $this->step_1(); |
|
1115 | + } |
|
1116 | + } |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * Unused since 3.5.0. |
|
1120 | + * |
|
1121 | + * @since 3.4.0 |
|
1122 | + * |
|
1123 | + * @param array $form_fields |
|
1124 | + * @return array $form_fields |
|
1125 | + */ |
|
1126 | + public function attachment_fields_to_edit( $form_fields ) { |
|
1127 | + return $form_fields; |
|
1128 | + } |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * Unused since 3.5.0. |
|
1132 | + * |
|
1133 | + * @since 3.4.0 |
|
1134 | + * |
|
1135 | + * @param array $tabs |
|
1136 | + * @return array $tabs |
|
1137 | + */ |
|
1138 | + public function filter_upload_tabs( $tabs ) { |
|
1139 | + return $tabs; |
|
1140 | + } |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * Choose a header image, selected from existing uploaded and default headers, |
|
1144 | + * or provide an array of uploaded header data (either new, or from media library). |
|
1145 | + * |
|
1146 | + * @since 3.4.0 |
|
1147 | + * |
|
1148 | + * @param mixed $choice Which header image to select. Allows for values of 'random-default-image', |
|
1149 | + * for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling |
|
1150 | + * among the uploaded images; the key of a default image registered for that theme; and |
|
1151 | + * the key of an image uploaded for that theme (the attachment ID of the image). |
|
1152 | + * Or an array of arguments: attachment_id, url, width, height. All are required. |
|
1153 | + */ |
|
1154 | + final public function set_header_image( $choice ) { |
|
1155 | + if ( is_array( $choice ) || is_object( $choice ) ) { |
|
1156 | + $choice = (array) $choice; |
|
1157 | + |
|
1158 | + if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) { |
|
1159 | + return; |
|
1160 | + } |
|
1161 | + |
|
1162 | + $choice['url'] = esc_url_raw( $choice['url'] ); |
|
1163 | + |
|
1164 | + $header_image_data = (object) array( |
|
1165 | + 'attachment_id' => $choice['attachment_id'], |
|
1166 | + 'url' => $choice['url'], |
|
1167 | + 'thumbnail_url' => $choice['url'], |
|
1168 | + 'height' => $choice['height'], |
|
1169 | + 'width' => $choice['width'], |
|
1170 | + ); |
|
1171 | + |
|
1172 | + update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); |
|
1173 | + |
|
1174 | + set_theme_mod( 'header_image', $choice['url'] ); |
|
1175 | + set_theme_mod( 'header_image_data', $header_image_data ); |
|
1176 | + |
|
1177 | + return; |
|
1178 | + } |
|
1179 | + |
|
1180 | + if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) { |
|
1181 | + set_theme_mod( 'header_image', $choice ); |
|
1182 | + remove_theme_mod( 'header_image_data' ); |
|
1183 | + |
|
1184 | + return; |
|
1185 | + } |
|
1186 | + |
|
1187 | + $uploaded = get_uploaded_header_images(); |
|
1188 | + |
|
1189 | + if ( $uploaded && isset( $uploaded[ $choice ] ) ) { |
|
1190 | + $header_image_data = $uploaded[ $choice ]; |
|
1191 | + } else { |
|
1192 | + $this->process_default_headers(); |
|
1193 | + if ( isset( $this->default_headers[ $choice ] ) ) { |
|
1194 | + $header_image_data = $this->default_headers[ $choice ]; |
|
1195 | + } else { |
|
1196 | + return; |
|
1197 | + } |
|
1198 | + } |
|
1199 | + |
|
1200 | + set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) ); |
|
1201 | + set_theme_mod( 'header_image_data', $header_image_data ); |
|
1202 | + } |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * Remove a header image. |
|
1206 | + * |
|
1207 | + * @since 3.4.0 |
|
1208 | + */ |
|
1209 | + final public function remove_header_image() { |
|
1210 | + $this->set_header_image( 'remove-header' ); |
|
1211 | + } |
|
1212 | + |
|
1213 | + /** |
|
1214 | + * Reset a header image to the default image for the theme. |
|
1215 | + * |
|
1216 | + * This method does not do anything if the theme does not have a default header image. |
|
1217 | + * |
|
1218 | + * @since 3.4.0 |
|
1219 | + */ |
|
1220 | + final public function reset_header_image() { |
|
1221 | + $this->process_default_headers(); |
|
1222 | + $default = get_theme_support( 'custom-header', 'default-image' ); |
|
1223 | + |
|
1224 | + if ( ! $default ) { |
|
1225 | + $this->remove_header_image(); |
|
1226 | + return; |
|
1227 | + } |
|
1228 | + |
|
1229 | + $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1230 | + |
|
1231 | + $default_data = array(); |
|
1232 | + foreach ( $this->default_headers as $header => $details ) { |
|
1233 | + if ( $details['url'] === $default ) { |
|
1234 | + $default_data = $details; |
|
1235 | + break; |
|
1236 | + } |
|
1237 | + } |
|
1238 | + |
|
1239 | + set_theme_mod( 'header_image', $default ); |
|
1240 | + set_theme_mod( 'header_image_data', (object) $default_data ); |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * Calculate width and height based on what the currently selected theme supports. |
|
1245 | + * |
|
1246 | + * @since 3.9.0 |
|
1247 | + * |
|
1248 | + * @param array $dimensions |
|
1249 | + * @return array dst_height and dst_width of header image. |
|
1250 | + */ |
|
1251 | + final public function get_header_dimensions( $dimensions ) { |
|
1252 | + $max_width = 0; |
|
1253 | + $width = absint( $dimensions['width'] ); |
|
1254 | + $height = absint( $dimensions['height'] ); |
|
1255 | + $theme_height = get_theme_support( 'custom-header', 'height' ); |
|
1256 | + $theme_width = get_theme_support( 'custom-header', 'width' ); |
|
1257 | + $has_flex_width = current_theme_supports( 'custom-header', 'flex-width' ); |
|
1258 | + $has_flex_height = current_theme_supports( 'custom-header', 'flex-height' ); |
|
1259 | + $has_max_width = current_theme_supports( 'custom-header', 'max-width' ); |
|
1260 | + $dst = array( |
|
1261 | + 'dst_height' => null, |
|
1262 | + 'dst_width' => null, |
|
1263 | + ); |
|
1264 | + |
|
1265 | + // For flex, limit size of image displayed to 1500px unless theme says otherwise. |
|
1266 | + if ( $has_flex_width ) { |
|
1267 | + $max_width = 1500; |
|
1268 | + } |
|
1269 | + |
|
1270 | + if ( $has_max_width ) { |
|
1271 | + $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); |
|
1272 | + } |
|
1273 | + $max_width = max( $max_width, $theme_width ); |
|
1274 | + |
|
1275 | + if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) { |
|
1276 | + $dst['dst_height'] = absint( $height * ( $max_width / $width ) ); |
|
1277 | + } elseif ( $has_flex_height && $has_flex_width ) { |
|
1278 | + $dst['dst_height'] = $height; |
|
1279 | + } else { |
|
1280 | + $dst['dst_height'] = $theme_height; |
|
1281 | + } |
|
1282 | + |
|
1283 | + if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) { |
|
1284 | + $dst['dst_width'] = absint( $width * ( $max_width / $width ) ); |
|
1285 | + } elseif ( $has_flex_width && $has_flex_height ) { |
|
1286 | + $dst['dst_width'] = $width; |
|
1287 | + } else { |
|
1288 | + $dst['dst_width'] = $theme_width; |
|
1289 | + } |
|
1290 | + |
|
1291 | + return $dst; |
|
1292 | + } |
|
1293 | + |
|
1294 | + /** |
|
1295 | + * Create an attachment 'object'. |
|
1296 | + * |
|
1297 | + * @since 3.9.0 |
|
1298 | + * |
|
1299 | + * @param string $cropped Cropped image URL. |
|
1300 | + * @param int $parent_attachment_id Attachment ID of parent image. |
|
1301 | + * @return array An array with attachment object data. |
|
1302 | + */ |
|
1303 | + final public function create_attachment_object( $cropped, $parent_attachment_id ) { |
|
1304 | + $parent = get_post( $parent_attachment_id ); |
|
1305 | + $parent_url = wp_get_attachment_url( $parent->ID ); |
|
1306 | + $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); |
|
1307 | + |
|
1308 | + $size = wp_getimagesize( $cropped ); |
|
1309 | + $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; |
|
1310 | + |
|
1311 | + $attachment = array( |
|
1312 | + 'ID' => $parent_attachment_id, |
|
1313 | + 'post_title' => wp_basename( $cropped ), |
|
1314 | + 'post_mime_type' => $image_type, |
|
1315 | + 'guid' => $url, |
|
1316 | + 'context' => 'custom-header', |
|
1317 | + 'post_parent' => $parent_attachment_id, |
|
1318 | + ); |
|
1319 | + |
|
1320 | + return $attachment; |
|
1321 | + } |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * Insert an attachment and its metadata. |
|
1325 | + * |
|
1326 | + * @since 3.9.0 |
|
1327 | + * |
|
1328 | + * @param array $attachment An array with attachment object data. |
|
1329 | + * @param string $cropped File path to cropped image. |
|
1330 | + * @return int Attachment ID. |
|
1331 | + */ |
|
1332 | + final public function insert_attachment( $attachment, $cropped ) { |
|
1333 | + $parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null; |
|
1334 | + unset( $attachment['post_parent'] ); |
|
1335 | + |
|
1336 | + $attachment_id = wp_insert_attachment( $attachment, $cropped ); |
|
1337 | + $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); |
|
1338 | + |
|
1339 | + // If this is a crop, save the original attachment ID as metadata. |
|
1340 | + if ( $parent_id ) { |
|
1341 | + $metadata['attachment_parent'] = $parent_id; |
|
1342 | + } |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * Filters the header image attachment metadata. |
|
1346 | + * |
|
1347 | + * @since 3.9.0 |
|
1348 | + * |
|
1349 | + * @see wp_generate_attachment_metadata() |
|
1350 | + * |
|
1351 | + * @param array $metadata Attachment metadata. |
|
1352 | + */ |
|
1353 | + $metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata ); |
|
1354 | + |
|
1355 | + wp_update_attachment_metadata( $attachment_id, $metadata ); |
|
1356 | + |
|
1357 | + return $attachment_id; |
|
1358 | + } |
|
1359 | + |
|
1360 | + /** |
|
1361 | + * Gets attachment uploaded by Media Manager, crops it, then saves it as a |
|
1362 | + * new object. Returns JSON-encoded object details. |
|
1363 | + * |
|
1364 | + * @since 3.9.0 |
|
1365 | + */ |
|
1366 | + public function ajax_header_crop() { |
|
1367 | + check_ajax_referer( 'image_editor-' . $_POST['id'], 'nonce' ); |
|
1368 | + |
|
1369 | + if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1370 | + wp_send_json_error(); |
|
1371 | + } |
|
1372 | + |
|
1373 | + if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { |
|
1374 | + wp_send_json_error(); |
|
1375 | + } |
|
1376 | + |
|
1377 | + $crop_details = $_POST['cropDetails']; |
|
1378 | + |
|
1379 | + $dimensions = $this->get_header_dimensions( |
|
1380 | + array( |
|
1381 | + 'height' => $crop_details['height'], |
|
1382 | + 'width' => $crop_details['width'], |
|
1383 | + ) |
|
1384 | + ); |
|
1385 | + |
|
1386 | + $attachment_id = absint( $_POST['id'] ); |
|
1387 | + |
|
1388 | + $cropped = wp_crop_image( |
|
1389 | + $attachment_id, |
|
1390 | + (int) $crop_details['x1'], |
|
1391 | + (int) $crop_details['y1'], |
|
1392 | + (int) $crop_details['width'], |
|
1393 | + (int) $crop_details['height'], |
|
1394 | + (int) $dimensions['dst_width'], |
|
1395 | + (int) $dimensions['dst_height'] |
|
1396 | + ); |
|
1397 | + |
|
1398 | + if ( ! $cropped || is_wp_error( $cropped ) ) { |
|
1399 | + wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) ); |
|
1400 | + } |
|
1401 | + |
|
1402 | + /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ |
|
1403 | + $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. |
|
1404 | + |
|
1405 | + $attachment = $this->create_attachment_object( $cropped, $attachment_id ); |
|
1406 | + |
|
1407 | + $previous = $this->get_previous_crop( $attachment ); |
|
1408 | + |
|
1409 | + if ( $previous ) { |
|
1410 | + $attachment['ID'] = $previous; |
|
1411 | + } else { |
|
1412 | + unset( $attachment['ID'] ); |
|
1413 | + } |
|
1414 | + |
|
1415 | + $new_attachment_id = $this->insert_attachment( $attachment, $cropped ); |
|
1416 | + |
|
1417 | + $attachment['attachment_id'] = $new_attachment_id; |
|
1418 | + $attachment['url'] = wp_get_attachment_url( $new_attachment_id ); |
|
1419 | + |
|
1420 | + $attachment['width'] = $dimensions['dst_width']; |
|
1421 | + $attachment['height'] = $dimensions['dst_height']; |
|
1422 | + |
|
1423 | + wp_send_json_success( $attachment ); |
|
1424 | + } |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * Given an attachment ID for a header image, updates its "last used" |
|
1428 | + * timestamp to now. |
|
1429 | + * |
|
1430 | + * Triggered when the user tries adds a new header image from the |
|
1431 | + * Media Manager, even if s/he doesn't save that change. |
|
1432 | + * |
|
1433 | + * @since 3.9.0 |
|
1434 | + */ |
|
1435 | + public function ajax_header_add() { |
|
1436 | + check_ajax_referer( 'header-add', 'nonce' ); |
|
1437 | + |
|
1438 | + if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1439 | + wp_send_json_error(); |
|
1440 | + } |
|
1441 | + |
|
1442 | + $attachment_id = absint( $_POST['attachment_id'] ); |
|
1443 | + if ( $attachment_id < 1 ) { |
|
1444 | + wp_send_json_error(); |
|
1445 | + } |
|
1446 | + |
|
1447 | + $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1448 | + update_post_meta( $attachment_id, $key, time() ); |
|
1449 | + update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); |
|
1450 | + |
|
1451 | + wp_send_json_success(); |
|
1452 | + } |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * Given an attachment ID for a header image, unsets it as a user-uploaded |
|
1456 | + * header image for the active theme. |
|
1457 | + * |
|
1458 | + * Triggered when the user clicks the overlay "X" button next to each image |
|
1459 | + * choice in the Customizer's Header tool. |
|
1460 | + * |
|
1461 | + * @since 3.9.0 |
|
1462 | + */ |
|
1463 | + public function ajax_header_remove() { |
|
1464 | + check_ajax_referer( 'header-remove', 'nonce' ); |
|
1465 | + |
|
1466 | + if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
1467 | + wp_send_json_error(); |
|
1468 | + } |
|
1469 | + |
|
1470 | + $attachment_id = absint( $_POST['attachment_id'] ); |
|
1471 | + if ( $attachment_id < 1 ) { |
|
1472 | + wp_send_json_error(); |
|
1473 | + } |
|
1474 | + |
|
1475 | + $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1476 | + delete_post_meta( $attachment_id, $key ); |
|
1477 | + delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); |
|
1478 | + |
|
1479 | + wp_send_json_success(); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * Updates the last-used postmeta on a header image attachment after saving a new header image via the Customizer. |
|
1484 | + * |
|
1485 | + * @since 3.9.0 |
|
1486 | + * |
|
1487 | + * @param WP_Customize_Manager $wp_customize Customize manager. |
|
1488 | + */ |
|
1489 | + public function customize_set_last_used( $wp_customize ) { |
|
1490 | + |
|
1491 | + $header_image_data_setting = $wp_customize->get_setting( 'header_image_data' ); |
|
1492 | + |
|
1493 | + if ( ! $header_image_data_setting ) { |
|
1494 | + return; |
|
1495 | + } |
|
1496 | + |
|
1497 | + $data = $header_image_data_setting->post_value(); |
|
1498 | + |
|
1499 | + if ( ! isset( $data['attachment_id'] ) ) { |
|
1500 | + return; |
|
1501 | + } |
|
1502 | + |
|
1503 | + $attachment_id = $data['attachment_id']; |
|
1504 | + $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1505 | + update_post_meta( $attachment_id, $key, time() ); |
|
1506 | + } |
|
1507 | + |
|
1508 | + /** |
|
1509 | + * Gets the details of default header images if defined. |
|
1510 | + * |
|
1511 | + * @since 3.9.0 |
|
1512 | + * |
|
1513 | + * @return array Default header images. |
|
1514 | + */ |
|
1515 | + public function get_default_header_images() { |
|
1516 | + $this->process_default_headers(); |
|
1517 | + |
|
1518 | + // Get the default image if there is one. |
|
1519 | + $default = get_theme_support( 'custom-header', 'default-image' ); |
|
1520 | + |
|
1521 | + if ( ! $default ) { // If not, easy peasy. |
|
1522 | + return $this->default_headers; |
|
1523 | + } |
|
1524 | + |
|
1525 | + $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1526 | + |
|
1527 | + $already_has_default = false; |
|
1528 | + |
|
1529 | + foreach ( $this->default_headers as $k => $h ) { |
|
1530 | + if ( $h['url'] === $default ) { |
|
1531 | + $already_has_default = true; |
|
1532 | + break; |
|
1533 | + } |
|
1534 | + } |
|
1535 | + |
|
1536 | + if ( $already_has_default ) { |
|
1537 | + return $this->default_headers; |
|
1538 | + } |
|
1539 | + |
|
1540 | + // If the one true image isn't included in the default set, prepend it. |
|
1541 | + $header_images = array(); |
|
1542 | + $header_images['default'] = array( |
|
1543 | + 'url' => $default, |
|
1544 | + 'thumbnail_url' => $default, |
|
1545 | + 'description' => 'Default', |
|
1546 | + ); |
|
1547 | + |
|
1548 | + // The rest of the set comes after. |
|
1549 | + return array_merge( $header_images, $this->default_headers ); |
|
1550 | + } |
|
1551 | + |
|
1552 | + /** |
|
1553 | + * Gets the previously uploaded header images. |
|
1554 | + * |
|
1555 | + * @since 3.9.0 |
|
1556 | + * |
|
1557 | + * @return array Uploaded header images. |
|
1558 | + */ |
|
1559 | + public function get_uploaded_header_images() { |
|
1560 | + $header_images = get_uploaded_header_images(); |
|
1561 | + $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); |
|
1562 | + $alt_text_key = '_wp_attachment_image_alt'; |
|
1563 | + |
|
1564 | + foreach ( $header_images as &$header_image ) { |
|
1565 | + $header_meta = get_post_meta( $header_image['attachment_id'] ); |
|
1566 | + $header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : ''; |
|
1567 | + $header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : ''; |
|
1568 | + } |
|
1569 | + |
|
1570 | + return $header_images; |
|
1571 | + } |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * Get the ID of a previous crop from the same base image. |
|
1575 | + * |
|
1576 | + * @since 4.9.0 |
|
1577 | + * |
|
1578 | + * @param array $attachment An array with a cropped attachment object data. |
|
1579 | + * @return int|false An attachment ID if one exists. False if none. |
|
1580 | + */ |
|
1581 | + public function get_previous_crop( $attachment ) { |
|
1582 | + $header_images = $this->get_uploaded_header_images(); |
|
1583 | + |
|
1584 | + // Bail early if there are no header images. |
|
1585 | + if ( empty( $header_images ) ) { |
|
1586 | + return false; |
|
1587 | + } |
|
1588 | + |
|
1589 | + $previous = false; |
|
1590 | + |
|
1591 | + foreach ( $header_images as $image ) { |
|
1592 | + if ( $image['attachment_parent'] === $attachment['post_parent'] ) { |
|
1593 | + $previous = $image['attachment_id']; |
|
1594 | + break; |
|
1595 | + } |
|
1596 | + } |
|
1597 | + |
|
1598 | + return $previous; |
|
1599 | + } |
|
1600 | 1600 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | |
55 | 55 | // Prerendering. |
56 | 56 | if ( ! is_customize_preview() ) { |
57 | - add_filter( 'admin_print_styles', 'wp_resource_hints', 1 ); |
|
57 | + add_filter( 'admin_print_styles', 'wp_resource_hints', 1 ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | add_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
@@ -17,128 +17,128 @@ |
||
17 | 17 | */ |
18 | 18 | class Theme_Upgrader_Skin extends WP_Upgrader_Skin { |
19 | 19 | |
20 | - /** |
|
21 | - * Holds the theme slug in the Theme Directory. |
|
22 | - * |
|
23 | - * @since 2.8.0 |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $theme = ''; |
|
20 | + /** |
|
21 | + * Holds the theme slug in the Theme Directory. |
|
22 | + * |
|
23 | + * @since 2.8.0 |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $theme = ''; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - * |
|
32 | - * Sets up the theme upgrader skin. |
|
33 | - * |
|
34 | - * @since 2.8.0 |
|
35 | - * |
|
36 | - * @param array $args Optional. The theme upgrader skin arguments to |
|
37 | - * override default options. Default empty array. |
|
38 | - */ |
|
39 | - public function __construct( $args = array() ) { |
|
40 | - $defaults = array( |
|
41 | - 'url' => '', |
|
42 | - 'theme' => '', |
|
43 | - 'nonce' => '', |
|
44 | - 'title' => __( 'Update Theme' ), |
|
45 | - ); |
|
46 | - $args = wp_parse_args( $args, $defaults ); |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + * |
|
32 | + * Sets up the theme upgrader skin. |
|
33 | + * |
|
34 | + * @since 2.8.0 |
|
35 | + * |
|
36 | + * @param array $args Optional. The theme upgrader skin arguments to |
|
37 | + * override default options. Default empty array. |
|
38 | + */ |
|
39 | + public function __construct( $args = array() ) { |
|
40 | + $defaults = array( |
|
41 | + 'url' => '', |
|
42 | + 'theme' => '', |
|
43 | + 'nonce' => '', |
|
44 | + 'title' => __( 'Update Theme' ), |
|
45 | + ); |
|
46 | + $args = wp_parse_args( $args, $defaults ); |
|
47 | 47 | |
48 | - $this->theme = $args['theme']; |
|
48 | + $this->theme = $args['theme']; |
|
49 | 49 | |
50 | - parent::__construct( $args ); |
|
51 | - } |
|
50 | + parent::__construct( $args ); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Action to perform following a single theme update. |
|
55 | - * |
|
56 | - * @since 2.8.0 |
|
57 | - */ |
|
58 | - public function after() { |
|
59 | - $this->decrement_update_count( 'theme' ); |
|
53 | + /** |
|
54 | + * Action to perform following a single theme update. |
|
55 | + * |
|
56 | + * @since 2.8.0 |
|
57 | + */ |
|
58 | + public function after() { |
|
59 | + $this->decrement_update_count( 'theme' ); |
|
60 | 60 | |
61 | - $update_actions = array(); |
|
62 | - $theme_info = $this->upgrader->theme_info(); |
|
63 | - if ( $theme_info ) { |
|
64 | - $name = $theme_info->display( 'Name' ); |
|
65 | - $stylesheet = $this->upgrader->result['destination_name']; |
|
66 | - $template = $theme_info->get_template(); |
|
61 | + $update_actions = array(); |
|
62 | + $theme_info = $this->upgrader->theme_info(); |
|
63 | + if ( $theme_info ) { |
|
64 | + $name = $theme_info->display( 'Name' ); |
|
65 | + $stylesheet = $this->upgrader->result['destination_name']; |
|
66 | + $template = $theme_info->get_template(); |
|
67 | 67 | |
68 | - $activate_link = add_query_arg( |
|
69 | - array( |
|
70 | - 'action' => 'activate', |
|
71 | - 'template' => urlencode( $template ), |
|
72 | - 'stylesheet' => urlencode( $stylesheet ), |
|
73 | - ), |
|
74 | - admin_url( 'themes.php' ) |
|
75 | - ); |
|
76 | - $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
|
68 | + $activate_link = add_query_arg( |
|
69 | + array( |
|
70 | + 'action' => 'activate', |
|
71 | + 'template' => urlencode( $template ), |
|
72 | + 'stylesheet' => urlencode( $stylesheet ), |
|
73 | + ), |
|
74 | + admin_url( 'themes.php' ) |
|
75 | + ); |
|
76 | + $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
|
77 | 77 | |
78 | - $customize_url = add_query_arg( |
|
79 | - array( |
|
80 | - 'theme' => urlencode( $stylesheet ), |
|
81 | - 'return' => urlencode( admin_url( 'themes.php' ) ), |
|
82 | - ), |
|
83 | - admin_url( 'customize.php' ) |
|
84 | - ); |
|
78 | + $customize_url = add_query_arg( |
|
79 | + array( |
|
80 | + 'theme' => urlencode( $stylesheet ), |
|
81 | + 'return' => urlencode( admin_url( 'themes.php' ) ), |
|
82 | + ), |
|
83 | + admin_url( 'customize.php' ) |
|
84 | + ); |
|
85 | 85 | |
86 | - if ( get_stylesheet() === $stylesheet ) { |
|
87 | - if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
88 | - $update_actions['preview'] = sprintf( |
|
89 | - '<a href="%s" class="hide-if-no-customize load-customize">' . |
|
90 | - '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
|
91 | - esc_url( $customize_url ), |
|
92 | - __( 'Customize' ), |
|
93 | - /* translators: %s: Theme name. */ |
|
94 | - sprintf( __( 'Customize “%s”' ), $name ) |
|
95 | - ); |
|
96 | - } |
|
97 | - } elseif ( current_user_can( 'switch_themes' ) ) { |
|
98 | - if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
99 | - $update_actions['preview'] = sprintf( |
|
100 | - '<a href="%s" class="hide-if-no-customize load-customize">' . |
|
101 | - '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
|
102 | - esc_url( $customize_url ), |
|
103 | - __( 'Live Preview' ), |
|
104 | - /* translators: %s: Theme name. */ |
|
105 | - sprintf( __( 'Live Preview “%s”' ), $name ) |
|
106 | - ); |
|
107 | - } |
|
86 | + if ( get_stylesheet() === $stylesheet ) { |
|
87 | + if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
88 | + $update_actions['preview'] = sprintf( |
|
89 | + '<a href="%s" class="hide-if-no-customize load-customize">' . |
|
90 | + '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
|
91 | + esc_url( $customize_url ), |
|
92 | + __( 'Customize' ), |
|
93 | + /* translators: %s: Theme name. */ |
|
94 | + sprintf( __( 'Customize “%s”' ), $name ) |
|
95 | + ); |
|
96 | + } |
|
97 | + } elseif ( current_user_can( 'switch_themes' ) ) { |
|
98 | + if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
99 | + $update_actions['preview'] = sprintf( |
|
100 | + '<a href="%s" class="hide-if-no-customize load-customize">' . |
|
101 | + '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
|
102 | + esc_url( $customize_url ), |
|
103 | + __( 'Live Preview' ), |
|
104 | + /* translators: %s: Theme name. */ |
|
105 | + sprintf( __( 'Live Preview “%s”' ), $name ) |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | |
109 | - $update_actions['activate'] = sprintf( |
|
110 | - '<a href="%s" class="activatelink">' . |
|
111 | - '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
|
112 | - esc_url( $activate_link ), |
|
113 | - __( 'Activate' ), |
|
114 | - /* translators: %s: Theme name. */ |
|
115 | - sprintf( _x( 'Activate “%s”', 'theme' ), $name ) |
|
116 | - ); |
|
117 | - } |
|
109 | + $update_actions['activate'] = sprintf( |
|
110 | + '<a href="%s" class="activatelink">' . |
|
111 | + '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', |
|
112 | + esc_url( $activate_link ), |
|
113 | + __( 'Activate' ), |
|
114 | + /* translators: %s: Theme name. */ |
|
115 | + sprintf( _x( 'Activate “%s”', 'theme' ), $name ) |
|
116 | + ); |
|
117 | + } |
|
118 | 118 | |
119 | - if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) { |
|
120 | - unset( $update_actions['preview'], $update_actions['activate'] ); |
|
121 | - } |
|
122 | - } |
|
119 | + if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) { |
|
120 | + unset( $update_actions['preview'], $update_actions['activate'] ); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - $update_actions['themes_page'] = sprintf( |
|
125 | - '<a href="%s" target="_parent">%s</a>', |
|
126 | - self_admin_url( 'themes.php' ), |
|
127 | - __( 'Go to Themes page' ) |
|
128 | - ); |
|
124 | + $update_actions['themes_page'] = sprintf( |
|
125 | + '<a href="%s" target="_parent">%s</a>', |
|
126 | + self_admin_url( 'themes.php' ), |
|
127 | + __( 'Go to Themes page' ) |
|
128 | + ); |
|
129 | 129 | |
130 | - /** |
|
131 | - * Filters the list of action links available following a single theme update. |
|
132 | - * |
|
133 | - * @since 2.8.0 |
|
134 | - * |
|
135 | - * @param string[] $update_actions Array of theme action links. |
|
136 | - * @param string $theme Theme directory name. |
|
137 | - */ |
|
138 | - $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme ); |
|
130 | + /** |
|
131 | + * Filters the list of action links available following a single theme update. |
|
132 | + * |
|
133 | + * @since 2.8.0 |
|
134 | + * |
|
135 | + * @param string[] $update_actions Array of theme action links. |
|
136 | + * @param string $theme Theme directory name. |
|
137 | + */ |
|
138 | + $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme ); |
|
139 | 139 | |
140 | - if ( ! empty( $update_actions ) ) { |
|
141 | - $this->feedback( implode( ' | ', (array) $update_actions ) ); |
|
142 | - } |
|
143 | - } |
|
140 | + if ( ! empty( $update_actions ) ) { |
|
141 | + $this->feedback( implode( ' | ', (array) $update_actions ) ); |
|
142 | + } |
|
143 | + } |
|
144 | 144 | } |
@@ -100,138 +100,138 @@ discard block |
||
100 | 100 | * for more information on the make-up of possible return values depending on the value of `$action`. |
101 | 101 | */ |
102 | 102 | function plugins_api( $action, $args = array() ) { |
103 | - // Include an unmodified $wp_version. |
|
104 | - require ABSPATH . WPINC . '/version.php'; |
|
105 | - |
|
106 | - if ( is_array( $args ) ) { |
|
107 | - $args = (object) $args; |
|
108 | - } |
|
109 | - |
|
110 | - if ( 'query_plugins' === $action ) { |
|
111 | - if ( ! isset( $args->per_page ) ) { |
|
112 | - $args->per_page = 24; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - if ( ! isset( $args->locale ) ) { |
|
117 | - $args->locale = get_user_locale(); |
|
118 | - } |
|
119 | - |
|
120 | - if ( ! isset( $args->wp_version ) ) { |
|
121 | - $args->wp_version = substr( $wp_version, 0, 3 ); // x.y |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Filters the WordPress.org Plugin Installation API arguments. |
|
126 | - * |
|
127 | - * Important: An object MUST be returned to this filter. |
|
128 | - * |
|
129 | - * @since 2.7.0 |
|
130 | - * |
|
131 | - * @param object $args Plugin API arguments. |
|
132 | - * @param string $action The type of information being requested from the Plugin Installation API. |
|
133 | - */ |
|
134 | - $args = apply_filters( 'plugins_api_args', $args, $action ); |
|
135 | - |
|
136 | - /** |
|
137 | - * Filters the response for the current WordPress.org Plugin Installation API request. |
|
138 | - * |
|
139 | - * Returning a non-false value will effectively short-circuit the WordPress.org API request. |
|
140 | - * |
|
141 | - * If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed. |
|
142 | - * If `$action` is 'hot_tags' or 'hot_categories', an array should be passed. |
|
143 | - * |
|
144 | - * @since 2.7.0 |
|
145 | - * |
|
146 | - * @param false|object|array $result The result object or array. Default false. |
|
147 | - * @param string $action The type of information being requested from the Plugin Installation API. |
|
148 | - * @param object $args Plugin API arguments. |
|
149 | - */ |
|
150 | - $res = apply_filters( 'plugins_api', false, $action, $args ); |
|
151 | - |
|
152 | - if ( false === $res ) { |
|
153 | - |
|
154 | - $url = 'http://api.wordpress.org/plugins/info/1.2/'; |
|
155 | - $url = add_query_arg( |
|
156 | - array( |
|
157 | - 'action' => $action, |
|
158 | - 'request' => $args, |
|
159 | - ), |
|
160 | - $url |
|
161 | - ); |
|
162 | - |
|
163 | - $http_url = $url; |
|
164 | - $ssl = wp_http_supports( array( 'ssl' ) ); |
|
165 | - if ( $ssl ) { |
|
166 | - $url = set_url_scheme( $url, 'https' ); |
|
167 | - } |
|
168 | - |
|
169 | - $http_args = array( |
|
170 | - 'timeout' => 15, |
|
171 | - 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
|
172 | - ); |
|
173 | - $request = wp_remote_get( $url, $http_args ); |
|
174 | - |
|
175 | - if ( $ssl && is_wp_error( $request ) ) { |
|
176 | - if ( ! wp_is_json_request() ) { |
|
177 | - trigger_error( |
|
178 | - sprintf( |
|
179 | - /* translators: %s: Support forums URL. */ |
|
180 | - __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
181 | - __( 'https://wordpress.org/support/forums/' ) |
|
182 | - ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), |
|
183 | - headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - $request = wp_remote_get( $http_url, $http_args ); |
|
188 | - } |
|
189 | - |
|
190 | - if ( is_wp_error( $request ) ) { |
|
191 | - $res = new WP_Error( |
|
192 | - 'plugins_api_failed', |
|
193 | - sprintf( |
|
194 | - /* translators: %s: Support forums URL. */ |
|
195 | - __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
196 | - __( 'https://wordpress.org/support/forums/' ) |
|
197 | - ), |
|
198 | - $request->get_error_message() |
|
199 | - ); |
|
200 | - } else { |
|
201 | - $res = json_decode( wp_remote_retrieve_body( $request ), true ); |
|
202 | - if ( is_array( $res ) ) { |
|
203 | - // Object casting is required in order to match the info/1.0 format. |
|
204 | - $res = (object) $res; |
|
205 | - } elseif ( null === $res ) { |
|
206 | - $res = new WP_Error( |
|
207 | - 'plugins_api_failed', |
|
208 | - sprintf( |
|
209 | - /* translators: %s: Support forums URL. */ |
|
210 | - __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
211 | - __( 'https://wordpress.org/support/forums/' ) |
|
212 | - ), |
|
213 | - wp_remote_retrieve_body( $request ) |
|
214 | - ); |
|
215 | - } |
|
216 | - |
|
217 | - if ( isset( $res->error ) ) { |
|
218 | - $res = new WP_Error( 'plugins_api_failed', $res->error ); |
|
219 | - } |
|
220 | - } |
|
221 | - } elseif ( ! is_wp_error( $res ) ) { |
|
222 | - $res->external = true; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Filters the Plugin Installation API response results. |
|
227 | - * |
|
228 | - * @since 2.7.0 |
|
229 | - * |
|
230 | - * @param object|WP_Error $res Response object or WP_Error. |
|
231 | - * @param string $action The type of information being requested from the Plugin Installation API. |
|
232 | - * @param object $args Plugin API arguments. |
|
233 | - */ |
|
234 | - return apply_filters( 'plugins_api_result', $res, $action, $args ); |
|
103 | + // Include an unmodified $wp_version. |
|
104 | + require ABSPATH . WPINC . '/version.php'; |
|
105 | + |
|
106 | + if ( is_array( $args ) ) { |
|
107 | + $args = (object) $args; |
|
108 | + } |
|
109 | + |
|
110 | + if ( 'query_plugins' === $action ) { |
|
111 | + if ( ! isset( $args->per_page ) ) { |
|
112 | + $args->per_page = 24; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + if ( ! isset( $args->locale ) ) { |
|
117 | + $args->locale = get_user_locale(); |
|
118 | + } |
|
119 | + |
|
120 | + if ( ! isset( $args->wp_version ) ) { |
|
121 | + $args->wp_version = substr( $wp_version, 0, 3 ); // x.y |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Filters the WordPress.org Plugin Installation API arguments. |
|
126 | + * |
|
127 | + * Important: An object MUST be returned to this filter. |
|
128 | + * |
|
129 | + * @since 2.7.0 |
|
130 | + * |
|
131 | + * @param object $args Plugin API arguments. |
|
132 | + * @param string $action The type of information being requested from the Plugin Installation API. |
|
133 | + */ |
|
134 | + $args = apply_filters( 'plugins_api_args', $args, $action ); |
|
135 | + |
|
136 | + /** |
|
137 | + * Filters the response for the current WordPress.org Plugin Installation API request. |
|
138 | + * |
|
139 | + * Returning a non-false value will effectively short-circuit the WordPress.org API request. |
|
140 | + * |
|
141 | + * If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed. |
|
142 | + * If `$action` is 'hot_tags' or 'hot_categories', an array should be passed. |
|
143 | + * |
|
144 | + * @since 2.7.0 |
|
145 | + * |
|
146 | + * @param false|object|array $result The result object or array. Default false. |
|
147 | + * @param string $action The type of information being requested from the Plugin Installation API. |
|
148 | + * @param object $args Plugin API arguments. |
|
149 | + */ |
|
150 | + $res = apply_filters( 'plugins_api', false, $action, $args ); |
|
151 | + |
|
152 | + if ( false === $res ) { |
|
153 | + |
|
154 | + $url = 'http://api.wordpress.org/plugins/info/1.2/'; |
|
155 | + $url = add_query_arg( |
|
156 | + array( |
|
157 | + 'action' => $action, |
|
158 | + 'request' => $args, |
|
159 | + ), |
|
160 | + $url |
|
161 | + ); |
|
162 | + |
|
163 | + $http_url = $url; |
|
164 | + $ssl = wp_http_supports( array( 'ssl' ) ); |
|
165 | + if ( $ssl ) { |
|
166 | + $url = set_url_scheme( $url, 'https' ); |
|
167 | + } |
|
168 | + |
|
169 | + $http_args = array( |
|
170 | + 'timeout' => 15, |
|
171 | + 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
|
172 | + ); |
|
173 | + $request = wp_remote_get( $url, $http_args ); |
|
174 | + |
|
175 | + if ( $ssl && is_wp_error( $request ) ) { |
|
176 | + if ( ! wp_is_json_request() ) { |
|
177 | + trigger_error( |
|
178 | + sprintf( |
|
179 | + /* translators: %s: Support forums URL. */ |
|
180 | + __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
181 | + __( 'https://wordpress.org/support/forums/' ) |
|
182 | + ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), |
|
183 | + headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + $request = wp_remote_get( $http_url, $http_args ); |
|
188 | + } |
|
189 | + |
|
190 | + if ( is_wp_error( $request ) ) { |
|
191 | + $res = new WP_Error( |
|
192 | + 'plugins_api_failed', |
|
193 | + sprintf( |
|
194 | + /* translators: %s: Support forums URL. */ |
|
195 | + __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
196 | + __( 'https://wordpress.org/support/forums/' ) |
|
197 | + ), |
|
198 | + $request->get_error_message() |
|
199 | + ); |
|
200 | + } else { |
|
201 | + $res = json_decode( wp_remote_retrieve_body( $request ), true ); |
|
202 | + if ( is_array( $res ) ) { |
|
203 | + // Object casting is required in order to match the info/1.0 format. |
|
204 | + $res = (object) $res; |
|
205 | + } elseif ( null === $res ) { |
|
206 | + $res = new WP_Error( |
|
207 | + 'plugins_api_failed', |
|
208 | + sprintf( |
|
209 | + /* translators: %s: Support forums URL. */ |
|
210 | + __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
|
211 | + __( 'https://wordpress.org/support/forums/' ) |
|
212 | + ), |
|
213 | + wp_remote_retrieve_body( $request ) |
|
214 | + ); |
|
215 | + } |
|
216 | + |
|
217 | + if ( isset( $res->error ) ) { |
|
218 | + $res = new WP_Error( 'plugins_api_failed', $res->error ); |
|
219 | + } |
|
220 | + } |
|
221 | + } elseif ( ! is_wp_error( $res ) ) { |
|
222 | + $res->external = true; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Filters the Plugin Installation API response results. |
|
227 | + * |
|
228 | + * @since 2.7.0 |
|
229 | + * |
|
230 | + * @param object|WP_Error $res Response object or WP_Error. |
|
231 | + * @param string $action The type of information being requested from the Plugin Installation API. |
|
232 | + * @param object $args Plugin API arguments. |
|
233 | + */ |
|
234 | + return apply_filters( 'plugins_api_result', $res, $action, $args ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -243,21 +243,21 @@ discard block |
||
243 | 243 | * @return array|WP_Error |
244 | 244 | */ |
245 | 245 | function install_popular_tags( $args = array() ) { |
246 | - $key = md5( serialize( $args ) ); |
|
247 | - $tags = get_site_transient( 'poptags_' . $key ); |
|
248 | - if ( false !== $tags ) { |
|
249 | - return $tags; |
|
250 | - } |
|
246 | + $key = md5( serialize( $args ) ); |
|
247 | + $tags = get_site_transient( 'poptags_' . $key ); |
|
248 | + if ( false !== $tags ) { |
|
249 | + return $tags; |
|
250 | + } |
|
251 | 251 | |
252 | - $tags = plugins_api( 'hot_tags', $args ); |
|
252 | + $tags = plugins_api( 'hot_tags', $args ); |
|
253 | 253 | |
254 | - if ( is_wp_error( $tags ) ) { |
|
255 | - return $tags; |
|
256 | - } |
|
254 | + if ( is_wp_error( $tags ) ) { |
|
255 | + return $tags; |
|
256 | + } |
|
257 | 257 | |
258 | - set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS ); |
|
258 | + set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS ); |
|
259 | 259 | |
260 | - return $tags; |
|
260 | + return $tags; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -266,44 +266,44 @@ discard block |
||
266 | 266 | * @since 2.7.0 |
267 | 267 | */ |
268 | 268 | function install_dashboard() { |
269 | - display_plugins_table(); |
|
270 | - ?> |
|
269 | + display_plugins_table(); |
|
270 | + ?> |
|
271 | 271 | |
272 | 272 | <div class="plugins-popular-tags-wrapper"> |
273 | 273 | <h2><?php _e( 'Popular tags' ); ?></h2> |
274 | 274 | <p><?php _e( 'You may also browse based on the most popular tags in the Plugin Directory:' ); ?></p> |
275 | 275 | <?php |
276 | 276 | |
277 | - $api_tags = install_popular_tags(); |
|
278 | - |
|
279 | - echo '<p class="popular-tags">'; |
|
280 | - if ( is_wp_error( $api_tags ) ) { |
|
281 | - echo $api_tags->get_error_message(); |
|
282 | - } else { |
|
283 | - // Set up the tags in a way which can be interpreted by wp_generate_tag_cloud(). |
|
284 | - $tags = array(); |
|
285 | - foreach ( (array) $api_tags as $tag ) { |
|
286 | - $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) ); |
|
287 | - $data = array( |
|
288 | - 'link' => esc_url( $url ), |
|
289 | - 'name' => $tag['name'], |
|
290 | - 'slug' => $tag['slug'], |
|
291 | - 'id' => sanitize_title_with_dashes( $tag['name'] ), |
|
292 | - 'count' => $tag['count'], |
|
293 | - ); |
|
294 | - $tags[ $tag['name'] ] = (object) $data; |
|
295 | - } |
|
296 | - echo wp_generate_tag_cloud( |
|
297 | - $tags, |
|
298 | - array( |
|
299 | - /* translators: %s: Number of plugins. */ |
|
300 | - 'single_text' => __( '%s plugin' ), |
|
301 | - /* translators: %s: Number of plugins. */ |
|
302 | - 'multiple_text' => __( '%s plugins' ), |
|
303 | - ) |
|
304 | - ); |
|
305 | - } |
|
306 | - echo '</p><br class="clear" /></div>'; |
|
277 | + $api_tags = install_popular_tags(); |
|
278 | + |
|
279 | + echo '<p class="popular-tags">'; |
|
280 | + if ( is_wp_error( $api_tags ) ) { |
|
281 | + echo $api_tags->get_error_message(); |
|
282 | + } else { |
|
283 | + // Set up the tags in a way which can be interpreted by wp_generate_tag_cloud(). |
|
284 | + $tags = array(); |
|
285 | + foreach ( (array) $api_tags as $tag ) { |
|
286 | + $url = self_admin_url( 'plugin-install.php?tab=search&type=tag&s=' . urlencode( $tag['name'] ) ); |
|
287 | + $data = array( |
|
288 | + 'link' => esc_url( $url ), |
|
289 | + 'name' => $tag['name'], |
|
290 | + 'slug' => $tag['slug'], |
|
291 | + 'id' => sanitize_title_with_dashes( $tag['name'] ), |
|
292 | + 'count' => $tag['count'], |
|
293 | + ); |
|
294 | + $tags[ $tag['name'] ] = (object) $data; |
|
295 | + } |
|
296 | + echo wp_generate_tag_cloud( |
|
297 | + $tags, |
|
298 | + array( |
|
299 | + /* translators: %s: Number of plugins. */ |
|
300 | + 'single_text' => __( '%s plugin' ), |
|
301 | + /* translators: %s: Number of plugins. */ |
|
302 | + 'multiple_text' => __( '%s plugins' ), |
|
303 | + ) |
|
304 | + ); |
|
305 | + } |
|
306 | + echo '</p><br class="clear" /></div>'; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | * @param bool $deprecated Not used. |
316 | 316 | */ |
317 | 317 | function install_search_form( $deprecated = true ) { |
318 | - $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; |
|
319 | - $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; |
|
320 | - ?> |
|
318 | + $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; |
|
319 | + $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; |
|
320 | + ?> |
|
321 | 321 | <form class="search-form search-plugins" method="get"> |
322 | 322 | <input type="hidden" name="tab" value="search" /> |
323 | 323 | <label class="screen-reader-text" for="typeselector"><?php _e( 'Search plugins by:' ); ?></label> |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @since 2.8.0 |
340 | 340 | */ |
341 | 341 | function install_plugins_upload() { |
342 | - ?> |
|
342 | + ?> |
|
343 | 343 | <div class="upload-plugin"> |
344 | 344 | <p class="install-help"><?php _e( 'If you have a plugin in a .zip format, you may install or update it by uploading it here.' ); ?></p> |
345 | 345 | <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'update.php?action=upload-plugin' ); ?>"> |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | * @since 3.5.0 |
359 | 359 | */ |
360 | 360 | function install_plugins_favorites_form() { |
361 | - $user = get_user_option( 'wporg_favorites' ); |
|
362 | - $action = 'save_wporg_username_' . get_current_user_id(); |
|
363 | - ?> |
|
361 | + $user = get_user_option( 'wporg_favorites' ); |
|
362 | + $action = 'save_wporg_username_' . get_current_user_id(); |
|
363 | + ?> |
|
364 | 364 | <p><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p> |
365 | 365 | <form method="get"> |
366 | 366 | <input type="hidden" name="tab" value="favorites" /> |
@@ -382,33 +382,33 @@ discard block |
||
382 | 382 | * @global WP_List_Table $wp_list_table |
383 | 383 | */ |
384 | 384 | function display_plugins_table() { |
385 | - global $wp_list_table; |
|
386 | - |
|
387 | - switch ( current_filter() ) { |
|
388 | - case 'install_plugins_beta': |
|
389 | - printf( |
|
390 | - /* translators: %s: URL to "Features as Plugins" page. */ |
|
391 | - '<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>', |
|
392 | - 'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/' |
|
393 | - ); |
|
394 | - break; |
|
395 | - case 'install_plugins_featured': |
|
396 | - printf( |
|
397 | - /* translators: %s: https://wordpress.org/plugins/ */ |
|
398 | - '<p>' . __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ) . '</p>', |
|
399 | - __( 'https://wordpress.org/plugins/' ) |
|
400 | - ); |
|
401 | - break; |
|
402 | - case 'install_plugins_recommended': |
|
403 | - echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>'; |
|
404 | - break; |
|
405 | - case 'install_plugins_favorites': |
|
406 | - if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) { |
|
407 | - return; |
|
408 | - } |
|
409 | - break; |
|
410 | - } |
|
411 | - ?> |
|
385 | + global $wp_list_table; |
|
386 | + |
|
387 | + switch ( current_filter() ) { |
|
388 | + case 'install_plugins_beta': |
|
389 | + printf( |
|
390 | + /* translators: %s: URL to "Features as Plugins" page. */ |
|
391 | + '<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>', |
|
392 | + 'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/' |
|
393 | + ); |
|
394 | + break; |
|
395 | + case 'install_plugins_featured': |
|
396 | + printf( |
|
397 | + /* translators: %s: https://wordpress.org/plugins/ */ |
|
398 | + '<p>' . __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%s">WordPress Plugin Directory</a> or upload a plugin in .zip format by clicking the button at the top of this page.' ) . '</p>', |
|
399 | + __( 'https://wordpress.org/plugins/' ) |
|
400 | + ); |
|
401 | + break; |
|
402 | + case 'install_plugins_recommended': |
|
403 | + echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>'; |
|
404 | + break; |
|
405 | + case 'install_plugins_favorites': |
|
406 | + if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) { |
|
407 | + return; |
|
408 | + } |
|
409 | + break; |
|
410 | + } |
|
411 | + ?> |
|
412 | 412 | <form id="plugin-filter" method="post"> |
413 | 413 | <?php $wp_list_table->display(); ?> |
414 | 414 | </form> |
@@ -432,77 +432,77 @@ discard block |
||
432 | 432 | * } |
433 | 433 | */ |
434 | 434 | function install_plugin_install_status( $api, $loop = false ) { |
435 | - // This function is called recursively, $loop prevents further loops. |
|
436 | - if ( is_array( $api ) ) { |
|
437 | - $api = (object) $api; |
|
438 | - } |
|
439 | - |
|
440 | - // Default to a "new" plugin. |
|
441 | - $status = 'install'; |
|
442 | - $url = false; |
|
443 | - $update_file = false; |
|
444 | - $version = ''; |
|
445 | - |
|
446 | - /* |
|
435 | + // This function is called recursively, $loop prevents further loops. |
|
436 | + if ( is_array( $api ) ) { |
|
437 | + $api = (object) $api; |
|
438 | + } |
|
439 | + |
|
440 | + // Default to a "new" plugin. |
|
441 | + $status = 'install'; |
|
442 | + $url = false; |
|
443 | + $update_file = false; |
|
444 | + $version = ''; |
|
445 | + |
|
446 | + /* |
|
447 | 447 | * Check to see if this plugin is known to be installed, |
448 | 448 | * and has an update awaiting it. |
449 | 449 | */ |
450 | - $update_plugins = get_site_transient( 'update_plugins' ); |
|
451 | - if ( isset( $update_plugins->response ) ) { |
|
452 | - foreach ( (array) $update_plugins->response as $file => $plugin ) { |
|
453 | - if ( $plugin->slug === $api->slug ) { |
|
454 | - $status = 'update_available'; |
|
455 | - $update_file = $file; |
|
456 | - $version = $plugin->new_version; |
|
457 | - if ( current_user_can( 'update_plugins' ) ) { |
|
458 | - $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); |
|
459 | - } |
|
460 | - break; |
|
461 | - } |
|
462 | - } |
|
463 | - } |
|
464 | - |
|
465 | - if ( 'install' === $status ) { |
|
466 | - if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { |
|
467 | - $installed_plugin = get_plugins( '/' . $api->slug ); |
|
468 | - if ( empty( $installed_plugin ) ) { |
|
469 | - if ( current_user_can( 'install_plugins' ) ) { |
|
470 | - $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); |
|
471 | - } |
|
472 | - } else { |
|
473 | - $key = array_keys( $installed_plugin ); |
|
474 | - // Use the first plugin regardless of the name. |
|
475 | - // Could have issues for multiple plugins in one directory if they share different version numbers. |
|
476 | - $key = reset( $key ); |
|
477 | - |
|
478 | - $update_file = $api->slug . '/' . $key; |
|
479 | - if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { |
|
480 | - $status = 'latest_installed'; |
|
481 | - } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { |
|
482 | - $status = 'newer_installed'; |
|
483 | - $version = $installed_plugin[ $key ]['Version']; |
|
484 | - } else { |
|
485 | - // If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh. |
|
486 | - if ( ! $loop ) { |
|
487 | - delete_site_transient( 'update_plugins' ); |
|
488 | - wp_update_plugins(); |
|
489 | - return install_plugin_install_status( $api, true ); |
|
490 | - } |
|
491 | - } |
|
492 | - } |
|
493 | - } else { |
|
494 | - // "install" & no directory with that slug. |
|
495 | - if ( current_user_can( 'install_plugins' ) ) { |
|
496 | - $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - if ( isset( $_GET['from'] ) ) { |
|
501 | - $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); |
|
502 | - } |
|
503 | - |
|
504 | - $file = $update_file; |
|
505 | - return compact( 'status', 'url', 'version', 'file' ); |
|
450 | + $update_plugins = get_site_transient( 'update_plugins' ); |
|
451 | + if ( isset( $update_plugins->response ) ) { |
|
452 | + foreach ( (array) $update_plugins->response as $file => $plugin ) { |
|
453 | + if ( $plugin->slug === $api->slug ) { |
|
454 | + $status = 'update_available'; |
|
455 | + $update_file = $file; |
|
456 | + $version = $plugin->new_version; |
|
457 | + if ( current_user_can( 'update_plugins' ) ) { |
|
458 | + $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); |
|
459 | + } |
|
460 | + break; |
|
461 | + } |
|
462 | + } |
|
463 | + } |
|
464 | + |
|
465 | + if ( 'install' === $status ) { |
|
466 | + if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { |
|
467 | + $installed_plugin = get_plugins( '/' . $api->slug ); |
|
468 | + if ( empty( $installed_plugin ) ) { |
|
469 | + if ( current_user_can( 'install_plugins' ) ) { |
|
470 | + $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); |
|
471 | + } |
|
472 | + } else { |
|
473 | + $key = array_keys( $installed_plugin ); |
|
474 | + // Use the first plugin regardless of the name. |
|
475 | + // Could have issues for multiple plugins in one directory if they share different version numbers. |
|
476 | + $key = reset( $key ); |
|
477 | + |
|
478 | + $update_file = $api->slug . '/' . $key; |
|
479 | + if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { |
|
480 | + $status = 'latest_installed'; |
|
481 | + } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { |
|
482 | + $status = 'newer_installed'; |
|
483 | + $version = $installed_plugin[ $key ]['Version']; |
|
484 | + } else { |
|
485 | + // If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh. |
|
486 | + if ( ! $loop ) { |
|
487 | + delete_site_transient( 'update_plugins' ); |
|
488 | + wp_update_plugins(); |
|
489 | + return install_plugin_install_status( $api, true ); |
|
490 | + } |
|
491 | + } |
|
492 | + } |
|
493 | + } else { |
|
494 | + // "install" & no directory with that slug. |
|
495 | + if ( current_user_can( 'install_plugins' ) ) { |
|
496 | + $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + if ( isset( $_GET['from'] ) ) { |
|
501 | + $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); |
|
502 | + } |
|
503 | + |
|
504 | + $file = $update_file; |
|
505 | + return compact( 'status', 'url', 'version', 'file' ); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -513,95 +513,95 @@ discard block |
||
513 | 513 | * @global string $tab |
514 | 514 | */ |
515 | 515 | function install_plugin_information() { |
516 | - global $tab; |
|
517 | - |
|
518 | - if ( empty( $_REQUEST['plugin'] ) ) { |
|
519 | - return; |
|
520 | - } |
|
521 | - |
|
522 | - $api = plugins_api( |
|
523 | - 'plugin_information', |
|
524 | - array( |
|
525 | - 'slug' => wp_unslash( $_REQUEST['plugin'] ), |
|
526 | - ) |
|
527 | - ); |
|
528 | - |
|
529 | - if ( is_wp_error( $api ) ) { |
|
530 | - wp_die( $api ); |
|
531 | - } |
|
532 | - |
|
533 | - $plugins_allowedtags = array( |
|
534 | - 'a' => array( |
|
535 | - 'href' => array(), |
|
536 | - 'title' => array(), |
|
537 | - 'target' => array(), |
|
538 | - ), |
|
539 | - 'abbr' => array( 'title' => array() ), |
|
540 | - 'acronym' => array( 'title' => array() ), |
|
541 | - 'code' => array(), |
|
542 | - 'pre' => array(), |
|
543 | - 'em' => array(), |
|
544 | - 'strong' => array(), |
|
545 | - 'div' => array( 'class' => array() ), |
|
546 | - 'span' => array( 'class' => array() ), |
|
547 | - 'p' => array(), |
|
548 | - 'br' => array(), |
|
549 | - 'ul' => array(), |
|
550 | - 'ol' => array(), |
|
551 | - 'li' => array(), |
|
552 | - 'h1' => array(), |
|
553 | - 'h2' => array(), |
|
554 | - 'h3' => array(), |
|
555 | - 'h4' => array(), |
|
556 | - 'h5' => array(), |
|
557 | - 'h6' => array(), |
|
558 | - 'img' => array( |
|
559 | - 'src' => array(), |
|
560 | - 'class' => array(), |
|
561 | - 'alt' => array(), |
|
562 | - ), |
|
563 | - 'blockquote' => array( 'cite' => true ), |
|
564 | - ); |
|
565 | - |
|
566 | - $plugins_section_titles = array( |
|
567 | - 'description' => _x( 'Description', 'Plugin installer section title' ), |
|
568 | - 'installation' => _x( 'Installation', 'Plugin installer section title' ), |
|
569 | - 'faq' => _x( 'FAQ', 'Plugin installer section title' ), |
|
570 | - 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), |
|
571 | - 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), |
|
572 | - 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), |
|
573 | - 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), |
|
574 | - ); |
|
575 | - |
|
576 | - // Sanitize HTML. |
|
577 | - foreach ( (array) $api->sections as $section_name => $content ) { |
|
578 | - $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); |
|
579 | - } |
|
580 | - |
|
581 | - foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { |
|
582 | - if ( isset( $api->$key ) ) { |
|
583 | - $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); |
|
584 | - } |
|
585 | - } |
|
586 | - |
|
587 | - $_tab = esc_attr( $tab ); |
|
588 | - |
|
589 | - // Default to the Description tab, Do not translate, API returns English. |
|
590 | - $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; |
|
591 | - if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { |
|
592 | - $section_titles = array_keys( (array) $api->sections ); |
|
593 | - $section = reset( $section_titles ); |
|
594 | - } |
|
595 | - |
|
596 | - iframe_header( __( 'Plugin Installation' ) ); |
|
597 | - |
|
598 | - $_with_banner = ''; |
|
599 | - |
|
600 | - if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { |
|
601 | - $_with_banner = 'with-banner'; |
|
602 | - $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; |
|
603 | - $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; |
|
604 | - ?> |
|
516 | + global $tab; |
|
517 | + |
|
518 | + if ( empty( $_REQUEST['plugin'] ) ) { |
|
519 | + return; |
|
520 | + } |
|
521 | + |
|
522 | + $api = plugins_api( |
|
523 | + 'plugin_information', |
|
524 | + array( |
|
525 | + 'slug' => wp_unslash( $_REQUEST['plugin'] ), |
|
526 | + ) |
|
527 | + ); |
|
528 | + |
|
529 | + if ( is_wp_error( $api ) ) { |
|
530 | + wp_die( $api ); |
|
531 | + } |
|
532 | + |
|
533 | + $plugins_allowedtags = array( |
|
534 | + 'a' => array( |
|
535 | + 'href' => array(), |
|
536 | + 'title' => array(), |
|
537 | + 'target' => array(), |
|
538 | + ), |
|
539 | + 'abbr' => array( 'title' => array() ), |
|
540 | + 'acronym' => array( 'title' => array() ), |
|
541 | + 'code' => array(), |
|
542 | + 'pre' => array(), |
|
543 | + 'em' => array(), |
|
544 | + 'strong' => array(), |
|
545 | + 'div' => array( 'class' => array() ), |
|
546 | + 'span' => array( 'class' => array() ), |
|
547 | + 'p' => array(), |
|
548 | + 'br' => array(), |
|
549 | + 'ul' => array(), |
|
550 | + 'ol' => array(), |
|
551 | + 'li' => array(), |
|
552 | + 'h1' => array(), |
|
553 | + 'h2' => array(), |
|
554 | + 'h3' => array(), |
|
555 | + 'h4' => array(), |
|
556 | + 'h5' => array(), |
|
557 | + 'h6' => array(), |
|
558 | + 'img' => array( |
|
559 | + 'src' => array(), |
|
560 | + 'class' => array(), |
|
561 | + 'alt' => array(), |
|
562 | + ), |
|
563 | + 'blockquote' => array( 'cite' => true ), |
|
564 | + ); |
|
565 | + |
|
566 | + $plugins_section_titles = array( |
|
567 | + 'description' => _x( 'Description', 'Plugin installer section title' ), |
|
568 | + 'installation' => _x( 'Installation', 'Plugin installer section title' ), |
|
569 | + 'faq' => _x( 'FAQ', 'Plugin installer section title' ), |
|
570 | + 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), |
|
571 | + 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), |
|
572 | + 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), |
|
573 | + 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), |
|
574 | + ); |
|
575 | + |
|
576 | + // Sanitize HTML. |
|
577 | + foreach ( (array) $api->sections as $section_name => $content ) { |
|
578 | + $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); |
|
579 | + } |
|
580 | + |
|
581 | + foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { |
|
582 | + if ( isset( $api->$key ) ) { |
|
583 | + $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); |
|
584 | + } |
|
585 | + } |
|
586 | + |
|
587 | + $_tab = esc_attr( $tab ); |
|
588 | + |
|
589 | + // Default to the Description tab, Do not translate, API returns English. |
|
590 | + $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; |
|
591 | + if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { |
|
592 | + $section_titles = array_keys( (array) $api->sections ); |
|
593 | + $section = reset( $section_titles ); |
|
594 | + } |
|
595 | + |
|
596 | + iframe_header( __( 'Plugin Installation' ) ); |
|
597 | + |
|
598 | + $_with_banner = ''; |
|
599 | + |
|
600 | + if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { |
|
601 | + $_with_banner = 'with-banner'; |
|
602 | + $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; |
|
603 | + $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; |
|
604 | + ?> |
|
605 | 605 | <style type="text/css"> |
606 | 606 | #plugin-information-title.with-banner { |
607 | 607 | background-image: url( <?php echo esc_url( $low ); ?> ); |
@@ -613,38 +613,38 @@ discard block |
||
613 | 613 | } |
614 | 614 | </style> |
615 | 615 | <?php |
616 | - } |
|
617 | - |
|
618 | - echo '<div id="plugin-information-scrollable">'; |
|
619 | - echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; |
|
620 | - echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; |
|
621 | - |
|
622 | - foreach ( (array) $api->sections as $section_name => $content ) { |
|
623 | - if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { |
|
624 | - continue; |
|
625 | - } |
|
626 | - |
|
627 | - if ( isset( $plugins_section_titles[ $section_name ] ) ) { |
|
628 | - $title = $plugins_section_titles[ $section_name ]; |
|
629 | - } else { |
|
630 | - $title = ucwords( str_replace( '_', ' ', $section_name ) ); |
|
631 | - } |
|
632 | - |
|
633 | - $class = ( $section_name === $section ) ? ' class="current"' : ''; |
|
634 | - $href = add_query_arg( |
|
635 | - array( |
|
636 | - 'tab' => $tab, |
|
637 | - 'section' => $section_name, |
|
638 | - ) |
|
639 | - ); |
|
640 | - $href = esc_url( $href ); |
|
641 | - $san_section = esc_attr( $section_name ); |
|
642 | - echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; |
|
643 | - } |
|
644 | - |
|
645 | - echo "</div>\n"; |
|
646 | - |
|
647 | - ?> |
|
616 | + } |
|
617 | + |
|
618 | + echo '<div id="plugin-information-scrollable">'; |
|
619 | + echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; |
|
620 | + echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; |
|
621 | + |
|
622 | + foreach ( (array) $api->sections as $section_name => $content ) { |
|
623 | + if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { |
|
624 | + continue; |
|
625 | + } |
|
626 | + |
|
627 | + if ( isset( $plugins_section_titles[ $section_name ] ) ) { |
|
628 | + $title = $plugins_section_titles[ $section_name ]; |
|
629 | + } else { |
|
630 | + $title = ucwords( str_replace( '_', ' ', $section_name ) ); |
|
631 | + } |
|
632 | + |
|
633 | + $class = ( $section_name === $section ) ? ' class="current"' : ''; |
|
634 | + $href = add_query_arg( |
|
635 | + array( |
|
636 | + 'tab' => $tab, |
|
637 | + 'section' => $section_name, |
|
638 | + ) |
|
639 | + ); |
|
640 | + $href = esc_url( $href ); |
|
641 | + $san_section = esc_attr( $section_name ); |
|
642 | + echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; |
|
643 | + } |
|
644 | + |
|
645 | + echo "</div>\n"; |
|
646 | + |
|
647 | + ?> |
|
648 | 648 | <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'> |
649 | 649 | <div class="fyi"> |
650 | 650 | <ul> |
@@ -655,17 +655,17 @@ discard block |
||
655 | 655 | <?php } if ( ! empty( $api->last_updated ) ) { ?> |
656 | 656 | <li><strong><?php _e( 'Last Updated:' ); ?></strong> |
657 | 657 | <?php |
658 | - /* translators: %s: Human-readable time difference. */ |
|
659 | - printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); |
|
660 | - ?> |
|
658 | + /* translators: %s: Human-readable time difference. */ |
|
659 | + printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); |
|
660 | + ?> |
|
661 | 661 | </li> |
662 | 662 | <?php } if ( ! empty( $api->requires ) ) { ?> |
663 | 663 | <li> |
664 | 664 | <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> |
665 | 665 | <?php |
666 | - /* translators: %s: Version number. */ |
|
667 | - printf( __( '%s or higher' ), $api->requires ); |
|
668 | - ?> |
|
666 | + /* translators: %s: Version number. */ |
|
667 | + printf( __( '%s or higher' ), $api->requires ); |
|
668 | + ?> |
|
669 | 669 | </li> |
670 | 670 | <?php } if ( ! empty( $api->tested ) ) { ?> |
671 | 671 | <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li> |
@@ -673,26 +673,26 @@ discard block |
||
673 | 673 | <li> |
674 | 674 | <strong><?php _e( 'Requires PHP Version:' ); ?></strong> |
675 | 675 | <?php |
676 | - /* translators: %s: Version number. */ |
|
677 | - printf( __( '%s or higher' ), $api->requires_php ); |
|
678 | - ?> |
|
676 | + /* translators: %s: Version number. */ |
|
677 | + printf( __( '%s or higher' ), $api->requires_php ); |
|
678 | + ?> |
|
679 | 679 | </li> |
680 | 680 | <?php } if ( isset( $api->active_installs ) ) { ?> |
681 | 681 | <li><strong><?php _e( 'Active Installations:' ); ?></strong> |
682 | 682 | <?php |
683 | - if ( $api->active_installs >= 1000000 ) { |
|
684 | - $active_installs_millions = floor( $api->active_installs / 1000000 ); |
|
685 | - printf( |
|
686 | - /* translators: %s: Number of millions. */ |
|
687 | - _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ), |
|
688 | - number_format_i18n( $active_installs_millions ) |
|
689 | - ); |
|
690 | - } elseif ( $api->active_installs < 10 ) { |
|
691 | - _ex( 'Less Than 10', 'Active plugin installations' ); |
|
692 | - } else { |
|
693 | - echo number_format_i18n( $api->active_installs ) . '+'; |
|
694 | - } |
|
695 | - ?> |
|
683 | + if ( $api->active_installs >= 1000000 ) { |
|
684 | + $active_installs_millions = floor( $api->active_installs / 1000000 ); |
|
685 | + printf( |
|
686 | + /* translators: %s: Number of millions. */ |
|
687 | + _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ), |
|
688 | + number_format_i18n( $active_installs_millions ) |
|
689 | + ); |
|
690 | + } elseif ( $api->active_installs < 10 ) { |
|
691 | + _ex( 'Less Than 10', 'Active plugin installations' ); |
|
692 | + } else { |
|
693 | + echo number_format_i18n( $api->active_installs ) . '+'; |
|
694 | + } |
|
695 | + ?> |
|
696 | 696 | </li> |
697 | 697 | <?php } if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?> |
698 | 698 | <li><a target="_blank" href="<?php echo esc_url( __( 'https://wordpress.org/plugins/' ) . $api->slug ); ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a></li> |
@@ -705,58 +705,58 @@ discard block |
||
705 | 705 | <?php if ( ! empty( $api->rating ) ) { ?> |
706 | 706 | <h3><?php _e( 'Average Rating' ); ?></h3> |
707 | 707 | <?php |
708 | - wp_star_rating( |
|
709 | - array( |
|
710 | - 'rating' => $api->rating, |
|
711 | - 'type' => 'percent', |
|
712 | - 'number' => $api->num_ratings, |
|
713 | - ) |
|
714 | - ); |
|
715 | - ?> |
|
708 | + wp_star_rating( |
|
709 | + array( |
|
710 | + 'rating' => $api->rating, |
|
711 | + 'type' => 'percent', |
|
712 | + 'number' => $api->num_ratings, |
|
713 | + ) |
|
714 | + ); |
|
715 | + ?> |
|
716 | 716 | <p aria-hidden="true" class="fyi-description"> |
717 | 717 | <?php |
718 | - printf( |
|
719 | - /* translators: %s: Number of ratings. */ |
|
720 | - _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), |
|
721 | - number_format_i18n( $api->num_ratings ) |
|
722 | - ); |
|
723 | - ?> |
|
718 | + printf( |
|
719 | + /* translators: %s: Number of ratings. */ |
|
720 | + _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), |
|
721 | + number_format_i18n( $api->num_ratings ) |
|
722 | + ); |
|
723 | + ?> |
|
724 | 724 | </p> |
725 | 725 | <?php |
726 | - } |
|
726 | + } |
|
727 | 727 | |
728 | - if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { |
|
729 | - ?> |
|
728 | + if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { |
|
729 | + ?> |
|
730 | 730 | <h3><?php _e( 'Reviews' ); ?></h3> |
731 | 731 | <p class="fyi-description"><?php _e( 'Read all reviews on WordPress.org or write your own!' ); ?></p> |
732 | 732 | <?php |
733 | - foreach ( $api->ratings as $key => $ratecount ) { |
|
734 | - // Avoid div-by-zero. |
|
735 | - $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; |
|
736 | - $aria_label = esc_attr( |
|
737 | - sprintf( |
|
738 | - /* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */ |
|
739 | - _n( |
|
740 | - 'Reviews with %1$d star: %2$s. Opens in a new tab.', |
|
741 | - 'Reviews with %1$d stars: %2$s. Opens in a new tab.', |
|
742 | - $key |
|
743 | - ), |
|
744 | - $key, |
|
745 | - number_format_i18n( $ratecount ) |
|
746 | - ) |
|
747 | - ); |
|
748 | - ?> |
|
733 | + foreach ( $api->ratings as $key => $ratecount ) { |
|
734 | + // Avoid div-by-zero. |
|
735 | + $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; |
|
736 | + $aria_label = esc_attr( |
|
737 | + sprintf( |
|
738 | + /* translators: 1: Number of stars (used to determine singular/plural), 2: Number of reviews. */ |
|
739 | + _n( |
|
740 | + 'Reviews with %1$d star: %2$s. Opens in a new tab.', |
|
741 | + 'Reviews with %1$d stars: %2$s. Opens in a new tab.', |
|
742 | + $key |
|
743 | + ), |
|
744 | + $key, |
|
745 | + number_format_i18n( $ratecount ) |
|
746 | + ) |
|
747 | + ); |
|
748 | + ?> |
|
749 | 749 | <div class="counter-container"> |
750 | 750 | <span class="counter-label"> |
751 | 751 | <?php |
752 | - printf( |
|
753 | - '<a href="%s" target="_blank" aria-label="%s">%s</a>', |
|
754 | - "https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}", |
|
755 | - $aria_label, |
|
756 | - /* translators: %s: Number of stars. */ |
|
757 | - sprintf( _n( '%d star', '%d stars', $key ), $key ) |
|
758 | - ); |
|
759 | - ?> |
|
752 | + printf( |
|
753 | + '<a href="%s" target="_blank" aria-label="%s">%s</a>', |
|
754 | + "https://wordpress.org/support/plugin/{$api->slug}/reviews/?filter={$key}", |
|
755 | + $aria_label, |
|
756 | + /* translators: %s: Number of stars. */ |
|
757 | + sprintf( _n( '%d star', '%d stars', $key ), $key ) |
|
758 | + ); |
|
759 | + ?> |
|
760 | 760 | </span> |
761 | 761 | <span class="counter-back"> |
762 | 762 | <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span> |
@@ -764,26 +764,26 @@ discard block |
||
764 | 764 | <span class="counter-count" aria-hidden="true"><?php echo number_format_i18n( $ratecount ); ?></span> |
765 | 765 | </div> |
766 | 766 | <?php |
767 | - } |
|
768 | - } |
|
769 | - if ( ! empty( $api->contributors ) ) { |
|
770 | - ?> |
|
767 | + } |
|
768 | + } |
|
769 | + if ( ! empty( $api->contributors ) ) { |
|
770 | + ?> |
|
771 | 771 | <h3><?php _e( 'Contributors' ); ?></h3> |
772 | 772 | <ul class="contributors"> |
773 | 773 | <?php |
774 | - foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) { |
|
775 | - $contrib_name = $contrib_details['display_name']; |
|
776 | - if ( ! $contrib_name ) { |
|
777 | - $contrib_name = $contrib_username; |
|
778 | - } |
|
779 | - $contrib_name = esc_html( $contrib_name ); |
|
780 | - |
|
781 | - $contrib_profile = esc_url( $contrib_details['profile'] ); |
|
782 | - $contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) ); |
|
783 | - |
|
784 | - echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>"; |
|
785 | - } |
|
786 | - ?> |
|
774 | + foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) { |
|
775 | + $contrib_name = $contrib_details['display_name']; |
|
776 | + if ( ! $contrib_name ) { |
|
777 | + $contrib_name = $contrib_username; |
|
778 | + } |
|
779 | + $contrib_name = esc_html( $contrib_name ); |
|
780 | + |
|
781 | + $contrib_profile = esc_url( $contrib_details['profile'] ); |
|
782 | + $contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) ); |
|
783 | + |
|
784 | + echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>"; |
|
785 | + } |
|
786 | + ?> |
|
787 | 787 | </ul> |
788 | 788 | <?php if ( ! empty( $api->donate_link ) ) { ?> |
789 | 789 | <a target="_blank" href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> |
@@ -792,101 +792,101 @@ discard block |
||
792 | 792 | </div> |
793 | 793 | <div id="section-holder"> |
794 | 794 | <?php |
795 | - $requires_php = isset( $api->requires_php ) ? $api->requires_php : null; |
|
796 | - $requires_wp = isset( $api->requires ) ? $api->requires : null; |
|
797 | - |
|
798 | - $compatible_php = is_php_version_compatible( $requires_php ); |
|
799 | - $compatible_wp = is_wp_version_compatible( $requires_wp ); |
|
800 | - $tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) ); |
|
801 | - |
|
802 | - if ( ! $compatible_php ) { |
|
803 | - echo '<div class="notice notice-error notice-alt"><p>'; |
|
804 | - _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' ); |
|
805 | - if ( current_user_can( 'update_php' ) ) { |
|
806 | - printf( |
|
807 | - /* translators: %s: URL to Update PHP page. */ |
|
808 | - ' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ), |
|
809 | - esc_url( wp_get_update_php_url() ) |
|
810 | - ); |
|
811 | - |
|
812 | - wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
813 | - } else { |
|
814 | - echo '</p>'; |
|
815 | - } |
|
816 | - echo '</div>'; |
|
817 | - } |
|
818 | - |
|
819 | - if ( ! $tested_wp ) { |
|
820 | - echo '<div class="notice notice-warning notice-alt"><p>'; |
|
821 | - _e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ); |
|
822 | - echo '</p></div>'; |
|
823 | - } elseif ( ! $compatible_wp ) { |
|
824 | - echo '<div class="notice notice-error notice-alt"><p>'; |
|
825 | - _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' ); |
|
826 | - if ( current_user_can( 'update_core' ) ) { |
|
827 | - printf( |
|
828 | - /* translators: %s: URL to WordPress Updates screen. */ |
|
829 | - ' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ), |
|
830 | - self_admin_url( 'update-core.php' ) |
|
831 | - ); |
|
832 | - } |
|
833 | - echo '</p></div>'; |
|
834 | - } |
|
835 | - |
|
836 | - foreach ( (array) $api->sections as $section_name => $content ) { |
|
837 | - $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); |
|
838 | - $content = links_add_target( $content, '_blank' ); |
|
839 | - |
|
840 | - $san_section = esc_attr( $section_name ); |
|
841 | - |
|
842 | - $display = ( $section_name === $section ) ? 'block' : 'none'; |
|
843 | - |
|
844 | - echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; |
|
845 | - echo $content; |
|
846 | - echo "\t</div>\n"; |
|
847 | - } |
|
848 | - echo "</div>\n"; |
|
849 | - echo "</div>\n"; |
|
850 | - echo "</div>\n"; // #plugin-information-scrollable |
|
851 | - echo "<div id='$tab-footer'>\n"; |
|
852 | - if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { |
|
853 | - $status = install_plugin_install_status( $api ); |
|
854 | - switch ( $status['status'] ) { |
|
855 | - case 'install': |
|
856 | - if ( $status['url'] ) { |
|
857 | - if ( $compatible_php && $compatible_wp ) { |
|
858 | - echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>'; |
|
859 | - } else { |
|
860 | - printf( |
|
861 | - '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>', |
|
862 | - _x( 'Cannot Install', 'plugin' ) |
|
863 | - ); |
|
864 | - } |
|
865 | - } |
|
866 | - break; |
|
867 | - case 'update_available': |
|
868 | - if ( $status['url'] ) { |
|
869 | - if ( $compatible_php ) { |
|
870 | - echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>'; |
|
871 | - } else { |
|
872 | - printf( |
|
873 | - '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>', |
|
874 | - _x( 'Cannot Update', 'plugin' ) |
|
875 | - ); |
|
876 | - } |
|
877 | - } |
|
878 | - break; |
|
879 | - case 'newer_installed': |
|
880 | - /* translators: %s: Plugin version. */ |
|
881 | - echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), esc_html( $status['version'] ) ) . '</a>'; |
|
882 | - break; |
|
883 | - case 'latest_installed': |
|
884 | - echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>'; |
|
885 | - break; |
|
886 | - } |
|
887 | - } |
|
888 | - echo "</div>\n"; |
|
889 | - |
|
890 | - iframe_footer(); |
|
891 | - exit; |
|
795 | + $requires_php = isset( $api->requires_php ) ? $api->requires_php : null; |
|
796 | + $requires_wp = isset( $api->requires ) ? $api->requires : null; |
|
797 | + |
|
798 | + $compatible_php = is_php_version_compatible( $requires_php ); |
|
799 | + $compatible_wp = is_wp_version_compatible( $requires_wp ); |
|
800 | + $tested_wp = ( empty( $api->tested ) || version_compare( get_bloginfo( 'version' ), $api->tested, '<=' ) ); |
|
801 | + |
|
802 | + if ( ! $compatible_php ) { |
|
803 | + echo '<div class="notice notice-error notice-alt"><p>'; |
|
804 | + _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' ); |
|
805 | + if ( current_user_can( 'update_php' ) ) { |
|
806 | + printf( |
|
807 | + /* translators: %s: URL to Update PHP page. */ |
|
808 | + ' ' . __( '<a href="%s" target="_blank">Click here to learn more about updating PHP</a>.' ), |
|
809 | + esc_url( wp_get_update_php_url() ) |
|
810 | + ); |
|
811 | + |
|
812 | + wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
813 | + } else { |
|
814 | + echo '</p>'; |
|
815 | + } |
|
816 | + echo '</div>'; |
|
817 | + } |
|
818 | + |
|
819 | + if ( ! $tested_wp ) { |
|
820 | + echo '<div class="notice notice-warning notice-alt"><p>'; |
|
821 | + _e( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' ); |
|
822 | + echo '</p></div>'; |
|
823 | + } elseif ( ! $compatible_wp ) { |
|
824 | + echo '<div class="notice notice-error notice-alt"><p>'; |
|
825 | + _e( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' ); |
|
826 | + if ( current_user_can( 'update_core' ) ) { |
|
827 | + printf( |
|
828 | + /* translators: %s: URL to WordPress Updates screen. */ |
|
829 | + ' ' . __( '<a href="%s" target="_parent">Click here to update WordPress</a>.' ), |
|
830 | + self_admin_url( 'update-core.php' ) |
|
831 | + ); |
|
832 | + } |
|
833 | + echo '</p></div>'; |
|
834 | + } |
|
835 | + |
|
836 | + foreach ( (array) $api->sections as $section_name => $content ) { |
|
837 | + $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); |
|
838 | + $content = links_add_target( $content, '_blank' ); |
|
839 | + |
|
840 | + $san_section = esc_attr( $section_name ); |
|
841 | + |
|
842 | + $display = ( $section_name === $section ) ? 'block' : 'none'; |
|
843 | + |
|
844 | + echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; |
|
845 | + echo $content; |
|
846 | + echo "\t</div>\n"; |
|
847 | + } |
|
848 | + echo "</div>\n"; |
|
849 | + echo "</div>\n"; |
|
850 | + echo "</div>\n"; // #plugin-information-scrollable |
|
851 | + echo "<div id='$tab-footer'>\n"; |
|
852 | + if ( ! empty( $api->download_link ) && ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { |
|
853 | + $status = install_plugin_install_status( $api ); |
|
854 | + switch ( $status['status'] ) { |
|
855 | + case 'install': |
|
856 | + if ( $status['url'] ) { |
|
857 | + if ( $compatible_php && $compatible_wp ) { |
|
858 | + echo '<a data-slug="' . esc_attr( $api->slug ) . '" id="plugin_install_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>'; |
|
859 | + } else { |
|
860 | + printf( |
|
861 | + '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>', |
|
862 | + _x( 'Cannot Install', 'plugin' ) |
|
863 | + ); |
|
864 | + } |
|
865 | + } |
|
866 | + break; |
|
867 | + case 'update_available': |
|
868 | + if ( $status['url'] ) { |
|
869 | + if ( $compatible_php ) { |
|
870 | + echo '<a data-slug="' . esc_attr( $api->slug ) . '" data-plugin="' . esc_attr( $status['file'] ) . '" id="plugin_update_from_iframe" class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>'; |
|
871 | + } else { |
|
872 | + printf( |
|
873 | + '<button type="button" class="button button-primary button-disabled right" disabled="disabled">%s</button>', |
|
874 | + _x( 'Cannot Update', 'plugin' ) |
|
875 | + ); |
|
876 | + } |
|
877 | + } |
|
878 | + break; |
|
879 | + case 'newer_installed': |
|
880 | + /* translators: %s: Plugin version. */ |
|
881 | + echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), esc_html( $status['version'] ) ) . '</a>'; |
|
882 | + break; |
|
883 | + case 'latest_installed': |
|
884 | + echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>'; |
|
885 | + break; |
|
886 | + } |
|
887 | + } |
|
888 | + echo "</div>\n"; |
|
889 | + |
|
890 | + iframe_footer(); |
|
891 | + exit; |
|
892 | 892 | } |
@@ -13,221 +13,221 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class Custom_Background { |
15 | 15 | |
16 | - /** |
|
17 | - * Callback for administration header. |
|
18 | - * |
|
19 | - * @var callable |
|
20 | - * @since 3.0.0 |
|
21 | - */ |
|
22 | - public $admin_header_callback; |
|
23 | - |
|
24 | - /** |
|
25 | - * Callback for header div. |
|
26 | - * |
|
27 | - * @var callable |
|
28 | - * @since 3.0.0 |
|
29 | - */ |
|
30 | - public $admin_image_div_callback; |
|
31 | - |
|
32 | - /** |
|
33 | - * Used to trigger a success message when settings updated and set to true. |
|
34 | - * |
|
35 | - * @since 3.0.0 |
|
36 | - * @var bool |
|
37 | - */ |
|
38 | - private $updated; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor - Register administration header callback. |
|
42 | - * |
|
43 | - * @since 3.0.0 |
|
44 | - * @param callable $admin_header_callback |
|
45 | - * @param callable $admin_image_div_callback Optional custom image div output callback. |
|
46 | - */ |
|
47 | - public function __construct( $admin_header_callback = '', $admin_image_div_callback = '' ) { |
|
48 | - $this->admin_header_callback = $admin_header_callback; |
|
49 | - $this->admin_image_div_callback = $admin_image_div_callback; |
|
50 | - |
|
51 | - add_action( 'admin_menu', array( $this, 'init' ) ); |
|
52 | - |
|
53 | - add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) ); |
|
54 | - |
|
55 | - // Unused since 3.5.0. |
|
56 | - add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Set up the hooks for the Custom Background admin page. |
|
61 | - * |
|
62 | - * @since 3.0.0 |
|
63 | - */ |
|
64 | - public function init() { |
|
65 | - $page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) ); |
|
66 | - if ( ! $page ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - add_action( "load-{$page}", array( $this, 'admin_load' ) ); |
|
71 | - add_action( "load-{$page}", array( $this, 'take_action' ), 49 ); |
|
72 | - add_action( "load-{$page}", array( $this, 'handle_upload' ), 49 ); |
|
73 | - |
|
74 | - if ( $this->admin_header_callback ) { |
|
75 | - add_action( "admin_head-{$page}", $this->admin_header_callback, 51 ); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Set up the enqueue for the CSS & JavaScript files. |
|
81 | - * |
|
82 | - * @since 3.0.0 |
|
83 | - */ |
|
84 | - public function admin_load() { |
|
85 | - get_current_screen()->add_help_tab( |
|
86 | - array( |
|
87 | - 'id' => 'overview', |
|
88 | - 'title' => __( 'Overview' ), |
|
89 | - 'content' => |
|
90 | - '<p>' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '</p>' . |
|
91 | - '<p>' . __( 'To use a background image, simply upload it or choose an image that has already been uploaded to your Media Library by clicking the “Choose Image” button. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '</p>' . |
|
92 | - '<p>' . __( 'You can also choose a background color by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
|
93 | - '<p>' . __( 'Do not forget to click on the Save Changes button when you are finished.' ) . '</p>', |
|
94 | - ) |
|
95 | - ); |
|
96 | - |
|
97 | - get_current_screen()->set_help_sidebar( |
|
98 | - '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
|
99 | - '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen">Documentation on Custom Background</a>' ) . '</p>' . |
|
100 | - '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
|
101 | - ); |
|
102 | - |
|
103 | - wp_enqueue_media(); |
|
104 | - wp_enqueue_script( 'custom-background' ); |
|
105 | - wp_enqueue_style( 'wp-color-picker' ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Execute custom background modification. |
|
110 | - * |
|
111 | - * @since 3.0.0 |
|
112 | - */ |
|
113 | - public function take_action() { |
|
114 | - if ( empty( $_POST ) ) { |
|
115 | - return; |
|
116 | - } |
|
117 | - |
|
118 | - if ( isset( $_POST['reset-background'] ) ) { |
|
119 | - check_admin_referer( 'custom-background-reset', '_wpnonce-custom-background-reset' ); |
|
120 | - |
|
121 | - remove_theme_mod( 'background_image' ); |
|
122 | - remove_theme_mod( 'background_image_thumb' ); |
|
123 | - |
|
124 | - $this->updated = true; |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( isset( $_POST['remove-background'] ) ) { |
|
129 | - // @todo Uploaded files are not removed here. |
|
130 | - check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' ); |
|
131 | - |
|
132 | - set_theme_mod( 'background_image', '' ); |
|
133 | - set_theme_mod( 'background_image_thumb', '' ); |
|
134 | - |
|
135 | - $this->updated = true; |
|
136 | - wp_safe_redirect( $_POST['_wp_http_referer'] ); |
|
137 | - return; |
|
138 | - } |
|
139 | - |
|
140 | - if ( isset( $_POST['background-preset'] ) ) { |
|
141 | - check_admin_referer( 'custom-background' ); |
|
142 | - |
|
143 | - if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { |
|
144 | - $preset = $_POST['background-preset']; |
|
145 | - } else { |
|
146 | - $preset = 'default'; |
|
147 | - } |
|
148 | - |
|
149 | - set_theme_mod( 'background_preset', $preset ); |
|
150 | - } |
|
151 | - |
|
152 | - if ( isset( $_POST['background-position'] ) ) { |
|
153 | - check_admin_referer( 'custom-background' ); |
|
154 | - |
|
155 | - $position = explode( ' ', $_POST['background-position'] ); |
|
156 | - |
|
157 | - if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) { |
|
158 | - $position_x = $position[0]; |
|
159 | - } else { |
|
160 | - $position_x = 'left'; |
|
161 | - } |
|
162 | - |
|
163 | - if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) { |
|
164 | - $position_y = $position[1]; |
|
165 | - } else { |
|
166 | - $position_y = 'top'; |
|
167 | - } |
|
168 | - |
|
169 | - set_theme_mod( 'background_position_x', $position_x ); |
|
170 | - set_theme_mod( 'background_position_y', $position_y ); |
|
171 | - } |
|
172 | - |
|
173 | - if ( isset( $_POST['background-size'] ) ) { |
|
174 | - check_admin_referer( 'custom-background' ); |
|
175 | - |
|
176 | - if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) { |
|
177 | - $size = $_POST['background-size']; |
|
178 | - } else { |
|
179 | - $size = 'auto'; |
|
180 | - } |
|
181 | - |
|
182 | - set_theme_mod( 'background_size', $size ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( isset( $_POST['background-repeat'] ) ) { |
|
186 | - check_admin_referer( 'custom-background' ); |
|
187 | - |
|
188 | - $repeat = $_POST['background-repeat']; |
|
189 | - |
|
190 | - if ( 'no-repeat' !== $repeat ) { |
|
191 | - $repeat = 'repeat'; |
|
192 | - } |
|
193 | - |
|
194 | - set_theme_mod( 'background_repeat', $repeat ); |
|
195 | - } |
|
16 | + /** |
|
17 | + * Callback for administration header. |
|
18 | + * |
|
19 | + * @var callable |
|
20 | + * @since 3.0.0 |
|
21 | + */ |
|
22 | + public $admin_header_callback; |
|
23 | + |
|
24 | + /** |
|
25 | + * Callback for header div. |
|
26 | + * |
|
27 | + * @var callable |
|
28 | + * @since 3.0.0 |
|
29 | + */ |
|
30 | + public $admin_image_div_callback; |
|
31 | + |
|
32 | + /** |
|
33 | + * Used to trigger a success message when settings updated and set to true. |
|
34 | + * |
|
35 | + * @since 3.0.0 |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | + private $updated; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor - Register administration header callback. |
|
42 | + * |
|
43 | + * @since 3.0.0 |
|
44 | + * @param callable $admin_header_callback |
|
45 | + * @param callable $admin_image_div_callback Optional custom image div output callback. |
|
46 | + */ |
|
47 | + public function __construct( $admin_header_callback = '', $admin_image_div_callback = '' ) { |
|
48 | + $this->admin_header_callback = $admin_header_callback; |
|
49 | + $this->admin_image_div_callback = $admin_image_div_callback; |
|
50 | + |
|
51 | + add_action( 'admin_menu', array( $this, 'init' ) ); |
|
52 | + |
|
53 | + add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) ); |
|
54 | + |
|
55 | + // Unused since 3.5.0. |
|
56 | + add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Set up the hooks for the Custom Background admin page. |
|
61 | + * |
|
62 | + * @since 3.0.0 |
|
63 | + */ |
|
64 | + public function init() { |
|
65 | + $page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) ); |
|
66 | + if ( ! $page ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + add_action( "load-{$page}", array( $this, 'admin_load' ) ); |
|
71 | + add_action( "load-{$page}", array( $this, 'take_action' ), 49 ); |
|
72 | + add_action( "load-{$page}", array( $this, 'handle_upload' ), 49 ); |
|
73 | + |
|
74 | + if ( $this->admin_header_callback ) { |
|
75 | + add_action( "admin_head-{$page}", $this->admin_header_callback, 51 ); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Set up the enqueue for the CSS & JavaScript files. |
|
81 | + * |
|
82 | + * @since 3.0.0 |
|
83 | + */ |
|
84 | + public function admin_load() { |
|
85 | + get_current_screen()->add_help_tab( |
|
86 | + array( |
|
87 | + 'id' => 'overview', |
|
88 | + 'title' => __( 'Overview' ), |
|
89 | + 'content' => |
|
90 | + '<p>' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '</p>' . |
|
91 | + '<p>' . __( 'To use a background image, simply upload it or choose an image that has already been uploaded to your Media Library by clicking the “Choose Image” button. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '</p>' . |
|
92 | + '<p>' . __( 'You can also choose a background color by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
|
93 | + '<p>' . __( 'Do not forget to click on the Save Changes button when you are finished.' ) . '</p>', |
|
94 | + ) |
|
95 | + ); |
|
96 | + |
|
97 | + get_current_screen()->set_help_sidebar( |
|
98 | + '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
|
99 | + '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen">Documentation on Custom Background</a>' ) . '</p>' . |
|
100 | + '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
|
101 | + ); |
|
102 | + |
|
103 | + wp_enqueue_media(); |
|
104 | + wp_enqueue_script( 'custom-background' ); |
|
105 | + wp_enqueue_style( 'wp-color-picker' ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Execute custom background modification. |
|
110 | + * |
|
111 | + * @since 3.0.0 |
|
112 | + */ |
|
113 | + public function take_action() { |
|
114 | + if ( empty( $_POST ) ) { |
|
115 | + return; |
|
116 | + } |
|
117 | + |
|
118 | + if ( isset( $_POST['reset-background'] ) ) { |
|
119 | + check_admin_referer( 'custom-background-reset', '_wpnonce-custom-background-reset' ); |
|
120 | + |
|
121 | + remove_theme_mod( 'background_image' ); |
|
122 | + remove_theme_mod( 'background_image_thumb' ); |
|
123 | + |
|
124 | + $this->updated = true; |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( isset( $_POST['remove-background'] ) ) { |
|
129 | + // @todo Uploaded files are not removed here. |
|
130 | + check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' ); |
|
131 | + |
|
132 | + set_theme_mod( 'background_image', '' ); |
|
133 | + set_theme_mod( 'background_image_thumb', '' ); |
|
134 | + |
|
135 | + $this->updated = true; |
|
136 | + wp_safe_redirect( $_POST['_wp_http_referer'] ); |
|
137 | + return; |
|
138 | + } |
|
139 | + |
|
140 | + if ( isset( $_POST['background-preset'] ) ) { |
|
141 | + check_admin_referer( 'custom-background' ); |
|
142 | + |
|
143 | + if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { |
|
144 | + $preset = $_POST['background-preset']; |
|
145 | + } else { |
|
146 | + $preset = 'default'; |
|
147 | + } |
|
148 | + |
|
149 | + set_theme_mod( 'background_preset', $preset ); |
|
150 | + } |
|
151 | + |
|
152 | + if ( isset( $_POST['background-position'] ) ) { |
|
153 | + check_admin_referer( 'custom-background' ); |
|
154 | + |
|
155 | + $position = explode( ' ', $_POST['background-position'] ); |
|
156 | + |
|
157 | + if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) { |
|
158 | + $position_x = $position[0]; |
|
159 | + } else { |
|
160 | + $position_x = 'left'; |
|
161 | + } |
|
162 | + |
|
163 | + if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) { |
|
164 | + $position_y = $position[1]; |
|
165 | + } else { |
|
166 | + $position_y = 'top'; |
|
167 | + } |
|
168 | + |
|
169 | + set_theme_mod( 'background_position_x', $position_x ); |
|
170 | + set_theme_mod( 'background_position_y', $position_y ); |
|
171 | + } |
|
172 | + |
|
173 | + if ( isset( $_POST['background-size'] ) ) { |
|
174 | + check_admin_referer( 'custom-background' ); |
|
175 | + |
|
176 | + if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) { |
|
177 | + $size = $_POST['background-size']; |
|
178 | + } else { |
|
179 | + $size = 'auto'; |
|
180 | + } |
|
181 | + |
|
182 | + set_theme_mod( 'background_size', $size ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( isset( $_POST['background-repeat'] ) ) { |
|
186 | + check_admin_referer( 'custom-background' ); |
|
187 | + |
|
188 | + $repeat = $_POST['background-repeat']; |
|
189 | + |
|
190 | + if ( 'no-repeat' !== $repeat ) { |
|
191 | + $repeat = 'repeat'; |
|
192 | + } |
|
193 | + |
|
194 | + set_theme_mod( 'background_repeat', $repeat ); |
|
195 | + } |
|
196 | 196 | |
197 | - if ( isset( $_POST['background-attachment'] ) ) { |
|
198 | - check_admin_referer( 'custom-background' ); |
|
199 | - |
|
200 | - $attachment = $_POST['background-attachment']; |
|
197 | + if ( isset( $_POST['background-attachment'] ) ) { |
|
198 | + check_admin_referer( 'custom-background' ); |
|
199 | + |
|
200 | + $attachment = $_POST['background-attachment']; |
|
201 | 201 | |
202 | - if ( 'fixed' !== $attachment ) { |
|
203 | - $attachment = 'scroll'; |
|
204 | - } |
|
202 | + if ( 'fixed' !== $attachment ) { |
|
203 | + $attachment = 'scroll'; |
|
204 | + } |
|
205 | 205 | |
206 | - set_theme_mod( 'background_attachment', $attachment ); |
|
207 | - } |
|
206 | + set_theme_mod( 'background_attachment', $attachment ); |
|
207 | + } |
|
208 | 208 | |
209 | - if ( isset( $_POST['background-color'] ) ) { |
|
210 | - check_admin_referer( 'custom-background' ); |
|
209 | + if ( isset( $_POST['background-color'] ) ) { |
|
210 | + check_admin_referer( 'custom-background' ); |
|
211 | 211 | |
212 | - $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['background-color'] ); |
|
212 | + $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['background-color'] ); |
|
213 | 213 | |
214 | - if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { |
|
215 | - set_theme_mod( 'background_color', $color ); |
|
216 | - } else { |
|
217 | - set_theme_mod( 'background_color', '' ); |
|
218 | - } |
|
219 | - } |
|
214 | + if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { |
|
215 | + set_theme_mod( 'background_color', $color ); |
|
216 | + } else { |
|
217 | + set_theme_mod( 'background_color', '' ); |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - $this->updated = true; |
|
222 | - } |
|
221 | + $this->updated = true; |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Display the custom background page. |
|
226 | - * |
|
227 | - * @since 3.0.0 |
|
228 | - */ |
|
229 | - public function admin_page() { |
|
230 | - ?> |
|
224 | + /** |
|
225 | + * Display the custom background page. |
|
226 | + * |
|
227 | + * @since 3.0.0 |
|
228 | + */ |
|
229 | + public function admin_page() { |
|
230 | + ?> |
|
231 | 231 | <div class="wrap" id="custom-background"> |
232 | 232 | <h1><?php _e( 'Custom Background' ); ?></h1> |
233 | 233 | |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | <div class="notice notice-info hide-if-no-customize"> |
236 | 236 | <p> |
237 | 237 | <?php |
238 | - printf( |
|
239 | - /* translators: %s: URL to background image configuration in Customizer. */ |
|
240 | - __( 'You can now manage and live-preview Custom Backgrounds in the <a href="%s">Customizer</a>.' ), |
|
241 | - admin_url( 'customize.php?autofocus[control]=background_image' ) |
|
242 | - ); |
|
243 | - ?> |
|
238 | + printf( |
|
239 | + /* translators: %s: URL to background image configuration in Customizer. */ |
|
240 | + __( 'You can now manage and live-preview Custom Backgrounds in the <a href="%s">Customizer</a>.' ), |
|
241 | + admin_url( 'customize.php?autofocus[control]=background_image' ) |
|
242 | + ); |
|
243 | + ?> |
|
244 | 244 | </p> |
245 | 245 | </div> |
246 | 246 | <?php } ?> |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | <div id="message" class="updated"> |
250 | 250 | <p> |
251 | 251 | <?php |
252 | - /* translators: %s: Home URL. */ |
|
253 | - printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); |
|
254 | - ?> |
|
252 | + /* translators: %s: Home URL. */ |
|
253 | + printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); |
|
254 | + ?> |
|
255 | 255 | </p> |
256 | 256 | </div> |
257 | 257 | <?php } ?> |
@@ -264,32 +264,32 @@ discard block |
||
264 | 264 | <th scope="row"><?php _e( 'Preview' ); ?></th> |
265 | 265 | <td> |
266 | 266 | <?php |
267 | - if ( $this->admin_image_div_callback ) { |
|
268 | - call_user_func( $this->admin_image_div_callback ); |
|
269 | - } else { |
|
270 | - $background_styles = ''; |
|
271 | - $bgcolor = get_background_color(); |
|
272 | - if ( $bgcolor ) { |
|
273 | - $background_styles .= 'background-color: #' . $bgcolor . ';'; |
|
274 | - } |
|
275 | - |
|
276 | - $background_image_thumb = get_background_image(); |
|
277 | - if ( $background_image_thumb ) { |
|
278 | - $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); |
|
279 | - $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
|
280 | - $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); |
|
281 | - $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); |
|
282 | - $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
|
283 | - $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
|
284 | - |
|
285 | - // Background-image URL must be single quote, see below. |
|
286 | - $background_styles .= " background-image: url('$background_image_thumb');" |
|
287 | - . " background-size: $background_size;" |
|
288 | - . " background-position: $background_position_x $background_position_y;" |
|
289 | - . " background-repeat: $background_repeat;" |
|
290 | - . " background-attachment: $background_attachment;"; |
|
291 | - } |
|
292 | - ?> |
|
267 | + if ( $this->admin_image_div_callback ) { |
|
268 | + call_user_func( $this->admin_image_div_callback ); |
|
269 | + } else { |
|
270 | + $background_styles = ''; |
|
271 | + $bgcolor = get_background_color(); |
|
272 | + if ( $bgcolor ) { |
|
273 | + $background_styles .= 'background-color: #' . $bgcolor . ';'; |
|
274 | + } |
|
275 | + |
|
276 | + $background_image_thumb = get_background_image(); |
|
277 | + if ( $background_image_thumb ) { |
|
278 | + $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); |
|
279 | + $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
|
280 | + $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); |
|
281 | + $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); |
|
282 | + $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
|
283 | + $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
|
284 | + |
|
285 | + // Background-image URL must be single quote, see below. |
|
286 | + $background_styles .= " background-image: url('$background_image_thumb');" |
|
287 | + . " background-size: $background_size;" |
|
288 | + . " background-position: $background_position_x $background_position_y;" |
|
289 | + . " background-repeat: $background_repeat;" |
|
290 | + . " background-attachment: $background_attachment;"; |
|
291 | + } |
|
292 | + ?> |
|
293 | 293 | <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // Must be double quote, see above. ?> |
294 | 294 | <?php if ( $background_image_thumb ) { ?> |
295 | 295 | <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br /> |
@@ -359,57 +359,57 @@ discard block |
||
359 | 359 | <input name="background-preset" type="hidden" value="custom"> |
360 | 360 | |
361 | 361 | <?php |
362 | - $background_position = sprintf( |
|
363 | - '%s %s', |
|
364 | - get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ), |
|
365 | - get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ) |
|
366 | - ); |
|
367 | - |
|
368 | - $background_position_options = array( |
|
369 | - array( |
|
370 | - 'left top' => array( |
|
371 | - 'label' => __( 'Top Left' ), |
|
372 | - 'icon' => 'dashicons dashicons-arrow-left-alt', |
|
373 | - ), |
|
374 | - 'center top' => array( |
|
375 | - 'label' => __( 'Top' ), |
|
376 | - 'icon' => 'dashicons dashicons-arrow-up-alt', |
|
377 | - ), |
|
378 | - 'right top' => array( |
|
379 | - 'label' => __( 'Top Right' ), |
|
380 | - 'icon' => 'dashicons dashicons-arrow-right-alt', |
|
381 | - ), |
|
382 | - ), |
|
383 | - array( |
|
384 | - 'left center' => array( |
|
385 | - 'label' => __( 'Left' ), |
|
386 | - 'icon' => 'dashicons dashicons-arrow-left-alt', |
|
387 | - ), |
|
388 | - 'center center' => array( |
|
389 | - 'label' => __( 'Center' ), |
|
390 | - 'icon' => 'background-position-center-icon', |
|
391 | - ), |
|
392 | - 'right center' => array( |
|
393 | - 'label' => __( 'Right' ), |
|
394 | - 'icon' => 'dashicons dashicons-arrow-right-alt', |
|
395 | - ), |
|
396 | - ), |
|
397 | - array( |
|
398 | - 'left bottom' => array( |
|
399 | - 'label' => __( 'Bottom Left' ), |
|
400 | - 'icon' => 'dashicons dashicons-arrow-left-alt', |
|
401 | - ), |
|
402 | - 'center bottom' => array( |
|
403 | - 'label' => __( 'Bottom' ), |
|
404 | - 'icon' => 'dashicons dashicons-arrow-down-alt', |
|
405 | - ), |
|
406 | - 'right bottom' => array( |
|
407 | - 'label' => __( 'Bottom Right' ), |
|
408 | - 'icon' => 'dashicons dashicons-arrow-right-alt', |
|
409 | - ), |
|
410 | - ), |
|
411 | - ); |
|
412 | - ?> |
|
362 | + $background_position = sprintf( |
|
363 | + '%s %s', |
|
364 | + get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ), |
|
365 | + get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ) |
|
366 | + ); |
|
367 | + |
|
368 | + $background_position_options = array( |
|
369 | + array( |
|
370 | + 'left top' => array( |
|
371 | + 'label' => __( 'Top Left' ), |
|
372 | + 'icon' => 'dashicons dashicons-arrow-left-alt', |
|
373 | + ), |
|
374 | + 'center top' => array( |
|
375 | + 'label' => __( 'Top' ), |
|
376 | + 'icon' => 'dashicons dashicons-arrow-up-alt', |
|
377 | + ), |
|
378 | + 'right top' => array( |
|
379 | + 'label' => __( 'Top Right' ), |
|
380 | + 'icon' => 'dashicons dashicons-arrow-right-alt', |
|
381 | + ), |
|
382 | + ), |
|
383 | + array( |
|
384 | + 'left center' => array( |
|
385 | + 'label' => __( 'Left' ), |
|
386 | + 'icon' => 'dashicons dashicons-arrow-left-alt', |
|
387 | + ), |
|
388 | + 'center center' => array( |
|
389 | + 'label' => __( 'Center' ), |
|
390 | + 'icon' => 'background-position-center-icon', |
|
391 | + ), |
|
392 | + 'right center' => array( |
|
393 | + 'label' => __( 'Right' ), |
|
394 | + 'icon' => 'dashicons dashicons-arrow-right-alt', |
|
395 | + ), |
|
396 | + ), |
|
397 | + array( |
|
398 | + 'left bottom' => array( |
|
399 | + 'label' => __( 'Bottom Left' ), |
|
400 | + 'icon' => 'dashicons dashicons-arrow-left-alt', |
|
401 | + ), |
|
402 | + 'center bottom' => array( |
|
403 | + 'label' => __( 'Bottom' ), |
|
404 | + 'icon' => 'dashicons dashicons-arrow-down-alt', |
|
405 | + ), |
|
406 | + 'right bottom' => array( |
|
407 | + 'label' => __( 'Bottom Right' ), |
|
408 | + 'icon' => 'dashicons dashicons-arrow-right-alt', |
|
409 | + ), |
|
410 | + ), |
|
411 | + ); |
|
412 | + ?> |
|
413 | 413 | <tr> |
414 | 414 | <th scope="row"><?php _e( 'Image Position' ); ?></th> |
415 | 415 | <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend> |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | <th scope="row"><?php _e( 'Background Color' ); ?></th> |
461 | 461 | <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> |
462 | 462 | <?php |
463 | - $default_color = ''; |
|
464 | - if ( current_theme_supports( 'custom-background', 'default-color' ) ) { |
|
465 | - $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"'; |
|
466 | - } |
|
467 | - ?> |
|
463 | + $default_color = ''; |
|
464 | + if ( current_theme_supports( 'custom-background', 'default-color' ) ) { |
|
465 | + $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"'; |
|
466 | + } |
|
467 | + ?> |
|
468 | 468 | <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color; ?>> |
469 | 469 | </fieldset></td> |
470 | 470 | </tr> |
@@ -477,149 +477,149 @@ discard block |
||
477 | 477 | |
478 | 478 | </div> |
479 | 479 | <?php |
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Handle an Image upload for the background image. |
|
484 | - * |
|
485 | - * @since 3.0.0 |
|
486 | - */ |
|
487 | - public function handle_upload() { |
|
488 | - if ( empty( $_FILES ) ) { |
|
489 | - return; |
|
490 | - } |
|
491 | - |
|
492 | - check_admin_referer( 'custom-background-upload', '_wpnonce-custom-background-upload' ); |
|
493 | - |
|
494 | - $overrides = array( 'test_form' => false ); |
|
495 | - |
|
496 | - $uploaded_file = $_FILES['import']; |
|
497 | - $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] ); |
|
498 | - if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
|
499 | - wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) ); |
|
500 | - } |
|
501 | - |
|
502 | - $file = wp_handle_upload( $uploaded_file, $overrides ); |
|
503 | - |
|
504 | - if ( isset( $file['error'] ) ) { |
|
505 | - wp_die( $file['error'] ); |
|
506 | - } |
|
507 | - |
|
508 | - $url = $file['url']; |
|
509 | - $type = $file['type']; |
|
510 | - $file = $file['file']; |
|
511 | - $filename = wp_basename( $file ); |
|
512 | - |
|
513 | - // Construct the attachment array. |
|
514 | - $attachment = array( |
|
515 | - 'post_title' => $filename, |
|
516 | - 'post_content' => $url, |
|
517 | - 'post_mime_type' => $type, |
|
518 | - 'guid' => $url, |
|
519 | - 'context' => 'custom-background', |
|
520 | - ); |
|
521 | - |
|
522 | - // Save the data. |
|
523 | - $id = wp_insert_attachment( $attachment, $file ); |
|
524 | - |
|
525 | - // Add the metadata. |
|
526 | - wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
|
527 | - update_post_meta( $id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) ); |
|
528 | - |
|
529 | - set_theme_mod( 'background_image', esc_url_raw( $url ) ); |
|
530 | - |
|
531 | - $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); |
|
532 | - set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); |
|
533 | - |
|
534 | - /** This action is documented in wp-admin/includes/class-custom-image-header.php */ |
|
535 | - do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication. |
|
536 | - $this->updated = true; |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Ajax handler for adding custom background context to an attachment. |
|
541 | - * |
|
542 | - * Triggers when the user adds a new background image from the |
|
543 | - * Media Manager. |
|
544 | - * |
|
545 | - * @since 4.1.0 |
|
546 | - */ |
|
547 | - public function ajax_background_add() { |
|
548 | - check_ajax_referer( 'background-add', 'nonce' ); |
|
549 | - |
|
550 | - if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
551 | - wp_send_json_error(); |
|
552 | - } |
|
553 | - |
|
554 | - $attachment_id = absint( $_POST['attachment_id'] ); |
|
555 | - if ( $attachment_id < 1 ) { |
|
556 | - wp_send_json_error(); |
|
557 | - } |
|
558 | - |
|
559 | - update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() ); |
|
560 | - |
|
561 | - wp_send_json_success(); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * @since 3.4.0 |
|
566 | - * @deprecated 3.5.0 |
|
567 | - * |
|
568 | - * @param array $form_fields |
|
569 | - * @return array $form_fields |
|
570 | - */ |
|
571 | - public function attachment_fields_to_edit( $form_fields ) { |
|
572 | - return $form_fields; |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * @since 3.4.0 |
|
577 | - * @deprecated 3.5.0 |
|
578 | - * |
|
579 | - * @param array $tabs |
|
580 | - * @return array $tabs |
|
581 | - */ |
|
582 | - public function filter_upload_tabs( $tabs ) { |
|
583 | - return $tabs; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * @since 3.4.0 |
|
588 | - * @deprecated 3.5.0 |
|
589 | - */ |
|
590 | - public function wp_set_background_image() { |
|
591 | - check_ajax_referer( 'custom-background' ); |
|
592 | - |
|
593 | - if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) { |
|
594 | - exit; |
|
595 | - } |
|
596 | - |
|
597 | - $attachment_id = absint( $_POST['attachment_id'] ); |
|
598 | - |
|
599 | - $sizes = array_keys( |
|
600 | - /** This filter is documented in wp-admin/includes/media.php */ |
|
601 | - apply_filters( |
|
602 | - 'image_size_names_choose', |
|
603 | - array( |
|
604 | - 'thumbnail' => __( 'Thumbnail' ), |
|
605 | - 'medium' => __( 'Medium' ), |
|
606 | - 'large' => __( 'Large' ), |
|
607 | - 'full' => __( 'Full Size' ), |
|
608 | - ) |
|
609 | - ) |
|
610 | - ); |
|
611 | - |
|
612 | - $size = 'thumbnail'; |
|
613 | - if ( in_array( $_POST['size'], $sizes, true ) ) { |
|
614 | - $size = esc_attr( $_POST['size'] ); |
|
615 | - } |
|
616 | - |
|
617 | - update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) ); |
|
618 | - |
|
619 | - $url = wp_get_attachment_image_src( $attachment_id, $size ); |
|
620 | - $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); |
|
621 | - set_theme_mod( 'background_image', esc_url_raw( $url[0] ) ); |
|
622 | - set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); |
|
623 | - exit; |
|
624 | - } |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Handle an Image upload for the background image. |
|
484 | + * |
|
485 | + * @since 3.0.0 |
|
486 | + */ |
|
487 | + public function handle_upload() { |
|
488 | + if ( empty( $_FILES ) ) { |
|
489 | + return; |
|
490 | + } |
|
491 | + |
|
492 | + check_admin_referer( 'custom-background-upload', '_wpnonce-custom-background-upload' ); |
|
493 | + |
|
494 | + $overrides = array( 'test_form' => false ); |
|
495 | + |
|
496 | + $uploaded_file = $_FILES['import']; |
|
497 | + $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] ); |
|
498 | + if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { |
|
499 | + wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) ); |
|
500 | + } |
|
501 | + |
|
502 | + $file = wp_handle_upload( $uploaded_file, $overrides ); |
|
503 | + |
|
504 | + if ( isset( $file['error'] ) ) { |
|
505 | + wp_die( $file['error'] ); |
|
506 | + } |
|
507 | + |
|
508 | + $url = $file['url']; |
|
509 | + $type = $file['type']; |
|
510 | + $file = $file['file']; |
|
511 | + $filename = wp_basename( $file ); |
|
512 | + |
|
513 | + // Construct the attachment array. |
|
514 | + $attachment = array( |
|
515 | + 'post_title' => $filename, |
|
516 | + 'post_content' => $url, |
|
517 | + 'post_mime_type' => $type, |
|
518 | + 'guid' => $url, |
|
519 | + 'context' => 'custom-background', |
|
520 | + ); |
|
521 | + |
|
522 | + // Save the data. |
|
523 | + $id = wp_insert_attachment( $attachment, $file ); |
|
524 | + |
|
525 | + // Add the metadata. |
|
526 | + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
|
527 | + update_post_meta( $id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) ); |
|
528 | + |
|
529 | + set_theme_mod( 'background_image', esc_url_raw( $url ) ); |
|
530 | + |
|
531 | + $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); |
|
532 | + set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); |
|
533 | + |
|
534 | + /** This action is documented in wp-admin/includes/class-custom-image-header.php */ |
|
535 | + do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication. |
|
536 | + $this->updated = true; |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Ajax handler for adding custom background context to an attachment. |
|
541 | + * |
|
542 | + * Triggers when the user adds a new background image from the |
|
543 | + * Media Manager. |
|
544 | + * |
|
545 | + * @since 4.1.0 |
|
546 | + */ |
|
547 | + public function ajax_background_add() { |
|
548 | + check_ajax_referer( 'background-add', 'nonce' ); |
|
549 | + |
|
550 | + if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
551 | + wp_send_json_error(); |
|
552 | + } |
|
553 | + |
|
554 | + $attachment_id = absint( $_POST['attachment_id'] ); |
|
555 | + if ( $attachment_id < 1 ) { |
|
556 | + wp_send_json_error(); |
|
557 | + } |
|
558 | + |
|
559 | + update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() ); |
|
560 | + |
|
561 | + wp_send_json_success(); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * @since 3.4.0 |
|
566 | + * @deprecated 3.5.0 |
|
567 | + * |
|
568 | + * @param array $form_fields |
|
569 | + * @return array $form_fields |
|
570 | + */ |
|
571 | + public function attachment_fields_to_edit( $form_fields ) { |
|
572 | + return $form_fields; |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * @since 3.4.0 |
|
577 | + * @deprecated 3.5.0 |
|
578 | + * |
|
579 | + * @param array $tabs |
|
580 | + * @return array $tabs |
|
581 | + */ |
|
582 | + public function filter_upload_tabs( $tabs ) { |
|
583 | + return $tabs; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * @since 3.4.0 |
|
588 | + * @deprecated 3.5.0 |
|
589 | + */ |
|
590 | + public function wp_set_background_image() { |
|
591 | + check_ajax_referer( 'custom-background' ); |
|
592 | + |
|
593 | + if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) { |
|
594 | + exit; |
|
595 | + } |
|
596 | + |
|
597 | + $attachment_id = absint( $_POST['attachment_id'] ); |
|
598 | + |
|
599 | + $sizes = array_keys( |
|
600 | + /** This filter is documented in wp-admin/includes/media.php */ |
|
601 | + apply_filters( |
|
602 | + 'image_size_names_choose', |
|
603 | + array( |
|
604 | + 'thumbnail' => __( 'Thumbnail' ), |
|
605 | + 'medium' => __( 'Medium' ), |
|
606 | + 'large' => __( 'Large' ), |
|
607 | + 'full' => __( 'Full Size' ), |
|
608 | + ) |
|
609 | + ) |
|
610 | + ); |
|
611 | + |
|
612 | + $size = 'thumbnail'; |
|
613 | + if ( in_array( $_POST['size'], $sizes, true ) ) { |
|
614 | + $size = esc_attr( $_POST['size'] ); |
|
615 | + } |
|
616 | + |
|
617 | + update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) ); |
|
618 | + |
|
619 | + $url = wp_get_attachment_image_src( $attachment_id, $size ); |
|
620 | + $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); |
|
621 | + set_theme_mod( 'background_image', esc_url_raw( $url[0] ) ); |
|
622 | + set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); |
|
623 | + exit; |
|
624 | + } |
|
625 | 625 | } |
@@ -17,149 +17,149 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class WP_Themes_List_Table extends WP_List_Table { |
19 | 19 | |
20 | - protected $search_terms = array(); |
|
21 | - public $features = array(); |
|
22 | - |
|
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @since 3.1.0 |
|
27 | - * |
|
28 | - * @see WP_List_Table::__construct() for more information on default arguments. |
|
29 | - * |
|
30 | - * @param array $args An associative array of arguments. |
|
31 | - */ |
|
32 | - public function __construct( $args = array() ) { |
|
33 | - parent::__construct( |
|
34 | - array( |
|
35 | - 'ajax' => true, |
|
36 | - 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
37 | - ) |
|
38 | - ); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function ajax_user_can() { |
|
45 | - // Do not check edit_theme_options here. Ajax calls for available themes require switch_themes. |
|
46 | - return current_user_can( 'switch_themes' ); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - */ |
|
51 | - public function prepare_items() { |
|
52 | - $themes = wp_get_themes( array( 'allowed' => true ) ); |
|
53 | - |
|
54 | - if ( ! empty( $_REQUEST['s'] ) ) { |
|
55 | - $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) ); |
|
56 | - } |
|
57 | - |
|
58 | - if ( ! empty( $_REQUEST['features'] ) ) { |
|
59 | - $this->features = $_REQUEST['features']; |
|
60 | - } |
|
61 | - |
|
62 | - if ( $this->search_terms || $this->features ) { |
|
63 | - foreach ( $themes as $key => $theme ) { |
|
64 | - if ( ! $this->search_theme( $theme ) ) { |
|
65 | - unset( $themes[ $key ] ); |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
69 | - |
|
70 | - unset( $themes[ get_option( 'stylesheet' ) ] ); |
|
71 | - WP_Theme::sort_by_name( $themes ); |
|
72 | - |
|
73 | - $per_page = 36; |
|
74 | - $page = $this->get_pagenum(); |
|
75 | - |
|
76 | - $start = ( $page - 1 ) * $per_page; |
|
77 | - |
|
78 | - $this->items = array_slice( $themes, $start, $per_page, true ); |
|
79 | - |
|
80 | - $this->set_pagination_args( |
|
81 | - array( |
|
82 | - 'total_items' => count( $themes ), |
|
83 | - 'per_page' => $per_page, |
|
84 | - 'infinite_scroll' => true, |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - */ |
|
91 | - public function no_items() { |
|
92 | - if ( $this->search_terms || $this->features ) { |
|
93 | - _e( 'No items found.' ); |
|
94 | - return; |
|
95 | - } |
|
96 | - |
|
97 | - $blog_id = get_current_blog_id(); |
|
98 | - if ( is_multisite() ) { |
|
99 | - if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { |
|
100 | - printf( |
|
101 | - /* translators: 1: URL to Themes tab on Edit Site screen, 2: URL to Add Themes screen. */ |
|
102 | - __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), |
|
103 | - network_admin_url( 'site-themes.php?id=' . $blog_id ), |
|
104 | - network_admin_url( 'theme-install.php' ) |
|
105 | - ); |
|
106 | - |
|
107 | - return; |
|
108 | - } elseif ( current_user_can( 'manage_network_themes' ) ) { |
|
109 | - printf( |
|
110 | - /* translators: %s: URL to Themes tab on Edit Site screen. */ |
|
111 | - __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%s">enable</a> more themes.' ), |
|
112 | - network_admin_url( 'site-themes.php?id=' . $blog_id ) |
|
113 | - ); |
|
114 | - |
|
115 | - return; |
|
116 | - } |
|
117 | - // Else, fallthrough. install_themes doesn't help if you can't enable it. |
|
118 | - } else { |
|
119 | - if ( current_user_can( 'install_themes' ) ) { |
|
120 | - printf( |
|
121 | - /* translators: %s: URL to Add Themes screen. */ |
|
122 | - __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), |
|
123 | - admin_url( 'theme-install.php' ) |
|
124 | - ); |
|
125 | - |
|
126 | - return; |
|
127 | - } |
|
128 | - } |
|
129 | - // Fallthrough. |
|
130 | - printf( |
|
131 | - /* translators: %s: Network title. */ |
|
132 | - __( 'Only the active theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), |
|
133 | - get_site_option( 'site_name' ) |
|
134 | - ); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $which |
|
139 | - */ |
|
140 | - public function tablenav( $which = 'top' ) { |
|
141 | - if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) { |
|
142 | - return; |
|
143 | - } |
|
144 | - ?> |
|
20 | + protected $search_terms = array(); |
|
21 | + public $features = array(); |
|
22 | + |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @since 3.1.0 |
|
27 | + * |
|
28 | + * @see WP_List_Table::__construct() for more information on default arguments. |
|
29 | + * |
|
30 | + * @param array $args An associative array of arguments. |
|
31 | + */ |
|
32 | + public function __construct( $args = array() ) { |
|
33 | + parent::__construct( |
|
34 | + array( |
|
35 | + 'ajax' => true, |
|
36 | + 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
37 | + ) |
|
38 | + ); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function ajax_user_can() { |
|
45 | + // Do not check edit_theme_options here. Ajax calls for available themes require switch_themes. |
|
46 | + return current_user_can( 'switch_themes' ); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + */ |
|
51 | + public function prepare_items() { |
|
52 | + $themes = wp_get_themes( array( 'allowed' => true ) ); |
|
53 | + |
|
54 | + if ( ! empty( $_REQUEST['s'] ) ) { |
|
55 | + $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) ); |
|
56 | + } |
|
57 | + |
|
58 | + if ( ! empty( $_REQUEST['features'] ) ) { |
|
59 | + $this->features = $_REQUEST['features']; |
|
60 | + } |
|
61 | + |
|
62 | + if ( $this->search_terms || $this->features ) { |
|
63 | + foreach ( $themes as $key => $theme ) { |
|
64 | + if ( ! $this->search_theme( $theme ) ) { |
|
65 | + unset( $themes[ $key ] ); |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | + |
|
70 | + unset( $themes[ get_option( 'stylesheet' ) ] ); |
|
71 | + WP_Theme::sort_by_name( $themes ); |
|
72 | + |
|
73 | + $per_page = 36; |
|
74 | + $page = $this->get_pagenum(); |
|
75 | + |
|
76 | + $start = ( $page - 1 ) * $per_page; |
|
77 | + |
|
78 | + $this->items = array_slice( $themes, $start, $per_page, true ); |
|
79 | + |
|
80 | + $this->set_pagination_args( |
|
81 | + array( |
|
82 | + 'total_items' => count( $themes ), |
|
83 | + 'per_page' => $per_page, |
|
84 | + 'infinite_scroll' => true, |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + */ |
|
91 | + public function no_items() { |
|
92 | + if ( $this->search_terms || $this->features ) { |
|
93 | + _e( 'No items found.' ); |
|
94 | + return; |
|
95 | + } |
|
96 | + |
|
97 | + $blog_id = get_current_blog_id(); |
|
98 | + if ( is_multisite() ) { |
|
99 | + if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { |
|
100 | + printf( |
|
101 | + /* translators: 1: URL to Themes tab on Edit Site screen, 2: URL to Add Themes screen. */ |
|
102 | + __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), |
|
103 | + network_admin_url( 'site-themes.php?id=' . $blog_id ), |
|
104 | + network_admin_url( 'theme-install.php' ) |
|
105 | + ); |
|
106 | + |
|
107 | + return; |
|
108 | + } elseif ( current_user_can( 'manage_network_themes' ) ) { |
|
109 | + printf( |
|
110 | + /* translators: %s: URL to Themes tab on Edit Site screen. */ |
|
111 | + __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%s">enable</a> more themes.' ), |
|
112 | + network_admin_url( 'site-themes.php?id=' . $blog_id ) |
|
113 | + ); |
|
114 | + |
|
115 | + return; |
|
116 | + } |
|
117 | + // Else, fallthrough. install_themes doesn't help if you can't enable it. |
|
118 | + } else { |
|
119 | + if ( current_user_can( 'install_themes' ) ) { |
|
120 | + printf( |
|
121 | + /* translators: %s: URL to Add Themes screen. */ |
|
122 | + __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), |
|
123 | + admin_url( 'theme-install.php' ) |
|
124 | + ); |
|
125 | + |
|
126 | + return; |
|
127 | + } |
|
128 | + } |
|
129 | + // Fallthrough. |
|
130 | + printf( |
|
131 | + /* translators: %s: Network title. */ |
|
132 | + __( 'Only the active theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), |
|
133 | + get_site_option( 'site_name' ) |
|
134 | + ); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $which |
|
139 | + */ |
|
140 | + public function tablenav( $which = 'top' ) { |
|
141 | + if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) { |
|
142 | + return; |
|
143 | + } |
|
144 | + ?> |
|
145 | 145 | <div class="tablenav themes <?php echo $which; ?>"> |
146 | 146 | <?php $this->pagination( $which ); ?> |
147 | 147 | <span class="spinner"></span> |
148 | 148 | <br class="clear" /> |
149 | 149 | </div> |
150 | 150 | <?php |
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Displays the themes table. |
|
155 | - * |
|
156 | - * Overrides the parent display() method to provide a different container. |
|
157 | - * |
|
158 | - * @since 3.1.0 |
|
159 | - */ |
|
160 | - public function display() { |
|
161 | - wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); |
|
162 | - ?> |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Displays the themes table. |
|
155 | + * |
|
156 | + * Overrides the parent display() method to provide a different container. |
|
157 | + * |
|
158 | + * @since 3.1.0 |
|
159 | + */ |
|
160 | + public function display() { |
|
161 | + wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); |
|
162 | + ?> |
|
163 | 163 | <?php $this->tablenav( 'top' ); ?> |
164 | 164 | |
165 | 165 | <div id="availablethemes"> |
@@ -168,82 +168,82 @@ discard block |
||
168 | 168 | |
169 | 169 | <?php $this->tablenav( 'bottom' ); ?> |
170 | 170 | <?php |
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - public function get_columns() { |
|
177 | - return array(); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - */ |
|
182 | - public function display_rows_or_placeholder() { |
|
183 | - if ( $this->has_items() ) { |
|
184 | - $this->display_rows(); |
|
185 | - } else { |
|
186 | - echo '<div class="no-items">'; |
|
187 | - $this->no_items(); |
|
188 | - echo '</div>'; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - */ |
|
194 | - public function display_rows() { |
|
195 | - $themes = $this->items; |
|
196 | - |
|
197 | - foreach ( $themes as $theme ) : |
|
198 | - ?> |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + public function get_columns() { |
|
177 | + return array(); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + */ |
|
182 | + public function display_rows_or_placeholder() { |
|
183 | + if ( $this->has_items() ) { |
|
184 | + $this->display_rows(); |
|
185 | + } else { |
|
186 | + echo '<div class="no-items">'; |
|
187 | + $this->no_items(); |
|
188 | + echo '</div>'; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + */ |
|
194 | + public function display_rows() { |
|
195 | + $themes = $this->items; |
|
196 | + |
|
197 | + foreach ( $themes as $theme ) : |
|
198 | + ?> |
|
199 | 199 | <div class="available-theme"> |
200 | 200 | <?php |
201 | 201 | |
202 | - $template = $theme->get_template(); |
|
203 | - $stylesheet = $theme->get_stylesheet(); |
|
204 | - $title = $theme->display( 'Name' ); |
|
205 | - $version = $theme->display( 'Version' ); |
|
206 | - $author = $theme->display( 'Author' ); |
|
207 | - |
|
208 | - $activate_link = wp_nonce_url( 'themes.php?action=activate&template=' . urlencode( $template ) . '&stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); |
|
209 | - |
|
210 | - $actions = array(); |
|
211 | - $actions['activate'] = sprintf( |
|
212 | - '<a href="%s" class="activatelink" title="%s">%s</a>', |
|
213 | - $activate_link, |
|
214 | - /* translators: %s: Theme name. */ |
|
215 | - esc_attr( sprintf( _x( 'Activate “%s”', 'theme' ), $title ) ), |
|
216 | - __( 'Activate' ) |
|
217 | - ); |
|
218 | - |
|
219 | - if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
220 | - $actions['preview'] .= sprintf( |
|
221 | - '<a href="%s" class="load-customize hide-if-no-customize">%s</a>', |
|
222 | - wp_customize_url( $stylesheet ), |
|
223 | - __( 'Live Preview' ) |
|
224 | - ); |
|
225 | - } |
|
226 | - |
|
227 | - if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) { |
|
228 | - $actions['delete'] = sprintf( |
|
229 | - '<a class="submitdelete deletion" href="%s" onclick="return confirm( \'%s\' );">%s</a>', |
|
230 | - wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ), |
|
231 | - /* translators: %s: Theme name. */ |
|
232 | - esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ), |
|
233 | - __( 'Delete' ) |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
|
238 | - $actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' ); |
|
239 | - |
|
240 | - /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
|
241 | - $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, 'all' ); |
|
242 | - $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; |
|
243 | - unset( $actions['delete'] ); |
|
244 | - |
|
245 | - $screenshot = $theme->get_screenshot(); |
|
246 | - ?> |
|
202 | + $template = $theme->get_template(); |
|
203 | + $stylesheet = $theme->get_stylesheet(); |
|
204 | + $title = $theme->display( 'Name' ); |
|
205 | + $version = $theme->display( 'Version' ); |
|
206 | + $author = $theme->display( 'Author' ); |
|
207 | + |
|
208 | + $activate_link = wp_nonce_url( 'themes.php?action=activate&template=' . urlencode( $template ) . '&stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); |
|
209 | + |
|
210 | + $actions = array(); |
|
211 | + $actions['activate'] = sprintf( |
|
212 | + '<a href="%s" class="activatelink" title="%s">%s</a>', |
|
213 | + $activate_link, |
|
214 | + /* translators: %s: Theme name. */ |
|
215 | + esc_attr( sprintf( _x( 'Activate “%s”', 'theme' ), $title ) ), |
|
216 | + __( 'Activate' ) |
|
217 | + ); |
|
218 | + |
|
219 | + if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
|
220 | + $actions['preview'] .= sprintf( |
|
221 | + '<a href="%s" class="load-customize hide-if-no-customize">%s</a>', |
|
222 | + wp_customize_url( $stylesheet ), |
|
223 | + __( 'Live Preview' ) |
|
224 | + ); |
|
225 | + } |
|
226 | + |
|
227 | + if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) { |
|
228 | + $actions['delete'] = sprintf( |
|
229 | + '<a class="submitdelete deletion" href="%s" onclick="return confirm( \'%s\' );">%s</a>', |
|
230 | + wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ), |
|
231 | + /* translators: %s: Theme name. */ |
|
232 | + esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ), |
|
233 | + __( 'Delete' ) |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
|
238 | + $actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' ); |
|
239 | + |
|
240 | + /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ |
|
241 | + $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, 'all' ); |
|
242 | + $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; |
|
243 | + unset( $actions['delete'] ); |
|
244 | + |
|
245 | + $screenshot = $theme->get_screenshot(); |
|
246 | + ?> |
|
247 | 247 | |
248 | 248 | <span class="screenshot hide-if-customize"> |
249 | 249 | <?php if ( $screenshot ) : ?> |
@@ -259,9 +259,9 @@ discard block |
||
259 | 259 | <h3><?php echo $title; ?></h3> |
260 | 260 | <div class="theme-author"> |
261 | 261 | <?php |
262 | - /* translators: %s: Theme author. */ |
|
263 | - printf( __( 'By %s' ), $author ); |
|
264 | - ?> |
|
262 | + /* translators: %s: Theme author. */ |
|
263 | + printf( __( 'By %s' ), $author ); |
|
264 | + ?> |
|
265 | 265 | </div> |
266 | 266 | <div class="action-links"> |
267 | 267 | <ul> |
@@ -279,83 +279,83 @@ discard block |
||
279 | 279 | <p><strong><?php _e( 'Version:' ); ?></strong> <?php echo $version; ?></p> |
280 | 280 | <p><?php echo $theme->display( 'Description' ); ?></p> |
281 | 281 | <?php |
282 | - if ( $theme->parent() ) { |
|
283 | - printf( |
|
284 | - /* translators: 1: Link to documentation on child themes, 2: Name of parent theme. */ |
|
285 | - ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>', |
|
286 | - __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ), |
|
287 | - $theme->parent()->display( 'Name' ) |
|
288 | - ); |
|
289 | - } |
|
290 | - ?> |
|
282 | + if ( $theme->parent() ) { |
|
283 | + printf( |
|
284 | + /* translators: 1: Link to documentation on child themes, 2: Name of parent theme. */ |
|
285 | + ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>', |
|
286 | + __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ), |
|
287 | + $theme->parent()->display( 'Name' ) |
|
288 | + ); |
|
289 | + } |
|
290 | + ?> |
|
291 | 291 | </div> |
292 | 292 | |
293 | 293 | </div> |
294 | 294 | <?php |
295 | - endforeach; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * @param WP_Theme $theme |
|
300 | - * @return bool |
|
301 | - */ |
|
302 | - public function search_theme( $theme ) { |
|
303 | - // Search the features. |
|
304 | - foreach ( $this->features as $word ) { |
|
305 | - if ( ! in_array( $word, $theme->get( 'Tags' ), true ) ) { |
|
306 | - return false; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - // Match all phrases. |
|
311 | - foreach ( $this->search_terms as $word ) { |
|
312 | - if ( in_array( $word, $theme->get( 'Tags' ), true ) ) { |
|
313 | - continue; |
|
314 | - } |
|
315 | - |
|
316 | - foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) { |
|
317 | - // Don't mark up; Do translate. |
|
318 | - if ( false !== stripos( strip_tags( $theme->display( $header, false, true ) ), $word ) ) { |
|
319 | - continue 2; |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - if ( false !== stripos( $theme->get_stylesheet(), $word ) ) { |
|
324 | - continue; |
|
325 | - } |
|
326 | - |
|
327 | - if ( false !== stripos( $theme->get_template(), $word ) ) { |
|
328 | - continue; |
|
329 | - } |
|
330 | - |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - return true; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Send required variables to JavaScript land |
|
339 | - * |
|
340 | - * @since 3.4.0 |
|
341 | - * |
|
342 | - * @param array $extra_args |
|
343 | - */ |
|
344 | - public function _js_vars( $extra_args = array() ) { |
|
345 | - $search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; |
|
346 | - |
|
347 | - $args = array( |
|
348 | - 'search' => $search_string, |
|
349 | - 'features' => $this->features, |
|
350 | - 'paged' => $this->get_pagenum(), |
|
351 | - 'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1, |
|
352 | - ); |
|
353 | - |
|
354 | - if ( is_array( $extra_args ) ) { |
|
355 | - $args = array_merge( $args, $extra_args ); |
|
356 | - } |
|
357 | - |
|
358 | - printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) ); |
|
359 | - parent::_js_vars(); |
|
360 | - } |
|
295 | + endforeach; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * @param WP_Theme $theme |
|
300 | + * @return bool |
|
301 | + */ |
|
302 | + public function search_theme( $theme ) { |
|
303 | + // Search the features. |
|
304 | + foreach ( $this->features as $word ) { |
|
305 | + if ( ! in_array( $word, $theme->get( 'Tags' ), true ) ) { |
|
306 | + return false; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + // Match all phrases. |
|
311 | + foreach ( $this->search_terms as $word ) { |
|
312 | + if ( in_array( $word, $theme->get( 'Tags' ), true ) ) { |
|
313 | + continue; |
|
314 | + } |
|
315 | + |
|
316 | + foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) { |
|
317 | + // Don't mark up; Do translate. |
|
318 | + if ( false !== stripos( strip_tags( $theme->display( $header, false, true ) ), $word ) ) { |
|
319 | + continue 2; |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + if ( false !== stripos( $theme->get_stylesheet(), $word ) ) { |
|
324 | + continue; |
|
325 | + } |
|
326 | + |
|
327 | + if ( false !== stripos( $theme->get_template(), $word ) ) { |
|
328 | + continue; |
|
329 | + } |
|
330 | + |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + return true; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Send required variables to JavaScript land |
|
339 | + * |
|
340 | + * @since 3.4.0 |
|
341 | + * |
|
342 | + * @param array $extra_args |
|
343 | + */ |
|
344 | + public function _js_vars( $extra_args = array() ) { |
|
345 | + $search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; |
|
346 | + |
|
347 | + $args = array( |
|
348 | + 'search' => $search_string, |
|
349 | + 'features' => $this->features, |
|
350 | + 'paged' => $this->get_pagenum(), |
|
351 | + 'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1, |
|
352 | + ); |
|
353 | + |
|
354 | + if ( is_array( $extra_args ) ) { |
|
355 | + $args = array_merge( $args, $extra_args ); |
|
356 | + } |
|
357 | + |
|
358 | + printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) ); |
|
359 | + parent::_js_vars(); |
|
360 | + } |
|
361 | 361 | } |
@@ -14,220 +14,220 @@ |
||
14 | 14 | */ |
15 | 15 | class WP_Site_Icon { |
16 | 16 | |
17 | - /** |
|
18 | - * The minimum size of the site icon. |
|
19 | - * |
|
20 | - * @since 4.3.0 |
|
21 | - * @var int |
|
22 | - */ |
|
23 | - public $min_size = 512; |
|
24 | - |
|
25 | - /** |
|
26 | - * The size to which to crop the image so that we can display it in the UI nicely. |
|
27 | - * |
|
28 | - * @since 4.3.0 |
|
29 | - * @var int |
|
30 | - */ |
|
31 | - public $page_crop = 512; |
|
32 | - |
|
33 | - /** |
|
34 | - * List of site icon sizes. |
|
35 | - * |
|
36 | - * @since 4.3.0 |
|
37 | - * @var int[] |
|
38 | - */ |
|
39 | - public $site_icon_sizes = array( |
|
40 | - /* |
|
17 | + /** |
|
18 | + * The minimum size of the site icon. |
|
19 | + * |
|
20 | + * @since 4.3.0 |
|
21 | + * @var int |
|
22 | + */ |
|
23 | + public $min_size = 512; |
|
24 | + |
|
25 | + /** |
|
26 | + * The size to which to crop the image so that we can display it in the UI nicely. |
|
27 | + * |
|
28 | + * @since 4.3.0 |
|
29 | + * @var int |
|
30 | + */ |
|
31 | + public $page_crop = 512; |
|
32 | + |
|
33 | + /** |
|
34 | + * List of site icon sizes. |
|
35 | + * |
|
36 | + * @since 4.3.0 |
|
37 | + * @var int[] |
|
38 | + */ |
|
39 | + public $site_icon_sizes = array( |
|
40 | + /* |
|
41 | 41 | * Square, medium sized tiles for IE11+. |
42 | 42 | * |
43 | 43 | * See https://msdn.microsoft.com/library/dn455106(v=vs.85).aspx |
44 | 44 | */ |
45 | - 270, |
|
45 | + 270, |
|
46 | 46 | |
47 | - /* |
|
47 | + /* |
|
48 | 48 | * App icon for Android/Chrome. |
49 | 49 | * |
50 | 50 | * @link https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android |
51 | 51 | * @link https://developer.chrome.com/multidevice/android/installtohomescreen |
52 | 52 | */ |
53 | - 192, |
|
53 | + 192, |
|
54 | 54 | |
55 | - /* |
|
55 | + /* |
|
56 | 56 | * App icons up to iPhone 6 Plus. |
57 | 57 | * |
58 | 58 | * See https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html |
59 | 59 | */ |
60 | - 180, |
|
61 | - |
|
62 | - // Our regular Favicon. |
|
63 | - 32, |
|
64 | - ); |
|
65 | - |
|
66 | - /** |
|
67 | - * Registers actions and filters. |
|
68 | - * |
|
69 | - * @since 4.3.0 |
|
70 | - */ |
|
71 | - public function __construct() { |
|
72 | - add_action( 'delete_attachment', array( $this, 'delete_attachment_data' ) ); |
|
73 | - add_filter( 'get_post_metadata', array( $this, 'get_post_metadata' ), 10, 4 ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Creates an attachment 'object'. |
|
78 | - * |
|
79 | - * @since 4.3.0 |
|
80 | - * |
|
81 | - * @param string $cropped Cropped image URL. |
|
82 | - * @param int $parent_attachment_id Attachment ID of parent image. |
|
83 | - * @return array An array with attachment object data. |
|
84 | - */ |
|
85 | - public function create_attachment_object( $cropped, $parent_attachment_id ) { |
|
86 | - $parent = get_post( $parent_attachment_id ); |
|
87 | - $parent_url = wp_get_attachment_url( $parent->ID ); |
|
88 | - $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); |
|
89 | - |
|
90 | - $size = wp_getimagesize( $cropped ); |
|
91 | - $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; |
|
92 | - |
|
93 | - $attachment = array( |
|
94 | - 'ID' => $parent_attachment_id, |
|
95 | - 'post_title' => wp_basename( $cropped ), |
|
96 | - 'post_content' => $url, |
|
97 | - 'post_mime_type' => $image_type, |
|
98 | - 'guid' => $url, |
|
99 | - 'context' => 'site-icon', |
|
100 | - ); |
|
101 | - |
|
102 | - return $attachment; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Inserts an attachment. |
|
107 | - * |
|
108 | - * @since 4.3.0 |
|
109 | - * |
|
110 | - * @param array $attachment An array with attachment object data. |
|
111 | - * @param string $file File path of the attached image. |
|
112 | - * @return int Attachment ID. |
|
113 | - */ |
|
114 | - public function insert_attachment( $attachment, $file ) { |
|
115 | - $attachment_id = wp_insert_attachment( $attachment, $file ); |
|
116 | - $metadata = wp_generate_attachment_metadata( $attachment_id, $file ); |
|
117 | - |
|
118 | - /** |
|
119 | - * Filters the site icon attachment metadata. |
|
120 | - * |
|
121 | - * @since 4.3.0 |
|
122 | - * |
|
123 | - * @see wp_generate_attachment_metadata() |
|
124 | - * |
|
125 | - * @param array $metadata Attachment metadata. |
|
126 | - */ |
|
127 | - $metadata = apply_filters( 'site_icon_attachment_metadata', $metadata ); |
|
128 | - wp_update_attachment_metadata( $attachment_id, $metadata ); |
|
129 | - |
|
130 | - return $attachment_id; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Adds additional sizes to be made when creating the site icon images. |
|
135 | - * |
|
136 | - * @since 4.3.0 |
|
137 | - * |
|
138 | - * @param array[] $sizes Array of arrays containing information for additional sizes. |
|
139 | - * @return array[] Array of arrays containing additional image sizes. |
|
140 | - */ |
|
141 | - public function additional_sizes( $sizes = array() ) { |
|
142 | - $only_crop_sizes = array(); |
|
143 | - |
|
144 | - /** |
|
145 | - * Filters the different dimensions that a site icon is saved in. |
|
146 | - * |
|
147 | - * @since 4.3.0 |
|
148 | - * |
|
149 | - * @param int[] $site_icon_sizes Array of sizes available for the Site Icon. |
|
150 | - */ |
|
151 | - $this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes ); |
|
152 | - |
|
153 | - // Use a natural sort of numbers. |
|
154 | - natsort( $this->site_icon_sizes ); |
|
155 | - $this->site_icon_sizes = array_reverse( $this->site_icon_sizes ); |
|
156 | - |
|
157 | - // Ensure that we only resize the image into sizes that allow cropping. |
|
158 | - foreach ( $sizes as $name => $size_array ) { |
|
159 | - if ( isset( $size_array['crop'] ) ) { |
|
160 | - $only_crop_sizes[ $name ] = $size_array; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - foreach ( $this->site_icon_sizes as $size ) { |
|
165 | - if ( $size < $this->min_size ) { |
|
166 | - $only_crop_sizes[ 'site_icon-' . $size ] = array( |
|
167 | - 'width ' => $size, |
|
168 | - 'height' => $size, |
|
169 | - 'crop' => true, |
|
170 | - ); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - return $only_crop_sizes; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Adds Site Icon sizes to the array of image sizes on demand. |
|
179 | - * |
|
180 | - * @since 4.3.0 |
|
181 | - * |
|
182 | - * @param string[] $sizes Array of image size names. |
|
183 | - * @return string[] Array of image size names. |
|
184 | - */ |
|
185 | - public function intermediate_image_sizes( $sizes = array() ) { |
|
186 | - /** This filter is documented in wp-admin/includes/class-wp-site-icon.php */ |
|
187 | - $this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes ); |
|
188 | - foreach ( $this->site_icon_sizes as $size ) { |
|
189 | - $sizes[] = 'site_icon-' . $size; |
|
190 | - } |
|
191 | - |
|
192 | - return $sizes; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Deletes the Site Icon when the image file is deleted. |
|
197 | - * |
|
198 | - * @since 4.3.0 |
|
199 | - * |
|
200 | - * @param int $post_id Attachment ID. |
|
201 | - */ |
|
202 | - public function delete_attachment_data( $post_id ) { |
|
203 | - $site_icon_id = get_option( 'site_icon' ); |
|
204 | - |
|
205 | - if ( $site_icon_id && $post_id == $site_icon_id ) { |
|
206 | - delete_option( 'site_icon' ); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Adds custom image sizes when meta data for an image is requested, that happens to be used as Site Icon. |
|
212 | - * |
|
213 | - * @since 4.3.0 |
|
214 | - * |
|
215 | - * @param null|array|string $value The value get_metadata() should return a single metadata value, or an |
|
216 | - * array of values. |
|
217 | - * @param int $post_id Post ID. |
|
218 | - * @param string $meta_key Meta key. |
|
219 | - * @param bool $single Whether to return only the first value of the specified `$meta_key`. |
|
220 | - * @return array|null|string The attachment metadata value, array of values, or null. |
|
221 | - */ |
|
222 | - public function get_post_metadata( $value, $post_id, $meta_key, $single ) { |
|
223 | - if ( $single && '_wp_attachment_backup_sizes' === $meta_key ) { |
|
224 | - $site_icon_id = get_option( 'site_icon' ); |
|
225 | - |
|
226 | - if ( $post_id == $site_icon_id ) { |
|
227 | - add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) ); |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - return $value; |
|
232 | - } |
|
60 | + 180, |
|
61 | + |
|
62 | + // Our regular Favicon. |
|
63 | + 32, |
|
64 | + ); |
|
65 | + |
|
66 | + /** |
|
67 | + * Registers actions and filters. |
|
68 | + * |
|
69 | + * @since 4.3.0 |
|
70 | + */ |
|
71 | + public function __construct() { |
|
72 | + add_action( 'delete_attachment', array( $this, 'delete_attachment_data' ) ); |
|
73 | + add_filter( 'get_post_metadata', array( $this, 'get_post_metadata' ), 10, 4 ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Creates an attachment 'object'. |
|
78 | + * |
|
79 | + * @since 4.3.0 |
|
80 | + * |
|
81 | + * @param string $cropped Cropped image URL. |
|
82 | + * @param int $parent_attachment_id Attachment ID of parent image. |
|
83 | + * @return array An array with attachment object data. |
|
84 | + */ |
|
85 | + public function create_attachment_object( $cropped, $parent_attachment_id ) { |
|
86 | + $parent = get_post( $parent_attachment_id ); |
|
87 | + $parent_url = wp_get_attachment_url( $parent->ID ); |
|
88 | + $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); |
|
89 | + |
|
90 | + $size = wp_getimagesize( $cropped ); |
|
91 | + $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; |
|
92 | + |
|
93 | + $attachment = array( |
|
94 | + 'ID' => $parent_attachment_id, |
|
95 | + 'post_title' => wp_basename( $cropped ), |
|
96 | + 'post_content' => $url, |
|
97 | + 'post_mime_type' => $image_type, |
|
98 | + 'guid' => $url, |
|
99 | + 'context' => 'site-icon', |
|
100 | + ); |
|
101 | + |
|
102 | + return $attachment; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Inserts an attachment. |
|
107 | + * |
|
108 | + * @since 4.3.0 |
|
109 | + * |
|
110 | + * @param array $attachment An array with attachment object data. |
|
111 | + * @param string $file File path of the attached image. |
|
112 | + * @return int Attachment ID. |
|
113 | + */ |
|
114 | + public function insert_attachment( $attachment, $file ) { |
|
115 | + $attachment_id = wp_insert_attachment( $attachment, $file ); |
|
116 | + $metadata = wp_generate_attachment_metadata( $attachment_id, $file ); |
|
117 | + |
|
118 | + /** |
|
119 | + * Filters the site icon attachment metadata. |
|
120 | + * |
|
121 | + * @since 4.3.0 |
|
122 | + * |
|
123 | + * @see wp_generate_attachment_metadata() |
|
124 | + * |
|
125 | + * @param array $metadata Attachment metadata. |
|
126 | + */ |
|
127 | + $metadata = apply_filters( 'site_icon_attachment_metadata', $metadata ); |
|
128 | + wp_update_attachment_metadata( $attachment_id, $metadata ); |
|
129 | + |
|
130 | + return $attachment_id; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Adds additional sizes to be made when creating the site icon images. |
|
135 | + * |
|
136 | + * @since 4.3.0 |
|
137 | + * |
|
138 | + * @param array[] $sizes Array of arrays containing information for additional sizes. |
|
139 | + * @return array[] Array of arrays containing additional image sizes. |
|
140 | + */ |
|
141 | + public function additional_sizes( $sizes = array() ) { |
|
142 | + $only_crop_sizes = array(); |
|
143 | + |
|
144 | + /** |
|
145 | + * Filters the different dimensions that a site icon is saved in. |
|
146 | + * |
|
147 | + * @since 4.3.0 |
|
148 | + * |
|
149 | + * @param int[] $site_icon_sizes Array of sizes available for the Site Icon. |
|
150 | + */ |
|
151 | + $this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes ); |
|
152 | + |
|
153 | + // Use a natural sort of numbers. |
|
154 | + natsort( $this->site_icon_sizes ); |
|
155 | + $this->site_icon_sizes = array_reverse( $this->site_icon_sizes ); |
|
156 | + |
|
157 | + // Ensure that we only resize the image into sizes that allow cropping. |
|
158 | + foreach ( $sizes as $name => $size_array ) { |
|
159 | + if ( isset( $size_array['crop'] ) ) { |
|
160 | + $only_crop_sizes[ $name ] = $size_array; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + foreach ( $this->site_icon_sizes as $size ) { |
|
165 | + if ( $size < $this->min_size ) { |
|
166 | + $only_crop_sizes[ 'site_icon-' . $size ] = array( |
|
167 | + 'width ' => $size, |
|
168 | + 'height' => $size, |
|
169 | + 'crop' => true, |
|
170 | + ); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + return $only_crop_sizes; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Adds Site Icon sizes to the array of image sizes on demand. |
|
179 | + * |
|
180 | + * @since 4.3.0 |
|
181 | + * |
|
182 | + * @param string[] $sizes Array of image size names. |
|
183 | + * @return string[] Array of image size names. |
|
184 | + */ |
|
185 | + public function intermediate_image_sizes( $sizes = array() ) { |
|
186 | + /** This filter is documented in wp-admin/includes/class-wp-site-icon.php */ |
|
187 | + $this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes ); |
|
188 | + foreach ( $this->site_icon_sizes as $size ) { |
|
189 | + $sizes[] = 'site_icon-' . $size; |
|
190 | + } |
|
191 | + |
|
192 | + return $sizes; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Deletes the Site Icon when the image file is deleted. |
|
197 | + * |
|
198 | + * @since 4.3.0 |
|
199 | + * |
|
200 | + * @param int $post_id Attachment ID. |
|
201 | + */ |
|
202 | + public function delete_attachment_data( $post_id ) { |
|
203 | + $site_icon_id = get_option( 'site_icon' ); |
|
204 | + |
|
205 | + if ( $site_icon_id && $post_id == $site_icon_id ) { |
|
206 | + delete_option( 'site_icon' ); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Adds custom image sizes when meta data for an image is requested, that happens to be used as Site Icon. |
|
212 | + * |
|
213 | + * @since 4.3.0 |
|
214 | + * |
|
215 | + * @param null|array|string $value The value get_metadata() should return a single metadata value, or an |
|
216 | + * array of values. |
|
217 | + * @param int $post_id Post ID. |
|
218 | + * @param string $meta_key Meta key. |
|
219 | + * @param bool $single Whether to return only the first value of the specified `$meta_key`. |
|
220 | + * @return array|null|string The attachment metadata value, array of values, or null. |
|
221 | + */ |
|
222 | + public function get_post_metadata( $value, $post_id, $meta_key, $single ) { |
|
223 | + if ( $single && '_wp_attachment_backup_sizes' === $meta_key ) { |
|
224 | + $site_icon_id = get_option( 'site_icon' ); |
|
225 | + |
|
226 | + if ( $post_id == $site_icon_id ) { |
|
227 | + add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) ); |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + return $value; |
|
232 | + } |
|
233 | 233 | } |