This repository has been archived by the owner on Oct 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
wp-optimize.php
206 lines (161 loc) · 6.98 KB
/
wp-optimize.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
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
<?php
/*
Plugin Name: WP-Optimize
Plugin URI: http://wp-optimize.ruhanirabin.com/
Description: This plugin helps you to keep your database clean by removing post revisions and spam in a blaze. Additionally, it allows you to run the optimize command on your WordPress core tables (please use with caution).
Version: 1.9.1
Author: Ruhani Rabin
Author URI: https://github.com/ruhanirabin/WP-Optimize
Text Domain: wp-optimize
Domain Path: /languages
Git URI: https://github.com/ruhanirabin/wp-optimize
GitHub Plugin URI: https://github.com/ruhanirabin/wp-optimize
GitHub Branch: master
Copyright 2009-2016 Ruhani Rabin (email : plugins@ruhanirabin.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// ----------------------------------------
// Find and replace version info in all files
// ----------------------------------------
// ---------------------------------------
// prevent file from being accessed directly
// ---------------------------------------
if ( ! defined( 'WPINC' ) ) {
die;
}
global $current_user;
//error_reporting( error_reporting() & ~E_NOTICE );
if (! defined('WPO_VERSION'))
define('WPO_VERSION', '1.9.1');
if (! defined('WPO_PLUGIN_MAIN_PATH'))
define('WPO_PLUGIN_MAIN_PATH', plugin_dir_path( __FILE__ ));
if (! defined('WPO_PAYPAL'))
define('WPO_PAYPAL', 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LTCMF6JDX94QS');
if ( file_exists(WPO_PLUGIN_MAIN_PATH . 'wp-optimize-common.php')) {
require_once (WPO_PLUGIN_MAIN_PATH . 'wp-optimize-common.php');
} else {
die ('Functions File is missing!');
}
register_activation_hook(__FILE__,'wpo_admin_actions');
register_deactivation_hook(__FILE__,'wpo_admin_actions_remove');
// init text domain
add_action('init', 'wp_optimize_textdomain');
function wp_optimize_textdomain() {
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain('wp-optimize', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
}
function wp_optimize_menu(){
include_once( 'wp-optimize-admin.php' );
}
function wpo_admin_bar() {
global $wp_admin_bar;
//Add a link called at the top admin bar
$wp_admin_bar->add_node(array(
'id' => 'wp-optimize',
'title' => 'WP-Optimize',
'href' => menu_page_url( 'WP-Optimize', false ),
));
}
// Add settings link on plugin page
function wpo_plugin_settings_link($links) {
//$optimize_link = '<a href="admin.php?page=WP-Optimize">Optimizer</a>';
$settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=WP-Optimize&tab=wp_optimize_settings' ) ) . '">' . __( 'Settings', 'wp-optimize' ) . '</a>';
$optimize_link = '<a href="' . esc_url( admin_url( 'admin.php?page=WP-Optimize' ) ) . '">' . __( 'Optimizer', 'wp-optimize' ) . '</a>';
array_unshift($links, $settings_link);
array_unshift($links, $optimize_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'wpo_plugin_settings_link' );
// plugin activation actions
function wpo_admin_actions()
{
if ( current_user_can('manage_options') ) {
if (function_exists('add_meta_box')) {
add_menu_page("WP-Optimize", "WP-Optimize", "manage_options", "WP-Optimize", "wp_optimize_menu", plugin_dir_url( __FILE__ ).'wpo.png');
} else {
add_submenu_page("index.php", "WP-Optimize", "WP-Optimize", "manage_options", "WP-Optimize", "wp_optimize_menu", plugin_dir_url( __FILE__ ).'wpo.png');
} // end if addmeta box
if (get_option( OPTION_NAME_ENABLE_ADMIN_MENU, 'false' ) == 'true' ){
add_action( 'wp_before_admin_bar_render', 'wpo_admin_bar' );
}
//wpo_detectDBType();
wpo_PluginOptionsSetDefaults();
wpo_cron_activate();
}
}
// TODO: Need to find out why the schedule time is not refreshing
function wpo_cron_activate() {
//wpo_debugLog('running wpo_cron_activate()');
$gmtoffset = (int) (3600 * ((double) get_option('gmt_offset')));
if ( get_option( OPTION_NAME_SCHEDULE ) !== false ) {
if ( get_option(OPTION_NAME_SCHEDULE) == 'true') {
if (!wp_next_scheduled('wpo_cron_event2')) {
$schedule_type = get_option(OPTION_NAME_SCHEDULE_TYPE, 'wpo_weekly');
switch ($schedule_type) {
case "wpo_daily":
//
$this_time = 60*60*24;
break;
case "wpo_weekly":
//
$this_time = 60*60*24*7;
break;
case "wpo_otherweekly":
//
$this_time = 60*60*24*14;
break;
case "wpo_monthly":
//
$this_time = 60*60*24*31;
break;
default:
$this_time = 60*60*24*7;
break;
}
add_action('wpo_cron_event2', 'wpo_cron_action');
wp_schedule_event(current_time( "timestamp", 0 ) + $this_time , $schedule_type, 'wpo_cron_event2');
wpo_debugLog('running wp_schedule_event()');
}
}
} else wpo_PluginOptionsSetDefaults();
}
function wpo_cron_deactivate() {
//wp_clear_scheduled_hook('wpo_cron_event');
wpo_debugLog('running wpo_cron_deactivate()');
wp_clear_scheduled_hook('wpo_cron_event2');
}
add_action('wpo_cron_event2', 'wpo_cron_action');
add_filter('cron_schedules', 'wpo_cron_update_sched');
// scheduler functions to update schedulers
function wpo_cron_update_sched( $schedules ) {
$schedules['wpo_daily'] = array('interval' => 60*60*24, 'display' => 'Once Daily');
$schedules['wpo_weekly'] = array('interval' => 60*60*24*7, 'display' => 'Once Weekly');
$schedules['wpo_otherweekly'] = array('interval' => 60*60*24*14, 'display' => 'Once Every Other Week');
$schedules['wpo_monthly'] = array('interval' => 60*60*24*31, 'display' => 'Once Every Month');
return $schedules;
}
// plugin deactivation actions
function wpo_admin_actions_remove()
{
wpo_cron_deactivate();
wpo_removeOptions();
}
add_action('admin_menu', 'wpo_admin_actions');
function wpo_admin_register_head() {
$style_url = plugins_url( '/css/wpo_admin.css', __FILE__ ) ;
echo "<link rel='stylesheet' type='text/css' href='".$style_url."' />\n";
}
add_action('admin_head', 'wpo_admin_register_head');
?>