0

So I added a new submission button to the edit page:

Using the post_submitbox_misc_actions hook with the submit_button($text, $type, $name); function.

I wanted to modify the data that's saved based on what button the user clicks. So if the user clicks on the regular update/submit button then the post would save normally. However if the user clicks on the new button, then I would modify some information about that post.

I was planning to use the wp_insert_post_data hook to modify the data, but the problem is that I don't know what button the user clicked (using php).

So my question... is it possible to identify which button the user clicked using a hook (or some other method)?

Or, is this not the correct approach? And I should use some other method to interfere the save action?

Update:

I also tried logging $_GET and $_POST to see if there was any relevant information there, but couldn't find anything.

1 Answer 1

0

The function submit_button() does generate:

<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"  />

As seen on the codex documentation page. Which gives you the possibility to check for a $_POST or, depending on the form, $_GET or generic $_REQUEST variable - to be exact for $_POST[ 'submit' ] or $_GET[ 'submit' ] or $_REQUEST[ 'submit' ]. The key for the variable is determined by the input tags name attribute value, which you can change for submit_button() by making use of the $name parameter.

3
  • 1
    Gotcha. I was expecting to see something like $_POST['submit'] = 'my_submit_button_value", where the array key is always 'submit', but the value changes according to the name attribute. But instead, what I see is the key as the submit button 'name' and the value as the submit button 'value'. So I just need to check of the key exists, and if it matches the value.
    – gdaniel
    Commented Jan 13, 2016 at 21:20
  • Totally forgot to explain the value part, but you figured it out yourself anyway. I would figure that should be enough to determine the button pressed, right? @gdaniel Commented Jan 13, 2016 at 21:21
  • @gdaniel My pleasure! Commented Jan 13, 2016 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.