add_settings_error example

/* * Switch translation in case WPLANG was changed. * The global $locale is used in get_locale() which is * used as a fallback in get_user_locale(). */
        unset( $GLOBALS['locale'] );
        $user_language_new = get_user_locale();
        if ( $user_language_old !== $user_language_new ) {
            load_default_textdomain( $user_language_new );
        }
    } else {
        add_settings_error( 'general', 'settings_updated', __( 'Settings save failed.' ), 'error' );
    }

    /* * Handle settings errors and return to options page. */

    // If no settings errors were registered add a general 'updated' message.     if ( ! count( get_settings_errors() ) ) {
        add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
    }

    
break;
    }

    if ( null !== $error ) {
        if ( '' === $error && is_wp_error( $value ) ) {
            /* translators: 1: Option name, 2: Error code. */
            $error = sprintf( __( 'Could not sanitize the %1$s option. Error code: %2$s' )$option$value->get_error_code() );
        }

        $value = get_option( $option );
        if ( function_exists( 'add_settings_error' ) ) {
            add_settings_error( $option, "invalid_{$option}", $error );
        }
    }

    /** * Filters an option value following sanitization. * * @since 2.3.0 * @since 4.3.0 Added the `$original_value` parameter. * * @param string $value The sanitized option value. * @param string $option The option name. * @param string $original_value The original value passed to the function. */

function _wp_personal_data_handle_actions() {
    if ( isset( $_POST['privacy_action_email_retry'] ) ) {
        check_admin_referer( 'bulk-privacy_requests' );

        $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) );
        $result     = _wp_privacy_resend_request( $request_id );

        if ( is_wp_error( $result ) ) {
            add_settings_error(
                'privacy_action_email_retry',
                'privacy_action_email_retry',
                $result->get_error_message(),
                'error'
            );
        } else {
            add_settings_error(
                'privacy_action_email_retry',
                'privacy_action_email_retry',
                __( 'Confirmation request sent again successfully.' ),
                'success'
            );
foreach ( $request_ids as $request_id ) {
                    $resend = _wp_privacy_resend_request( $request_id );

                    if ( $resend && ! is_wp_error( $resend ) ) {
                        $count++;
                    } else {
                        $failures++;
                    }
                }

                if ( $failures ) {
                    add_settings_error(
                        'bulk_action',
                        'bulk_action',
                        sprintf(
                            /* translators: %d: Number of requests. */
                            _n(
                                '%d confirmation request failed to resend.',
                                '%d confirmation requests failed to resend.',
                                $failures
                            ),
                            $failures
                        ),
                        
&& current_user_can( 'edit_theme_options' )
                && current_theme_supports( 'menus' )
            ) {
                $privacy_page_updated_message = sprintf(
                    /* translators: %s: URL to Customizer -> Menus. */
                    __( 'Privacy Policy page setting updated successfully. Remember to <a href="%s">update your menus</a>!' ),
                    esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) )
                );
            }
        }

        add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' );
    } elseif ( 'create-privacy-page' === $action ) {

        if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php';
        }

        $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content();
        $privacy_policy_page_id      = wp_insert_post(
            array(
                'post_title'   => __( 'Privacy Policy' ),
                'post_status'  => 'draft',
                


wp_reset_vars( array( 'action' ) );

if ( isset( $_GET['updated'] ) && isset( $_GET['page'] ) ) {
    // For back-compat with plugins that don't use the Settings API and just set updated=1 in the redirect.     add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'success' );
}

settings_errors();

        } elseif ( ! $is_nginx && $htaccess_update_required && ! $writable ) {
            $message = sprintf(
                /* translators: %s: .htaccess */
                __( 'You should update your %s file now.' ),
                '<code>.htaccess</code>'
            );
        }
    }

    if ( ! get_settings_errors() ) {
        add_settings_error( 'general', 'settings_updated', $message, 'success' );
    }

    set_transient( 'settings_errors', get_settings_errors(), 30 ); // 30 seconds.
    wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
    exit;
}

flush_rewrite_rules();

require_once ABSPATH . 'wp-admin/admin-header.php';
Home | Imprint | This part of the site doesn't use cookies.