[wp-hackers] nested shortcode
Daiv Mowbray
daiv at daivmowbray.com
Sat Jan 17 23:58:56 GMT 2009
I've been around the bend on this one.
is it possible to do the following?
hello list
I add a shortcode [myclass] anywhere in a post
which will then add to any image in that post the class of myclass.
remember that a post image probably has [caption] shortcode already.
I have (inside my plugin class):
add_shortcode ( 'myclass' , array(&$this, 'class_shortcode_out'));
function class_shortcode_out( $attr, $content='' ){
extract(shortcode_atts(array(
'class_height' => '',
'class_color' => ''), $attr));
$content = $this->class_replace($content);
return do_shortcode($content);
}
function class_replace($content) {
$pattern = "/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)
('|\")(.*?)class=('|\")(.*?)('|\")(.*?) \/>/i";
$replacement = "<img$1src=$2$3.$4$5$6class=$7$8 myclass$9$10 /
>";
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
This isn't working for me. The preg_replace works, but not with the
[captions] shortcode.
Any ideas?
Thanx.
----------
Daiv Mowbray
daiv at daivmowbray.com
----------
More information about the wp-hackers
mailing list