GC_Customize_Nav_Menus::ajax_load_available_items()
最后更新于:2021-11-27 03:40:23
GC_Customize_Nav_Menus::ajax_load_available_items()Ajax handler for loading available menu items.
源文件
文件: gc-includes/class-gc-customize-nav-menus.php
public function ajax_load_available_items() {
check_ajax_referer( 'customize-menus', 'customize-menus-nonce' );
if ( ! current_user_can( 'edit_theme_options' ) ) {
gc_die( -1 );
}
$all_items = array();
$item_types = array();
if ( isset( $_POST['item_types'] ) && is_array( $_POST['item_types'] ) ) {
$item_types = gc_unslash( $_POST['item_types'] );
} elseif ( isset( $_POST['type'] ) && isset( $_POST['object'] ) ) { // Back compat.
$item_types[] = array(
'type' => gc_unslash( $_POST['type'] ),
'object' => gc_unslash( $_POST['object'] ),
'page' => empty( $_POST['page'] ) ? 0 : absint( $_POST['page'] ),
);
} else {
gc_send_json_error( 'nav_menus_missing_type_or_object_parameter' );
}
foreach ( $item_types as $item_type ) {
if ( empty( $item_type['type'] ) || empty( $item_type['object'] ) ) {
gc_send_json_error( 'nav_menus_missing_type_or_object_parameter' );
}
$type = sanitize_key( $item_type['type'] );
$object = sanitize_key( $item_type['object'] );
$page = empty( $item_type['page'] ) ? 0 : absint( $item_type['page'] );
$items = $this->load_available_items_query( $type, $object, $page );
if ( is_gc_error( $items ) ) {
gc_send_json_error( $items->get_error_code() );
}
$all_items[ $item_type['type'] . ':' . $item_type['object'] ] = $items;
}
gc_send_json_success( array( 'items' => $all_items ) );
}