Support » Plugins » Help with my first plugin

  • 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?

    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:
     function test_nav() {
      //add_options_page(Title,Menu title,Access Level,File,Function)
    function test_admin() {
    	echo '
    <form method="post" action="'.$_SERVER['PHP_SELF'].'">
    <input type="text" name="word" />
    <br />
    Replace with:
    <input type="text" name="replacewith" /><br />
    <input type="submit" />
    if($_POST["word"] && $_POST["replacewith"]){
    function replace( $content ) {
        $word = $_POST["word"];
        $replace = $_POST["replacewith"];
    	$content = str_replace($word,$replace, $content);
    	return $content;

Viewing 3 replies - 1 through 3 (of 3 total)
  • SO nobody has the answer to this? I thought it would be an easy question for anyone experienced :S

    I cant believe nobody knows this? Have I asked in the wrong section or something?

    It is not working because the content filter is used when viewing individual posts/pages. It is not going to apply to every post/page when submitting a form from the admin area.

    The form in the admin area should save the word and replacewith to a db table or text file. Then the replace code could read from the table or file and replace the word when a post/page is being viewed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help with my first plugin’ is closed to new replies.