WordPress.org

Support

Support » Plugins and Hacks » Execute set of commands while posting

Execute set of commands while posting

  • Hello all,

    Is there any plugin available to execute set of php statements while creating a post ?

    my concern is, while submitting a post, the user will submit a URL as a custom field and couple of other custom fields. I need validate the URL submitted by user whether it is broken or not, then accept the post.

    let me know if there is any existing plugins available or show me a way how to do it.

    BTW, i know little bit of php & mysql πŸ˜‰

Viewing 8 replies - 1 through 8 (of 8 total)
  • Samuel Wood (Otto)
    WordPress.org Tech Dude

    @otto42

    Make your own plugin. It’s easy.
    http://codex.wordpress.org/Writing_a_Plugin

    Also see this:
    http://codex.wordpress.org/Plugin_API

    Look carefully at the action hooks, especially the “publish_post” action.

    thanks. I have tried quickly and now I would like to know some more info.

    a. I would like to find the post id of the post I am submitting to.
    b. I would like to find the custom fields submitted by user. (for the post I am trying to publish)

    I already tried get_post_custom_values(“mycustomfield”) but it doesn’t work.

    Thanks a lot πŸ™‚

    Samuel Wood (Otto)
    WordPress.org Tech Dude

    @otto42

    The publish_post action passes the ID of the post to your function.

    function whatever($postid) {
    // $postid has the post id in it.
    }
    add_action('publish_post','whatever');

    Then, you can use get_post_custom_values('whatever',$postid); as well.

    thanks. i will give a try. πŸ™‚

    okay. it works great. thanks for helping me. πŸ˜€

    Now i am facing a new problem. it executes the function every time we publish the post. I mean if we edit the same post it executes the function again.

    Is there any way to execute only once ?

    Samuel Wood (Otto)
    WordPress.org Tech Dude

    @otto42

    There’s six different statuses for posts:
    publish
    draft
    private
    future
    pending
    new

    Whenever a post status changes, a OLD_to_NEW action occurs. So new_to_draft happens when you create a new draft, sort of thing.

    If you make five different hooks (all to your existing function), with all of the types going to_publish, then you can hook all the ways to publish a post for the first time. Like new_to_publish, pending_to_publish, etc.

    Thanks I will give a try during weekend. πŸ˜€

    BTW, I have written a new plugin :D:D

    Thanks a lot for your help πŸ™‚

    mschaefer
    Member

    @mschaefer

    I can’t find any documentation for the OLD_to_NEW postsβ€”can you please point the way?

    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Execute set of commands while posting’ is closed to new replies.