help writing plugin
-
I’m just scratching the topic, learning php and how WP plugins are coded.
I need some help to understand a couple of things.
My first plugin is very very basic, preg_replace to change whatever is wrapped in <replace_this> in a post, so far it works, now I’m trying to add stuff inside the post.
My first functions is:
function my_replace($test) { $needed = "test"; // actually it should be the function my_func() $test = preg_replace('/<replace_this>(.*?)<\/replace_this>/i',$needed,$test); return $test; } add_filter('the_content', 'my_replace');
the other functions is:
function my_func() { $container_open = "<div style='border:1px solid #000; width:380px; margin:4px auto; background:#bbaa99;padding:4px;'>"; //ugly way to do it $container_close = "</div>"; // even uglier ah ah $myarray = array("cool","ok","awesome","great","meh"); sort ($myarray); for ($i=0; $i<count($myarray); $i++){ echo $container_open.$i." is ".$myarray[$i]."".$container_close; } }return $content; add_filter('the_content', 'my_func');
So, $needed should output the array of the second function but I don’t know how to do it.
I even tried to do something like $needed = “<?php my_func(); ?>”; and use the plugin Exec-PHP to run that code inside the post but doesn’t work.I know I’m doing it wrong, but right now I’m trying to get into the logic of programming and can’t think of another way (that I’m aware of).
Any input is appreciated, thanks.
- The topic ‘help writing plugin’ is closed to new replies.