129 /** |
129 /** |
130 * Performs the post_type and taxonomy queries for loading available menu items. |
130 * Performs the post_type and taxonomy queries for loading available menu items. |
131 * |
131 * |
132 * @since 4.3.0 |
132 * @since 4.3.0 |
133 * |
133 * |
134 * @param string $type Optional. Accepts any custom object type and has built-in support for |
134 * @param string $object_type Optional. Accepts any custom object type and has built-in support for |
135 * 'post_type' and 'taxonomy'. Default is 'post_type'. |
135 * 'post_type' and 'taxonomy'. Default is 'post_type'. |
136 * @param string $object Optional. Accepts any registered taxonomy or post type name. Default is 'page'. |
136 * @param string $object_name Optional. Accepts any registered taxonomy or post type name. Default is 'page'. |
137 * @param int $page Optional. The page number used to generate the query offset. Default is '0'. |
137 * @param int $page Optional. The page number used to generate the query offset. Default is '0'. |
138 * @return array|WP_Error An array of menu items on success, a WP_Error object on failure. |
138 * @return array|WP_Error An array of menu items on success, a WP_Error object on failure. |
139 */ |
139 */ |
140 public function load_available_items_query( $type = 'post_type', $object = 'page', $page = 0 ) { |
140 public function load_available_items_query( $object_type = 'post_type', $object_name = 'page', $page = 0 ) { |
141 $items = array(); |
141 $items = array(); |
142 |
142 |
143 if ( 'post_type' === $type ) { |
143 if ( 'post_type' === $object_type ) { |
144 $post_type = get_post_type_object( $object ); |
144 $post_type = get_post_type_object( $object_name ); |
145 if ( ! $post_type ) { |
145 if ( ! $post_type ) { |
146 return new WP_Error( 'nav_menus_invalid_post_type' ); |
146 return new WP_Error( 'nav_menus_invalid_post_type' ); |
147 } |
147 } |
148 |
148 |
149 /* |
149 /* |
150 * If we're dealing with pages, let's prioritize the Front Page, |
150 * If we're dealing with pages, let's prioritize the Front Page, |
151 * Posts Page and Privacy Policy Page at the top of the list. |
151 * Posts Page and Privacy Policy Page at the top of the list. |
152 */ |
152 */ |
153 $important_pages = array(); |
153 $important_pages = array(); |
154 $suppress_page_ids = array(); |
154 $suppress_page_ids = array(); |
155 if ( 0 === $page && 'page' === $object ) { |
155 if ( 0 === $page && 'page' === $object_name ) { |
156 // Insert Front Page or custom "Home" link. |
156 // Insert Front Page or custom "Home" link. |
157 $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; |
157 $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; |
158 if ( ! empty( $front_page ) ) { |
158 if ( ! empty( $front_page ) ) { |
159 $front_page_obj = get_post( $front_page ); |
159 $front_page_obj = get_post( $front_page ); |
160 $important_pages[] = $front_page_obj; |
160 $important_pages[] = $front_page_obj; |
186 if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { |
186 if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { |
187 $important_pages[] = $privacy_policy_page; |
187 $important_pages[] = $privacy_policy_page; |
188 $suppress_page_ids[] = $privacy_policy_page->ID; |
188 $suppress_page_ids[] = $privacy_policy_page->ID; |
189 } |
189 } |
190 } |
190 } |
191 } elseif ( 'post' !== $object && 0 === $page && $post_type->has_archive ) { |
191 } elseif ( 'post' !== $object_name && 0 === $page && $post_type->has_archive ) { |
192 // Add a post type archive link. |
192 // Add a post type archive link. |
193 $items[] = array( |
193 $items[] = array( |
194 'id' => $object . '-archive', |
194 'id' => $object_name . '-archive', |
195 'title' => $post_type->labels->archives, |
195 'title' => $post_type->labels->archives, |
196 'type' => 'post_type_archive', |
196 'type' => 'post_type_archive', |
197 'type_label' => __( 'Post Type Archive' ), |
197 'type_label' => __( 'Post Type Archive' ), |
198 'object' => $object, |
198 'object' => $object_name, |
199 'url' => get_post_type_archive_link( $object ), |
199 'url' => get_post_type_archive_link( $object_name ), |
200 ); |
200 ); |
201 } |
201 } |
202 |
202 |
203 // Prepend posts with nav_menus_created_posts on first page. |
203 // Prepend posts with nav_menus_created_posts on first page. |
204 $posts = array(); |
204 $posts = array(); |
214 $args = array( |
214 $args = array( |
215 'numberposts' => 10, |
215 'numberposts' => 10, |
216 'offset' => 10 * $page, |
216 'offset' => 10 * $page, |
217 'orderby' => 'date', |
217 'orderby' => 'date', |
218 'order' => 'DESC', |
218 'order' => 'DESC', |
219 'post_type' => $object, |
219 'post_type' => $object_name, |
220 ); |
220 ); |
221 |
221 |
222 // Add suppression array to arguments for get_posts. |
222 // Add suppression array to arguments for get_posts. |
223 if ( ! empty( $suppress_page_ids ) ) { |
223 if ( ! empty( $suppress_page_ids ) ) { |
224 $args['post__not_in'] = $suppress_page_ids; |
224 $args['post__not_in'] = $suppress_page_ids; |
251 'object' => $post->post_type, |
251 'object' => $post->post_type, |
252 'object_id' => (int) $post->ID, |
252 'object_id' => (int) $post->ID, |
253 'url' => get_permalink( (int) $post->ID ), |
253 'url' => get_permalink( (int) $post->ID ), |
254 ); |
254 ); |
255 } |
255 } |
256 } elseif ( 'taxonomy' === $type ) { |
256 } elseif ( 'taxonomy' === $object_type ) { |
257 $terms = get_terms( |
257 $terms = get_terms( |
258 array( |
258 array( |
259 'taxonomy' => $object, |
259 'taxonomy' => $object_name, |
260 'child_of' => 0, |
260 'child_of' => 0, |
261 'exclude' => '', |
261 'exclude' => '', |
262 'hide_empty' => false, |
262 'hide_empty' => false, |
263 'hierarchical' => 1, |
263 'hierarchical' => 1, |
264 'include' => '', |
264 'include' => '', |
290 /** |
290 /** |
291 * Filters the available menu items. |
291 * Filters the available menu items. |
292 * |
292 * |
293 * @since 4.3.0 |
293 * @since 4.3.0 |
294 * |
294 * |
295 * @param array $items The array of menu items. |
295 * @param array $items The array of menu items. |
296 * @param string $type The object type. |
296 * @param string $object_type The object type. |
297 * @param string $object The object name. |
297 * @param string $object_name The object name. |
298 * @param int $page The current page number. |
298 * @param int $page The current page number. |
299 */ |
299 */ |
300 $items = apply_filters( 'customize_nav_menu_available_items', $items, $type, $object, $page ); |
300 $items = apply_filters( 'customize_nav_menu_available_items', $items, $object_type, $object_name, $page ); |
301 |
301 |
302 return $items; |
302 return $items; |
303 } |
303 } |
304 |
304 |
305 /** |
305 /** |
876 public function intval_base10( $value ) { |
876 public function intval_base10( $value ) { |
877 return intval( $value, 10 ); |
877 return intval( $value, 10 ); |
878 } |
878 } |
879 |
879 |
880 /** |
880 /** |
881 * Return an array of all the available item types. |
881 * Returns an array of all the available item types. |
882 * |
882 * |
883 * @since 4.3.0 |
883 * @since 4.3.0 |
884 * @since 4.7.0 Each array item now includes a `$type_label` in addition to `$title`, `$type`, and `$object`. |
884 * @since 4.7.0 Each array item now includes a `$type_label` in addition to `$title`, `$type`, and `$object`. |
885 * |
885 * |
886 * @return array The available menu item types. |
886 * @return array The available menu item types. |
1117 <p class="customize-control-description customize-section-title-menu_locations-description">{{ data.l10n.locationsDescription }}</p> |
1117 <p class="customize-control-description customize-section-title-menu_locations-description">{{ data.l10n.locationsDescription }}</p> |
1118 </script> |
1118 </script> |
1119 |
1119 |
1120 <script type="text/html" id="tmpl-nav-menu-create-menu-section-title"> |
1120 <script type="text/html" id="tmpl-nav-menu-create-menu-section-title"> |
1121 <p class="add-new-menu-notice"> |
1121 <p class="add-new-menu-notice"> |
1122 <?php _e( 'It doesn’t look like your site has any menus yet. Want to build one? Click the button to start.' ); ?> |
1122 <?php _e( 'It does not look like your site has any menus yet. Want to build one? Click the button to start.' ); ?> |
1123 </p> |
1123 </p> |
1124 <p class="add-new-menu-notice"> |
1124 <p class="add-new-menu-notice"> |
1125 <?php _e( 'You’ll create a menu, assign it a location, and add menu items like links to pages and categories. If your theme has multiple menu areas, you might need to create more than one.' ); ?> |
1125 <?php _e( 'You’ll create a menu, assign it a location, and add menu items like links to pages and categories. If your theme has multiple menu areas, you might need to create more than one.' ); ?> |
1126 </p> |
1126 </p> |
1127 <h3> |
1127 <h3> |
1190 </div><!-- #available-menu-items --> |
1190 </div><!-- #available-menu-items --> |
1191 <?php |
1191 <?php |
1192 } |
1192 } |
1193 |
1193 |
1194 /** |
1194 /** |
1195 * Print the markup for new menu items. |
1195 * Prints the markup for new menu items. |
1196 * |
1196 * |
1197 * To be used in the template #available-menu-items. |
1197 * To be used in the template #available-menu-items. |
1198 * |
1198 * |
1199 * @since 4.7.0 |
1199 * @since 4.7.0 |
1200 * |
1200 * |
1201 * @param array $available_item_type Menu item data to output, including title, type, and label. |
1201 * @param array $available_item_type Menu item data to output, including title, type, and label. |
1202 * @return void |
|
1203 */ |
1202 */ |
1204 protected function print_post_type_container( $available_item_type ) { |
1203 protected function print_post_type_container( $available_item_type ) { |
1205 $id = sprintf( 'available-menu-items-%s-%s', $available_item_type['type'], $available_item_type['object'] ); |
1204 $id = sprintf( 'available-menu-items-%s-%s', $available_item_type['type'], $available_item_type['object'] ); |
1206 ?> |
1205 ?> |
1207 <div id="<?php echo esc_attr( $id ); ?>" class="accordion-section"> |
1206 <div id="<?php echo esc_attr( $id ); ?>" class="accordion-section"> |
1328 add_filter( 'wp_footer', array( $this, 'export_preview_data' ), 1 ); |
1325 add_filter( 'wp_footer', array( $this, 'export_preview_data' ), 1 ); |
1329 add_filter( 'customize_render_partials_response', array( $this, 'export_partial_rendered_nav_menu_instances' ) ); |
1326 add_filter( 'customize_render_partials_response', array( $this, 'export_partial_rendered_nav_menu_instances' ) ); |
1330 } |
1327 } |
1331 |
1328 |
1332 /** |
1329 /** |
1333 * Make the auto-draft status protected so that it can be queried. |
1330 * Makes the auto-draft status protected so that it can be queried. |
1334 * |
1331 * |
1335 * @since 4.7.0 |
1332 * @since 4.7.0 |
1336 * |
1333 * |
1337 * @global array $wp_post_statuses List of post statuses. |
1334 * @global stdClass[] $wp_post_statuses List of post statuses. |
1338 */ |
1335 */ |
1339 public function make_auto_draft_status_previewable() { |
1336 public function make_auto_draft_status_previewable() { |
1340 global $wp_post_statuses; |
1337 global $wp_post_statuses; |
1341 $wp_post_statuses['auto-draft']->protected = true; |
1338 $wp_post_statuses['auto-draft']->protected = true; |
1342 } |
1339 } |
1343 |
1340 |
1344 /** |
1341 /** |
1345 * Sanitize post IDs for posts created for nav menu items to be published. |
1342 * Sanitizes post IDs for posts created for nav menu items to be published. |
1346 * |
1343 * |
1347 * @since 4.7.0 |
1344 * @since 4.7.0 |
1348 * |
1345 * |
1349 * @param array $value Post IDs. |
1346 * @param array $value Post IDs. |
1350 * @return array Post IDs. |
1347 * @return array Post IDs. |
1370 } |
1367 } |
1371 return $post_ids; |
1368 return $post_ids; |
1372 } |
1369 } |
1373 |
1370 |
1374 /** |
1371 /** |
1375 * Publish the auto-draft posts that were created for nav menu items. |
1372 * Publishes the auto-draft posts that were created for nav menu items. |
1376 * |
1373 * |
1377 * The post IDs will have been sanitized by already by |
1374 * The post IDs will have been sanitized by already by |
1378 * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to |
1375 * `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to |
1379 * remove any post IDs for which the user cannot publish or for which the |
1376 * remove any post IDs for which the user cannot publish or for which the |
1380 * post is not an auto-draft. |
1377 * post is not an auto-draft. |
1515 public function hash_nav_menu_args( $args ) { |
1512 public function hash_nav_menu_args( $args ) { |
1516 return wp_hash( serialize( $args ) ); |
1513 return wp_hash( serialize( $args ) ); |
1517 } |
1514 } |
1518 |
1515 |
1519 /** |
1516 /** |
1520 * Enqueue scripts for the Customizer preview. |
1517 * Enqueues scripts for the Customizer preview. |
1521 * |
1518 * |
1522 * @since 4.3.0 |
1519 * @since 4.3.0 |
1523 */ |
1520 */ |
1524 public function customize_preview_enqueue_deps() { |
1521 public function customize_preview_enqueue_deps() { |
1525 wp_enqueue_script( 'customize-preview-nav-menus' ); // Note that we have overridden this. |
1522 wp_enqueue_script( 'customize-preview-nav-menus' ); // Note that we have overridden this. |