当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

「関数リファレンス/add settings error」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(en:Function_Reference/add_settings_error 13:24, 1 April 2015 Jarim 版を流し込み。)
 
(見出しとリンク先のみ和訳。)
1行目: 1行目:
== Description ==
+
{{NeedTrans}}
 +
 
 +
<div id="Description">
 +
== 説明 ==
 +
</div>
  
 
Register a settings error to be displayed to the user.
 
Register a settings error to be displayed to the user.
5行目: 9行目:
 
Part of the [[Settings API]]. Use this to show messages to users about settings validation problems, missing settings or anything else.  
 
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 <tt>$sanitize_callback</tt> function defined in [[Function_Reference/register_setting|<tt>register_setting()</tt>]] for a given setting to give feedback about the submission.
+
Settings errors should be added inside the <tt>$sanitize_callback</tt> function defined in [[関数リファレンス/register_setting|<tt>register_setting()</tt>]] 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 <tt>settings_errors()</tt> can be used to show errors even when the settings page is first accessed.
 
By default messages will show immediately after the submission that generated the error. Additional calls to <tt>settings_errors()</tt> can be used to show errors even when the settings page is first accessed.
  
== Usage ==
+
<div id="Usage">
 +
== 使い方 ==
 +
</div>
  
%%%<?php add_settings_error( $setting, $code, $message, $type ) ?>%%%
+
<?php add_settings_error( $setting, $code, $message, $type ) ?>
  
== Parameters ==
+
<div id="Parameters">
 +
== パラメータ ==
 +
</div>
  
 
{{Parameter|$setting|string|Slug title of the setting to which this error applies.}}
 
{{Parameter|$setting|string|Slug title of the setting to which this error applies.}}
 
{{Parameter|$code|string|Slug-name to identify the error. Used as part of 'id' attribute in HTML output. A prefix of 'setting-error-' will be added to the string in $code and assigned to the 'id' attribute of the outermost &lt;div&gt; for this error.}}
 
{{Parameter|$code|string|Slug-name to identify the error. Used as part of 'id' attribute in HTML output. A prefix of 'setting-error-' will be added to the string in $code and assigned to the 'id' attribute of the outermost &lt;div&gt; for this error.}}
{{Parameter|$message|string|The formatted message text to display to the user (will be shown inside styled &lt;div&gt; and &lt;p&gt;).}}
+
{{Parameter|$message|string|The formatted message text to display to the user (will be shown inside styled <nowiki><div></nowiki> and <nowiki><p></nowiki>).}}
{{Parameter|$type|string|The type of message it is. $type will be add an HTML class of the same name of the outermost &lt;div&gt;. To add multiple classes separate them with a space.<ul><li>''error''</li><li>''updated''</li></ul>|optional|'error'}}
+
{{Parameter|$type|string|The type of message it is. $type will be add an HTML class of the same name of the outermost <nowiki><div></nowiki>. To add multiple classes separate them with a space.<ul><li>''error''</li><li>''updated''</li></ul>|optional|'error'}}
  
== Return Values ==
+
<div id="Return_Values">
 +
== 戻り値 ==
 +
</div>
  
 
; (void) : This function does not return a value.
 
; (void) : This function does not return a value.
  
== Examples ==
+
<div id="Examples">
<!-- Need creative examples. Feel free to link to external examples. -->
+
== 用例 ==
 +
</div>
  
 
<pre>function change( $data ) {
 
<pre>function change( $data ) {
64行目: 75行目:
 
}</pre>
 
}</pre>
  
== Notes ==
+
<div id="Notes">
 +
== 参考 ==
 +
</div>
  
 
The problem only occurs when I use add_menu_page() or add_submenu_page(). The validation errors are not shown.
 
The problem only occurs when I use add_menu_page() or add_submenu_page(). The validation errors are not shown.
75行目: 88行目:
 
</pre>
 
</pre>
  
== Change Log ==
+
<div id="Change_Log">
 +
== 変更履歴 ==
 +
</div>
  
 
Since: [[Version_3.0|3.0]]
 
Since: [[Version_3.0|3.0]]
  
== Source File ==
+
<div id="Source_File">
 +
== ソースファイル ==
 +
</div>
  
 
<tt>add_settings_error()</tt> is located in {{Trac|wp-admin/includes/template.php}}.
 
<tt>add_settings_error()</tt> is located in {{Trac|wp-admin/includes/template.php}}.
  
== Related ==
+
<div id="Related">
 +
== 関連項目 ==
 +
</div>
 +
 
 
{{Setting Tags}}
 
{{Setting Tags}}
  
 
{{Tag Footer}}
 
{{Tag Footer}}
  
[[Category:Functions]]
+
{{原文|Function_Reference/add_settings_error|153451}} <!-- 01:29, 16 August 2015 Gblsm 版 -->
[[Category:New_page_created]]
+
 
 +
{{DEFAULTSORT:Add_settings_error}}
 +
[[Category:関数]]
  
<!-- {{Languages|
+
[[en:Function_Reference/add_settings_error]]
{{en|Function_Reference/add_settings_error}}
+
{{ja|関数リファレンス/add_settings_error}}
+
}} -->
+

2015年8月16日 (日) 13:03時点における版

このページ「関数リファレンス/add settings 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.

使い方

<?php add_settings_error( $setting, $code, $message, $type ) ?>

パラメータ

$setting
string) (必須) Slug title of the setting to which this error applies.
初期値: なし
$code
string) (必須) Slug-name to identify the error. Used as part of 'id' attribute in HTML output. A prefix of 'setting-error-' will be added to the string in $code and assigned to the 'id' attribute of the outermost <div> for this error.
初期値: なし
$message
string) (必須) The formatted message text to display to the user (will be shown inside styled <div> and <p>).
初期値: なし
$type
string) (optional) The type of message it is. $type will be add an HTML class of the same name of the outermost <div>. To add multiple classes separate them with a space.
  • error
  • updated
初期値: 'error'

戻り値

(void) 
This function does not return a value.

用例

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
    );

}

参考

The problem only occurs when I use add_menu_page() or add_submenu_page(). The validation errors are not shown.

A simple work around is to add settings_errors() to my options page, which will make the notification box show... However, seems like a dirty fix

<h2>The heading of my settings page</h2>
<?php settings_errors(); ?>

変更履歴

Since: 3.0

ソースファイル

add_settings_error() is located in wp-admin/includes/template.php.

Settings API: register_setting(), unregister_setting(), add_settings_field(), add_settings_section(), add_settings_error(), get_settings_errors(), settings_errors(), settings_fields(), do_settings_sections(), do_settings_fields()



関数リファレンステンプレートタグ目次もご覧ください。


最新英語版: WordPress Codex » Function_Reference/add_settings_error最新版との差分