[wp-trac] [WordPress Trac] #55481: Add custom headers for `update_plugins_{$hostname}` filter's package

WordPress Trac noreply at wordpress.org
Tue Mar 29 23:53:41 UTC 2022


#55481: Add custom headers for `update_plugins_{$hostname}` filter's package
-------------------------------+------------------------------
 Reporter:  natsumesou         |       Owner:  (none)
     Type:  feature request    |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Upgrade/Install    |     Version:  trunk
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------
Changes (by pbiron):

 * keywords:   => reporter-feedback
 * component:  Plugins => Upgrade/Install


Comment:

 @natsumesou Thank you for the ticket...and welcome to Trac.

 If I understand what you problem is, you can use the
 [https://developer.wordpress.org/reference/hooks/http_request_args/
 http_request_args] filter to add the `Authentication` header.

 You should be able to do something like (note: the following code has
 **not** been tested):

 {{{#!php
 add_filter(
   'http_request_args',
   function( $parsed_args, $url ) {
     if ( MY_UPDATE_URL === $url ) {
       if ( empty( $parsed_args['headers'] ) ) {
         $parsed_args['headers'] = array();
       }

       $parsed_args['headers']['AUTHORIZATION'] = MY_AUTH_HEADER_VALUE;
     }

     return $parsed_args;
   },
   10,
   2
 );
 }}}

 where `MY_UPDATE_URL` and `MY_UPDATE_URL` are just placeholders (and not
 to be interpreted as PHP constants) and should be replaced by whatever
 your use case requires.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55481#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list