-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-kitab.php
173 lines (130 loc) · 4.42 KB
/
wp-kitab.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
<?php
/**
*
* @link https://github.com/Ahrary
* @since 1.0.0
* @package WP_Kitab
*
* @wordpress-plugin
* Plugin Name: WP Kitab
* Plugin URI: https://github.com/Ahrary/wp-kitab
* Description: WP Kitab is a simple plugin that allows you to add book post type and taxonomies to your wordpress website.
* Version: 1.0.4
* Requires at least: 5.2
* Tested up to: 5.8.2
* Requires PHP: 7.0
* Author: Ahrary
* Author URI: https://github.com/Ahrary
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-kitab
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('ABSPATH')) {
die('We\'re sorry, but you can not directly access this file.');
}
// define required wp version
define('AFZUNA_WP_VERSION', '4.8');
define('AFZUNA_TEXTDOMAIN', 'wp-kitab');
define('AFZUNA_NAME', 'WP Kitab');
define('AFZUNA_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('AFZUNA_PLUGIN_URL', plugin_dir_url(__FILE__));
define('AFZUNA_MIN_PHP_VERSION', '7.0');
define('AFZUNA_ACF_VERSION', '5.0.0');
// load plugin text domain
add_action(
'init',
static function () {
load_plugin_textdomain(AFZUNA_TEXTDOMAIN, false, dirname(plugin_basename(__FILE__)) . '/languages');
}
);
// include required files
require_once AFZUNA_PLUGIN_DIR . 'includes/class-wp-kitab.php';
require_once AFZUNA_PLUGIN_DIR . 'includes/class-wp-kitab-cpt.php';
require_once AFZUNA_PLUGIN_DIR . 'includes/class-wp-kitab-taxonomies.php';
require_once AFZUNA_PLUGIN_DIR . 'includes/class-wp-kitab-acf.php';
// require_once AFZUNA_PLUGIN_DIR . 'includes/class-wp-kitab-shortcodes.php';
require_once AFZUNA_PLUGIN_DIR . 'functions/functions.php';
function wp_kitab_init()
{
// check if wp version is compatible
if (version_compare(get_bloginfo('version'), AFZUNA_WP_VERSION, '<')) {
add_action('admin_notices', 'wp_kitab_admin_notice_wp_version');
return;
}
// check if php version is compatible
if (version_compare(PHP_VERSION, AFZUNA_MIN_PHP_VERSION, '<')) {
add_action('admin_notices', 'wp_kitab_admin_notice_php_version');
return;
}
// create post type
$post_type = new WP_Kitab_CPT();
$post_type->register();
// create taxonomy
$taxonomy = new WP_Kitab_Taxonomies();
$taxonomy->register();
// flush rewrite rules
flush_rewrite_rules();
}
add_action('init', 'wp_kitab_init');
function wp_kitab_admin_notice_php_version()
{
$class = 'notice notice-error';
$message = sprintf(__('WP Kitab requires PHP version %s or higher.', 'wp-kitab'), AFZUNA_MIN_PHP_VERSION);
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
}
function wp_kitab_admin_notice_wp_version()
{
$class = 'notice notice-error';
$message = sprintf(__('WP Kitab requires WordPress version %s or higher.', 'wp-kitab'), AFZUNA_WP_VERSION);
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
}
function wp_kitab_admin_notice_acf_version()
{
$class = 'notice notice-error';
$message = sprintf(__('WP Kitab requires Advanced Custom Fields version %s or higher.', 'wp-kitab'), AFZUNA_ACF_VERSION);
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
}
function wp_kitab_admin_notice_acf_not_active()
{
$class = 'notice notice-error';
$message = __('Advanced Custom Fields is not active.', 'wp-kitab');
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
}
function wp_kitab_admin_notice_acf_not_installed()
{
$class = 'notice notice-error';
$message = __('Advanced Custom Fields is not installed.', 'wp-kitab');
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
}
// deactivation hook
function wp_kitab_deactivation()
{
// unregister post type
$post_type = new WP_Kitab_CPT();
$post_type->unregister();
// unregister taxonomy
$taxonomy = new WP_Kitab_Taxonomies();
$taxonomy->unregister();
}
register_deactivation_hook(__FILE__, 'wp_kitab_deactivation');
// uninstall hook
function wp_kitab_uninstall()
{
// unregister post type
$post_type = new WP_Kitab_CPT();
$post_type->unregister();
// unregister taxonomy
$taxonomy = new WP_Kitab_Taxonomies();
$taxonomy->unregister();
}
register_uninstall_hook(__FILE__, 'wp_kitab_uninstall');
// run plugin
if (!wp_installing()) {
function run_wp_kitab()
{
$plugin = new WP_Kitab();
$plugin->run();
}
}