-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
63 lines (50 loc) · 1.22 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
<?php declare( strict_types=1 );
namespace lloc\Nowpayments;
class Plugin {
public const SLUG = 'nowpayments';
public const LANGUAGE_DIR = 'languages';
/**
* @param string $file
*/
private function __construct(
private readonly string $file
) { }
/**
* @param string $file
*
* @return Plugin
*/
public static function init( string $file ): Plugin {
$plugin = new self( $file );
add_action( 'plugins_loaded', array( $plugin, 'plugins_loaded' ) );
add_action( 'init', array( $plugin, 'block_init' ) );
return $plugin;
}
/**
* @return void
*/
public function plugins_loaded(): void {
load_plugin_textdomain( 'wp-nowpayments-integration', false, $this->dirname( self::LANGUAGE_DIR ) );
}
public function block_init(): void {
if ( ! function_exists( 'register_block_type' ) ) {
return;
}
$path = $this->dirname( 'js/wp-nowpayments-integration-block' );
register_block_type( $path );
}
/**
* @param string $path
*
* @return string
*/
public function dirname( string $path ): string {
return plugin_dir_path( $this->file ) . trailingslashit( $path );
}
/**
* @return string
*/
public function plugin_dir_url(): string {
return plugin_dir_url( $this->file );
}
}