PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | json-endpoints/class.wpcom-json-api-menus-v1-1-endpoint.php +34 -3 12.5.2 → 16.3-a.7 View file →
@@ -1,8 +1,12 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 3 // phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
4 4
5 +if ( ! defined( 'ABSPATH' ) ) {
6 + exit( 0 );
7 +}
8 +
5 9 /**
6 10 * Menus abstract endpoint class.
7 11 */
8 12 abstract class WPCOM_JSON_API_Menus_Abstract_Endpoint extends WPCOM_JSON_API_Endpoint {
@@ -101,8 +105,22 @@
101 105 */
102 106 protected $filters = array();
103 107
104 108 /**
109 + * False if $menus was an array on construct, true otherwise.
110 + *
111 + * @var bool
112 + */
113 + public $is_single_menu;
114 +
115 + /**
116 + * A menu or array of menus.
117 + *
118 + * @var mixed
119 + */
120 + public $menus;
121 +
122 + /**
105 123 * Class constructor.
106 124 *
107 125 * @param mixed $menus - a menu or list of menus.
108 126 */
@@ -765,9 +783,8 @@
765 783 return array_key_exists( $location_name, get_registered_nav_menus() ) ||
766 784 array_key_exists( $location_name, $existing_locations ) ||
767 785 in_array( $location_name, $widget_location_names, true );
768 786 }
769 -
770 787 }
771 788
772 789 new WPCOM_JSON_API_Menus_New_Menu_Endpoint(
773 790 array(
@@ -796,8 +813,10 @@
796 813 );
797 814
798 815 /**
799 816 * New menu endpoint class.
817 + *
818 + * @phan-constructor-used-for-side-effects
800 819 */
801 820 class WPCOM_JSON_API_Menus_New_Menu_Endpoint extends WPCOM_JSON_API_Menus_Abstract_Endpoint {
802 821
803 822 /**
@@ -860,8 +879,10 @@
860 879 );
861 880
862 881 /**
863 882 * Update menu endpoint class.
883 + *
884 + * @phan-constructor-used-for-side-effects
864 885 */
865 886 class WPCOM_JSON_API_Menus_Update_Menu_Endpoint extends WPCOM_JSON_API_Menus_Abstract_Endpoint {
866 887
867 888 /**
@@ -892,9 +913,9 @@
892 913 }
893 914 $data = $data[0];
894 915
895 916 // Avoid special-case handling of an unset 'items' field in empty menus
896 - $data['items'] = isset( $data['items'] ) ? $data['items'] : array();
917 + $data['items'] ??= array();
897 918
898 919 $data = $this->create_new_items( $data, $menu_id );
899 920
900 921 $result = wp_update_nav_menu_object( $menu_id, array( 'menu-name' => $data['menu-name'] ) );
@@ -908,9 +929,9 @@
908 929 return $delete_status;
909 930 }
910 931
911 932 foreach ( $data['items'] as $item ) {
912 - $item_id = isset( $item['menu-item-db-id'] ) ? $item['menu-item-db-id'] : 0;
933 + $item_id = $item['menu-item-db-id'] ?? 0;
913 934 $result = wp_update_nav_menu_item( $menu_id, $item_id, $item );
914 935 if ( is_wp_error( $result ) ) {
915 936 return $result;
916 937 }
@@ -1023,8 +1044,10 @@
1023 1044 );
1024 1045
1025 1046 /**
1026 1047 * List menus endpoint class.
1048 + *
1049 + * @phan-constructor-used-for-side-effects
1027 1050 */
1028 1051 class WPCOM_JSON_API_Menus_List_Menus_Endpoint extends WPCOM_JSON_API_Menus_Abstract_Endpoint {
1029 1052
1030 1053 /**
@@ -1097,8 +1120,10 @@
1097 1120 );
1098 1121
1099 1122 /**
1100 1123 * Get menu endpoint class.
1124 + *
1125 + * @phan-constructor-used-for-side-effects
1101 1126 */
1102 1127 class WPCOM_JSON_API_Menus_Get_Menu_Endpoint extends WPCOM_JSON_API_Menus_Abstract_Endpoint {
1103 1128
1104 1129 /**
@@ -1126,8 +1151,12 @@
1126 1151 if ( is_wp_error( $menu ) ) {
1127 1152 return $menu;
1128 1153 }
1129 1154
1155 + if ( ! $menu instanceof WP_Term ) {
1156 + return new WP_Error( 'menu-not-found', 'Menu not found.', 404 );
1157 + }
1158 +
1130 1159 $items = wp_get_nav_menu_items( $menu_id, array( 'update_post_term_cache' => false ) );
1131 1160
1132 1161 if ( is_wp_error( $items ) ) {
1133 1162 return $items;
@@ -1161,8 +1190,10 @@
1161 1190 );
1162 1191
1163 1192 /**
1164 1193 * Delete menu endpoint class.
1194 + *
1195 + * @phan-constructor-used-for-side-effects
1165 1196 */
1166 1197 class WPCOM_JSON_API_Menus_Delete_Menu_Endpoint extends WPCOM_JSON_API_Menus_Abstract_Endpoint {
1167 1198
1168 1199 /**