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