Support » Plugin: WP Hide & Security Enhancer » Smart Slider 3 does not work with custom admin url

  • Hi @nsp-code, @tdgu,
    I’m the developer of Smart Slider 3 and we have an issue with your plugin. When we use custom admin url and disable the original admin url, our plugin does not work properly.
    We use ajax to save the content on the admin area and there are cases when we need to generate admin_url in those ajax calls. So I narrowed the problem and it seems like that your plugin does not give real admin url when admin-ajax.php used.

    wp-hide-security-enhancer/modules/components/admin-admin_url.php

    Related code:

    function update_admin_url( $url, $path, $blog_id )
    {
        if( strpos( $_SERVER['REQUEST_URI'], "/admin-ajax.php")    === FALSE )
            return $url;
    
        //replace the wp-admin with custom slug
        $admin_url     =   $this->wph->functions->get_module_item_setting('admin_url');
        
        $url    =   str_replace('/wp-admin', '/' . $admin_url, $url);
            
        return $url;
           
    }

    Do you have any suggestion how we would be able to generate real admin urls when we use admin-ajax.php?

    Are you sure that the following code is necessary?

        if( strpos( $_SERVER['REQUEST_URI'], "/admin-ajax.php")    === FALSE )
            return $url;

    Related ticket: @moultrexhttps://wordpress.org/support/topic/not-compatible-with-wp-hide-security-enhancer/

    • This topic was modified 1 year, 5 months ago by  Nextendweb.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author tdgu

    (@tdgu)

    Hi @nextendweb,
    Thanks for your feedback. I’ll run into a debug, propose and agree on the best solution to fix the problem.

    Thanks

    Plugin Author tdgu

    (@tdgu)

    Hi @nextendweb,
    Checked a bit into this, where exactly you encounter the issue? I found something when doing an import, is there any other place where reporter issue occurs?

    Regarding your question, the update_admin_url function is being used to adjust any admin-ajax.php links, so the code

    if( strpos( $_SERVER['REQUEST_URI'], "/admin-ajax.php")    === FALSE )
            return $url;

    is mandatory.

    Thanks

    @tdgu,
    When user creates a slider in Smart Slider 3, data posted with ajax call. This ajax call can throw back errors, but when everything is fine, it sends back a location where the page should redirect.
    I haven’t tested the following code, but probably it works and fails with that setting:

    
    add_action( 'wp_ajax_my_action', function(){
      echo admin_url('testing');
      exit;
    });
    

    Call: wp-admin/admin-ajax.php?action=my_action

    Sorry @tdgu, I gave you the wrong code also my observation was not thorough.

    The following code only replaces admin url when the page is currently the /admin-ajax.php:

    function update_admin_url( $url, $path, $blog_id )
    {
        if( strpos( $_SERVER['REQUEST_URI'], "/admin-ajax.php")    === FALSE )
            return $url;
    
        //replace the wp-admin with custom slug
        $admin_url     =   $this->wph->functions->get_module_item_setting('admin_url');
        
        $url    =   str_replace('/wp-admin', '/' . $admin_url, $url);
            
        return $url;
    }

    So, if the admin_url generated on the wp-admin/admin-ajax.php, everything seems normal as you replace the urls.
    When it is not that page, you do not update the admin_url with the admin_url filter.
    Instead you use your url replacer, which can replace the occurrences of the default admin url in the body:
    $this->wph->functions->add_replacement( $default_url, $new_url);

    Example code which shows your the problem:

    add_action('init', function () {
        if ($_REQUEST['page'] == 'test') {
    
            echo('Test:' . admin_url('testing'));
            header('Test:' . admin_url('testing'));
            exit;
        }
    });

    Then open: /wp-admin/admin.php?page=test

    In my case aaaaaa is the custom admin url in your plugin. The body is fine as your replacer does its job, but your replacer can not replace the content of the header and the header will contain the default wp-admin url.

    Screenshot: https://i.imgur.com/ycEVPEF.png

    This is the reason why I think the following code should be removed. Also it would speed up the url replacer as there would be less thing to do.

        if( strpos( $_SERVER['REQUEST_URI'], "/admin-ajax.php")    === FALSE )
            return $url;
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Smart Slider 3 does not work with custom admin url’ is closed to new replies.