Skip to content

Commit

Permalink
add slash to namespace wp functions
Browse files Browse the repository at this point in the history
  • Loading branch information
circlecube committed Nov 6, 2024
1 parent 002cc3d commit 42284c8
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions includes/HiiveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function ajax_verify() {
'token' => $_REQUEST['token'],
'valid' => $valid,
);
wp_send_json( $data, $status );
\wp_send_json( $data, $status );
}

/**
Expand Down Expand Up @@ -133,15 +133,15 @@ public function connect( string $path = '/sites/v2/connect', ?string $authorizat

$this->throttle();

$token = md5( wp_generate_password() );
$token = md5( \wp_generate_password() );
Transient::set( 'nfd_data_verify_token', $token, 5 * constant( 'MINUTE_IN_SECONDS' ) );

$data = $this->get_core_data();
$data['verify_token'] = $token;
$data['plugins'] = PluginHelper::collect_installed();

$args = array(
'body' => wp_json_encode( $data ),
'body' => \wp_json_encode( $data ),
'headers' => array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
Expand All @@ -155,18 +155,18 @@ public function connect( string $path = '/sites/v2/connect', ?string $authorizat
}

$attempts = intval( get_option( 'nfd_data_connection_attempts', 0 ) );
update_option( 'nfd_data_connection_attempts', $attempts + 1 );
\update_option( 'nfd_data_connection_attempts', $attempts + 1 );

$response = wp_remote_post( $this->api . $path, $args );
$status = wp_remote_retrieve_response_code( $response );
$response = \wp_remote_post( $this->api . $path, $args );
$status = \wp_remote_retrieve_response_code( $response );

// Created = 201; Updated = 200
if ( 201 === $status || 200 === $status ) {
$body = json_decode( wp_remote_retrieve_body( $response ) );
$body = json_decode( \wp_remote_retrieve_body( $response ) );
if ( ! empty( $body->token ) ) {

// Token is auto-encrypted using the `pre_update_option_nfd_data_token` hook.
update_option( 'nfd_data_token', $body->token );
\update_option( 'nfd_data_token', $body->token );
return true;
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ public function throttle() {
*/
public function get_throttle_interval() {

$attempts = intval( get_option( 'nfd_data_connection_attempts', 0 ) );
$attempts = intval( \get_option( 'nfd_data_connection_attempts', 0 ) );

// Throttle intervals step-up:
// Hourly for 4 hours
Expand Down Expand Up @@ -258,14 +258,14 @@ public function send_event( Event $event ) {
return $hiive_response;
}

$status_code = wp_remote_retrieve_response_code( $hiive_response );
$status_code = \wp_remote_retrieve_response_code( $hiive_response );

if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
return new \WP_Error( $status_code, wp_remote_retrieve_response_message( $hiive_response ) );
return new \WP_Error( $status_code, \wp_remote_retrieve_response_message( $hiive_response ) );
}

/** @var array{data:array{id:string,locations:array,query:string|null,expiration:int,content:string}} $response_payload */
$response_payload = json_decode( wp_remote_retrieve_body( $hiive_response ), true );
$response_payload = json_decode( \wp_remote_retrieve_body( $hiive_response ), true );

