The “word_count” function below returns different values depending on where its called from. Why?
add_action('save_post', 'my_custom_save', 10, 2);
function myPlugin($post)
{
global $rockScore;
global $text;
$text = strip_tags($post->post_content);
echo word_count($post); //returns "350"
}
function word_count($post)
{
global $text;
$word_count = explode(' ', $text);
$word_count = count($word_count);
return $word_count;
}
function my_custom_save($postID, $post){
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $postID;
}
else
{
if($parent_id = wp_is_post_revision($postID))
{
$postID = $parent_id;
}
echo word_count($post);die; //still returns "1"
}
}
register_activation_hook(__FILE__, 'myPlugin');
Probably revisions. Check $post->post_type.