vk-all-in-one-expansion-unit
Last commit date
.husky
3 years ago
admin
3 years ago
assets
2 years ago
inc
2 years ago
vendor
2 years ago
.eslintignore
3 years ago
LICENSE
6 years ago
delete-old-option-meta.php
4 years ago
initialize.php
3 years ago
playwright.config.ts
3 years ago
readme.txt
2 years ago
screenshot-1.png
6 years ago
screenshot-2.png
6 years ago
uninstaller.php
4 years ago
veu-package-manager.php
3 years ago
veu-packages.php
2 years ago
vkExUnit.php
2 years ago
webpack.config.js
3 years ago
initialize.php
168 lines
| 1 | <?php |
| 2 | /* |
| 3 | Delete old function data |
| 4 | Load modules |
| 5 | Add vkExUnit css |
| 6 | Add vkExUnit js |
| 7 | /*-------------------------------------------*/ |
| 8 | |
| 9 | /* |
| 10 | Delete old function data |
| 11 | /*-------------------------------------------*/ |
| 12 | require VEU_DIRECTORY_PATH . '/veu-package-manager.php'; |
| 13 | $options = get_option( 'veu_deprecated' ); |
| 14 | if ( empty( $options['9.72.0'] ) ) { |
| 15 | require VEU_DIRECTORY_PATH . '/delete-old-option-meta.php'; |
| 16 | $options['9.72.0'] = 'done'; |
| 17 | update_option( 'veu_deprecated', $options ); |
| 18 | } |
| 19 | |
| 20 | /* |
| 21 | Load modules |
| 22 | /* |
| 23 | -------------------------------------------*/ |
| 24 | // template-tags-veuでpackageの関数を使うので package-managerを� |
| 25 | �に読み込んでいる |
| 26 | require_once VEU_DIRECTORY_PATH . '/inc/template-tags/template-tags-config.php'; |
| 27 | require_once VEU_DIRECTORY_PATH . '/inc/common-block.php'; |
| 28 | require_once VEU_DIRECTORY_PATH . '/admin/admin.php'; |
| 29 | require VEU_DIRECTORY_PATH . '/inc/footer-copyright-change.php'; |
| 30 | |
| 31 | veu_package_include(); // package_manager.php |
| 32 | |
| 33 | /* |
| 34 | Add vkExUnit css |
| 35 | /*-------------------------------------------*/ |
| 36 | add_action( 'after_setup_theme', 'veu_load_css_action' ); |
| 37 | function veu_load_css_action() { |
| 38 | $hook_point = apply_filters( 'veu_enqueue_point_common_css', 'wp_enqueue_scripts' ); |
| 39 | // priority 5 : possible to overwrite from theme design skin |
| 40 | add_action( $hook_point, 'veu_print_css', 5 ); |
| 41 | } |
| 42 | |
| 43 | add_action( 'wp_enqueue_scripts', 'vwu_register_css', 3 ); |
| 44 | add_action( 'admin_enqueue_scripts', 'vwu_register_css', 3 ); |
| 45 | function vwu_register_css() { |
| 46 | $options = veu_get_common_options(); |
| 47 | |
| 48 | wp_register_style( 'vkExUnit_common_style', plugins_url( '', __FILE__ ) . '/assets/css/vkExUnit_style.css', array(), VEU_VERSION, 'all' ); |
| 49 | } |
| 50 | |
| 51 | function veu_print_css() { |
| 52 | wp_enqueue_style( 'vkExUnit_common_style' ); |
| 53 | } |
| 54 | |
| 55 | function veu_print_editor_css() { |
| 56 | add_editor_style( plugins_url( '', __FILE__ ) . '/assets/css/vkExUnit_editor_style.css' ); |
| 57 | } |
| 58 | add_action( 'after_setup_theme', 'veu_print_editor_css' ); |
| 59 | |
| 60 | // ブロックエディタ用のCSS読み込み( ↑ だけだと効かない ) |
| 61 | function veu_print_block_editor_css() { |
| 62 | wp_register_style( |
| 63 | 'veu-block-editor', |
| 64 | plugins_url( '', __FILE__ ) . '/assets/css/vkExUnit_editor_style.css', |
| 65 | array(), |
| 66 | filemtime( plugin_dir_path( __FILE__ ) ) |
| 67 | ); |
| 68 | } |
| 69 | add_action( 'init', 'veu_print_block_editor_css' ); |
| 70 | |
| 71 | /* |
| 72 | Add vkExUnit js |
| 73 | -------------------------------------------*/ |
| 74 | add_action( 'wp_enqueue_scripts', 'veu_print_js' ); |
| 75 | function veu_print_js() { |
| 76 | $options = apply_filters( 'vkExUnit_master_js_options', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
| 77 | |
| 78 | wp_register_script( 'vkExUnit_master-js', plugins_url( '', __FILE__ ) . '/assets/js/all.min.js', array(), VEU_VERSION, true ); |
| 79 | wp_localize_script( 'vkExUnit_master-js', 'vkExOpt', apply_filters( 'vkExUnit_localize_options', $options ) ); |
| 80 | wp_enqueue_script( 'vkExUnit_master-js' ); |
| 81 | } |
| 82 | |
| 83 | if ( function_exists( 'register_activation_hook' ) ) { |
| 84 | register_activation_hook( dirname( __FILE__ ) . '/vkExUnit.php', 'veu_install_function' ); |
| 85 | } |
| 86 | |
| 87 | function veu_install_function() { |
| 88 | $opt = get_option( 'vkExUnit_common_options' ); |
| 89 | if ( ! $opt ) { |
| 90 | add_option( 'vkExUnit_common_options', veu_get_common_options_default() ); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * change old options |
| 96 | */ |
| 97 | function change_old_options() { |
| 98 | $option = get_option( 'vkExUnit_pagespeeding' ); |
| 99 | |
| 100 | if ( isset( $option['common'] ) ) { |
| 101 | $option['css_exunit'] = true; |
| 102 | unset( $option['common'] ); |
| 103 | } |
| 104 | |
| 105 | if ( isset( $option['css_exunit'] ) ) { |
| 106 | $option['css_optimize'] = 'tree-shaking'; |
| 107 | unset( $option['css_exunit'] ); |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | add_action( 'after_setup_theme', 'change_old_options', 4 ); |
| 112 | |
| 113 | /** |
| 114 | * Move JavaScripts To Footer |
| 115 | * https://nelog.jp/header-js-to-footer |
| 116 | */ |
| 117 | function veu_move_scripts_to_footer() { |
| 118 | $default = array( |
| 119 | 'css_exunit' => false, |
| 120 | 'js_footer' => false, |
| 121 | ); |
| 122 | $option = get_option( 'vkExUnit_pagespeeding', $default ); |
| 123 | $option = wp_parse_args( $option, $default ); |
| 124 | if ( $option['js_footer'] ) { |
| 125 | // Remove Header Scripts. |
| 126 | remove_action( 'wp_head', 'wp_print_scripts' ); |
| 127 | remove_action( 'wp_head', 'wp_print_head_scripts', 9 ); |
| 128 | remove_action( 'wp_head', 'wp_enqueue_scripts', 1 ); |
| 129 | |
| 130 | // Remove Footer Scripts. |
| 131 | add_action( 'wp_footer', 'wp_print_scripts', 5 ); |
| 132 | add_action( 'wp_footer', 'wp_print_head_scripts', 5 ); |
| 133 | add_action( 'wp_footer', 'wp_enqueue_scripts', 5 ); |
| 134 | } |
| 135 | } |
| 136 | add_action( 'wp_enqueue_scripts', 'veu_move_scripts_to_footer' ); |
| 137 | |
| 138 | |
| 139 | function veu_change_enqueue_point_to_footer( $enqueue_point ) { |
| 140 | $enqueue_point = 'wp_footer'; |
| 141 | return $enqueue_point; |
| 142 | } |
| 143 | |
| 144 | function veu_inline_styles() { |
| 145 | $dynamic_css = ':root { |
| 146 | --ver_page_top_button_url:url(' . VEU_DIRECTORY_URI . '/assets/images/to-top-btn-icon.svg' . '); |
| 147 | } |
| 148 | @font-face { |
| 149 | font-weight: normal; |
| 150 | font-style: normal; |
| 151 | font-family: "vk_sns"; |
| 152 | src: url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.eot?-bq20cj' . '"); |
| 153 | src: url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.eot?#iefix-bq20cj' . '") format("embedded-opentype"), |
| 154 | url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.woff?-bq20cj' . '") format("woff"), |
| 155 | url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.ttf?-bq20cj' . '") format("truetype"), |
| 156 | url("' . VEU_DIRECTORY_URI . '/inc/sns/icons/fonts/vk_sns.svg?-bq20cj#vk_sns' . '") format("svg"); |
| 157 | }'; |
| 158 | |
| 159 | // delete before after space |
| 160 | $dynamic_css = trim( $dynamic_css ); |
| 161 | // convert tab and br to space |
| 162 | $dynamic_css = preg_replace( '/[\n\r\t]/', '', $dynamic_css ); |
| 163 | // Change multiple spaces to single space |
| 164 | $dynamic_css = preg_replace( '/\s(?=\s)/', '', $dynamic_css ); |
| 165 | wp_add_inline_style( 'vkExUnit_common_style', $dynamic_css ); |
| 166 | } |
| 167 | add_action( 'wp_head', 'veu_inline_styles', 5 ); |
| 168 |