| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Anchor Block |
| 4 |
* Plugin URI: https://jeanbaptisteaudras.com/anchor-block/ |
| 5 |
* Description: Anchor Block let you generate internal link to any section of your Gutenberg pages. |
| 6 |
* Version: 0.1 |
| 7 |
* Author: audrasjb |
| 8 |
* Author URI: https://jeanbaptisteaudras.com/ |
| 9 |
* License: GPL-2.0+ |
| 10 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 11 |
* Text Domain: anchor-block |
| 12 |
*/ |
| 13 |
|
| 14 |
// If this file is called directly, abort. |
| 15 |
if ( ! defined( 'WPINC' ) ) { |
| 16 |
die; |
| 17 |
} |
| 18 |
|
| 19 |
if ( ! function_exists( 'register_block_type' ) ) { |
| 20 |
// Gutenberg is not active. |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
add_action( 'wp_enqueue_scripts', 'anchor_block_enqueue_scripts_public' ); |
| 25 |
function anchor_block_enqueue_scripts_public() { |
| 26 |
wp_enqueue_style( |
| 27 |
'anchor-block-public-styles', |
| 28 |
plugin_dir_url( __FILE__ ) . 'public/anchor-block.css', |
| 29 |
array(), |
| 30 |
'', |
| 31 |
'all' |
| 32 |
); |
| 33 |
wp_register_script( |
| 34 |
'anchor-block-public-scripts', |
| 35 |
plugins_url( 'public/anchor-block.js', __FILE__ ), |
| 36 |
array( 'jquery' ), |
| 37 |
filemtime( plugin_dir_path( __FILE__ ) . 'public/anchor-block.js' ), |
| 38 |
true |
| 39 |
); |
| 40 |
wp_enqueue_script( 'anchor-block-public-scripts' ); |
| 41 |
} |
| 42 |
add_action( 'admin_enqueue_scripts', 'anchor_block_enqueue_scripts_admin' ); |
| 43 |
function anchor_block_enqueue_scripts_admin() { |
| 44 |
wp_enqueue_style( |
| 45 |
'anchor-block-admin-styles', |
| 46 |
plugin_dir_url( __FILE__ ) . 'admin/block.css', |
| 47 |
array(), |
| 48 |
'', |
| 49 |
'all' |
| 50 |
); |
| 51 |
wp_register_script( |
| 52 |
'anchor-block-admin-scripts', |
| 53 |
plugins_url( 'admin/block.js', __FILE__ ), |
| 54 |
array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ), |
| 55 |
filemtime( plugin_dir_path( __FILE__ ) . 'admin/block.js' ), |
| 56 |
true |
| 57 |
); |
| 58 |
wp_enqueue_script( 'anchor-block-admin-scripts' ); |
| 59 |
} |
| 60 |
register_block_type( 'anchor-block/standard', |
| 61 |
array( |
| 62 |
'editor_script' => 'anchor-block-admin-scripts', |
| 63 |
) |
| 64 |
); |
| 65 |
|
| 66 |
|