[wp-hackers] Re: Back on the plugin scene -- some questions
Stephanie Booth
bunnylists at gmail.com
Sat Dec 29 17:36:05 GMT 2007
On Dec 29, 2007 11:53 AM, Stephanie Booth <bunnylists at gmail.com> wrote:
> 1. Print CSS
this is mostly solved, cf. my other mail about it.
> 2. Is feed or not?
Thanks to Peter and Lutz for their suggestions. Seems solved to me (I
now understand my mistake).
> 3. Sandbox drop-down menu problem in IE/win
this is still open.
> 4. Using ob_start()
>
> I've been told this could be a bit nasty, but it seems a solution for
> my Basic Bilingual plugin (updated last night in the plugin
> repository, btw!), which I would like to make capable of inserting
> lang="xx" attributes in various pre-existing elements in templates.
>
> Can somebody tell me if I'm on the right track with the following:
>
> function bb_replace($buffer) {
> $search = blah blah
> $replace = blah blih bloh
> return preg_replace($search, $replace, $buffer);
> }
>
> function bb_buffer() {
> ob_start('bb_replace');
> }
>
> add_action('template_redirect', 'bb_buffer'); // is this the correct
> hook to use?
>
After a few hit-and-miss attempts, I'm a little more advanced, and the
problem has morphed into a regex issue. Here's what I have:
function bll_insert_slug_links($buffer) {
$search = '</div><!-- #access -->';
$replace = bll_make_slug_links() . $search;
// return preg_replace($search, $replace, $buffer);
return str_replace($search, $replace, $buffer);
}
function bll_embed_slug_links_well($buffer) {
ob_start('bll_insert_slug_links');
}
add_action('template_redirect', 'bll_embed_slug_links_well');
I've tested it and it works, inserting the code generated by
bll_make_slug_links() right before the closing </div> I wanted. So, to
answer my own question, I was indeed on the right track.
It gets more complicated, however, when the code I try to match is
'</ul></div> .....some whitespace..... </div><!-- #access -->'. As the
nature of the whitespace is undetermined, that means I have to use
ereg_replace() or preg_replace() (I don't think it's possible with
str_replace(), correct me if I'm wrong). And this is where all goes to
hell because I've forgotten how to format regexes properly.
Here's my first (failing) attempt:
$search='/<\/ul><\/div>\s\s+<\/div><\!-- \#access -->/';
Assistance from a regex wizard would be muchly appreciated. Also, am I
going to have to escape the string returned by bll_make_slug_links()?
(it's a bunch of HTML links).
Thanks for your help,
Steph
--
web: http://stephanie-booth.com
blog: http://climbtothestars.org
skype: steph-booth or +41 44 586 42 74 | cell: +41 78 625 44 74
ICQ: 23836265 | MSN: gummywabbit at hotmail.com | AIM: Gummywabbit
For the rest... Google me!
More information about the wp-hackers
mailing list