- Timestamp:
- 04/22/2024 08:52:49 AM (12 months ago)
- Location:
- astra-sites/tags/4.1.7
- Files:
-
- 1 edited
- 1 copied
-
. (copied) (copied from astra-sites/trunk)
-
inc/classes/class-astra-sites.php (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
astra-sites/tags/4.1.7/inc/classes/class-astra-sites.php
r3062079 r3074863 154 154 'astra-sites-favorite' => 'add_to_favorite', 155 155 'astra-sites-api-request' => 'api_request', 156 'astra-sites-ai-api-request' => 'ai_api_request',157 156 'astra-sites-elementor-api-request' => 'elementor_api_request', 158 157 'astra-sites-elementor-flush-request' => 'elementor_flush_request', … … 365 364 ); 366 365 367 $response = wp_ remote_post( $url, $args );366 $response = wp_safe_remote_post( $url, $args ); 368 367 369 368 if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { … … 406 405 ), 407 406 ); 408 $result = wp_ remote_post( $this->search_analytics_url, $args );407 $result = wp_safe_remote_post( $this->search_analytics_url, $args ); 409 408 $response['ast-sites-search-terms'] = wp_remote_retrieve_body( $result ); 410 409 … … 536 535 } 537 536 538 $response = wp_ remote_get( $api_url );537 $response = wp_safe_remote_get( $api_url ); 539 538 540 539 if ( is_wp_error( $response ) ) { … … 629 628 ); 630 629 631 $request = wp_ remote_get( $api_url, $api_args );630 $request = wp_safe_remote_get( $api_url, $api_args ); 632 631 633 632 Astra_Sites_Error_Handler::get_instance()->stop_error_handler(); … … 695 694 * API Request 696 695 * 697 * @since 4.0.0698 */ 699 public function ai_api_request() {696 * @since 3.2.4 697 */ 698 public function elementor_api_request() { 700 699 701 700 // Verify Nonce. … … 706 705 } 707 706 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 ) ) { 715 711 wp_send_json_error( 716 712 array( 717 'message' => __( 'Provided API URL isempty! Please try again!', 'astra-sites' ),713 'message' => __( 'Provided API details are empty! Please try again!', 'astra-sites' ), 718 714 'code' => 'Error', 719 715 ) … … 723 719 $api_args = apply_filters( 724 720 'astra_sites_api_params', array( 725 'uuid' => $uuid, 721 'url' => site_url(), 722 'version' => ASTRA_SITES_VER, 726 723 ) 727 724 ); 728 725 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 ); 730 727 731 728 if ( ! astra_sites_is_valid_url( $api_url ) ) { 732 729 wp_send_json_error( 733 730 array( 734 /* Translators: %s is APIURL. */731 /* Translators: %s is Request URL. */ 735 732 'message' => sprintf( __( 'Invalid Request URL - %s', 'astra-sites' ), $api_url ), 736 733 'code' => 'Error', … … 747 744 ); 748 745 749 $request = wp_ remote_get( $api_url, $api_args );746 $request = wp_safe_remote_get( $api_url, $api_args ); 750 747 751 748 Astra_Sites_Error_Handler::get_instance()->stop_error_handler(); … … 778 775 779 776 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 Request813 *814 * @since 3.2.4815 */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 ) {895 777 update_option( 'astra_sites_import_elementor_data_' . $id, $demo_data, 'no' ); 896 778 wp_send_json_success( $demo_data ); … … 1073 955 } 1074 956 1075 $response = wp_ remote_get( $api_url );957 $response = wp_safe_remote_get( $api_url ); 1076 958 1077 959 if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) { … … 1153 1035 $api_url = add_query_arg( $params, $this->pixabay_url ); 1154 1036 1155 $response = wp_ remote_get( $api_url );1037 $response = wp_safe_remote_get( $api_url ); 1156 1038 1157 1039 if ( is_wp_error( $response ) ) { … … 1791 1673 'empty_api_key' => __( 'Please enter an API key.', 'astra-sites' ), 1792 1674 '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' ) : '', 1794 1676 ) 1795 1677 ); … … 1851 1733 'installing' => __( 'Installing...', 'astra-sites' ), 1852 1734 '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' ) : '', 1854 1736 ) 1855 1737 ); … … 2007 1889 'getUpgradeText' => __( 'Upgrade', 'astra-sites' ), 2008 1890 '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' ) : '', 2010 1892 'requiredPlugins' => array(), 2011 1893 '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>', … … 2446 2328 'default_page_builder_sites' => Astra_Sites_Page::get_instance()->get_sites_by_page_builder( 'elementor' ), 2447 2329 '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' ) : '', 2449 2331 'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false, 2450 2332 'license_msg' => $license_msg,
Note: See TracChangeset
for help on using the changeset viewer.