Hi guys
Im hoping to start developing wordpress plugins to expand my knowledge of PHP while also making plugins to help people out.
This is my first plugin, so I thought i would go with something Extremely simple, or so I thought it would be. Basicly, when you activate this plugin, and goto the plugin menu in the admin panel, you can select a word you wish to replace, and then the word you wish to replace it with, and the plugin will do this for you, if you wish to change back - you can simply disable the plugin.
As far as I can tell, in theory the following code should work, however it is not. I was wondering if some-body could explain why not?
<?php
/*
Plugin name: Jake's plugin
Plugin Description: This is a plugin which when activated, will replace a word with another word..
Version: 1.00
Author: Jake Austwick
Author URI: http://www.game-tec.com
*/
?>
<?php
function test_nav() {
//add_options_page(Title,Menu title,Access Level,File,Function)
add_options_page("test","test",1,"plugin.php","test_admin");
}
add_action("admin_menu","test_nav");
function test_admin() {
echo '
<form method="post" action="'.$_SERVER['PHP_SELF'].'">
Word:
<input type="text" name="word" />
<br />
Replace with:
<input type="text" name="replacewith" /><br />
<input type="submit" />
</form>
';}
if($_POST["word"] && $_POST["replacewith"]){
function replace( $content ) {
$word = $_POST["word"];
$replace = $_POST["replacewith"];
$content = str_replace($word,$replace, $content);
return $content;
}
add_filter("the_content",replace);
}
?>