Forum Replies Created

Viewing 15 replies - 1 through 15 (of 18 total)
  • Thread Starter lodoubleg

    (@loqee)

    very nice. thank you for your fast work !

    Thread Starter lodoubleg

    (@loqee)

    hello,

    yes the file is there and the function code starts at line # 1086

    function download_url( $url, $timeout = 300, $signature_verification = false ) {
    	// WARNING: The file is not automatically deleted, the script must unlink() the file.
    	if ( ! $url ) {
    		return new WP_Error( 'http_no_url', __( 'Invalid URL Provided.' ) );
    	}
    
    	$url_filename = basename( parse_url( $url, PHP_URL_PATH ) );
    
    	$tmpfname = wp_tempnam( $url_filename );
    	if ( ! $tmpfname ) {
    		return new WP_Error( 'http_no_file', __( 'Could not create temporary file.' ) );
    	}
    
    	$response = wp_safe_remote_get(
    		$url,
    		array(
    			'timeout'  => $timeout,
    			'stream'   => true,
    			'filename' => $tmpfname,
    		)
    	);
    
    	if ( is_wp_error( $response ) ) {
    		unlink( $tmpfname );
    		return $response;
    	}
    
    	$response_code = wp_remote_retrieve_response_code( $response );
    
    	if ( 200 !== $response_code ) {
    		$data = array(
    			'code' => $response_code,
    		);
    
    		// Retrieve a sample of the response body for debugging purposes.
    		$tmpf = fopen( $tmpfname, 'rb' );
    
    		if ( $tmpf ) {
    			/**
    			 * Filters the maximum error response body size in <code>download_url()</code>.
    			 *
    			 * @since 5.1.0
    			 *
    			 * @see download_url()
    			 *
    			 * @param int $size The maximum error response body size. Default 1 KB.
    			 */
    			$response_size = apply_filters( 'download_url_error_max_body_size', KB_IN_BYTES );
    
    			$data['body'] = fread( $tmpf, $response_size );
    			fclose( $tmpf );
    		}
    
    		unlink( $tmpfname );
    
    		return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ), $data );
    	}
    
    	$content_md5 = wp_remote_retrieve_header( $response, 'content-md5' );
    
    	if ( $content_md5 ) {
    		$md5_check = verify_file_md5( $tmpfname, $content_md5 );
    
    		if ( is_wp_error( $md5_check ) ) {
    			unlink( $tmpfname );
    			return $md5_check;
    		}
    	}
    
    	// If the caller expects signature verification to occur, check to see if this URL supports it.
    	if ( $signature_verification ) {
    		/**
    		 * Filters the list of hosts which should have Signature Verification attempted on.
    		 *
    		 * @since 5.2.0
    		 *
    		 * @param string[] $hostnames List of hostnames.
    		 */
    		$signed_hostnames = apply_filters( 'wp_signature_hosts', array( 'ww.wp.xz.cn', 'downloads.wp.xz.cn', 's.w.org' ) );
    
    		$signature_verification = in_array( parse_url( $url, PHP_URL_HOST ), $signed_hostnames, true );
    	}
    
    	// Perform signature valiation if supported.
    	if ( $signature_verification ) {
    		$signature = wp_remote_retrieve_header( $response, 'x-content-signature' );
    
    		if ( ! $signature ) {
    			// Retrieve signatures from a file if the header wasn't included.
    			// ww.wp.xz.cn stores signatures at $package_url.sig.
    
    			$signature_url = false;
    			$url_path      = parse_url( $url, PHP_URL_PATH );
    
    			if ( '.zip' === substr( $url_path, -4 ) || '.tar.gz' === substr( $url_path, -7 ) ) {
    				$signature_url = str_replace( $url_path, $url_path . '.sig', $url );
    			}
    
    			/**
    			 * Filters the URL where the signature for a file is located.
    			 *
    			 * @since 5.2.0
    			 *
    			 * @param false|string $signature_url The URL where signatures can be found for a file, or false if none are known.
    			 * @param string $url                 The URL being verified.
    			 */
    			$signature_url = apply_filters( 'wp_signature_url', $signature_url, $url );
    
    			if ( $signature_url ) {
    				$signature_request = wp_safe_remote_get(
    					$signature_url,
    					array(
    						'limit_response_size' => 10 * KB_IN_BYTES, // 10KB should be large enough for quite a few signatures.
    					)
    				);
    
    				if ( ! is_wp_error( $signature_request ) && 200 === wp_remote_retrieve_response_code( $signature_request ) ) {
    					$signature = explode( "\n", wp_remote_retrieve_body( $signature_request ) );
    				}
    			}
    		}
    
    		// Perform the checks.
    		$signature_verification = verify_file_signature( $tmpfname, $signature, basename( parse_url( $url, PHP_URL_PATH ) ) );
    	}
    
    	if ( is_wp_error( $signature_verification ) ) {
    		if (
    			/**
    			 * Filters whether Signature Verification failures should be allowed to soft fail.
    			 *
    			 * WARNING: This may be removed from a future release.
    			 *
    			 * @since 5.2.0
    			 *
    			 * @param bool   $signature_softfail If a softfail is allowed.
    			 * @param string $url                The url being accessed.
    			 */
    			apply_filters( 'wp_signature_softfail', true, $url )
    		) {
    			$signature_verification->add_data( $tmpfname, 'softfail-filename' );
    		} else {
    			// Hard-fail.
    			unlink( $tmpfname );
    		}
    
    		return $signature_verification;
    	}
    
    	return $tmpfname;
    }
    Thread Starter lodoubleg

    (@loqee)

    • This reply was modified 3 years, 8 months ago by lodoubleg.
    Thread Starter lodoubleg

    (@loqee)

    hi. wow, that was fast!

    WordPress 5.8.5
    PHP 7.4.30

    in console it gives an error 500 at line 1 of source (doctype part)
    page still shows up, but throws this error above into the error.log

    • This reply was modified 3 years, 8 months ago by lodoubleg.
    Thread Starter lodoubleg

    (@loqee)

    actually its not completely working. it replaces a few rows (the first ones i guess), but stops in the middle, leaving a few rows unchanged). so if the job is big, it will not replace all rows, but if its just a few rows, it will replace all. still i get the error every time.

    i tried another plugin and it works there. still i would prefer your plugin 🙂

    is the 3.0 beta safe to use?

    • This reply was modified 4 years, 3 months ago by lodoubleg.
    • This reply was modified 4 years, 3 months ago by lodoubleg.
    Thread Starter lodoubleg

    (@loqee)

    oh yes. i forgot to add that the error.log and php_error.log are empty.

    Thread Starter lodoubleg

    (@loqee)

    hey, thanks for your detailed answer! i will try to deal with these external ressources and see what i can do. actually the core css and js coming from my site is minifying correctly.

    what made me pensive was that this same exact code works well on desktop test but not on mobile. i mean those external ressources do not affect the desktop lighthouse score.

    but however if this is actually still a good user experience, i dont care what the lightscore test from google pageinsights tells.

    thanks again!

    • This reply was modified 4 years, 10 months ago by lodoubleg.
    Thread Starter lodoubleg

    (@loqee)

    Thread Starter lodoubleg

    (@loqee)

    i can see the problem is mainly about the minify i think.
    none of my js and css is minified at the mobile test.

    Thread Starter lodoubleg

    (@loqee)

    im using a template builder (oxygen), when i deactivate it, it falls back to the wordpress default theme which is unchanged.

    Thread Starter lodoubleg

    (@loqee)

    hello. i tried that, but the error is still there. i disabled everything expect cf7.
    is there a server setting which could cause this, as i saw this happen to alot of people lately.

    did u find a solution to this??

    https://ww.wp.xz.cn/plugins/wp-rollback/

    be sure to make a backup of your site before rolling back to a previous version.

    i am using 5.3.2 now.

    yes many people have this or similar problems.

    a fix is needed by the author. you can revert back to the previous version for now

    im not using caching and have the same/similar problem…

    wp-json/contact-form-7/v1/contact-forms/129/feedback?_locale=user 401 (Unauthorized)

Viewing 15 replies - 1 through 15 (of 18 total)