Open patrickmj opened 7 months ago
Following are the subtasks/steps that can be followed to address the modularization and separation of responsibilities in the given code :-
Refactor Query Building Logic:
Separate Query Parameter Handling:
Handle AJAX Request and Non-AJAX Request Separately:
Ensure Data Sanitization and Validation:
Proper Commenting in the code:
Test the Refactored Code:
Update Dependencies and Libraries:
The shortcodes.php
file is successfully refactored and the changes are committed to shortcode-refactor
branch. Following are the key changes applied :-
check_ajax_referer
) to ensure the security of AJAX requests, which is a crucial aspect of WordPress development.process_drs_filters
and process_dpla_filters
functions, which can be extended easily with new cases as your API evolves or as new filters are introduced.build_dpla_url
function, $_POST['params']['pid'] ?? ""
ensures that if the pid parameter is not set, an empty string is used instead to avoid PHP errors.process_drs_filters
or process_dpla_filters function if the parameter name needs to be transformed or handled in a specific way.This refactoring makes the code more optimized, adaptable and easier to maintain, especially as the complexity of the application grows or as new features are added.
Estimated Time the initial estimate of the time required to completion
20+ hours
Description what the issue is about
That file contains a lot of the work to convert a shortcode into the query to the DRS. It needs to more modular, with particular emphasis on separation of responsibilities, with the URL for GET query being built up in distinct pieces.
The parameters for the query string are currently passed along in
$_POST
. The ability to continue using that will have to persist. However, for future CERES, we also need to be able to construct the same query string from data that does not arrive byPOST
. The same data will be present, just delivered via a different mechanism TBD.For both situations, though, separations of responsibility will be essential.
Sub tasks briefly and descriptively add sub tasks, which may be converted to issues