Plugin Directory


Ignore:
Timestamp:
04/22/2024 08:52:49 AM (12 months ago)
Author:
brainstormworg
Message:

Update to version 4.1.7 from GitHub

Location:
astra-sites/tags/4.1.7
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • astra-sites/tags/4.1.7/inc/classes/class-astra-sites.php

    r3062079 r3074863  
    154154                'astra-sites-favorite' => 'add_to_favorite',
    155155                'astra-sites-api-request' => 'api_request',
    156                 'astra-sites-ai-api-request' => 'ai_api_request',
    157156                'astra-sites-elementor-api-request' => 'elementor_api_request',
    158157                'astra-sites-elementor-flush-request' => 'elementor_flush_request',
     
    365364            );
    366365
    367             $response = wp_remote_post( $url, $args );
     366            $response = wp_safe_remote_post( $url, $args );
    368367
    369368            if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
     
    406405                ),
    407406            );
    408             $result                             = wp_remote_post( $this->search_analytics_url, $args );
     407            $result                             = wp_safe_remote_post( $this->search_analytics_url, $args );
    409408            $response['ast-sites-search-terms'] = wp_remote_retrieve_body( $result );
    410409
     
    536535            }
    537536
    538             $response = wp_remote_get( $api_url );
     537            $response = wp_safe_remote_get( $api_url );
    539538
    540539            if ( is_wp_error( $response ) ) {
     
    629628            );
    630629
    631             $request = wp_remote_get( $api_url, $api_args );
     630            $request = wp_safe_remote_get( $api_url, $api_args );
    632631
    633632            Astra_Sites_Error_Handler::get_instance()->stop_error_handler();
     
    695694         * API Request
    696695         *
    697          * @since 4.0.0
    698          */
    699         public function ai_api_request() {
     696         * @since 3.2.4
     697         */
     698        public function elementor_api_request() {
    700699
    701700            // Verify Nonce.
     
    706705            }
    707706
    708             $url = isset( $_POST['url'] ) ? sanitize_text_field( $_POST['url'] ) : '';
    709             $uuid = isset( $_POST['uuid'] ) ? sanitize_text_field( $_POST['uuid'] ) : '';
    710 
    711             update_option( 'ast_ai_import_current_url', $url );
    712             update_option( 'astra_sites_batch_process_complete', 'no' );
    713 
    714             if ( empty( $url ) ) {
     707            $id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : '';
     708            $type = isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : '';
     709
     710            if ( empty( $id ) || empty( $type ) ) {
    715711                wp_send_json_error(
    716712                    array(
    717                         'message' => __( 'Provided API URL is empty! Please try again!', 'astra-sites' ),
     713                        'message' => __( 'Provided API details are empty! Please try again!', 'astra-sites' ),
    718714                        'code'    => 'Error',
    719715                    )
     
    723719            $api_args = apply_filters(
    724720                'astra_sites_api_params', array(
    725                     'uuid' => $uuid,
     721                    'url' => site_url(),
     722                    'version' => ASTRA_SITES_VER,
    726723                )
    727724            );
    728725
    729             $api_url = add_query_arg( $api_args, trailingslashit( $url ) . 'wp-json/zipwp-client/v1/exporter/export' );
     726            $api_url = add_query_arg( $api_args, trailingslashit( self::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/' . $type . '/' . $id );
    730727
    731728            if ( ! astra_sites_is_valid_url( $api_url ) ) {
    732729                wp_send_json_error(
    733730                    array(
    734                         /* Translators: %s is API URL. */
     731                        /* Translators: %s is Request URL. */
    735732                        'message' => sprintf( __( 'Invalid Request URL - %s', 'astra-sites' ), $api_url ),
    736733                        'code'    => 'Error',
     
    747744            );
    748745
    749             $request = wp_remote_get( $api_url, $api_args );
     746            $request = wp_safe_remote_get( $api_url, $api_args );
    750747
    751748            Astra_Sites_Error_Handler::get_instance()->stop_error_handler();
     
    778775
    779776            if ( 200 === $code ) {
    780                 update_option( 'astra_sites_import_data', $demo_data, 'no' );
    781                 wp_send_json_success( $demo_data );
    782             }
    783 
    784             $message       = wp_remote_retrieve_body( $request );
    785             $response_code = $code;
    786 
    787             if ( 200 !== $code && is_array( $demo_data ) && isset( $demo_data['code'] ) ) {
    788                 $message = $demo_data['message'];
    789             }
    790 
    791             if ( 500 === $code ) {
    792                 $message = __( 'Internal Server Error.', 'astra-sites' );
    793             }
    794 
    795             if ( 200 !== $code && false !== strpos( $message, 'Cloudflare' ) ) {
    796                 $ip = Astra_Sites_Helper::get_client_ip();
    797                 /* translators: %s IP address. */
    798                 $message = sprintf( __( 'Client IP: %1$s </br> Error code: %2$s', 'astra-sites' ), $ip, $code );
    799                 $code    = 'Cloudflare';
    800             }
    801 
    802             wp_send_json_error(
    803                 array(
    804                     'message'       => $message,
    805                     'code'          => $code,
    806                     'response_code' => $response_code,
    807                 )
    808             );
    809         }
    810 
    811         /**
    812          * API Request
    813          *
    814          * @since 3.2.4
    815          */
    816         public function elementor_api_request() {
    817 
    818             // Verify Nonce.
    819             check_ajax_referer( 'astra-sites', '_ajax_nonce' );
    820 
    821             if ( ! current_user_can( 'edit_posts' ) ) {
    822                 wp_send_json_error();
    823             }
    824 
    825             $id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : '';
    826             $type = isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : '';
    827 
    828             if ( empty( $id ) || empty( $type ) ) {
    829                 wp_send_json_error(
    830                     array(
    831                         'message' => __( 'Provided API details are empty! Please try again!', 'astra-sites' ),
    832                         'code'    => 'Error',
    833                     )
    834                 );
    835             }
    836 
    837             $api_args = apply_filters(
    838                 'astra_sites_api_params', array(
    839                     'url' => site_url(),
    840                     'version' => ASTRA_SITES_VER,
    841                 )
    842             );
    843 
    844             $api_url = add_query_arg( $api_args, trailingslashit( self::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/' . $type . '/' . $id );
    845 
    846             if ( ! astra_sites_is_valid_url( $api_url ) ) {
    847                 wp_send_json_error(
    848                     array(
    849                         /* Translators: %s is Request URL. */
    850                         'message' => sprintf( __( 'Invalid Request URL - %s', 'astra-sites' ), $api_url ),
    851                         'code'    => 'Error',
    852                     )
    853                 );
    854             }
    855 
    856             Astra_Sites_Error_Handler::get_instance()->start_error_handler();
    857 
    858             $api_args = apply_filters(
    859                 'astra_sites_api_args', array(
    860                     'timeout' => 15,
    861                 )
    862             );
    863 
    864             $request = wp_remote_get( $api_url, $api_args );
    865 
    866             Astra_Sites_Error_Handler::get_instance()->stop_error_handler();
    867 
    868             if ( is_wp_error( $request ) ) {
    869                 $wp_error_code = $request->get_error_code();
    870                 switch ( $wp_error_code ) {
    871                     case 'http_request_not_executed':
    872                         /* translators: %s Error Message */
    873                         $message = sprintf( __( 'API Request could not be performed - %s', 'astra-sites' ), $request->get_error_message() );
    874                         break;
    875                     case 'http_request_failed':
    876                     default:
    877                         /* translators: %s Error Message */
    878                         $message = sprintf( __( 'API Request has failed - %s', 'astra-sites' ), $request->get_error_message() );
    879                         break;
    880                 }
    881 
    882                 wp_send_json_error(
    883                     array(
    884                         'message'       => $request->get_error_message(),
    885                         'code'          => 'WP_Error',
    886                         'response_code' => $wp_error_code,
    887                     )
    888                 );
    889             }
    890 
    891             $code      = (int) wp_remote_retrieve_response_code( $request );
    892             $demo_data = json_decode( wp_remote_retrieve_body( $request ), true );
    893 
    894             if ( 200 === $code ) {
    895777                update_option( 'astra_sites_import_elementor_data_' . $id, $demo_data, 'no' );
    896778                wp_send_json_success( $demo_data );
     
    1073955            }
    1074956
    1075             $response = wp_remote_get( $api_url );
     957            $response = wp_safe_remote_get( $api_url );
    1076958
    1077959            if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
     
    11531035            $api_url = add_query_arg( $params, $this->pixabay_url );
    11541036
    1155             $response = wp_remote_get( $api_url );
     1037            $response = wp_safe_remote_get( $api_url );
    11561038
    11571039            if ( is_wp_error( $response ) ) {
     
    17911673                    'empty_api_key'       => __( 'Please enter an API key.', 'astra-sites' ),
    17921674                    'error_api_key'       => __( 'An error occured with code ', 'astra-sites' ),
    1793                     '_ajax_nonce'         => wp_create_nonce( 'astra-sites' ),
     1675                    '_ajax_nonce'         => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'astra-sites' ) : '',
    17941676                )
    17951677            );
     
    18511733                    'installing'  => __( 'Installing...', 'astra-sites' ),
    18521734                    'ajaxurl'     => esc_url( admin_url( 'admin-ajax.php' ) ),
    1853                     '_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
     1735                    '_ajax_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'astra-sites' ) : '',
    18541736                )
    18551737            );
     
    20071889                    'getUpgradeText'                     => __( 'Upgrade', 'astra-sites' ),
    20081890                    'getUpgradeURL'                      => esc_url( 'https://wpastra.com/starter-templates-plans/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
    2009                     '_ajax_nonce'                        => wp_create_nonce( 'astra-sites' ),
     1891                    '_ajax_nonce'                        => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'astra-sites' ) : '',
    20101892                    'requiredPlugins'                    => array(),
    20111893                    'syncLibraryStart'                   => '<span class="message">' . esc_html__( 'Syncing template library in the background. The process can take anywhere between 2 to 3 minutes. We will notify you once done.', 'astra-sites' ) . '</span>',
     
    24462328                    'default_page_builder_sites' => Astra_Sites_Page::get_instance()->get_sites_by_page_builder( 'elementor' ),
    24472329                    'ApiURL'                     => $this->api_url,
    2448                     '_ajax_nonce'                => wp_create_nonce( 'astra-sites' ),
     2330                    '_ajax_nonce'                => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'astra-sites' ) : '',
    24492331                    'isPro'                      => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false,
    24502332                    'license_msg'                => $license_msg,
Note: See TracChangeset for help on using the changeset viewer.