| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: danixland gravatar block |
| 4 | * Description: Simple Gutemberg Block to insert a gravatar inside a post or page. |
| 5 | * Version: 0.1.0 |
| 6 | * Author: Danilo 'danix' Macri |
| 7 | * Author URI: https://danix.xyz |
| 8 | * License: GPL-2.0-or-later |
| 9 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | * Text Domain: dnxvatar |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 15 | * |
| 16 | * |
| 17 | * @package dnxvatar |
| 18 | */ |
| 19 | |
| 20 | /** |
| 21 | * Registers all block assets so that they can be enqueued through the block editor |
| 22 | * in the corresponding context. |
| 23 | * |
| 24 | * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/ |
| 25 | */ |
| 26 | function dnxvatar_danixland_gravatar_block_init() { |
| 27 | $dir = dirname( __FILE__ ); |
| 28 | |
| 29 | $script_asset_path = "$dir/build/index.asset.php"; |
| 30 | if ( ! file_exists( $script_asset_path ) ) { |
| 31 | throw new Error( |
| 32 | 'You need to run `npm start` or `npm run build` for the "dnxvatar/danixland-gravatar" block first.' |
| 33 | ); |
| 34 | } |
| 35 | $index_js = 'build/index.js'; |
| 36 | $script_asset = require( $script_asset_path ); |
| 37 | wp_register_script( |
| 38 | 'dnxvatar-danixland-gravatar-block-editor', |
| 39 | plugins_url( $index_js, __FILE__ ), |
| 40 | $script_asset['dependencies'], |
| 41 | $script_asset['version'] |
| 42 | ); |
| 43 | wp_set_script_translations( 'dnxvatar-danixland-gravatar-block-editor', 'dnxvatar' ); |
| 44 | |
| 45 | $editor_css = 'build/index.css'; |
| 46 | wp_register_style( |
| 47 | 'dnxvatar-danixland-gravatar-block-editor', |
| 48 | plugins_url( $editor_css, __FILE__ ), |
| 49 | array(), |
| 50 | filemtime( "$dir/$editor_css" ) |
| 51 | ); |
| 52 | |
| 53 | $style_css = 'build/style-index.css'; |
| 54 | wp_register_style( |
| 55 | 'dnxvatar-danixland-gravatar-block', |
| 56 | plugins_url( $style_css, __FILE__ ), |
| 57 | array(), |
| 58 | filemtime( "$dir/$style_css" ) |
| 59 | ); |
| 60 | |
| 61 | register_block_type( 'dnxvatar/danixland-gravatar', array( |
| 62 | 'editor_script' => 'dnxvatar-danixland-gravatar-block-editor', |
| 63 | 'editor_style' => 'dnxvatar-danixland-gravatar-block-editor', |
| 64 | 'style' => 'dnxvatar-danixland-gravatar-block', |
| 65 | ) ); |
| 66 | } |
| 67 | add_action( 'init', 'dnxvatar_danixland_gravatar_block_init' ); |