This repository has been archived by the owner on Jan 27, 2024. It is now read-only.
/
plugin.php
executable file
·133 lines (114 loc) · 3.69 KB
/
plugin.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Tutorial: Convert React.createClass to React.Component
*
* @link https://github.com/mattwatsoncodes/Tutorial-Convert-React.createClass-to-React.Component
* @package hwc\tutorial-reateclass-component
*
* Plugin Name: Tutorial: Convert React.createClass to React.Component
* Plugin URI: https://github.com/mattwatsoncodes/Tutorial-Convert-React.createClass-to-React.Component
* Description: How to get a component written with React.createClass to work in later versions of React.
* Version: 1.0.0
* Author: Matt Watson <hello@mattwatson.codes>
* Author URI: https://healthwealthcode.com
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Text Domain: tutorial-reateclass-component
* Domain Path: /languages
*/
/**
* Copyright (C) 2018 Matt Watson hello@mattwatson.codes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3, as
* published by the Free Software Foundation.
*
* 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace hwc\tutorial_createclass_component;
// Abort if this file is called directly.
if ( ! defined( 'WPINC' ) ) {
die;
}
// Constants.
define( 'HWC_TUTORIAL_CREATE_CLASS_COMPONENT_ROOT', __FILE__ );
define( 'HWC_TUTORIAL_CREATE_CLASS_COMPONENT_PREFIX', 'hwc_tutorial_createclass_component' );
/**
* The main loader for this plugin
*/
class Main {
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct() {}
/**
* Run all of the plugin functions.
*
* @since 1.0.0
*/
public function run() {
/**
* Load Text Domain
*/
load_plugin_textdomain( 'tutorial-reateclass-component', false, HWC_TUTORIAL_CREATE_CLASS_COMPONENT_ROOT . '\languages' );
/**
* Actions and Hooks
*/
// Load Assets
add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) ); // Load Editor Assets
add_action( 'enqueue_block_assets', array( $this, 'assets' ) ); // Load Front End Assets
}
/**
* Enqueue Editor JS and CSS
*/
public function editor_assets() {
$scripts = '/assets/js/editor.js';
$styles = '/assets/css/editor.css';
// Enqueue editor JS.
wp_enqueue_script(
'tutorial-reateclass-component-editor-js',
plugins_url( $scripts, __FILE__ ),
[ 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-editor' ],
filemtime( plugin_dir_path( __FILE__ ) . $scripts )
);
// Enqueue edtior Styles.
wp_enqueue_style(
'tutorial-reateclass-component-editor-css',
plugins_url( $styles, __FILE__ ),
[ 'wp-blocks' ],
filemtime( plugin_dir_path( __FILE__ ) . $styles )
);
}
/**
* Enqueue JS and CSS
*/
public function assets() {
$scripts = '/assets/js/script.js';
$styles = '/assets/css/style.css';
// Enqueue JS.
wp_enqueue_script(
'tutorial-reateclass-component-js',
plugins_url( $scripts, __FILE__ ),
[ 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-editor' ],
filemtime( plugin_dir_path( __FILE__ ) . $scripts )
);
// Enqueue Styles.
wp_enqueue_style(
'tutorial-reateclass-component-css',
plugins_url( $styles, __FILE__ ),
[ 'wp-blocks' ],
filemtime( plugin_dir_path( __FILE__ ) . $styles )
);
}
}
$main = new Main();
$main->run();