Last active
February 13, 2018 14:05
-
-
Save fjm/6004454457696984ea10 to your computer and use it in GitHub Desktop.
WordPress : Advanced Custom FieldsのRepeater Fields追加時のQuickTagsボタン効かない問題の対応 #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 管理画面に独自JSを読み込む = コンパイルしたwp-admin.coffeeを管理画面に読ませる | |
*/ | |
function dashboard_custom_files(){ | |
// js読み込み - 依存ファイルにjQueryを指定 | |
// wp_enqueue_script( 'handle', ファイル, 依存関係, バージョン, trueでフッタで読み込み) | |
wp_enqueue_script( 'custom_script', get_template_directory_uri().'/assets/js/wp-admin.js', array('jquery'), '', true); | |
} | |
add_action('admin_enqueue_scripts', 'dashboard_custom_files'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(($) -> | |
# ACFのRepeater フィールドで新規テキストエリア追加時にHTMLボタンが効かない問題 | |
# 以下で動くようになったが..そのうちACFがアップデートされるときになおるんじゃないかな. | |
# ============================== | |
# テキストエリアが存在する場合のみ | |
if $('.wp-editor-area').length | |
$(window).load -> | |
qtInitArray = [] #初期quicktags要素 | |
qtAddArray = [] #追加quicktags要素 | |
# 比較用に初期QTags要素をコレクション | |
for key, value of tinyMCEPreInit.qtInit | |
qtInitArray.push(key) | |
# Repeaterボタンクリック | |
$('.acf-button').on 'click', -> | |
setTimeout -> | |
$('.wp-editor-area').each -> | |
thisId = $(this).attr('id') | |
if $.inArray( thisId, qtInitArray ) is -1 && $.inArray( thisId, qtAddArray ) is -1 | |
qtAddArray.push(thisId) | |
$(this).prev('.quicktags-toolbar').remove() | |
tinyMCEPreInit.qtInit[thisId] = { id : thisId } | |
new QTags(thisId) | |
QTags._buttonsInit() | |
, 300 | |
) jQuery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment