Skip to content

Commit 7530adc

Browse files
committed
improvements - address copilot feedback
1 parent 27d74f2 commit 7530adc

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

classes/utils/class-onboard.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public function save_onboard_response() {
9696
* @return string
9797
*/
9898
public function get_remote_url( $endpoint = '' ) {
99+
// Sanitize and validate the endpoint parameter.
100+
$endpoint = \sanitize_key( $endpoint );
101+
$endpoint = \ltrim( $endpoint, '/' );
102+
99103
return \progress_planner()->get_remote_server_root_url() . self::REMOTE_API_URL . $endpoint;
100104
}
101105

@@ -108,7 +112,10 @@ public function get_remote_nonce() {
108112
// Make a POST request to the remote nonce endpoint.
109113
$response = \wp_remote_post(
110114
$this->get_remote_url( 'get-nonce' ),
111-
[ 'body' => [ 'site' => \set_url_scheme( \site_url() ) ] ]
115+
[
116+
'timeout' => 10,
117+
'body' => [ 'site' => \set_url_scheme( \site_url() ) ],
118+
]
112119
);
113120

114121
if ( \is_wp_error( $response ) ) {
@@ -146,7 +153,10 @@ public function make_remote_onboarding_request( $data = [] ) {
146153
// Make the request.
147154
$response = \wp_remote_post(
148155
$this->get_remote_url( 'onboard' ),
149-
[ 'body' => $data ]
156+
[
157+
'timeout' => 10,
158+
'body' => $data,
159+
]
150160
);
151161

152162
// Bail early if there is an error.
@@ -169,6 +179,12 @@ public function make_remote_onboarding_request( $data = [] ) {
169179
* @return void
170180
*/
171181
public function detect_site_url_changes() {
182+
// Only check once per day to avoid performance issues.
183+
if ( \get_transient( 'progress_planner_site_url_check_done' ) ) {
184+
return;
185+
}
186+
\set_transient( 'progress_planner_site_url_check_done', 1, DAY_IN_SECONDS );
187+
172188
$saved_site_url = \get_option( 'progress_planner_saved_site_url', false );
173189
$current_site_url = \set_url_scheme( \site_url() );
174190

@@ -189,7 +205,8 @@ public function detect_site_url_changes() {
189205
$response = \wp_remote_post(
190206
$this->get_remote_url( 'change-site-url' ),
191207
[
192-
'body' => [
208+
'timeout' => 10,
209+
'body' => [
193210
'license_key' => $saved_license_key,
194211
'old_url' => $saved_site_url,
195212
'new_url' => $current_site_url,

0 commit comments

Comments
 (0)