質問編集履歴
1
書式の改善
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -5,17 +5,13 @@
|
|
|
5
5
|
で作成しています。
|
|
6
6
|
|
|
7
7
|
デフォルトのエラーメッセージ『必須項目に入力してください。』を、
|
|
8
|
-
特定の項目(この場合電話番号)だけ文言を変更した
|
|
8
|
+
特定の項目(この場合電話番号)だけ文言を変更したく、以下参考サイトをもとに、
|
|
9
|
+
function.phpに追記したのですが文言が変更されませんでした。
|
|
9
10
|
|
|
10
|
-
wpcf7_validation_errorフックでエラー文言を変更しようとしています。
|
|
11
|
-
|
|
12
|
-
参考にして
|
|
11
|
+
参考にしてしたサイト
|
|
13
12
|
[https://qiita.com/_ruka_/items/a209606290e5a8f2ccb8](https://qiita.com/_ruka_/items/a209606290e5a8f2ccb8)
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
### 該当のソースコード
|
|
17
|
-
|
|
18
|
-
```
|
|
14
|
+
```PHP
|
|
19
15
|
function wpcf7_custom_error($error, $name, $instance){
|
|
20
16
|
if( $name === "your-tel") {
|
|
21
17
|
$error = '<span role="alert" class="wpcf7-not-valid-tip">ここに文言が入る</span>';
|
|
@@ -23,4 +19,49 @@
|
|
|
23
19
|
return $error;
|
|
24
20
|
}
|
|
25
21
|
add_filter('wpcf7_validation_error','wpcf7_custom_error',10,2);
|
|
26
|
-
```
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
wpcf7_validation_errorフック自体が動作していない可能性も含めて、
|
|
25
|
+
以下のコードですべてのエラー文言が書きわかるかどうか試したのですが、
|
|
26
|
+
動作していないようでした。
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```PHP
|
|
30
|
+
function wpcf7_custom_error($error, $name, $instance){
|
|
31
|
+
$error = '<span role="alert" class="wpcf7-not-valid-tip">ここに文言が入る</span>';
|
|
32
|
+
return $error;
|
|
33
|
+
}
|
|
34
|
+
add_filter('wpcf7_validation_error','wpcf7_custom_error',10,2);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
元のソースの、プラグイン内の\wp-content\plugins\contact-form-7\includes\contact-form.php
|
|
38
|
+
に以下の該当箇所もあり、問題ないとは思うのですが動作せずに困っております。
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
```PHP
|
|
42
|
+
public function validation_error( $name ) {
|
|
43
|
+
$error = '';
|
|
44
|
+
|
|
45
|
+
if ( $this->is_posted() ) {
|
|
46
|
+
$submission = WPCF7_Submission::get_instance();
|
|
47
|
+
|
|
48
|
+
if ( $invalid_field = $submission->get_invalid_field( $name ) ) {
|
|
49
|
+
$error = trim( $invalid_field['reason'] );
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ( ! $error ) {
|
|
54
|
+
return $error;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
$error = sprintf(
|
|
58
|
+
'<span role="alert" class="wpcf7-not-valid-tip">%s</span>',
|
|
59
|
+
esc_html( $error ) );
|
|
60
|
+
|
|
61
|
+
return apply_filters( 'wpcf7_validation_error', $error, $name, $this );
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
どなたかご教授頂けると助かります。
|
|
67
|
+
よろしくお願い致します。
|