Wordpress Hooks + Php question

Discussion in 'Programming' started by JayCool, Jan 8, 2012.

  1. #1
    Hi!


    First post. I am trying to make my own little plugin : ).


    1) What I am trying to accomplish:
    -I want the plugin to save options when you click "update" in the edit page/post in the admin area.


    Here is my little code:


    ====
    add_action('save_post', 'myplugin_save_postdata'); // <-- this doesn't work the way I want it to :(, as in it doesn't call the function, I think, when I click "update" or "publish"




    function myplugin_save_postdata( $post_id ) {
    ?>
    <script type="text/javascript">
    alert("SAVING POST");
    </script>
    <?php

    $mydata = $_POST['myplugin_new_field'];
    add_option('my_option', $mydata, '', 'yes');
    update_option('my_option', $mydata, '', 'yes');
    }
    ====


    The thing is, it doesn't work. I click update the post, and there is no javascript alert box.


    2) I want to echo <img src="lalala/img.png"> without it actually showing the picture.


    In other words, I want it to echo the text <img src="lalala/img.png">, and not the picture lalala/img.png.

    Can anyone help me ;).
     
    JayCool, Jan 8, 2012 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,832
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #2
    If you have a wysiwyg editor (like in wordpress) put the text into the visual site and then look at how it is altered in the backend - most specifically the < and > become &gt; and &lt; - if you use that coding too you will end up with text and not an image.
     
    sarahk, Jan 13, 2012 IP