[wp-hackers] register_settings and admin_notices

Ade Walker photofantaisie at gmail.com
Fri Oct 23 21:34:17 UTC 2009


@ Mohammad and Glenn,

Thanks for the feedback guys. Your comments gave me some ideas which led to
the following solution:

A conditional inside the register_settings() callback function checks if the
Settings page Reset checkbox has been checked. If true, it adds a new option
to the options array, called 'just-reset' with a value of 'true'. Then in
the admin_notices function, if 'just-reset' is true, the function outputs
the customised message. If the Settings page is updated without Reset,
'just-reset' is set to 'false', and no custom message is displayed. The
admin_notices function also checks the plugin's pagehook before doing
anything (good point, Glenn).

Plus, I can use the same method to add other validation messages, if
required, all hooked into admin_notices.

This works well, functionality-wise. I guess the only downside is the db
write and retrieval of the 'just-reset' option, but I don't think this is
really an issue given it's only happening in admin.

If anyone can see a better way, the feedback will be very welcome.

Thanks!

Ade.





2009/10/23 Glenn Ansley <glenn at glennansley.com>

> I haven't looked at the code to see if there's an API for that but
> rather than using javascript you could hook in before that chunk of
> code and unset $_GET['updated']. Then you could use the admin_notices
> to construct your own message. (Check to make sure it's your plugin's
> page before unsetting it though).
>
> Glenn Ansley
> http://fullthrottledevelopment.com
> http://twitter.com/full_throttle
> http://twitter.com/glennansley
>
> On Fri, Oct 23, 2009 at 8:27 AM, Mohammad Jangda <batmoo at gmail.com> wrote:
> > Here's the code that displays the "updated" message (in
> options-head.php):
> >
> > <?php if (isset($_GET['updated'])) : ?>
> >> <div id="message" class="updated fade"><p><strong><?php _e('Settings
> >> saved.') ?></strong></p></div>
> >> <?php endif; ?>
> >>
> >
> > I don't see an easy way to change that.
> >
> > You could use admin_notices to display the custom message and use
> javascript
> > to hide the default "Settings Saved" message (obviously a subpar
> solution).
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list