init_filesystem();
$wp_filesystem->touch( $path . DSEP . 'editor-style.min.css', $etime );
}
}
}
// クラシックブロック用にブロックエディタと旧エディタ両方で読み込むけど、いずれ旧エディタのみにする予定
require( INC . 'tinymce-before-init.php' );
// ブロックエディタを無効化する設定になってた場合
if( isset( $luxe['block_editor_off'] ) ) {
add_filter( 'use_block_editor_for_post', '__return_false' );
}
}, 9 );
/*---------------------------------------------------------------------------
* block categories
*---------------------------------------------------------------------------*/
add_filter( 'block_categories', function( $categories, $post ) {
return array_merge( $categories,
[
[
'slug' => 'luxe-blocks',
'title' => 'Luxeritas Blocks',
//'icon' => 'layout',
]
]
);
}, 10, 2 );
/*---------------------------------------------------------------------------
* enqueue block editor assets
*---------------------------------------------------------------------------*/
add_action( 'enqueue_block_editor_assets', function() {
global $luxe;
$uri = TDEL !== SDEL ? SDEL : TDEL;
wp_enqueue_style( 'editor-style', $uri . '/editor-style.min.css?v=' . $_SERVER['REQUEST_TIME'], [ 'wp-edit-blocks' ] );
wp_enqueue_style( 'editor-style-gutenberg', TDEL . '/editor-style-gutenberg.min.css?v=' . $_SERVER['REQUEST_TIME'], [ 'wp-edit-blocks' ] );
if( !isset( $luxe['block_debug'] ) ):
if( !isset( $luxe['luxe_block_toolbar_off'] ) && !isset( $luxe['luxe_blocks_off'] ) ) {
wp_enqueue_style( 'luxe-blocks-style', TDEL . '/styles/luxe-blocks-style.min.css?v=' . $_SERVER['REQUEST_TIME'], [ 'wp-edit-blocks'] );
wp_enqueue_style( 'luxe-blocks-editor-style', TDEL . '/css/luxe-blocks-editor-style.css?v=' . $_SERVER['REQUEST_TIME'], [ 'wp-edit-blocks'] );
$theme = THEME;
if( TPATH !== SPATH ) {
$curent = wp_get_theme();
$theme = wp_get_theme( $curent->get('Template') )->get('Name');
}
$handles = array();
if( !isset( $luxe['luxe_block_toolbar_off'] ) ) $handles[] = 'luxe-block-toolbar';
if( !isset( $luxe['luxe_blocks_off'] ) ) $handles[] = 'luxe-blocks';
foreach( $handles as $handle ) {
wp_enqueue_script(
$handle,
TDEL . '/js/' . $handle . '.js?v=' . $_SERVER['REQUEST_TIME'],
array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-rich-text', 'wp-i18n', 'wp-editor', 'wp-compose', 'wp-autop' ),
false
);
if( function_exists( 'wp_set_script_translations' ) === true ) {
wp_set_script_translations( $handle, 'luxeritas', get_template_directory() . '/languages/admin' );
}
wp_localize_script( $handle, 'themeName', strtolower( $theme ) );
}
if( !isset( $luxe['luxe_block_toolbar_off'] ) ) {
/* 登録されてるショートコードの一覧を blocks.js に渡す */
$registed = get_pattern_list( 'shortcode', true, false );
foreach( (array)$registed as $key => $value ) {
$dec = htmlspecialchars_decode($key);
if( !isset( $registed[$dec] ) ) {
unset( $registed[$key] );
}
$registed[$dec] = @json_decode( $value, true );
}
foreach( (array)$registed as $key => $value ) {
foreach( (array)$value as $k => $val ) {
if( $k === 'label' ) {
$registed[$key]['label'] = mb_strimwidth( $val, 0, 25 );
}
}
}
/* Luxeritas メニューのショートコード登録ではなく、functions.php 等で定義されてるショートコードがあったら、それもリストに加える */
global $shortcode_tags;
$start = false;
foreach( (array)$shortcode_tags as $key => $val ) {
if( $start === true && !isset( $registed[$key] ) ) {
$registed[$key] = ['label'=>$key,'php'=>false,'close'=>false,'hide'=>false,'active'=>false];
}
elseif( $val === '__return_false' ) {
$start = true;
}
}
/* ショートコードが全く登録されてない場合 */
if( empty( $registed ) ) {
$registed = ['empty'=>
['label'=>__('There is no active shortcode','luxeritas'),'php'=>false,'close'=>false,'hide'=>false,'active'=>false]
];
}
asort( $registed );
wp_localize_script( 'luxe-block-toolbar', 'luxeShortcodeList', $registed );
/* 定型文の一覧を blocks.js に渡す */
$registed = get_pattern_list( 'phrase', true, false );
foreach( (array)$registed as $key => $value ) {
$dec = htmlspecialchars_decode($key);
if( !isset( $registed[$dec] ) ) {
unset( $registed[$key] );
}
$registed[$dec] = @json_decode( $value, true );
}
foreach( (array)$registed as $key => $value ) {
$registed[$key]['file'] = strlen( $key ) . '-' . md5( $key );
foreach( (array)$value as $k => $val ) {
if( $k === 'label' ) {
$registed[$key]['label'] = mb_strimwidth( $val, 0, 25 );
}
}
}
if( empty( $registed ) ) {
$registed = ['empty'=>
['label'=>'','close'=>false,'file'=>'']
];
}
asort( $registed );
wp_localize_script( 'luxe-block-toolbar', 'luxePhraseList', $registed );
/* Nonce */
wp_localize_script( 'luxe-block-toolbar', 'luxePhraseNonce', wp_create_nonce( 'phrase_popup' ) );
/* 親テーマの URL を block.js に渡す(絵文字の表を表示する際に必要) */
wp_localize_script( 'luxe-block-toolbar', 'luxeThemeURL', get_template_directory_uri() );
/* 絵文字の一覧を block.js に渡す*/
ob_start();
require( TPATH . DSEP . 'json' . DSEP . 'emoji-twitter.json' );
$emoji_list = ob_get_clean();
wp_localize_script( 'luxe-block-toolbar', 'luxeEmojiList', trim( $emoji_list ) );
}
if( !isset( $luxe['luxe_blocks_off'] ) ) {
/* シンタックスハイライターの一覧を blocks.js に渡す */
$highlighter = thk_syntax_highlighter_list();
asort( $highlighter, SORT_NATURAL | SORT_FLAG_CASE );
wp_localize_script( 'luxe-block-toolbar', 'luxeHighlighterList', $highlighter );
/* アニメーションの一覧を blocks.js に渡す */
$animated = [
'fade',
'fade-up',
'fade-down',
'fade-left',
'fade-right',
'fade-up-right',
'fade-up-left',
'fade-down-right',
'fade-down-left',
'flip-up',
'flip-down',
'flip-left',
'flip-right',
'slide-up',
'slide-down',
'slide-left',
'slide-right',
'zoom-in',
'zoom-in-up',
'zoom-in-down',
'zoom-in-left',
'zoom-in-right',
'zoom-out',
'zoom-out-up',
'zoom-out-down',
'zoom-out-left',
'zoom-out-right',
];
wp_localize_script( 'luxe-blocks', 'luxeAnimeList', $animated );
/* ロケール情報を blocks.js に渡す */
$get_locale = get_locale();
wp_localize_script( 'luxe-blocks', 'luxeLocale', $get_locale );
}
}
endif;
add_action( 'admin_footer', function() {
?>
= $i; ++$i ) {
if( $i === 13 ) {
$font_sizes[] = array(
'name' => $i . 'px ( ' . __( 'Small', 'luxeritas' ) . ' )',
'shortName' => $i . 'px',
'size' => $i,
'slug' => 'small',
);
}
elseif( $i === 20 ) {
$font_sizes[] = array(
'name' => $i . 'px ( ' . __( 'Medium', 'luxeritas' ) . ' )',
'shortName' => $i . 'px',
'size' => $i,
'slug' => 'medium',
);
}
elseif( $i === 36 ) {
$font_sizes[] = array(
'name' => $i . 'px ( ' . __( 'Large', 'luxeritas' ) . ' )',
'shortName' => $i . 'px',
'size' => $i,
'slug' => 'large',
);
}
elseif( $i === 48 ) {
$font_sizes[] = array(
'name' => $i . 'px ( ' . __( 'Huge', 'luxeritas' ) . ' )',
'shortName' => $i . 'px',
'size' => $i,
'slug' => 'huge',
);
}
elseif( $i === $normal_font_size ) {
$font_sizes[] = array(
'name' => $i . 'px ( ' . __( 'Normal', 'luxeritas' ) . ' )',
'shortName' => $i . 'px',
'size' => $i,
'slug' => 'normal',
);
}
else {
$font_sizes[] = array(
'name' => $i . 'px',
'shortName' => $i . 'px',
'size' => $i,
'slug' => $i . 'px',
);
}
}
add_theme_support( 'editor-font-sizes', $font_sizes );
});