質問編集履歴

1

コードの追加

2021/06/20 00:52

投稿

spa
spa

スコア52

test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,301 @@
19
19
 
20
20
 
21
21
  試したこと:remove_actionで削除できるフックがないか探してみたがわからなかった。
22
+
23
+
24
+
25
+ ```php
26
+
27
+ <?php
28
+
29
+
30
+
31
+
32
+
33
+ // No direct calls to this script
34
+
35
+ if ( strpos($_SERVER['PHP_SELF'], basename(__FILE__) )) {
36
+
37
+ die('No direct calls allowed!');
38
+
39
+ }
40
+
41
+
42
+
43
+
44
+
45
+ /*
46
+
47
+ * Set meta_keys so we can find the post with the shortcode back.
48
+
49
+ *
50
+
51
+ * @param int $id ID of the post
52
+
53
+ */
54
+
55
+ function gwolle_gb_save_post($id) {
56
+
57
+
58
+
59
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
60
+
61
+ return;
62
+
63
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
64
+
65
+ return;
66
+
67
+ if ( defined( 'DOING_CRON' ) && DOING_CRON )
68
+
69
+ return;
70
+
71
+
72
+
73
+ if ( function_exists('has_shortcode') ) {
74
+
75
+ $post = get_post( $id );
76
+
77
+
78
+
79
+ if ( has_shortcode( $post->post_content, 'gwolle_gb' ) || has_shortcode( $post->post_content, 'gwolle_gb_read' ) ) {
80
+
81
+ // Set a meta_key so we can find the post with the shortcode back.
82
+
83
+ $meta_value = get_post_meta( $id, 'gwolle_gb_read', true );
84
+
85
+ if ( $meta_value != 'true' ) {
86
+
87
+ update_post_meta( $id, 'gwolle_gb_read', 'true' );
88
+
89
+ }
90
+
91
+ } else {
92
+
93
+ // Remove the meta_key in case it is set.
94
+
95
+ delete_post_meta( $id, 'gwolle_gb_read' );
96
+
97
+ }
98
+
99
+
100
+
101
+ if ( has_shortcode( $post->post_content, 'gwolle_gb' ) || has_shortcode( $post->post_content, 'gwolle_gb_read' ) || has_shortcode( $post->post_content, 'gwolle_gb_write' ) ) {
102
+
103
+ // Nothing to do
104
+
105
+ } else {
106
+
107
+ delete_post_meta( $id, 'gwolle_gb_book_id' );
108
+
109
+ }
110
+
111
+ }
112
+
113
+ }
114
+
115
+ add_action('save_post', 'gwolle_gb_save_post');
116
+
117
+
118
+
119
+
120
+
121
+ /*
122
+
123
+ * Set meta_keys so we can find the post with the shortcode back.
124
+
125
+ *
126
+
127
+ * @param string $content Content of the post
128
+
129
+ * @return string $content Content of the post
130
+
131
+ *
132
+
133
+ * @since 3.1.8
134
+
135
+ */
136
+
137
+ function gwolle_gb_content_filter_for_meta_keys( $content ) {
138
+
139
+
140
+
141
+ if ( ! is_singular() || ! is_main_query() || is_admin() ) {
142
+
143
+ return $content;
144
+
145
+ }
146
+
147
+
148
+
149
+ if ( function_exists('has_shortcode') ) {
150
+
151
+ $id = get_the_ID();
152
+
153
+
154
+
155
+ if ( has_shortcode( $content, 'gwolle_gb' ) || has_shortcode( $content, 'gwolle_gb_read' ) ) {
156
+
157
+ // Set a meta_key so we can find the post with the shortcode back.
158
+
159
+ $meta_value = get_post_meta( $id, 'gwolle_gb_read', true );
160
+
161
+ if ( $meta_value != 'true' ) {
162
+
163
+ update_post_meta( $id, 'gwolle_gb_read', 'true' );
164
+
165
+ }
166
+
167
+ } else {
168
+
169
+ // Remove the meta_key in case it is set.
170
+
171
+ delete_post_meta( $id, 'gwolle_gb_read' );
172
+
173
+ }
174
+
175
+
176
+
177
+ if ( has_shortcode( $content, 'gwolle_gb' ) || has_shortcode( $content, 'gwolle_gb_read' ) || has_shortcode( $content, 'gwolle_gb_write' ) ) {
178
+
179
+ // Nothing to do
180
+
181
+ } else {
182
+
183
+ delete_post_meta( $id, 'gwolle_gb_book_id' );
184
+
185
+ }
186
+
187
+ }
188
+
189
+
190
+
191
+ return $content;
192
+
193
+ }
194
+
195
+ add_filter( 'the_content', 'gwolle_gb_content_filter_for_meta_keys', 1 ); // before shortcodes are done.
196
+
197
+
198
+
199
+ /*
200
+
201
+ * Make our meta fields protected, so they are not in the custom fields metabox.
202
+
203
+ *
204
+
205
+ * @since 2.1.5
206
+
207
+ */
208
+
209
+ function gwolle_gb_is_protected_meta( $protected, $meta_key, $meta_type ) {
210
+
211
+
212
+
213
+ switch ($meta_key) {
214
+
215
+ case 'gwolle_gb_read':
216
+
217
+ return true;
218
+
219
+ case 'gwolle_gb_book_id':
220
+
221
+ return true;
222
+
223
+ }
224
+
225
+
226
+
227
+ return $protected;
228
+
229
+ }
230
+
231
+ add_filter( 'is_protected_meta', 'gwolle_gb_is_protected_meta', 10, 3 );
232
+
233
+
234
+
235
+
236
+
237
+ /*
238
+
239
+ * Set Meta_keys so we can find the post with the shortcode back.
240
+
241
+ * Gets called from frontend/gb-shortcodes.php.
242
+
243
+ *
244
+
245
+ * @param string $shortcode value 'write' or 'read'.
246
+
247
+ * @param array $shortcode_atts array with the shortcode attributes.
248
+
249
+ *
250
+
251
+ * @since 1.5.6
252
+
253
+ * @deprecated 3.1.8 Meta keys are now set in gwolle_gb_content_filter_for_meta_keys()
254
+
255
+ */
256
+
257
+ function gwolle_gb_set_meta_keys( $shortcode, $shortcode_atts ) {
258
+
259
+
260
+
261
+ _deprecated_function( __FUNCTION__, ' 3.1.8', 'gwolle_gb_content_filter_for_meta_keys()' );
262
+
263
+ return;
264
+
265
+
266
+
267
+ }
268
+
269
+
270
+
271
+
272
+
273
+ /*
274
+
275
+ * Check whether this post/page is a guestbook.
276
+
277
+ * Will test if the 'gwolle_gb_read' meta key is set to 'true'.
278
+
279
+ *
280
+
281
+ * @param bool $post_id the ID of the post to check.
282
+
283
+ * @return bool true if this post has a guestbook shortcode.
284
+
285
+ *
286
+
287
+ * @since 3.0.0
288
+
289
+ */
290
+
291
+ function gwolle_gb_post_is_guestbook( $post_id ) {
292
+
293
+
294
+
295
+ $meta_value_read = get_post_meta( $post_id, 'gwolle_gb_read', true );
296
+
297
+ if ( $meta_value_read == 'true' ) {
298
+
299
+ return true;
300
+
301
+ }
302
+
303
+
304
+
305
+ return false;
306
+
307
+
308
+
309
+ }
310
+
311
+
312
+
313
+ ```
314
+
315
+ gwolle-gb/functions/gb-post-meta.php
316
+
317
+ このphpの中身にHTMLの投稿に制限をかけているコードがあるかないか、そのあたりからわからないので
318
+
319
+ 教えていただけるとありがたいです。