WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to block a directory to everyone but WordPress's internal upgrade feature (I am trying to get WordPress to do auto-updates of my premium plugin). I have it updating, but I really would like to block the directory for everyone but WordPress. Anyone know what WP's internal User Agent is?

share|improve this question
Planning to do an .htaccess block if that matters – chriscct7 Jul 26 '12 at 19:49
up vote 6 down vote accepted

The WordPress user agent is set in the class WP_Http as

'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )

You can set it to a (secret) fixed value per filter:

add_filter( 'http_headers_useragent', 'wpse_59788_user_agent' );
function wpse_59788_user_agent()
    // to remove this filter immediately uncomment the following line
    // remove_filter( current_filter(), __FUNCTION__ );
    return 'alfgjlkgjlkgjsldkjhrkjh';

To change the user agent for a plugin upgrade only try something like this (not tested):

add_filter( 'upgrader_pre_install', 'wpse_59788_register' );
function wpse_59788_register( $dummy )
    add_filter( 'http_headers_useragent', 'wpse_59788_user_agent' );
    return $dummy;

And uncomment the self deactivation line in the first function.

share|improve this answer
Is this value now used in all outgoing requests to other servers then or do I need to edit the requests as well? – chriscct7 Jul 26 '12 at 20:53
Depends on how you use the filter. You could activate it for your personal updates only and deactivate it when the request is done. – toscho Jul 26 '12 at 20:55
Lets say I do this: add_filter(headers) update_function(); deregister_filter(header), the update function will use the UA automatically? – chriscct7 Jul 26 '12 at 21:00
@chriscct7 I made an update to my answer. – toscho Jul 26 '12 at 21:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.