-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamipress-gutenberg-blocks.php
202 lines (167 loc) · 5.69 KB
/
gamipress-gutenberg-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
<?php
/**
* Plugin Name: GamiPress - Gutenberg Blocks
* Plugin URI: https://github.com/rubengc/GamiPress-Gutenberg-Blocks
* Description: GamiPress blocks for Gutenberg.
* Version: 1.1.2
* Author: GamiPress
* Author URI: https://gamipress.com/
* Text Domain: gamipress-gutenberg-blocks
* Domain Path: /languages/
* Requires at least: 4.4
* Tested up to: 5.0
* License: GNU AGPL v3.0 (http://www.gnu.org/licenses/agpl.txt)
*
* @package GamiPress\Gutenberg_Blocks
* @author GamiPress
* @copyright Copyright (c) GamiPress
*/
final class GamiPress_Gutenberg_Blocks {
/**
* @var GamiPress_Gutenberg_Blocks $instance The one true GamiPress_Gutenberg_Blocks
* @since 1.0.0
*/
private static $instance;
/**
* Get active instance
*
* @access public
* @since 1.0.0
* @return object self::$instance The one true GamiPress_Gutenberg_Blocks
*/
public static function instance() {
if( !self::$instance ) {
self::$instance = new GamiPress_Gutenberg_Blocks();
self::$instance->constants();
self::$instance->includes();
self::$instance->hooks();
self::$instance->load_textdomain();
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
* @since 1.0.0
* @return void
*/
private function constants() {
// Plugin version
define( 'GAMIPRESS_GUTEMBERG_BLOCKS_VER', '1.1.2' );
// Plugin path
define( 'GAMIPRESS_GUTEMBERG_BLOCKS_DIR', plugin_dir_path( __FILE__ ) );
// Plugin URL
define( 'GAMIPRESS_GUTEMBERG_BLOCKS_URL', plugin_dir_url( __FILE__ ) );
}
/**
* Include plugin files
*
* @access private
* @since 1.0.0
* @return void
*/
private function includes() {
if( $this->meets_requirements() ) {
require_once GAMIPRESS_GUTEMBERG_BLOCKS_DIR . 'src/init.php';
}
}
/**
* Setup plugin hooks
*
* @access private
* @since 1.0.0
* @return void
*/
private function hooks() {
// Setup our activation and deactivation hooks
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
/**
* Activation hook for the plugin.
*
* @since 1.0.0
*/
function activate() {
if( $this->meets_requirements() ) {
}
}
/**
* Deactivation hook for the plugin.
*
* @since 1.0.0
*/
function deactivate() {
}
/**
* Plugin admin notices.
*
* @since 1.0.0
*/
public function admin_notices() {
if ( ! $this->meets_requirements() && ! defined( 'GAMIPRESS_ADMIN_NOTICES' ) ) : ?>
<div id="message" class="notice notice-error is-dismissible">
<p>
<?php printf(
__( 'GamiPress - Forminator integration requires %s in order to work. Please install and activate it.', 'gamipress-gutenberg-blocks' ),
'<a href="https://wordpress.org/plugins/gamipress/" target="_blank">GamiPress</a>'
); ?>
</p>
</div>
<?php define( 'GAMIPRESS_ADMIN_NOTICES', true ); ?>
<?php endif;
}
/**
* Check if there are all plugin requirements
*
* @since 1.0.0
*
* @return bool True if installation meets all requirements
*/
private function meets_requirements() {
if ( ! class_exists( 'GamiPress' ) ) {
return false;
}
return true;
}
/**
* Internationalization
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_textdomain() {
// Set filter for language directory
$lang_dir = GAMIPRESS_GUTEMBERG_BLOCKS_DIR . '/languages/';
$lang_dir = apply_filters( 'gamipress_forminator_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'gamipress-gutenberg-blocks' );
$mofile = sprintf( '%1$s-%2$s.mo', 'gamipress-gutenberg-blocks', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/gamipress-gutenberg-blocks/' . $mofile;
if( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/gamipress-gutenberg-blocks/ folder
load_textdomain( 'gamipress-gutenberg-blocks', $mofile_global );
} elseif( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/gamipress-gutenberg-blocks/languages/ folder
load_textdomain( 'gamipress-gutenberg-blocks', $mofile_local );
} else {
// Load the default language files
load_plugin_textdomain( 'gamipress-gutenberg-blocks', false, $lang_dir );
}
}
}
/**
* The main function responsible for returning the one true GamiPress_Gutenberg_Blocks instance to functions everywhere
*
* @since 1.0.0
* @return \GamiPress_Gutenberg_Blocks The one true GamiPress_Gutenberg_Blocks
*/
function GamiPress_Gutenberg_Blocks() {
return GamiPress_Gutenberg_Blocks::instance();
}
add_action( 'plugins_loaded', 'GamiPress_Gutenberg_Blocks' );