質問編集履歴

2

プラグインurlの追加

2017/08/24 01:28

投稿

sugadai
sugadai

スコア11

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,11 @@
6
6
 
7
7
  以下具体的な情報に変更。
8
8
 
9
+ 具体的に行いたいことは、woocommerce frontend manager
10
+
11
+ (https://wordpress.org/plugins/wc-frontend-manager/)
12
+
9
- 具体的に行いたいこは、woocommerce frontend managerというプラグインで、読み込まれるテンプレートファイル(wcfm-view-products-manage.php)を編集することです。
13
+ というプラグインで、読み込まれるテンプレートファイル(wcfm-view-products-manage.php)を編集することです。
10
14
 
11
15
  子テーマでの編集を行いたいのですが、子テーマでの上書きはサポートされていないため、フックを利用した編集を行うのがベストだと考えられます。編集内容が多く、wcfm-view-products-manage.phpにあるフックを利用するのは不可能であったため、読み込まれるファイルを自分で作ったnew-wcfm-view-products-manage.phpにしたいと思っています。
12
16
 

1

内容を具体的なものに変更

2017/08/24 01:28

投稿

sugadai
sugadai

スコア11

test CHANGED
File without changes
test CHANGED
@@ -4,64 +4,132 @@
4
4
 
5
5
 
6
6
 
7
- ----aaa.php----
7
+ 以下具体的な情報に変更。
8
8
 
9
- ~before~
9
+ 具体的に行いたいことは、woocommerce frontend managerというプラグインで、読み込まれるテンプレートファイル(wcfm-view-products-manage.php)を編集することです。
10
10
 
11
- require_once(bbb.php);
11
+ 子テーマでの編集を行いたいのですが、子テーマでの上書きはサポートされていないため、フックを利用した編集を行うのがベストだと考えられます。編集内容が多く、wcfm-view-products-manage.phpにあるフックを利用するのは不可能であったため、読み込まれるファイルを自分で作ったnew-wcfm-view-products-manage.phpにしたいと思っています。
12
-
13
- ~after~
14
-
15
- ----aaa.php----
16
12
 
17
13
 
18
14
 
15
+ ###該当のソースコード
19
16
 
17
+ class-wcfm-library.php
20
18
 
21
- のように、あるファイル内でbbb.phpを読み込んだときに、
19
+ (wcfm-view-products-manage.phpを読み込んでいるファイル)
22
20
 
23
- ~after~以下読み込まなくする方法はありますでしょうか。(全ての読み込みを終了するのではなく、aaa.phpにおいて、~after~の前にreturnが来るイメージです。)
21
+ ```ここに言語入力
24
22
 
23
+ class WCFM_Library {
25
24
 
25
+ public function load_views( $end_point, $menu = true ) {
26
26
 
27
- ----bbb.php----
27
+ do_action( 'before_wcfm_load_views', $end_point );
28
28
 
29
- return return;
29
+ switch( $end_point ) {
30
30
 
31
- ----bbb.php----
31
+ ~~
32
32
 
33
+ case 'wcfm-products-manage':
33
34
 
35
+ require_once( $this->views_path . 'wcfm-view-products-
34
36
 
35
- のようにできたら一番良いのですが、retunは返り値として返せないため困っています。
37
+ manage.php' );
36
38
 
37
- また、同様のパターンとして、
39
+ break;
38
40
 
39
- プラグインにおける関数内で、
41
+ ~~
40
42
 
43
+ }
41
44
 
45
+ }
42
46
 
43
- ~before~
47
+ ~~
44
48
 
45
- do_action($hook);
49
+ }
46
50
 
47
- ~after~
51
+ ```
48
52
 
53
+ class-wcfm-shortcode-wc-frontend-manager.php
49
54
 
55
+ (load_views()の記述があるファイル)
50
56
 
51
- のように記述されているときに、
57
+ ```
52
58
 
59
+ class WCFM_Frontend_Manager_Shortcode {
53
60
 
61
+ ~~
54
62
 
55
- add_action($hook,$function_to_add)
63
+ static public function output( $attr ) {
56
64
 
57
- function $function_to_add(){
65
+ ~~
58
66
 
59
- //ここの記述を実行
67
+ $WCFM->library->load_views( 'wcfm-dashboard' );
60
68
 
61
- //~after以下を実行しないような記述~
69
+ ~~
70
+
71
+ }
62
72
 
63
73
  }
64
74
 
65
75
 
66
76
 
77
+ ```
78
+
79
+ ###試したこと
80
+
67
- とすることは可能でしょうか。
81
+ 子テーマfunctions.php
82
+
83
+ do_actionの引数を最後に変更して、スイッチ文を働かなくさせる
84
+
85
+ ```
86
+
87
+ add_action('before_wcfm_load_views','new_wcfm_views');
88
+
89
+ function new_wcfm_views($end_point){
90
+
91
+ if($end_point = 'wcfm-products-manage'){
92
+
93
+ require_once( 子テーマのパス. 'new-wcfm-view-products-
94
+
95
+ manage.php' );
96
+
97
+ $end_point = '';
98
+
99
+ }
100
+
101
+ }
102
+
103
+ ```
104
+
105
+ この関数が読み込まれたあと、class-wcfm-library.phpまで戻るようにする
106
+
107
+ ```
108
+
109
+ add_action('before_wcfm_load_views','new_wcfm_views');
110
+
111
+ function new_wcfm_views($end_point){
112
+
113
+ if($end_point = 'wcfm-products-manage'){
114
+
115
+ require_once( 子テーマのパス. 'new-wcfm-view-products-
116
+
117
+ manage.php' );
118
+
119
+ return 'return'
120
+
121
+ }
122
+
123
+ }
124
+
125
+ ```
126
+
127
+
128
+
129
+ ###問題点
130
+
131
+ add_filterではなく、add_actionのため、最初の方法は使えなさそうです。
132
+
133
+ returnの返り値にretunはできないため、2つ上のファイルに戻る方法はなさそうです。
134
+
135
+ exitを用いると、2つ以上上のファイルの次の部分も読み込まれなくなってしまうので、希望と異なります。