Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this little php code for wordpress. It doesn't work. I want to make one add_action under another add_action. But the add_action that is under, is not working!

function no_reminder() {
    echo "no_reminder function is active";
    add_action('admin_menu','no_reminder');

    remove_action( 'admin_notices', 'update_nag', 3 );
}

add_action('admin_menu', 'custom');
function custom() {
    add_menu_page('settings', 'settings', '8', 'custom', 'customfunc');
}

function customfunc(){
    $wpp_rg = get_option('wpp_rg');
    if ($_POST['wpp_submit']):
        update_option('wpp_rg',$_POST['wpp_rg']);
    endif;
    $farzad = get_option('wpp_rg');
    /******************** IF1 ***********************/
    if ($farzad==1) {
        do_action('no_reminder');
        no_reminder();
        echo "If active";
    }
    if ($farzad==2) {
        echo "IF Not Active";
    }
/******************** IF1 ***********************/
?>
<div class="wrap">
<form action="" method="post">
<table width="50%" border="0" cellspacing="5" cellpadding="5">
<tr>
        <th scope="row">test mode :</th>
        <td><p>
         <label>
                <input name="wpp_rg" type="radio" value="1" id="RadioGroup1_0" <?php echo ($farzad==1 ? 'checked="checked"' : '') ?> />
                active</label>
         <br />
         <label>
                <input name="wpp_rg" type="radio" value="2" id="RadioGroup1_1" <?php echo ($farzad==2 ? 'checked="checked"' : '') ?>/>
                not active</label>
         <br />
        </p></td>
</tr>

<tr>
        <th></th>
        <td><input type="submit" name="wpp_submit" value="save" class="button" /></td>
</tr>
</table>
</form>
</div>
<?php
}

?>

What should i do ?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The preferred method of creating a settings page is to use the WordPress Settings API.

From your code example, it looks like it's too late to remove the admin_notices hook inside your callback in the admin_menu hook.

You should try to move the logic from the customfunc() callback into another callback activated from some earlier hook, for example admin_init.

Additionally:

You are also calling the new admin menu page settings, but the user might confuse it with the existing Settings page.

The User Levels you have in one of the add_menu_page() input parameters, are deprecated, use instead some of the Capabilites mentioned here.

So instead use for example:

add_menu_page( 'My settings', 'My settings', 'manage_options', 'custom', 'customfunc' );
share|improve this answer
3  
I agree that a lot of the OP's issues will probably resolve themselves once the OP starts using the Settings API correctly. –  helgatheviking Mar 8 at 10:56
1  
@UserPHP You can help "more" by specifying what "it's not working again" is. This is vague at its best. Please come up with specific debug/error output and a really detailed description of assumptions vs. real world output. –  kaiser Mar 8 at 16:00
1  
First, please read in Codex about debugging and WP_DEBUG. Second - as I already said - not working is no proper problem or error description. –  kaiser Mar 8 at 16:53
1  
While you are going through the settings API and the above suggestions, you might try to add something like this (untested) : pastebin.com/fcH4MV8r to your code snippet. I don't want to add this to the answer, since I think you should use the settings API ;-) –  birgire Mar 8 at 20:12
2  
I see, appreciate your thoughts and the vote on this answer, but please stop it on other questions, I would like to earn it through hard work. Could you down vote them back, thanks –  birgire Mar 9 at 18:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.