Both these functions does not set the $is_new_item as expected... i have tried elevated the priority to 1 when doing the add_action but no luck so far.
example code.
add_action('pods_api_post_save_pod_item_monkey', 'nh_pod_post_save_item_monkey', 1, 3);
function nh_pod_post_save_item_monkey($pieces, $is_new_item, $id ) {
if ($is_new_item)
{
die('its new monkey!');
} else {
die('No new monkey');
}
}
This will always return with no new monkey :(
But I like monkeys :(
@JoryHogeveen exactly! That's what makes it so sad :(
Where did you find this hook by the way?
http://pods.io/docs/code/action-reference/pods_api_post_save_pod_item/
http://pods.io/docs/code/action-reference/pods_api_post_save_pod_item_podname/
Hmms i maybe should try the "pre" save filter-version also.
That shouldn't make a difference.
This value is set before the pre hooks so the result would probably be the same.
From what I see it simply checks if the item exists or the params explicitly force it to be set to true:
https://github.com/pods-framework/pods/blob/2.x/classes/PodsAPI.php#L3103
// Allow Helpers to know what's going on, are we adding or saving?
$is_new_item = false;
if ( empty( $params->id ) )
$is_new_item = true;
if ( isset( $params->is_new_item ) )
$is_new_item = (boolean) $params->is_new_item;
if ( empty( $params->id ) ) is it here the trouble begins then?
Not sure, what are you using the Pods? Is this monkey a CPT?
Yes
And how are you adding the monkey? WP admin or a function/form?
WP admin
Did some tests etc. Though this seems weird to me, it appears that the save_post hook from WP that Pods uses is not passing the $update variable.
Will check in when I find more.
@sc0ttkclark
if I change the priority of the Pods hook for save_post anything other than 10 it works correctly...
https://github.com/pods-framework/pods/blob/2.x/classes/PodsMeta.php#L138
Heads up here, because Pods API isn't adding the post itself, it's already added by the time save_pod_item runs so it counts as an edit.
We could try and pass an extra parameter to the API in the PodsMeta save_post handling and adjust the save_pod_item handling to tell it that it's new.
Still, there are some weird things hapening:
save_post hook calls with a higher priority don't run anymore (not checked if this is Pods doing..)Even after running a debug_backtrace() I see that the hook to PodsMeta->save_post() passes only 2 parameters even when Pods requested 3.
At the hook call there are 3 parameters available (the third being $update set to true) but this never gets passed for some weird reason..