-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnelio-gutenberg-custom-button.php
94 lines (72 loc) · 2.36 KB
/
nelio-gutenberg-custom-button.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* The plugin bootstrap file.
*
* Plugin Name: Nelio Gutenberg Custom Button
* Plugin URI: https://neliosoftware.com/
* Description: Add custom button to Rich Text blocks in Gutenberg for WordPress.
* Version: 1.0.0
*
* Author: Nelio Software
* Author URI: https://neliosoftware.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* Text Domain: nelio
* Domain Path: /languages
*
* @package Nelio
* @author Antonio Villegas <antonio.villegas@neliosoftware.com>
* @since 1.0.0
*/
! defined( 'ABSPATH' ) && exit;
class NelioButton {
private static $_instance = null;
public $plugin_path;
public $plugin_url;
public $plugin_name;
public $plugin_version;
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
self::$_instance->init_options();
self::$_instance->init_hooks();
}
return self::$_instance;
}
public function init_options() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
// load textdomain.
load_plugin_textdomain( 'nelio', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
public function init_hooks() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
// we need to enqueue the main script earlier to let 3rd-party plugins add custom styles support.
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ), 9 );
}
public function enqueue_block_editor_assets() {
wp_enqueue_script(
'nelio-gutenberg-custom-button',
untrailingslashit( plugin_dir_url( __FILE__ ) ) . '/dist/js/gutenberg.js',
[],
'1.0.3',
true
);
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'nelio-gutenberg-custom-button', 'nelio' );
}//end if
}
public function admin_init() {
// get current plugin data.
$data = get_plugin_data( __FILE__ );
$this->plugin_name = $data['Name'];
$this->plugin_version = $data['Version'];
$this->plugin_slug = plugin_basename( __FILE__, '.php' );
$this->plugin_name_sanitized = basename( __FILE__, '.php' );
}
}
function nelio_button() {
return NelioButton::instance();
}
add_action( 'plugins_loaded', 'nelio_button' );