Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Demetrius Pop on "update_option based on selected option in admin panel"

$
0
0

I am building a 'test' wordpress plugin which should have 3 options from a select form in the admin page. When an option is selected, it should invoke a function.

Using update_option, I have this:

The code:

<select name="pytime">
        <option value="1">time</option>
        <option value="2">date</option>
        <option value="3">date-time</option>
    </select>

<?php
$pytime = $_POST['pytime'];
if($pytime == 1) {
    function add_copyright() {
        $copyright_message = "Copyright ". date(Y)  . ", All Rights Reserved";
        echo '<div id="plugin-copyright">' . $copyright_message . '</div>';
    }
    add_action("wp_footer",add_copyright);
}

if($pytime == 2) {
    function func2() {
       // func2 code
    }
    add_action("wp_footer",func2);
}

if($pytime == 3) {
    function func3() {
       // func3 code
    }
    add_action("wp_footer",func3);
}

$option_name = 'time' ;
$new_value = $_POST['pytime'];

if ( get_option( $option_name ) !== false ) {

    // The option already exists, so we just update it.
    update_option( $option_name, $new_value );

} else {

    // The option hasn't been added yet. We'll add it with $autoload set to 'no'.
    $deprecated = null;
    $autoload = 'no';
    add_option( $option_name, $new_value, $deprecated, $autoload );
}

What should I set $option_name and $new_value to in order to select the appropreiate function?


Viewing all articles
Browse latest Browse all 8245

Trending Articles