| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Typing Text |
| 4 |
* Description: Make Your Website Interactive With Typing Text Animation |
| 5 |
* Version: 1.0.0 |
| 6 |
* Author: WPDeveloper |
| 7 |
* Author URI: https://wpdeveloper.net |
| 8 |
* License: GPL-3.0-or-later |
| 9 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 10 |
* Text Domain: typing-text |
| 11 |
* |
| 12 |
* @package typing-text |
| 13 |
*/ |
| 14 |
|
| 15 |
/** |
| 16 |
* Registers all block assets so that they can be enqueued through the block editor |
| 17 |
* in the corresponding context. |
| 18 |
* |
| 19 |
* @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/ |
| 20 |
*/ |
| 21 |
|
| 22 |
require_once __DIR__ . '/includes/font-loader.php'; |
| 23 |
require_once __DIR__ . '/includes/post-meta.php'; |
| 24 |
|
| 25 |
function create_block_typing_text_block_init() { |
| 26 |
$dir = dirname( __FILE__ ); |
| 27 |
|
| 28 |
$script_asset_path = "$dir/build/index.asset.php"; |
| 29 |
if ( ! file_exists( $script_asset_path ) ) { |
| 30 |
throw new Error( |
| 31 |
'You need to run `npm start` or `npm run build` for the "block/typing-text" block first.' |
| 32 |
); |
| 33 |
} |
| 34 |
$index_js = 'build/index.js'; |
| 35 |
$script_asset = require( $script_asset_path ); |
| 36 |
wp_register_script( |
| 37 |
'create-block-typing-text-block-editor', |
| 38 |
plugins_url( $index_js, __FILE__ ), |
| 39 |
$script_asset['dependencies'], |
| 40 |
$script_asset['version'] |
| 41 |
); |
| 42 |
|
| 43 |
$style_css = 'build/style-index.css'; |
| 44 |
wp_register_style( |
| 45 |
'create-block-typing-text-block', |
| 46 |
plugins_url( $style_css, __FILE__ ), |
| 47 |
array(), |
| 48 |
filemtime( "$dir/$style_css" ) |
| 49 |
); |
| 50 |
|
| 51 |
$typed_js = 'src/js/typed.min.js'; |
| 52 |
wp_enqueue_script( |
| 53 |
'essential-blocks-typedjs', |
| 54 |
plugins_url($typed_js, __FILE__), |
| 55 |
array( "jquery","wp-editor"), |
| 56 |
true |
| 57 |
); |
| 58 |
|
| 59 |
$frontend_js = 'src/frontend.js'; |
| 60 |
wp_enqueue_script( |
| 61 |
'essential-blocks-typing-text-frontend', |
| 62 |
plugins_url($frontend_js, __FILE__), |
| 63 |
array( "jquery","wp-editor"), |
| 64 |
true |
| 65 |
); |
| 66 |
|
| 67 |
|
| 68 |
if( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/typing-text' ) ) { |
| 69 |
register_block_type( 'block/typing-text', array( |
| 70 |
'editor_script' => 'create-block-typing-text-block-editor', |
| 71 |
'style' => 'create-block-typing-text-block', |
| 72 |
) ); |
| 73 |
} |
| 74 |
} |
| 75 |
add_action( 'init', 'create_block_typing_text_block_init' ); |
| 76 |
|