• Hi, I’m writing my first plugin, so please bear with me. It’s supposed to execute when a post is initially published (when the button is clicked, but before the status change, hopefully, and check whether appropriate categories have been chosen, otherwise have a pop up appear telling the author to choose a category and then try again.

    So I have my basic plugin set up and add an action at “wp_publish” checking for the categories.

    And then I run into some problems comprehending the hook/filter structure and possibly experience the consequences of my general state of coding skills, i suppose.

    So I can use a add_filter(submitpost_box) to put a div under the submit button, but it will always be there. I cannnot dynamically but it there via the wp_publish hook, or can I?

    If I cannot, I could put an empty div there and possibly change it via Javascript, but how would I call a javascript function from within a php functin without an event handler of some sort?

    Sorry if these are stupid questions, my “how to write a plugin” tutorial doesn’t really answer them. Maybe someone here can.

    Thanks in advance!

    yms

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter youngmicroserf

    (@youngmicroserf)

    OK, I’ve managed to get an ajax script executed when someone clicks on “publish”. But I can’t access the post_id of the a post.

    I’m adding a javascript with wp_enqueue and it’s included just fine. And I want to use php to define some variable for the JS, including the post’s ID.

    But as much as I try I can’t access the post’s ID. I can see it in the URL, but apparently I cannot access the $post Object for some reason.

    I thought it’s caused by the fact that no ID had been assigned prior to saving / autosaving (at which point is a new post assigned an ID? Directly? First autosave?) but I can’t even access the ID of posts I know do have an id.

    Anyone? Help would really be appreciated!

    yms

    Thread Starter youngmicroserf

    (@youngmicroserf)

    OK, no worries, managed to get it done. Took the value of the #post_ID field that is updated by the autosave.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help! First plugin.’ is closed to new replies.