• Resolved emiliengerbois

    (@emiliengerbois)


    Hello and thank you for your work on WC Vendors,

    I use the following function (found on the internet), to force the listing of all of my users in the admin author dropdown, visible when editing posts.

    I found out that this function conflicts with WC Vendors, which prevents from adding new products… it breaks the process when clicking on “add product”. It’s solved when changing the theme or disabling WC Vendors, that’s how I found out where it comes from. I deleted piece by piece of code in my functions.php until I could identify the one causing the issue.

    Do you have an idea why this code breaks the process when WC Vendors is enabled? I’m not a developper so unfortunately I can’t understand what could be wrong between this snippet and your plugin…

    Thank you so so much for your help! Have a great day,
    Emilien

    // Filter to fix the Post Author Dropdown
    function author_override( $output ) {
        global $post, $user_ID;
    
        // return if this isn't the theme author override dropdown
        if (!preg_match('/post_author_override/', $output)) return $output;
    
        // return if we've already replaced the list (end recursion)
        if (preg_match ('/post_author_override_replaced/', $output)) return $output;
    
        // replacement call to wp_dropdown_users
          $output = wp_dropdown_users(array(
            'echo' => 0,
            'name' => 'post_author_override_replaced',
            'selected' => empty($post->ID) ? $user_ID : $post->post_author,
            'include_selected' => true
          ));
    
          // put the original name back
          $output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);
    
        return $output;
    }
    add_filter('wp_dropdown_users', 'author_override');

    https://www.ads-software.com/plugins/wc-vendors/

Viewing 12 replies - 1 through 12 (of 12 total)
  • It’s conflicting because you’re telling it to do something that WC Vendors already does. We add the vendors to the author dropdown. You’ll want to get rid of that function. ??

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Thank you for your quick answer! Actually I used it to take into account many custom roles I created… for now I removed it but is it possible to just exclude the roles already added by WC Vendors to avoid the redundancy without blocking other custom roles from being added to the author dropdown?

    Thank you again and have a great day,
    Emilien

    That I’m not entirely sure of. You could try excluding the role “Vendor”, and see if that works, but I do not think it will.

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Hi, Thank you for your answer!

    then what could be the best bet?
    Can I manually remove a piece of code in WC Vendors which probably conflicts? > The one adding Vendors to the Autor Dropdown? this way, wouldn’t the other snippet include the Vendor role just like it does for others? where could I do this in the WC Vendors code?

    thank you again, have a great day,
    Emilien

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Thank you I’ll have a look right now!
    can you just tell me where to put it please?
    As it seems to be .js I’ guess it doesn’t go in the functions.php file …

    thanks again,
    Emilien

    Thread Starter emiliengerbois

    (@emiliengerbois)

    and does it replace the previous snippet or does it have to be added alongside of it?

    It’s JavaScript, so you would have to edit the JavaScript file to remove the parts where it does the post_author modifications, which is basically the entire file. ?? You could just make the file “empty” aka 0 bytes, and then work from there. If you delete the file, you’ll get errors since the file is hard coded in the plugin. Once its deleted, your functions.php snippet could work fine. Every time you update WC Vendors you would have to re-edit this js file and make it empty again. Let me know how it goes! ??

    Ben

    Yes, it’s two steps. Empty out the js file, and then use your own functions.php code for your own post_author queries.

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Wha Ben thank you so much for such a great support!!! I’ll keep you posted ASAP ??
    Have a great day!!
    Emilien

    Thread Starter emiliengerbois

    (@emiliengerbois)

    Hi Ben,

    I tried to follow your advice but unfortunately it didn’t work… I don’t know what to do ?? what’s weird is the whole stuff worked before (few weeks ago) and I can’t understand what’s been changed that could have explained this bug…

    thank you for your help anyway! have a great day,
    Emilien

    I’m unsure, too. It’s custom code. Happy to support for the free plugin, but making it work with all the other custom functions on your site is up to you. ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘conflict with a function’ is closed to new replies.