-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecker.php
More file actions
152 lines (131 loc) · 4.66 KB
/
decker.php
File metadata and controls
152 lines (131 loc) · 4.66 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
<?php
/**
*
* Decker is a WordPress plugin focused on efficiently and structurally presenting a list of tasks.
*
* @link https://github.com/ateeducacion/wp-decker
* @package Decker
*
* @wordpress-plugin
* Plugin Name: Decker
* Plugin URI: https://github.com/ateeducacion/wp-decker
* Description: Decker is a WordPress plugin focused on efficiently and structurally presenting a list of tasks. It is a simple task management plugin that utilizes a Kanban board and a unique priority system.
* Version: 0.0.0
* Author: Área de Tecnología Educativa
* Author URI: https://www3.gobiernodecanarias.org/medusa/ecoescuela/ate/
* License: GPL-3.0+
* License URI: https://www.gnu.org/licenses/gpl-3.0-standalone.html
* Text Domain: decker
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'DECKER_VERSION', '0.0.0' );
define( 'DECKER_PLUGIN_FILE', __FILE__ );
/**
* The code that runs during plugin activation.
*/
function activate_decker() {
// In a Multisite network, verify the site is in the allowlist.
if ( is_multisite() && ! Decker_Network_Settings::is_site_allowed( get_current_blog_id() ) ) {
wp_die(
esc_html__(
'Decker cannot be activated on this site. Please ask your network administrator to add this site to the allowed sites list under Network Admin > Settings > Decker.',
'decker'
),
esc_html__( 'Plugin Activation Error', 'decker' ),
array( 'back_link' => true )
);
}
// Set the permalink structure if necessary.
if ( '/%postname%/' !== get_option( 'permalink_structure' ) ) {
update_option( 'permalink_structure', '/%postname%/' );
}
flush_rewrite_rules();
update_option( 'decker_flush_rewrites', true );
update_option( 'decker_version', DECKER_VERSION );
}
/**
* The code that runs during plugin deactivation.
*/
function deactivate_decker() {
flush_rewrite_rules();
}
/**
* Plugin Update Handler
*
* @param WP_Upgrader $upgrader_object Upgrader object.
* @param array $options Upgrade options.
*/
function decker_update_handler( $upgrader_object, $options ) {
// Check if the update is for your specific plugin.
if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) {
$plugins_updated = $options['plugins'];
// Replace with your plugin's base name (typically folder/main-plugin-file.php).
$plugin_file = plugin_basename( __FILE__ );
// Check if your plugin is in the list of updated plugins.
if ( in_array( $plugin_file, $plugins_updated ) ) {
// Perform update-specific tasks.
flush_rewrite_rules();
}
}
}
register_activation_hook( __FILE__, 'activate_decker' );
register_deactivation_hook( __FILE__, 'deactivate_decker' );
add_action( 'upgrader_process_complete', 'decker_update_handler', 10, 2 );
/**
* Maybe flush rewrite rules on init if needed.
*/
function decker_maybe_flush_rewrite_rules() {
$saved_version = get_option( 'decker_version' );
// If plugin version changed, or a flag has been set (e.g. on activation), flush rules.
if ( DECKER_VERSION !== $saved_version || get_option( 'decker_flush_rewrites' ) ) {
flush_rewrite_rules();
update_option( 'decker_version', DECKER_VERSION );
delete_option( 'decker_flush_rewrites' );
}
}
add_action( 'init', 'decker_maybe_flush_rewrite_rules', 999 );
/**
* Show an admin notice when Decker is active on a site excluded from the
* network allowlist, so administrators are aware of the mismatch.
*/
function decker_multisite_restriction_notice() {
if ( ! is_multisite() ) {
return;
}
if ( ! class_exists( 'Decker_Network_Settings' ) ) {
return;
}
if ( ! Decker_Network_Settings::is_site_allowed( get_current_blog_id() ) ) {
echo '<div class="notice notice-warning"><p>' .
esc_html__(
'Decker is active on this site, but the network administrator has not included it in the allowed sites list. Please contact your network administrator.',
'decker'
) .
'</p></div>';
}
}
add_action( 'admin_notices', 'decker_multisite_restriction_notice' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require_once plugin_dir_path( __FILE__ ) . 'includes/class-decker.php';
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-decker-wpcli.php';
}
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*/
function run_decker() {
$plugin = new Decker();
$plugin->run();
}
run_decker();