Skip to content
Snippets Groups Projects

SFP Basic Auth

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Erick Hitter

    Replace foo with username and bar with password.

    Edited
    sfp-basic-auth.php 707 B
    <?php
    /**
     * Basic Auth support for Stage File Proxy requests
     *
     * @package Stage_File_Proxy
     */
    
    /**
     * Add Basic Auth credentials to SFP requests
     *
     * @param array  $request WP_HTTP args.
     * @param string $url Request URL.
     * @return mixed
     */
    function sfp_basic_auth( $request, $url ) {
    	if ( ! function_exists( 'sfp_get_base_url' ) ) {
    		return $request;
    	}
    
    	$sfp_url    = sfp_get_base_url();
    	$sfp_domain = wp_parse_url( $sfp_url, PHP_URL_HOST );
    
    	if ( ! empty( $sfp_domain ) && wp_parse_url( $url, PHP_URL_HOST ) === $sfp_domain ) {
    		$request['headers']['Authorization'] = 'Basic ' . base64_encode( 'foo:bar' );
    	}
    
    	return $request;
    }
    add_filter( 'http_request_args', 'sfp_basic_auth', 10, 2 );
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment