I am trying to manipulate a post prior to saving. I first am using the category_save_pre filter to change the category based on some internal logic related to my app. It works fine.
Once the category is changed I need to alter the post content depending on the value of the new category. I'm having trouble getting the second function which will manipulate the post content to know what the new category is.
I have tried using a global variable in the first function and I know it works because if I create two functions outside of WP the second function will know the value of the global variable. So for example, I have something like so (note: I have simplified the logic to highlight what I'm trying to do):
function category_change($cat_holder)
{
global $replaced_cat;
if ($cat_holder[0] == 200)
{
$cat_holder[0] = 100;
}
return $cat_holder;
}
function content_change($text) {
global $replaced_cat;
$text = str_replace('%sbname%',$replaced_cat,$text);
return $text;
}
add_filter('category_save_pre','category_change');
add_filter('content_save_pre','content_change');
** So, if the category I'm trying to save is ID=200, the plugin will successfully change it to ID=100. However, if the text %sbname% is in the post content, it does not get replaced with the number 100. Instead it gets replaced with NULL.