diff options
| author | danix <danix@danix.xyz> | 2020-10-16 15:47:20 +0200 |
|---|---|---|
| committer | danix <danix@danix.xyz> | 2020-10-16 15:47:20 +0200 |
| commit | 70bd62adbc387a0545d63c3468d239cff606de90 (patch) | |
| tree | 9aeb593af7dd5a48b96437016277e21991d28cb4 /danixland-gravatar.php | |
| download | danixland-gravatar-70bd62adbc387a0545d63c3468d239cff606de90.tar.gz danixland-gravatar-70bd62adbc387a0545d63c3468d239cff606de90.zip | |
Initial commit of the plugin.
nuovo file: .editorconfig
nuovo file: .gitignore
nuovo file: block.json
nuovo file: build/index.asset.php
nuovo file: build/index.css
nuovo file: build/index.js
nuovo file: build/style-index.css
nuovo file: danixland-gravatar.php
nuovo file: package-lock.json
nuovo file: package.json
nuovo file: readme.txt
nuovo file: src/edit.js
nuovo file: src/editor.scss
nuovo file: src/index.js
nuovo file: src/save.js
nuovo file: src/style.scss
Diffstat (limited to 'danixland-gravatar.php')
| -rw-r--r-- | danixland-gravatar.php | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/danixland-gravatar.php b/danixland-gravatar.php new file mode 100644 index 0000000..6a06c46 --- /dev/null +++ b/danixland-gravatar.php @@ -0,0 +1,67 @@ +<?php +/** + * Plugin Name: danixland gravatar block + * Description: Simple Gutemberg Block to insert a gravatar inside a post or page. + * Version: 0.1.0 + * Author: Danilo 'danix' Macri + * Author URI: https://danix.xyz + * License: GPL-2.0-or-later + * License URI: https://www.gnu.org/licenses/gpl-2.0.html + * Text Domain: dnxvatar + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * + * @package dnxvatar + */ + +/** + * Registers all block assets so that they can be enqueued through the block editor + * in the corresponding context. + * + * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/ + */ +function dnxvatar_danixland_gravatar_block_init() { + $dir = dirname( __FILE__ ); + + $script_asset_path = "$dir/build/index.asset.php"; + if ( ! file_exists( $script_asset_path ) ) { + throw new Error( + 'You need to run `npm start` or `npm run build` for the "dnxvatar/danixland-gravatar" block first.' + ); + } + $index_js = 'build/index.js'; + $script_asset = require( $script_asset_path ); + wp_register_script( + 'dnxvatar-danixland-gravatar-block-editor', + plugins_url( $index_js, __FILE__ ), + $script_asset['dependencies'], + $script_asset['version'] + ); + wp_set_script_translations( 'dnxvatar-danixland-gravatar-block-editor', 'dnxvatar' ); + + $editor_css = 'build/index.css'; + wp_register_style( + 'dnxvatar-danixland-gravatar-block-editor', + plugins_url( $editor_css, __FILE__ ), + array(), + filemtime( "$dir/$editor_css" ) + ); + + $style_css = 'build/style-index.css'; + wp_register_style( + 'dnxvatar-danixland-gravatar-block', + plugins_url( $style_css, __FILE__ ), + array(), + filemtime( "$dir/$style_css" ) + ); + + register_block_type( 'dnxvatar/danixland-gravatar', array( + 'editor_script' => 'dnxvatar-danixland-gravatar-block-editor', + 'editor_style' => 'dnxvatar-danixland-gravatar-block-editor', + 'style' => 'dnxvatar-danixland-gravatar-block', + ) ); +} +add_action( 'init', 'dnxvatar_danixland_gravatar_block_init' ); |
