-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugin.php
128 lines (109 loc) · 3.56 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
<?php
/**
* Plugin Name: RediPress
* Plugin URI: https://github.com/devgeniem/redipress
* Description: A WordPress plugin that provides a blazing fast search engine and WP Query performance enhancements.
* Version: 2.0.13
* Author: Geniem
* Author URI: http://www.geniem.fi/
* License: GPL3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: redipress
* Domain Path: /languages
*/
namespace Geniem;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* RediPress plugin class
*/
class RediPressPlugin {
/**
* Plugin data
*
* @var array
*/
public $plugin_data = [
'Plugin Name',
'Plugin URI',
'Description',
'Version',
'Author',
'Author URI',
'Text Domain',
'Domain Path',
];
/**
* Plugin path
*
* @var string
*/
public $path = '';
/**
* Whether we are on debug mode or not.
*
* @var boolean
*/
public $debug = false;
/**
* Plugin public url
*
* @var string
*/
public $url = '';
/**
* Run the basic plugin functionalities
*/
public function __construct() {
// If a custom autoloader exists, use it.
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
}
// Ensure that the get_plugin_data() function is available.
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Get the plugin data and set it to the property
$plugin_data = \get_plugin_data( __FILE__, false, false );
$this->plugin_data = \wp_parse_args( $plugin_data, $this->plugin_data );
$this->path = __DIR__;
$this->url = plugin_dir_url( __FILE__ );
add_action( 'admin_enqueue_scripts', function() {
// Register admin JavaScripts
wp_register_script( 'RediPress', $this->url . 'assets/dist/admin.js', [ 'wp-i18n' ] );
wp_localize_script( 'RediPress', 'RediPress', [
'homeUrl' => \home_url(),
'restUrl' => \rest_url( RediPress\Rest::NAMESPACE ),
'restApiNonce' => \wp_create_nonce( 'wp_rest' ),
]);
wp_set_script_translations( 'RediPress', 'redipress' );
wp_enqueue_script( 'RediPress' );
});
// Whether we are on debug mode or not
$this->debug = true;
// Load the plugin textdomain.
load_plugin_textdomain( 'redipress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
// Initialize the plugin itself
new RediPress\RediPress( $this );
}
/**
* Show WordPress admin notice
*
* @param string $message The message to be shown.
* @param string $details Possible detailed error message.
* @param boolean $dismissible Is the message dismissible.
* @return void
*/
public function show_admin_error( string $message, string $details = '', bool $dismissible = true ) {
add_action( 'admin_notices', function() use ( $message, $details, $dismissible ) {
printf(
'<div class="notice notice-error%s"><p><b>RediPress:</b> %s</p>%s</div>',
esc_html( $dismissible ? ' is-dismissible' : '' ),
esc_html( $message ),
$this->debug && ! empty( $details ) ? '<p>' . esc_html( $details ) . '</p>' : ''
);
});
}
}
new RediPressPlugin();