^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数add_settings_error()用法示例

add_settings_error( string $setting,  string $code,  string $message,  string $type = 'error' )

Register a settings error to be displayed to the user


描述

Part of the Settings API. Use this to show messages to users about settings validation problems, missing settings or anything else.

Settings errors should be added inside the $sanitize_callback function defined in register_setting() for a given setting to give feedback about the submission.

By default messages will show immediately after the submission that generated the error. Additional calls to settings_errors() can be used to show errors even when the settings page is first accessed.


参数

$setting

(string)
(Required)
Slug title of the setting to which this error applies

$code

(string)
(Required)
Slug-name to identify the error. Used as part of ‘id’ attribute in HTML output.

$message

(string)
(Required)
The formatted message text to display to the user (will be shown inside styled <div> and <p> tags).

$type

(string)
(Optional)
Message type, controls HTML class. Accepts ‘error’ or ‘updated’.

Default value: ‘error’


源代码

File: wp-admin/includes/template.php

function add_settings_error( $setting, $code, $message, $type = 'error' ) {
	global $wp_settings_errors;

	$wp_settings_errors[] = array(
		'setting' => $setting,
		'code'    => $code,
		'message' => $message,
		'type'    => $type
	);
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

Used By

  • wp-includes/formatting.php:
    sanitize_option()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Basic Example

    
    function change( $data ) {
    
        $message = null;
        $type = null;
    
        if ( null != $data ) {
    
            if ( false === get_option( 'myOption' ) ) {
    
                add_option( 'myOption', $data );
                $type = 'updated';
                $message = __( 'Successfully saved', 'my-text-domain' );
    
            } else {
    
                update_option( 'myOption', $data );
                $type = 'updated';
                $message = __( 'Successfully updated', 'my-text-domain' );
    
            }
    
        } else {
    
            $type = 'error';
            $message = __( 'Data can not be empty', 'my-text-domain' );
    
        }
    
        add_settings_error(
            'myUniqueIdentifyer',
            esc_attr( 'settings_updated' ),
            $message,
            $type
        );
    
    }
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