15, 'sslverify' => $this->should_verify_ssl( $full_url ), 'headers' => array( 'X-HSSM-API-Key' => $api_key, 'Accept' => 'application/json', ), ); $response = wp_remote_get( $full_url, $args ); if ( is_wp_error( $response ) ) { return $response; } $code = wp_remote_retrieve_response_code( $response ); $body = wp_remote_retrieve_body( $response ); if ( 200 !== $code ) { return new WP_Error( 'api_error', sprintf( __( 'API returned code %d: %s', 'hi-school-slide-manager' ), $code, $body ) ); } $data = json_decode( $body, true ); if ( ! is_array( $data ) || ! isset( $data['slides'] ) ) { return new WP_Error( 'invalid_response', __( 'Invalid API response format.', 'hi-school-slide-manager' ) ); } $slides = $data['slides']; // Cache the results set_transient( $cache_key, $slides, $cache_duration ); return $slides; } /** * Clear the slides cache * * @since 1.1.0 */ /** * Verify SSL except on local Local/WP Engine hosts with self-signed certs. * * @since 1.1.3 * @param string $url Request URL. * @return bool */ private function should_verify_ssl( $url ) { $host = wp_parse_url( $url, PHP_URL_HOST ); $local_hosts = array( 'localhost', '127.0.0.1' ); $is_local = in_array( $host, $local_hosts, true ) || ( is_string( $host ) && preg_match( '/\.local$/', $host ) ); /** * Filter whether the client API should verify SSL certificates. * * @param bool $verify Whether to verify SSL. False for *.local hosts. * @param string $url Request URL. */ return (bool) apply_filters( 'hssm_api_sslverify', ! $is_local, $url ); } public function clear_cache() { $site_slug = get_option( 'hssm_client_site_slug' ); if ( ! empty( $site_slug ) ) { delete_transient( 'hssm_remote_slides_' . $site_slug ); } } }