assets
7 years ago
blocks.build.js
6 years ago
blocks.editor.build.css
6 years ago
blocks.style.build.css
6 years ago
init.php
2 months ago
newjavascript.js
7 years ago
init.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Blocks Initializer |
| 5 | * |
| 6 | * Enqueue CSS/JS of all the blocks. |
| 7 | * |
| 8 | * @since 1.0.0 |
| 9 | * @package Timeline Blocks for Gutenberg |
| 10 | */ |
| 11 | // Exit if accessed directly. |
| 12 | if (!defined('ABSPATH')) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | //PHP version compare |
| 17 | if (!version_compare(PHP_VERSION, '5.6', '>=')) { |
| 18 | add_action('admin_notices', 'tb_fail_php_version'); |
| 19 | } else { |
| 20 | require_once TB_DIR . "src/tb-helper/class-tb-loader.php"; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * PHP version fail error |
| 25 | * |
| 26 | * @since 1.0.0 |
| 27 | * @package Post Layouts for Gutenberg |
| 28 | */ |
| 29 | function tb_fail_php_version() { |
| 30 | /* translators: %s: PHP version */ |
| 31 | $message = sprintf(esc_html__('Timeline Block for Gutenberg requires PHP version %s+, plugin is currently NOT RUNNING.', 'timeline-blocks'), '5.6'); |
| 32 | $html_message = sprintf('<div class="error">%s</div>', wpautop($message)); |
| 33 | echo wp_kses($html_message, wp_kses_allowed_html('post')); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Enqueue assets for frontend and backend |
| 38 | * |
| 39 | * @since 1.0.0 |
| 40 | * @package Timeline Blocks for Gutenberg |
| 41 | */ |
| 42 | function timeline_block_assets() { |
| 43 | |
| 44 | // Load the compiled styles |
| 45 | wp_enqueue_style('tb-block-style-css', plugins_url('dist/blocks.style.build.css', dirname(__FILE__)), |
| 46 | array(), filemtime(plugin_dir_path(__FILE__) . 'blocks.style.build.css')); |
| 47 | |
| 48 | // Load the FontAwesome icon library |
| 49 | wp_enqueue_style('tb-block-fontawesome', plugins_url('dist/assets/fontawesome/css/all.css', dirname(__FILE__)), array(), filemtime(plugin_dir_path(__FILE__) . 'assets/fontawesome/css/all.css')); |
| 50 | } |
| 51 | add_action('enqueue_block_assets', 'timeline_block_assets'); |
| 52 | |
| 53 | /** |
| 54 | * Enqueue assets for backend editor |
| 55 | * |
| 56 | * @since 1.0.0 |
| 57 | * @package Timeline Blocks for Gutenberg |
| 58 | */ |
| 59 | function timeline_block_editor_assets() { |
| 60 | |
| 61 | // Load the compiled blocks into the editor |
| 62 | wp_enqueue_script('tb-block-js', plugins_url('/dist/blocks.build.js', dirname(__FILE__)), |
| 63 | array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-api' ), |
| 64 | filemtime(plugin_dir_path(__FILE__) . 'blocks.build.js')); |
| 65 | |
| 66 | // Load the compiled styles into the editor |
| 67 | wp_enqueue_style('tb-block-editor-css', plugins_url('dist/blocks.editor.build.css', dirname(__FILE__)), array(), filemtime(plugin_dir_path(__FILE__) . 'blocks.editor.build.css')); |
| 68 | |
| 69 | if (function_exists('wp_set_script_translations')) { |
| 70 | wp_add_inline_script( |
| 71 | 'timeline-blocks', sprintf( |
| 72 | 'var timeline_blocks = { localeData: %s };', wp_json_encode(wp_set_script_translations('timeline_blocks', 'timeline-blocks')) |
| 73 | ), 'before' |
| 74 | ); |
| 75 | } elseif (function_exists('gutenberg_set_script_translations')) { |
| 76 | wp_add_inline_script( |
| 77 | 'timeline-blocks', sprintf( |
| 78 | 'var timeline_blocks = { localeData: %s };', wp_json_encode(gutenberg_set_script_translations('timeline_blocks', 'timeline-blocks')) |
| 79 | ), 'before' |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | add_action('enqueue_block_editor_assets', 'timeline_block_editor_assets'); |
| 84 | |
| 85 | // Add custom block category |
| 86 | add_filter('block_categories_all', function( $categories, $post ) { |
| 87 | return array_merge( |
| 88 | $categories, array( |
| 89 | array( |
| 90 | 'slug' => 'timeline-blocks', |
| 91 | 'title' => __('Timeline Blocks by Techeshta', 'timeline-blocks'), |
| 92 | ), |
| 93 | ) |
| 94 | ); |
| 95 | }, 10, 2); |
| 96 |