-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobi-exclude-from-search.php
More file actions
218 lines (179 loc) · 4.55 KB
/
obi-exclude-from-search.php
File metadata and controls
218 lines (179 loc) · 4.55 KB
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
<?php
/**
* Plugin Name: Obi Exclude from Search
* Description: Include or exclude (custom) post types from the WordPress search feature.
* Version: 1.0.1
* Author: Obi Juan <hola@obijuan.dev>
* Author URI: https://obijuan.dev
* Plugin URI: https://obijuan.dev/obi-remove-post-types-from-search
* License: GPL2 or later
* Textdomain: obi-exclude-from-search
*
* @since 1.0.0
*/
// Check if accessed directly!
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Trying what?' );
}
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
use ObiExcludeFromSearch\Includes\Admin\AdminPage;
use ObiExcludeFromSearch\Includes\PostTypes;
/**
* Obi_Init
*
* Initialize the plugin
*
* @since 1.0.0
*/
final class Obi_Init {
/**
* Instance
*
* @var Obi_Init
* @access private
* @static
* @since 1.0.0
*/
private static $instance;
/**
* Initialize the plugin
*
* @since 1.0.0
*/
private function __construct() {
self::define_constants();
self::check_minimum_php_version();
}
/**
* Get the instance of the class.
*
* @since 1.0.0
* @return Obi_Init
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Define constants
*
* @since 1.0.0
*/
private static function define_constants() {
define( 'OBI_EXCLUDE_FROM_SEARCH_VERSION', '1.0.1' );
define( 'OBI_EXCLUDE_FROM_SEARCH_TEXTDOMAIN', 'obi-exclude-from-search' );
define( 'OBI_EXCLUDE_FROM_SEARCH_DIRNAME', plugin_basename( __DIR__ ) );
define( 'OBI_EXCLUDE_FROM_SEARCH_FILE', __FILE__ );
define( 'OBI_EXCLUDE_FROM_SEARCH_PREFIX', 'obi_exclude_from_search' );
define( 'OBI_EXCLUDE_FROM_SEARCH_PATH', plugin_dir_path( OBI_EXCLUDE_FROM_SEARCH_FILE ) );
define( 'OBI_EXCLUDE_FROM_SEARCH_URL', plugin_dir_url( OBI_EXCLUDE_FROM_SEARCH_FILE ) );
define( 'OBI_EXCLUDE_FROM_SEARCH_MINIMUM_PHP_REQUIREMENT', '7.4' );
}
/**
* Load the plugin
*
* Load the classes we depend on and initialize the plugin.
*
* @since 1.0.0
*/
public static function load_obi_plugin() {
// On plugins loaded...
AdminPage::get_instance();
PostTypes::get_instance();
}
/**
* Activate the plugin
*
* @since 1.0.0
*/
public static function activate() {
// On plugin activation...
// Initialize post type statuses.
PostTypes::initialize_post_type_statuses();
}
/**
* Deactivate the plugin
*
* @since 1.0.0
*/
public static function deactivate() {
// On plugin deactivation...
}
/**
* Get the minimum version of PHP required by this plugin.
*
* @return string Minimum version required.
*/
public static function obi_exclude_from_search_minimum_php_requirement() {
return OBI_EXCLUDE_FROM_SEARCH_MINIMUM_PHP_REQUIREMENT;
}
/**
* Whether PHP installation meets the minimum requirements
*
* @return bool True if meets minimum requirements, false otherwise.
*/
public static function obi_exclude_from_search_site_meets_php_requirements() {
return version_compare( phpversion(), self::obi_exclude_from_search_minimum_php_requirement(), '>=' );
}
/**
* Check if PHP version meets minimum requirements.
*
* Enqueue admin notice if not.
*
* @since 1.0.0
*/
public static function check_minimum_php_version() {
// Ensuring our PHP version requirement is met first before loading the Obi Exclude From Search plugin.
if ( ! self::obi_exclude_from_search_site_meets_php_requirements() ) {
add_action(
'admin_notices',
array( __CLASS__, 'obi_exclude_from_search_admin_notice_php_version' )
);
return;
}
}
/**
* Admin notice for PHP version requirement.
*/
public static function obi_exclude_from_search_admin_notice_php_version() {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'Obi Exclude From Search requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'obi-exclude-from-search' ),
esc_html( self::obi_exclude_from_search_minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
}
/**
* Get the instance of the class.
*
* @since 1.0.0
* @return Obi_Init
*/
$obi_plugin = Obi_Init::get_instance();
/**
* Load the classes we depend on to run the plugin.
*
* Load - AdminPage.
* Load - PostTypes.
*
* @since 1.0.0
*/
add_action( 'plugins_loaded', array( $obi_plugin, 'load_obi_plugin' ) );
/**
* Activate the plugin
*
* @since 1.0.0
*/
register_activation_hook( OBI_EXCLUDE_FROM_SEARCH_FILE, array( $obi_plugin, 'activate' ) );