Changeset 3369890
- Timestamp:
- 09/29/2025 04:36:09 PM (3 months ago)
- Location:
- wpgetapi
- Files:
-
- 6 edited
- 1 copied
-
tags/2.25.4 (copied) (copied from wpgetapi/trunk)
-
tags/2.25.4/includes/class-wpgetapi-admin-options.php (modified) (4 diffs)
-
tags/2.25.4/readme.txt (modified) (3 diffs)
-
tags/2.25.4/wpgetapi.php (modified) (2 diffs)
-
trunk/includes/class-wpgetapi-admin-options.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/wpgetapi.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wpgetapi/tags/2.25.4/includes/class-wpgetapi-admin-options.php
r3339581 r3369890 104 104 105 105 add_action( 'wp_ajax_wpgetapi_notice_dismiss', array( $this, 'wpgetapi_notice_dismiss_handler' ) ); 106 107 add_action( 'cmb2_options-page_process_fields_wpgetapi_setup', array( $this, 'cleanup_wpgetapi_removed_api_options' ), 10, 2 ); 106 108 } 107 109 … … 190 192 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ), 191 193 ); 194 195 // Hook to clean up data when API endpoints are removed. 196 add_action( 'cmb2_options-page_process_fields_wpgetapi_' . $api['id'], array( $this, 'cleanup_removed_api_endpoints' ), 10, 2 ); 192 197 193 198 } … … 727 732 } 728 733 729 $new_data = json_decode( stripslashes( $textarea ), true );734 $new_data = json_decode( $textarea, true ); 730 735 if ( ! isset( $new_data['endpoints'] ) ) { 731 736 echo 'No endpoints found.'; … … 1293 1298 ); 1294 1299 } 1300 1301 /** 1302 * Fires before fields have been processed/saved. 1303 * 1304 * Compares the existing API setup with the new one. If any APIs have been removed, 1305 * their associated endpoint options are deleted from the database. 1306 * 1307 * @link https://cmb2.io/api/source-class-CMB2.html#850 1308 * 1309 * @param array $cmb The CMB2 object. 1310 * @param int $object_id The ID of the current object. 1311 */ 1312 public function cleanup_wpgetapi_removed_api_options( $cmb, $object_id ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- $object_id is required by the action hook. 1313 $new_setup = $cmb->data_to_save; 1314 $old_setup = get_option( 'wpgetapi_setup' ); 1315 1316 $old_api_ids = isset( $old_setup['apis'] ) ? array_column( $old_setup['apis'], 'id' ) : array(); 1317 $new_api_ids = isset( $new_setup['apis'] ) ? array_column( $new_setup['apis'], 'id' ) : array(); 1318 1319 $removed_api_ids = array_diff( $old_api_ids, $new_api_ids ); 1320 1321 if ( empty( $removed_api_ids ) ) { 1322 return; 1323 } 1324 1325 foreach ( $removed_api_ids as $removed_api_id ) { 1326 /** 1327 * Fires before an API setup is removed from wpgetapi_setup. 1328 * 1329 * This action allows add-on plugins to clean up their own data or options 1330 * associated with the removed API or its endpoints, before the core plugin 1331 * deletes its related option. 1332 * 1333 * @param string $api_id The ID of the API that is being removed. 1334 */ 1335 do_action( 'wpgetapi_api_before_removed', $removed_api_id ); 1336 1337 delete_option( 'wpgetapi_' . $removed_api_id ); 1338 } 1339 } 1340 1341 /** 1342 * Fires before fields have been processed/saved. 1343 * 1344 * This compares the existing API endpoints with the newly saved ones. 1345 * If any endpoints have been removed, it fires a hook so that add-on 1346 * plugins can clean up their own data, before the core plugin 1347 * deletes its related options. 1348 * 1349 * @link https://cmb2.io/api//source-class-CMB2.html#850 1350 * 1351 * @param array $cmb The CMB2 object. 1352 * @param int $object_id The ID of the current CMB2 options object. 1353 * @return void 1354 */ 1355 public function cleanup_removed_api_endpoints( $cmb, $object_id ) { 1356 $new_endpoints = isset( $cmb->data_to_save['endpoints'] ) ? $cmb->data_to_save['endpoints'] : array(); 1357 $api_id = str_replace( 'wpgetapi_', '', $object_id ); 1358 $old_api_setup = get_option( $object_id ); 1359 1360 if ( empty( $old_api_setup ) || ! isset( $old_api_setup['endpoints'] ) ) { 1361 return; 1362 } 1363 1364 $new_endpoint_ids = array_column( $new_endpoints, 'id' ); 1365 $old_endpoint_ids = array_column( $old_api_setup['endpoints'], 'id' ); 1366 1367 $removed_endpoint_ids = array_diff( $old_endpoint_ids, $new_endpoint_ids ); 1368 1369 if ( empty( $removed_endpoint_ids ) ) { 1370 return; 1371 } 1372 1373 foreach ( $removed_endpoint_ids as $removed_endpoint_id ) { 1374 /** 1375 * Fires before an API endpoint is removed from an API setup. 1376 * 1377 * This allows add-on plugins to clean up their own data or options 1378 * associated with the removed endpoint, before the core plugin 1379 * deletes its related option. 1380 * 1381 * @param string $removed_endpoint_id The ID of the endpoint being removed. 1382 * @param string $api_id The ID of the API the endpoint belonged to. 1383 */ 1384 do_action( 'wpgetapi_before_endpoint_removed', $removed_endpoint_id, $api_id ); 1385 } 1386 } 1295 1387 } 1296 1388 -
wpgetapi/tags/2.25.4/readme.txt
r3339581 r3369890 2 2 Contributors: wpgetapi, DavidAnderson, pmbaldha, DNutbourne, aporter, webulous 3 3 Tags: api, external api, json, endpoint, rest 4 Requires at least: 5. 05 Requires PHP: 7. 04 Requires at least: 5.6 5 Requires PHP: 7.2 6 6 Tested up to: 6.8 7 Stable tag: 2.25. 37 Stable tag: 2.25.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 190 190 == Changelog == 191 191 192 = 2.25.4 - 22/Sep/2025 = 193 194 * FIX: Resolved JSON body parsing issue on endpoint import. 195 * TWEAK: Remove endpoints data when an API is deleted from the setup page. 196 * TWEAK: Updated minimum requirements to PHP 7.2 and WordPress 5.6. 197 192 198 = 2.25.3 - 01/Aug/2025 = 193 199 … … 553 559 554 560 == Upgrade Notice == 555 * 2.25. 3: Various fixes and a UI improvement. A recommended update for all.561 * 2.25.4: Fixes JSON parsing issue on imports, cleans up endpoint data on API deletion, and updates minimum requirements. A recommended update for all. -
wpgetapi/tags/2.25.4/wpgetapi.php
r3339581 r3369890 6 6 * Author: WPGetAPI 7 7 * Author URI: https://wpgetapi.com/ 8 * Version: 2.25. 38 * Version: 2.25.4 9 9 * Text Domain: wpgetapi 10 10 * License: GPL2 or later … … 30 30 protected static $_instance = null; 31 31 32 public $version = '2.25. 3';32 public $version = '2.25.4'; 33 33 34 34 /** -
wpgetapi/trunk/includes/class-wpgetapi-admin-options.php
r3339581 r3369890 104 104 105 105 add_action( 'wp_ajax_wpgetapi_notice_dismiss', array( $this, 'wpgetapi_notice_dismiss_handler' ) ); 106 107 add_action( 'cmb2_options-page_process_fields_wpgetapi_setup', array( $this, 'cleanup_wpgetapi_removed_api_options' ), 10, 2 ); 106 108 } 107 109 … … 190 192 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ), 191 193 ); 194 195 // Hook to clean up data when API endpoints are removed. 196 add_action( 'cmb2_options-page_process_fields_wpgetapi_' . $api['id'], array( $this, 'cleanup_removed_api_endpoints' ), 10, 2 ); 192 197 193 198 } … … 727 732 } 728 733