質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

1回答

736閲覧

Wordpress welcart及びAdvanced Custom Fieldsの連携について

kitikiti

総合スコア17

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2019/06/15 03:27

カスタムフィールドを使用するためにAdvanced Custom Fieldsのプラグインを利用して作成を行っていますが、フィールドグループで作成した他ののテンプレートまでが出てきてしまいます。
このフィールドグループを表示する条件(位置ルール)処理が全く反応していないようです。
作成したフィールドが全てwelcat(商品マスター編集画面)上に出てきてしまいます。
更新ができず困っています。
どのようにファイルを変更すればいいでしょうか。

下記フォーラムにて添付されているファイルを使用し利用しています。
https://www.welcart.com/community/forums/topic/advanced-custom-fields-%E3%81%A8%E3%81%AE%E9%80%A3%E5%8B%95%E3%81%AB%E9%96%A2%E3%81%97%E3%81%BE%E3%81%97%E3%81%A6

おそらくこのファイルをいじればなると思うのですが、よくわからず現在困っております。
おわかりになる方ご教授お願い致します。

php

1 function admin_head() { 2 3 // vars 4 $style_found = false; 5 6 7 // get field groups 8 $field_groups = acf_get_field_groups(); 9 10 11 // add meta boxes 12 if( !empty($field_groups) ) { 13 14 foreach( $field_groups as $i => $field_group ) { 15 16 // vars 17 $id = "acf-{$field_group['key']}"; 18 $title = $field_group['title']; 19 $context = $field_group['position']; 20 $priority = 'high'; 21 $args = array( 22 'field_group' => $field_group, 23 'visibility' => false 24 ); 25 26 27 // tweaks to vars 28 if( $context == 'side' ) { 29 30 $priority = 'core'; 31 32 } 33 34 35 // filter for 3rd party customization 36 $priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group); 37 38 39 // visibility 40 $args['visibility'] = acf_get_field_group_visibility( $field_group, array( 41 'post_id' => $this->post_id, 42 'post_type' => $this->typenow 43 )); 44 45 // add meta box 46 add_meta_box( $id, $title, array($this, 'render_meta_box'), $this->typenow, $context, $priority, $args ); 47 48 49 // update style 50 if( !$style_found && $args['visibility'] ) { 51 52 $style_found = true; 53 54 $this->style = acf_get_field_group_style( $field_group ); 55 56 } 57 58 } 59 60 } 61 62 63 // Allow 'acf_after_title' metabox position 64 add_action('edit_form_after_title', array($this, 'edit_form_after_title')); 65 66 67 // remove ACF from meta postbox 68 add_filter('is_protected_meta', array($this, 'is_protected_meta'), 10, 3); 69 70 } 71 72 73コード

php

1/* 2 * edit_form_after_title 3 * 4 * This action will allow ACF to render metaboxes after the title 5 * 6 * @type action 7 * @date 17/08/13 8 * 9 * @param n/a 10 * @return n/a 11 */ 12 13 function edit_form_after_title() { 14 15 // globals 16 global $post, $wp_meta_boxes; 17 18 // render post data 19 acf_form_data(array( 20 'post_id' => $this->post_id, 21 'nonce' => 'post', 22 'ajax' => 1 23 )); 24 25 26 // render 27 do_meta_boxes( get_current_screen(), 'acf_after_title', $post); 28 29 30 // clean up 31 unset( $wp_meta_boxes['post']['acf_after_title'] ); 32 33 } 34 35 36 /* 37 * render_meta_box 38 * 39 * description 40 * 41 * @type function 42 * @date 20/10/13 43 * @since 5.0.0 44 * 45 * @param $post_id (int) 46 * @return $post_id (int) 47 */ 48 49 function render_meta_box( $post, $args ) { 50 51 // extract args 52 extract( $args ); // all variables from the add_meta_box function 53 extract( $args ); // all variables from the args argument 54 55 56 // vars 57 $o = array( 58 'id' => $id, 59 'key' => $field_group['key'], 60 'style' => $field_group['style'], 61 'label' => $field_group['label_placement'], 62 'edit_url' => '', 63 'edit_title' => __('Edit field group', 'acf'), 64 'visibility' => $visibility 65 ); 66 67 68 // edit_url 69 if( $field_group['ID'] && acf_current_user_can_admin() ) { 70 71 $o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit'); 72 73 } 74 75 76 // load and render fields 77 if( $visibility ) { 78 79 // load fields 80 $fields = acf_get_fields( $field_group ); 81 82 83 // render 84 acf_render_fields( $this->post_id, $fields, 'div', $field_group['instruction_placement'] ); 85 86 // render replace-me div 87 } else { 88 89 echo '<div class="acf-replace-with-fields"><div class="acf-loading"></div></div>'; 90 91 } 92 93 ?> 94<script type="text/javascript"> 95if( typeof acf !== 'undefined' ) { 96 97 acf.postbox.render(<?php echo json_encode($o); ?>); 98 99} 100</script> 101<?php 102 103 } 104 105 106 /* 107 * admin_footer 108 * 109 * description 110 * 111 * @type function 112 * @date 21/10/13 113 * @since 5.0.0 114 * 115 * @param $post_id (int) 116 * @return $post_id (int) 117 */ 118 119 function admin_footer(){ 120 121 // get style of first field group 122 echo '<style type="text/css" id="acf-style">' . $this->style . '</style>'; 123 124 } 125 126 127 /* 128 * get_field_groups 129 * 130 * This function will return all the JSON data needed to render new metaboxes 131 * 132 * @type function 133 * @date 21/10/13 134 * @since 5.0.0 135 * 136 * @param n/a 137 * @return n/a 138 */ 139 140 function get_field_groups() { 141 142 // options 143 $options = acf_parse_args($_POST, array( 144 'nonce' => '', 145 'post_id' => 0, 146 'ajax' => 1, 147 'exists' => array() 148 )); 149 150 151 // vars 152 $json = array(); 153 $exists = acf_extract_var( $options, 'exists' ); 154 155 156 // verify nonce 157 if( !acf_verify_ajax() ) die(); 158 159 160 // get field groups 161 $field_groups = acf_get_field_groups( $options ); 162 163 164 // bail early if no field groups 165 if( empty($field_groups) ) { 166 167 wp_send_json_success( $json ); 168 169 } 170 171 172 // loop through field groups 173 foreach( $field_groups as $i => $field_group ) { 174 175 // vars 176 $item = array( 177 //'ID' => $field_group['ID'], - JSON does not have ID (not used by JS anyway) 178 'key' => $field_group['key'], 179 'title' => $field_group['title'], 180 'html' => '', 181 'style' => '' 182 ); 183 184 185 // style 186 if( $i == 0 ) { 187 188 $item['style'] = acf_get_field_group_style( $field_group ); 189 190 } 191 192 193 // html 194 if( !in_array($field_group['key'], $exists) ) { 195 196 // load fields 197 $fields = acf_get_fields( $field_group ); 198 199 200 // get field HTML 201 ob_start(); 202 203 204 // render 205 acf_render_fields( $options['post_id'], $fields, 'div', $field_group['instruction_placement'] ); 206 207 208 $item['html'] = ob_get_clean(); 209 210 211 } 212 213 214 // append 215 $json[] = $item; 216 217 } 218 219 220 // return 221 wp_send_json_success( $json ); 222 223 } 224 225 226 /* 227 * wp_insert_post_empty_content 228 * 229 * This function will allow WP to insert a new post without title / content if ACF data exists 230 * 231 * @type function 232 * @date 16/07/2014 233 * @since 5.0.1 234 * 235 * @param $maybe_empty (bool) whether the post should be considered "empty" 236 * @param $postarr (array) Array of post data 237 * @return $maybe_empty 238 */ 239 240 function wp_insert_post_empty_content( $maybe_empty, $postarr ) { 241 242 if( $maybe_empty && !empty($_POST['_acfchanged']) ) { 243 244 $maybe_empty = false; 245 246 } 247 248 249 // return 250 return $maybe_empty; 251 } 252 253 254 /* 255 * allow_save_post 256 * 257 * This function will return true if the post is allowed to be saved 258 * 259 * @type function 260 * @date 26/06/2016 261 * @since 5.3.8 262 * 263 * @param $post_id (int) 264 * @return $post_id (int) 265 */ 266 267 function allow_save_post( $post ) { 268 269 // vars 270 $allow = true; 271 $reject = array( 'auto-draft', 'revision', 'acf-field', 'acf-field-group' ); 272 $wp_preview = acf_maybe_get($_POST, 'wp-preview'); 273 274 275 // check post type 276 if( in_array($post->post_type, $reject) ) $allow = false; 277 278 279 // allow preview 280 if( $post->post_type == 'revision' && $wp_preview == 'dopreview' ) $allow = true; 281 282 283 // return 284 return $allow; 285 286 } 287 288 289 /* 290 * save_post 291 * 292 * This function will validate and save the $_POST data 293 * 294 * @type function 295 * @date 23/06/12 296 * @since 1.0.0 297 * 298 * @param $post_id (int) 299 * @return $post_id (int) 300 */ 301 302 function save_post( $post_id, $post ) { 303 304 // bail ealry if no allowed to save this post type 305 if( !$this->allow_save_post($post) ) return $post_id; 306 307 308 // ensure saving to the correct post 309// if( !acf_verify_nonce('post', $post_id) ) return $post_id; 310 311 312 // validate for published post (allow draft to save without validation) 313 if( $post->post_status == 'publish' ) { 314 315 // show errors 316 acf_validate_save_post( true ); 317 318 } 319 320 321 // save 322 acf_save_post( $post_id ); 323 324 325 // save revision 326 if( post_type_supports($post->post_type, 'revisions') ) { 327 328 acf_save_post_revision( $post_id ); 329 330 } 331 332 333 // return 334 return $post_id; 335 336 } 337 338 339 /* 340 * is_protected_meta 341 * 342 * This function will remove any ACF meta from showing in the meta postbox 343 * 344 * @type function 345 * @date 12/04/2014 346 * @since 5.0.0 347 * 348 * @param $post_id (int) 349 * @return $post_id (int) 350 */ 351 352 function is_protected_meta( $protected, $meta_key, $meta_type ) { 353 354 // if acf_get_field_reference returns a valid key, this is an acf value, so protect it! 355 if( !$protected ) { 356 357 $reference = acf_get_field_reference( $meta_key, $this->post_id ); 358 359 if( acf_is_field_key($reference) ) { 360 361 $protected = true; 362 363 } 364 365 } 366 367 368 // return 369 return $protected; 370 371 } 372 373} 374endif; // class_exists check 375 376 377global $acf; 378if( $acf ){ 379 new acf_form_welcart_item(); 380} 381コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

https://www.welcart.com/archives/techinfo/techinfo-20200218

パッチが公開されたようです!

投稿2020/02/19 14:42

nats

総合スコア22

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問