Posts: 75
Threads: 14
Joined: Apr 2011
During Affiliate Product Manager Plugin I face with one problem. I want page content xhtml code to have proper indentation or to be all in one line. But I can not figure how to process complete page code before output.
I realize that :
Quote:exec_action('index-posttemplate');
Do final work but I can not find where this function exists.
Posts: 3,491
Threads: 106
Joined: Mar 2010
'index-posttemplate' hook is fired *after* the page is rendered. If you want to alter the page content before it is displayed, you'll probably need to use the 'content' filter: see
http://get-simple.info/wiki/plugins:hook...re_filters
Posts: 75
Threads: 14
Joined: Apr 2011
I do not know what is problem I try:
Quote:add_filter('content','xhtml_one_line');
and function:
Quote:function xhtml_one_line($contents){
$temp = $contents;
$temp = preg_replace('/^\s+|\n|\r|\s+$/m', '', $temp);
$temp = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $temp);
$temp = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $temp);
$temp = preg_replace(array('(( )+{)','({( )+)'), '{', $temp);
$temp = preg_replace(array('(( )+})','(}( )+)','(;( )*})'), '}', $temp);
$temp = preg_replace(array('(;( )+)','(( )+'), ';', $temp);
$temp = preg_replace(array('( )+)','(( )+'), ':', $temp);
$temp = preg_replace('/(\s|)\,(\s|)/', ',', $temp);
return $temp;
}
But I do not see results for some reason, GSDEBUG enabled. No errors.
Posts: 524
Threads: 48
Joined: Mar 2011
It's $content I believe, not $contents.
Posts: 75
Threads: 14
Joined: Apr 2011
It doesn't make difference I look at Plugins that do more less same like Replacer and External commenting. They use this naming for function.
Posts: 3,491
Threads: 106
Joined: Mar 2010
bogyvet Wrote:I do not know what is problem I try:
I've tried a simpler test, code based on yours:
Code:
add_filter('content','stoz');
Code:
function stoz($contents){
$temp = $contents;
$temp = str_replace('s', 'z', $temp);
return $temp;
}
Thi
z work
z. :-)
So it may be something wrong in your
str_replace or
preg_replace lines. (No idea what, I haven't examined them...)
Posts: 3,491
Threads: 106
Joined: Mar 2010
2011-06-28, 01:52:02
(This post was last modified: 2011-06-28, 01:52:35 by fotothink.)
I've tried your code again. I don't know if it does all you expected, but looking at the page source, the page content is stuffed in just one line. So it does something.
Posts: 75
Threads: 14
Joined: Apr 2011
Thanks I will try another installation!!!