-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathplugin-name.php
More file actions
182 lines (157 loc) · 6.09 KB
/
Copy pathplugin-name.php
File metadata and controls
182 lines (157 loc) · 6.09 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
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://example.com
* @since 1.0.0
* @package Plugin_Name
*
* @wordpress-plugin
* Plugin Name: WordPress Plugin Boilerplate Tutorial
* Plugin URI: http://example.com/plugin-name-uri/
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 1.0.0
* Author: Your Name or Your Company
* Author URI: http://example.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: plugin-name
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'PLUGIN_NAME_PLUGIN_NAME', 'plugin-name' );
define( 'PLUGIN_NAME_VERSION', '1.0.0' );
define( 'PLUGIN_NAME_URL', plugin_dir_url( __FILE__ ) );
define( 'PLUGIN_NAME_PATH', plugin_dir_path( __FILE__ ) );
/**
* Store plugin base dir, for easier access later from other classes.
* (eg. Include, pubic or admin)
*/
define( 'PLUGIN_NAME_BASE_DIR', plugin_dir_path( __FILE__ ) );
/********************************************
* RUN CODE ON PLUGIN UPGRADE AND ADMIN NOTICE
*
* @tutorial run_code_on_plugin_upgrade_and_admin_notice.php
*/
define( 'PLUGIN_NAME_BASE_NAME', plugin_basename( __FILE__ ) );
// RUN CODE ON PLUGIN UPGRADE AND ADMIN NOTICE
/**
* Initialize custom templater
*/
if( ! class_exists( 'Exopite_Template' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/libraries/class-exopite-template.php';
}
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-plugin-name-activator.php
*/
function activate_plugin_name() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-activator.php';
Plugin_Name_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-plugin-name-deactivator.php
*/
function deactivate_plugin_name() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-deactivator.php';
Plugin_Name_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_plugin_name' );
register_deactivation_hook( __FILE__, 'deactivate_plugin_name' );
/*****************************************
* CUSTOM UPDATER FOR PLUGIN
* @tutorial custom_updater_for_plugin.php
*/
if ( is_admin() ) {
/**
* A custom update checker for WordPress plugins.
*
* How to use:
* - Copy vendor/plugin-update-checker to your plugin OR
* Download https://github.com/YahnisElsts/plugin-update-checker to the folder
* - Create a subdomain or a folder for the update server eg. https://updates.example.net
* Download https://github.com/YahnisElsts/wp-update-server and copy to the subdomain or folder
* - Add plguin zip to the 'packages' folder
*
* Useful if you don't want to host your project
* in the official WP repository, but would still like it to support automatic updates.
* Despite the name, it also works with themes.
*
* @link http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/
* @link https://github.com/YahnisElsts/plugin-update-checker
* @link https://github.com/YahnisElsts/wp-update-server
*/
if( ! class_exists( 'Puc_v4_Factory' ) ) {
require_once join( DIRECTORY_SEPARATOR, array( PLUGIN_NAME_BASE_DIR, 'vendor', 'plugin-update-checker', 'plugin-update-checker.php' ) );
}
$MyUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
// CHANGE THIS FOR YOUR UPDATE URL
'https://update.joeszalai.org/?action=get_metadata&slug=' . PLUGIN_NAME_PLUGIN_NAME, //Metadata URL.
__FILE__, //Full path to the main plugin file.
PLUGIN_NAME_PLUGIN_NAME //Plugin slug. Usually it's the same as the name of the directory.
);
/**
* add plugin upgrade notification
* https://andidittrich.de/2015/05/howto-upgrade-notice-for-wordpress-plugins.html
*/
add_action( 'in_plugin_update_message-' . PLUGIN_NAME_PLUGIN_NAME . '/' . PLUGIN_NAME_PLUGIN_NAME .'.php', 'plugin_name_show_upgrade_notification', 10, 2 );
function plugin_name_show_upgrade_notification( $current_plugin_metadata, $new_plugin_metadata ) {
/**
* Check "upgrade_notice" in readme.txt.
*
* Eg.:
* == Upgrade Notice ==
* = 20180624 = <- new version
* Notice <- message
*
*/
if ( isset( $new_plugin_metadata->upgrade_notice ) && strlen( trim( $new_plugin_metadata->upgrade_notice ) ) > 0 ) {
// Display "upgrade_notice".
echo sprintf( '<span style="background-color:#d54e21;padding:10px;color:#f9f9f9;margin-top:10px;display:block;"><strong>%1$s: </strong>%2$s</span>', esc_attr( 'Important Upgrade Notice', 'exopite-multifilter' ), esc_html( rtrim( $new_plugin_metadata->upgrade_notice ) ) );
}
}
}
// END CUSTOM UPDATER FOR PLUGIN
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name.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.
*
* @since 1.0.0
*/
// function run_plugin_name() {
// $plugin = new Plugin_Name();
// $plugin->run();
// }
// run_plugin_name();
/********************************************
* THIS ALLOW YOU TO ACCESS YOUR PLUGIN CLASS
* eg. in your template/outside of the plugin.
*
* Of course you do not need to use a global,
* you could wrap it in singleton too,
* or you can store it in a static class,
* etc...
*
* @tutorial access_plugin_and_its_methods_later_from_outside_of_plugin.php
*/
global $pbt_prefix_plugin_name;
$pbt_prefix_plugin_name = new Plugin_Name();
$pbt_prefix_plugin_name->run();
// END THIS ALLOW YOU TO ACCESS YOUR PLUGIN CLASS