Show error message with register_setting()
-
does anyone know how to incorporate an error message using register_setting()? I have a callback function that checks to see if a value of an option already exists and if so, prevents the user from overriding it. I can prevent the override, but I can’t display an error message. Additionally, WP shows the “settings saved” message.
This is the code:
// Sanitize and validate input function azs3_upload_pages_validate($input) { $upload_pages = ''; $upload_pages .= get_option('azs3_upload_pages'); if ( isset($_POST['delete_upload_page']) && '' != $_POST['delete_upload_page'] ) { $upload_page = $_POST['delete_upload_page']; if( '' != $upload_pages ) { $upload_pages = explode (',', $upload_pages); foreach ($upload_pages as $k => $v) { if ($v == $upload_page) unset($upload_pages[$k]); } $upload_pages = implode(',',$upload_pages); } } else { if( '' != $upload_pages ) { $assigned_pages = explode (',', $upload_pages); if( in_array($input, $assigned_pages) ) { $errors = new WP_Error(); $errors->add('pageexists', __('Page already exists.')); return $upload_pages; } else { $upload_pages .= ','.$input; } } else { $upload_pages = $input; } } return $upload_pages; }
The topic ‘Show error message with register_setting()’ is closed to new replies.