Forum Replies Created
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
ytilisMemberAh, gotcha. That does present me with the problem that I don’t have a way of passing the missing fields to the notice itself, but I can mitigate that by making the messaging more generic, and by setting those fields to required on the settings page, so I still have a way of showing what’s missing that way.
Thanks
ytilisMemberSure. I’ve pasted the anonymized code below:
<?php /* Notice ID: my_requirements Notice Type: error Role: administrator */ $settings = get_option('my_settings'); $admin_messages = []; if( !isset($settings['key']) || $settings['key'] == '' ){ $admin_messages[] = "A <strong>Key</strong> is required"; } if( !isset($settings['secret']) || $settings['secret'] == '' ){ $admin_messages[] = "An <strong>Secret</strong> is required"; } if(count($admin_messages) > 0) { $messages = ''; foreach ($admin_messages as $message) { $messages .= sprintf("<li>%s</li>", $message); } ?><p><strong>Warning!</strong> The following required settings for My Plugin are unset:</p> <ul> <?php echo $messages; ?> </ul><?php }?>This works great except when I no longer have any errors I need to show because the admin has filled out the required settings, in which case the notice just shows up empty. If there’s a better way to do what I’m trying to accomplish, or if I missed a step somewhere, feel free to let me know.
Thanks
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)