Support » Plugin: WordPress HTTPS (SSL) » admin_url() doesn't return proper scheme even when $scheme is passed

  • Jonathan Cowher


    I have a plugin that I manage and we use

    admin_url('admin-ajax.php', ( is_ssl() ) ? 'https' : 'http'));

    to make sure our ajax requests use the proper url.

    When the “force SSL on admin” setting is not enabled admin_url() will ALWAYS use http instead of https scheme. Here’s the workaround I used:

    //make sure admin_url() returns proper scheme - set to super low priority to make sure this is run last
    add_filter('admin_url', array(&$this, 'filter_admin_url'), 999);
     * Ensures that admin_url() uses the correct URL scheme when WordPress HTTPS
     * plugin is enabled
     * @since
     * @param string $url
     * @return string
    function filter_admin_url( $url ) {
       if ( class_exists('WordPressHTTPS') )
          return is_ssl() ? str_replace('http://', 'https://', $url) : str_replace('https://', 'http://', $url);
       return $url;

  • The topic ‘admin_url() doesn't return proper scheme even when $scheme is passed’ is closed to new replies.