Skip to content

Commit abba969

Browse files
authored
#2788 - Expiring Magic Links (#2894)
* Enhance magic URL setup with expiration control features - Added functionality to manage expiration settings for magic URLs, including enabling/disabling expiration controls based on user input. - Implemented logic to clear expiration data when links are reset, ensuring accurate link management. - Introduced initialization for expiration controls on page load to improve user experience. - Refactored app link reset logic to accommodate new expiration handling. * Refactor whitespace and formatting in magic URL setup for improved readability - Cleaned up unnecessary whitespace and adjusted formatting for consistency throughout the magic URL setup file. - Enhanced clarity in the code structure, ensuring better alignment of comments with the corresponding code sections. * Fix whitespace inconsistency in magic URL setup file * Refactor expiration control logic in magic URL setup - Removed outdated expiration control functions and initialization code to streamline the handling of expiration settings. - Updated validation logic to require both expiration amount and time unit, enhancing user input requirements. - Improved expiration display updates and data attribute management for better clarity and functionality. - Ensured consistent handling of expiration data when links are reset, enhancing overall user experience. * Enhance reset link functionality in magic URL setup - Updated reset link label to reflect its action of clearing expiration, improving user clarity. - Added logic to reset label text when expiration is cleared, ensuring consistent user feedback. - Refactored badge display logic for better handling of expiration states, enhancing overall user experience. * Update endpoint URLs in magic URL setup for consistency - Changed endpoint URLs to use the root property instead of site_url, ensuring uniformity in API calls. - This adjustment enhances the reliability of the API interactions within the magic URL setup functionality. * Enhance magic URL setup to support expiration helpers - Added logic to check if the active magic link plugin version supports expiration helpers, improving compatibility and functionality. - Updated conditions for displaying expiration-related UI elements based on the new support check, enhancing user experience and clarity. * Refactor magic URL setup to optimize link object fetching and expiration formatting - Cached link objects to improve performance and reduce redundant API calls. - Simplified expiration date formatting logic for better readability and maintainability. - Removed unused variable for link object ID, streamlining the code. - Enhanced data attributes for expiration display, ensuring accurate and user-friendly output. * Enhance magic URL functionality with instance ID handling and local timezone expiration display - Added support for instance ID in magic URL processing to improve link management. - Implemented local timezone formatting for magic link expiration timestamps, enhancing user experience. - Updated JavaScript to dynamically display expiration information in the app accordion, ensuring accurate and user-friendly output. * Add "Does not expire" Label and make past dates red
1 parent c5a8e71 commit abba969

2 files changed

Lines changed: 389 additions & 14 deletions

File tree

dt-reports/magic-url-class.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ public function parse_wp_rest_url_parts( $params ){
344344
$elements['post_type'] = $all_types[$elements['root']][$elements['type']]['post_type'];
345345
}
346346

347+
$instance_id = $types[ $elements['type'] ]['instance_id'] ?? '';
348+
if ( ! empty( $instance_id ) ) {
349+
$elements['instance_id'] = $instance_id;
350+
}
351+
347352
return $elements;
348353
}
349354
return false;
@@ -374,6 +379,21 @@ public function verify_rest_endpoint_permissions_on_post( WP_REST_Request $reque
374379
if ( (int) $parts['post_id'] !== (int) $params['parts']['post_id'] ){
375380
return false;
376381
}
382+
383+
// Align with HTML magic-link flow: deny REST when expiration metadata / link_obj says expired.
384+
if ( class_exists( 'Disciple_Tools_Bulk_Magic_Link_Sender_API' ) ) {
385+
$link_args = [
386+
'meta_key' => $parts['meta_key'],
387+
'public_key' => $parts['public_key'],
388+
'post_id' => $parts['post_id'],
389+
'post_type' => $parts['post_type'] ?? '',
390+
'instance_id' => $parts['instance_id'] ?? null,
391+
];
392+
if ( Disciple_Tools_Bulk_Magic_Link_Sender_API::evaluate_magic_link_continue( true, $link_args ) === false ) {
393+
return false;
394+
}
395+
}
396+
377397
return $return_parts ? $parts : true;
378398
}
379399

0 commit comments

Comments
 (0)