-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerful-blocks.php
238 lines (191 loc) · 5.72 KB
/
powerful-blocks.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/** بسم الله الرحمن الرحيم **
* Main Plugin File
*
* @package PowerfulBlocks
*/
/**
* Plugin Name: Gutenberg Blocks - Powerful Blocks for Gutenberg
* Plugin URI: https://powerfulblocks.com
* Description: Powerful Blocks is a Gutenberg Block Plugin With Awesome Blocks, Prebuilt Templates and Advanced Controls.
* Version: 1.0.3
* Author: ultraDevs
* Author URI: https://ultradevs.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: powerful-blocks
* Domain Path: /languages
*/
// If this file is called directly, abort!
defined( 'ABSPATH' ) || exit( 'bYe bYe!' );
// Constant.
define( 'POWERFUL_BLOCKS_VERSION', '1.0.0' );
define( 'POWERFUL_BLOCKS_NAME', plugin_basename( __FILE__ ) );
define( 'POWERFUL_BLOCKS_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'POWERFUL_BLOCKS_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'POWERFUL_BLOCKS_ASSETS', POWERFUL_BLOCKS_DIR_URL . 'assets/' );
define( 'POWERFUL_BLOCKS_MENU_SLUG', 'powerful-blocks' );
/**
* Require Composer Autoload
*/
require_once POWERFUL_BLOCKS_DIR_PATH . 'vendor/autoload.php';
/**
* Powerful Blocks class
*/
final class PowerfulBlocks {
/**
* Constructor
*/
public function __construct() {
$this->appsero_init_tracker_powerful_blocks();
add_action( 'plugins_loaded', array( $this, 'init' ) );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
add_filter( 'block_categories', array( $this, 'register_block_category' ), 10, 2 );
add_action( 'init', array( $this, 'load_text_domain' ) );
do_action( 'powerfulblocks_loaded' );
}
/**
* Begin execution of the plugin
*
* @return \PowerfulBlocks
*/
public static function run() {
/**
* Instance
*
* @var boolean
*/
static $instance = false;
if ( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Plugin Init
*/
public function init() {
// Blocks Helper Class.
$blocks_helper = new ultraDevs\PB\Blocks_Helper();
// Helper Class.
$helper = new ultraDevs\PB\Helper();
// Ajax Class.
$ajax = new ultraDevs\PB\Ajax();
// Assets Manager Class.
$assets_manager = new ultraDevs\PB\Assets_Manager();
// Activate.
$activate = new ultraDevs\PB\Activate();
// Rest API Manager.
$rest_api_manager = new ultraDevs\PB\API();
// Post Meta Manager.
// $post_meta = new ultraDevs\PB\Admin\Post_Meta();
// $post_meta->register();
if ( is_admin() ) {
// Activation_Redirect.
add_action( 'admin_init', array( $activate, 'activation_redirect' ) );
// Dashboard.
$dashboard = new ultraDevs\PB\Admin\Dashboard();
$dashboard->register();
// Admin Assets.
add_action( 'admin_enqueue_scripts', array( $assets_manager, 'admin_assets' ) );
// Block Editor Assets.
add_action( 'enqueue_block_editor_assets', array( $assets_manager, 'block_editor_assets' ) );
// Block Assets.
add_action( 'enqueue_block_assets', array( $assets_manager, 'block_assets' ) );
add_action( 'admin_enqueue_scripts', array( $assets_manager, 'load_fonts' ) );
// Plugin Action Links.
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
} else {
// Frontend Assets.
add_action( 'wp_enqueue_scripts', array( $assets_manager, 'frontend_assets' ) );
add_action( 'wp_head', array( $assets_manager, 'get_block_css' ) );
// Block Render.
add_filter( 'render_block', array( $blocks_helper, 'block_render' ), 10, 2 );
}
}
/**
* The code that runs during plugin activation.
*/
/**
* Plugin Activation.
*
* @return void
*/
public function activate() {
$activate = new ultraDevs\PB\Activate();
$activate->run();
}
/**
* Block Category
*
* @param array $categories Block Categories.
*
* @return array
*/
public function register_block_category( $categories ) {
$categories = array_merge(
$categories,
array(
array(
'slug' => 'powerful-blocks',
'title' => __( 'Powerful Blocks', 'powerful-blocks' ),
),
)
);
return $categories;
}
/**
* Loads a plugin’s translated strings.
*
* @return void
*/
public function load_text_domain() {
load_plugin_textdomain( 'powerful-blocks', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Plugin Action Links
*
* @param array $links Links.
* @return array
*/
public function plugin_action_links( $links ) {
$links[] = '<a href="' . admin_url( 'admin.php?page=' . POWERFUL_BLOCKS_MENU_SLUG ) . '">' . __( 'Settings', 'powerful-blocks' ) . '</a>';
if ( ! udpb_has_pro() ) {
$links[] = '<a target="_blank" href="https://powerfulblocks.com/pricing" style="color: #f30d55; font-weight: bold;">' . __( 'Get Pro', 'powerful-blocks' ) . '</a>';
}
return $links;
}
/**
* Initialize the plugin tracker
*
* @return void
*/
public function appsero_init_tracker_powerful_blocks() {
if ( ! class_exists( 'Appsero\Client' ) ) {
require_once POWERFUL_BLOCKS_DIR_PATH . '/vendor/appsero/src/Client.php';
}
$client = new Appsero\Client( '212f7849-a379-41d7-901e-5d512a25e63c', 'Powerful Blocks for Gutenberg', __FILE__ );
$powerful_blocks_data = array(
'pro_installed' => udpb_has_pro() ? 'Yes' : 'No',
'pro_version' => udpb_has_pro() ? POWERFUL_BLOCKS_PRO_VERSION : '',
);
// Active insights.
$client->insights()->add_extra( $powerful_blocks_data )->init();
// Active automatic updater.
$client->updater();
}
}
/**
* Check if powerful_blocks doesn't exist
*/
if ( ! function_exists( 'powerful_blocks' ) ) {
/**
* Load Powerful Blocks
*
* @return PowerfulBlocks
*/
function powerful_blocks() {
return PowerfulBlocks::run();
}
}
powerful_blocks();