return $response_payload['data'] ?? array();
}
Expand All @@ -289,12 +289,12 @@ public function notify( $events ) {

$hiive_response = $this->hiive_request( 'sites/v2/events', $payload );

if ( is_wp_error( ( $hiive_response ) ) ) {
if ( \is_wp_error( ( $hiive_response ) ) ) {
return $hiive_response;
}

if ( ! in_array( wp_remote_retrieve_response_code( $hiive_response ), array( 200, 201, 500 ) ) ) {
return new WP_Error( wp_remote_retrieve_response_code( $hiive_response ), wp_remote_retrieve_response_message( $hiive_response ) );
if ( ! in_array( \wp_remote_retrieve_response_code( $hiive_response ), array( 200, 201, 500 ) ) ) {
return new WP_Error( \wp_remote_retrieve_response_code( $hiive_response ), \wp_remote_retrieve_response_message( $hiive_response ) );
}

$response_body = json_decode( wp_remote_retrieve_body( $hiive_response ), true );
Expand Down Expand Up @@ -341,19 +341,19 @@ public function hiive_request( string $path, ?array $payload = array(), ?array $
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . self::get_auth_token(),
),
'timeout' => wp_is_serving_rest_request() ? 15 : 60, // If we're responding to the frontend, we need to be quick.
'timeout' => \wp_is_serving_rest_request() ? 15 : 60, // If we're responding to the frontend, we need to be quick.
);

$parsed_args = wp_parse_args( $args ?? array(), $defaults );
$parsed_args = \wp_parse_args( $args ?? array(), $defaults );

if ( ! empty( $payload ) ) {
$parsed_args['body'] = wp_json_encode( $payload );
$parsed_args['body'] = \wp_json_encode( $payload );
}

$request_response = wp_remote_request( "{$this->api}/{$path}", $parsed_args );
$request_response = \wp_remote_request( "{$this->api}/{$path}", $parsed_args );

// E.g. Hiive is down, or the site has disabled HTTP requests.
if ( is_wp_error( $request_response ) ) {
if ( \is_wp_error( $request_response ) ) {
return $request_response;
}

Expand All @@ -369,7 +369,7 @@ public function hiive_request( string $path, ?array $payload = array(), ?array $
}
}

remove_filter( 'http_headers_useragent', array( $this, 'add_plugin_name_version_to_user_agent' ) );
\remove_filter( 'http_headers_useragent', array( $this, 'add_plugin_name_version_to_user_agent' ) );

return $request_response;
}
Expand All @@ -382,7 +382,7 @@ public function hiive_request( string $path, ?array $payload = array(), ?array $
* @return string|false The decrypted token if it's set
*/
public static function get_auth_token() {
return get_option( 'nfd_data_token' );
return \get_option( 'nfd_data_token' );
}

/**
Expand All @@ -395,17 +395,17 @@ public function get_core_data() {
$container = container();

$data = array(
'brand' => sanitize_title( $container->plugin()->brand ),
'cache_level' => intval( get_option( 'newfold_cache_level', 2 ) ),
'cloudflare' => get_option( 'newfold_cloudflare_enabled', false ),
'brand' => \sanitize_title( $container->plugin()->brand ),
'cache_level' => intval( \get_option( 'newfold_cache_level', 2 ) ),
'cloudflare' => \get_option( 'newfold_cloudflare_enabled', false ),
'data' => defined( 'NFD_DATA_MODULE_VERSION' ) ? constant( 'NFD_DATA_MODULE_VERSION' ) : '0.0',
'email' => get_option( 'admin_email' ),
'email' => \get_option( 'admin_email' ),
'hostname' => gethostname(),
'mysql' => $wpdb->db_version(),
'origin' => $container->plugin()->get( 'id', 'error' ),
'php' => phpversion(),
'plugin' => $container->plugin()->get( 'version', '0' ),
'url' => get_site_url(),
'url' => \get_site_url(),
'username' => get_current_user(),
'wp' => $wp_version,
'server_path' => defined( 'ABSPATH' ) ? constant( 'ABSPATH' ) : '',
Expand All @@ -424,7 +424,7 @@ public function get_core_data() {
*/
public function add_plugin_name_version_to_user_agent( string $user_agent, string $url ): string {
$container = container();
$plugin_brand = sanitize_title( $container->plugin()->brand );
$plugin_brand = \sanitize_title( $container->plugin()->brand );
$plugin_version = $container->plugin()->get( 'version', '0' );

$user_agent_parts = array_map( 'trim', explode( ';', $user_agent ) );
Expand Down

0 comments on commit 42284c8

Please sign in to comment.