Support » Plugin: Require Post Category » Doesn’t work

  • Resolved net

    (@krstarica)


    jQuery(function($){ should be changed to (function($) {

    });</script> should be changed to })(jQuery);</script>

Viewing 15 replies - 1 through 15 (of 21 total)
  • Plugin Author Josh Hartman

    (@joshhartman)

    The way the code is executed hasn’t changed. What issue are you experiencing? On the site that you are having trouble, are you running code that modifies when or how jQuery is loaded in the admin? Or are you are dynamically adding editor components with JS?

    Thread Starter net

    (@krstarica)

    Not that I am aware of.

    But what I proposed is standard wrapping:
    http://stackoverflow.com/questions/2937227/what-does-function-jquery-mean

    Thread Starter net

    (@krstarica)

    And without this patch, it simply doesn’t do a thing.

    Plugin Author Josh Hartman

    (@joshhartman)

    I prefer to wait until I know the DOM is ready before working with it:
    https://learn.jquery.com/using-jquery-core/document-ready/

    The plugin does work for hundreds of users so I would suggest that you troubleshoot by disabling plugins and/or switching your theme until you find what piece of your site is conflicting.

    Thread Starter net

    (@krstarica)

    Josh, the problem is that jQuery is still not loaded. See:
    http://wordpress.stackexchange.com/questions/53021/how-can-i-include-javascript-that-use-jquery-on-admin-side

    I did try with:

    function my_enqueue($hook) {
    
        if( 'post.php' != $hook )
            return;
    
        wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__), array('jquery') );
    }
    add_action( 'admin_enqueue_scripts', 'my_enqueue' );
    

    and then it works fine with your JavaScript.

    Thread Starter net

    (@krstarica)

    Noticed that it works inline if add_action(‘admin_footer’, ‘rpc_admin_footer_post_func’); is used.

    But using this or my first patch still seeing in Console:

    TypeError: $(...).data(...) is undefined

    for

    var publish_click_events = $('#publish').data('events').click;

    Plugin Author Josh Hartman

    (@joshhartman)

    You’re right, wp_enqueue_script would ensure jQuery is loaded regardless of any plugins or code you may have that modify the order of things. Since there is some PHP in the JS code it’s not that simple though. In my development version I have even more PHP added to the JS to support the ability for developers to add their own custom post types and custom taxonomies. If I change the WordPress requirement to v3.3 It looks like I could use wp_localize_script to pass JSON data. I’ll take a look at converting over.

    For your reference, here is the source of a normal post edit page: http://pastebin.com/VyX7d1C3

    Note how jQuery is loaded on line 74 and the RPC script is on line 2680.

    Plugin Author Josh Hartman

    (@joshhartman)

    I’ve just released v1.0.7 which uses a separate JS file along with admin_enqueue_scripts, wp_enqueue_script, and wp_localize_script.

    Please delete the plugin from your site and reinstall. Let me know how it works for you.

    Thread Starter net

    (@krstarica)

    Plugin is working now, but still seeing in console after page loads:

    TypeError: $(...).data(...) is undefined in require-post-category.js:11:32

    That’s:

    var publish_click_events = $('#publish').data('events').click;

    Plugin Author Josh Hartman

    (@joshhartman)

    In the JS developer console, please run jQuery.fn.jquery to see what version of jQuery you are running. http://imgur.com/a/R9pBt

    The current version of jQuery in the admin is v1.12.4. I have a feeling that you are loading a much older version of jQuery. jQuery’s data method was added in jQuery v1.2.3.

    Thread Starter net

    (@krstarica)

    Seeing the same 1.12.4.

    Plugin Author Josh Hartman

    (@joshhartman)

    Hmmm, well I don’t know why you’re getting that error message then. If you want to put the page source in Pastebin I can take a look but it’s up to you. That code and what follows is involved in making the Require Post Category check the first action triggered on click.

    Thread Starter net

    (@krstarica)

    $(‘#publish’).data(‘events’) is undefined and that is the reason for error.

    I see you are checking ($(‘#save-post’).data(‘events’) != null), why not having the same check for $(‘#publish’).data(‘events’)?

    Interesting is that plugin works even with this error?

    Plugin Author Josh Hartman

    (@joshhartman)

    The “Publish/Update” button (#publish) always exists on the post editor but the “Save Draft” button (#save-post) does not, that’s why there is a check for the latter.

    If I could recreate the error I could troubleshoot further but as it is you are the only one that I know of that has encountered these errors.

    Thread Starter net

    (@krstarica)

    Here is the code for our Publish button:

    <input name="save" class="button button-primary button-large" id="publish" value="Ажурирај" type="submit">

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Doesn’t work’ is closed to new replies.