forked from godaddy-wordpress/block-unit-test
/
class-block-unit-test.php
159 lines (134 loc) · 4.12 KB
/
class-block-unit-test.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
<?php
/**
* Plugin Name: Gutenberg Block Unit Test
* Plugin URI: https://richtabor.com/gutenberg-block-unit-test/
* Description: @@pkg.description
* Author: Rich Tabor
* Author URI: https://richtabor.com
* Tags: gutenberg, editor, block, unit test, coblocks
* Version: 1.0.5
* Text Domain: '@@pkg.name'
* Domain Path: languages
* Tested up to: @@pkg.tested_up_to
*
* @@pkg.title 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 @@pkg.title. If not, see <http://www.gnu.org/licenses/>.
*
* @package @@pkg.title
* @author @@pkg.author
* @license @@pkg.license
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Main @@pkg.title Class
*
* @since 1.0.0
*/
class Block_Unit_Test {
/**
* The plugin instance.
*
* @var Block_Unit_Test
*/
private static $instance;
/**
* Registers the plugin.
*/
public static function register() {
if ( null === self::$instance ) {
self::$instance = new Block_Unit_Test();
self::$instance->includes();
}
}
/**
* The plugin version.
*
* @var string $_version
*/
private $_version;
/**
* The base URL path.
*
* @var string $_url
*/
private $_url;
/**
* The Constructor.
*/
private function __construct() {
$this->_version = '@@pkg.version';
$this->_url = untrailingslashit( plugins_url( '/assets/images', __FILE__ ) );
// Actions.
add_action( 'upgrader_process_complete', array( $this, 'upgrade_completed' ), 10, 2 );
// add_action( 'plugins_loaded', array( $this, 'suggest_coblocks' ) );
// Filters.
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
}
/**
* Include required files.
*
* @access private
* @since 1.0.3
* @return void
*/
private function includes() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once untrailingslashit( plugin_dir_path( '/', __FILE__ ) ) . 'includes/class-block-unit-test-standart.php';
// Check for woo-gutenberg-products-block.
if ( is_plugin_active( 'woo-gutenberg-products-block/woocommerce-gutenberg-products-block.php' ) ) {
require_once untrailingslashit( plugin_dir_path( '/', __FILE__ ) ) . 'includes/class-block-unit-test-wooblocks.php';
}
// Check for CoBlocks.
if ( is_plugin_active( 'coblocks/class-coblocks.php' ) ) {
require_once untrailingslashit( plugin_dir_path( '/', __FILE__ ) ) . 'includes/class-block-unit-test-coblocks.php';
}
// Check for atomBlocks.
if ( is_plugin_active( 'atomic-blocks/atomicblocks.php' ) ) {
require_once untrailingslashit( plugin_dir_path( '/', __FILE__ ) ) . 'includes/class-block-unit-test-atomblocks.php';
}
// Includes.
require_once untrailingslashit( plugin_dir_path( '/', __FILE__ ) ) . 'includes/class-block-unit-test-suggest-coblocks.php';
require_once untrailingslashit( plugin_dir_path( '/', __FILE__ ) ) . 'includes/vendors/dismiss-notices/dismiss-notices.php';
}
/**
* Reccommend CoBlocks, if the plugin is not installed.
*
* @access public
* @since 1.0.3
* @return void
*/
public function suggest_coblocks() {
// Check for CoBlocks and suggest it if it's not installed.
if ( ! class_exists( 'CoBlocks' ) ) {
$suggestion = new Block_Unit_Test_Suggest_CoBlocks( plugin_dir_path( __FILE__ ) );
$suggestion = $suggestion->run();
}
}
/**
* Plugin row meta links
*
* @param array|array $input already defined meta links.
* @param string|string $file plugin file path and name being processed.
* @return array $input
*/
public function plugin_row_meta( $input, $file ) {
if ( 'block-unit-test/class-block-unit-test.php' !== $file ) {
return $input;
}
$url = 'https://richtabor.com/gutenberg-block-unit-test/';
$links = array(
'<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html__( 'More information', '@@textdomain' ) . '</a>',
);
$input = array_merge( $input, $links );
return $input;
}
}
Block_Unit_Test::register();