| @@ -46,9 +46,9 @@ | ||
| 46 | 46 | register_deactivation_hook( VISUALIZER_BASEFILE, array( $this, 'deactivate' ) ); |
| 47 | 47 | $this->_addAction( 'visualizer_schedule_refresh_db', 'refreshDbChart' ); |
| 48 | 48 | $this->_addFilter( 'visualizer_schedule_refresh_chart', 'refresh_db_for_chart', 10, 3 ); |
| 49 | 49 | |
| 50 | - $this->_addAction( 'activated_plugin', 'onActivation' ); | |
| 50 | + $this->_addAction( 'admin_init', 'adminInit' ); | |
| 51 | 51 | $this->_addAction( 'init', 'setupCustomPostTypes' ); |
| 52 | 52 | $this->_addAction( 'plugins_loaded', 'loadTextDomain' ); |
| 53 | 53 | $this->_addFilter( 'visualizer_logger_data', 'getLoggerData' ); |
| 54 | 54 | $this->_addFilter( 'visualizer_get_chart_counts', 'getUsage', 10, 2 ); |
| @@ -192,25 +192,26 @@ | ||
| 192 | 192 | */ |
| 193 | 193 | public function activate() { |
| 194 | 194 | wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' ); |
| 195 | 195 | wp_schedule_event( strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 'hourly', 'visualizer_schedule_refresh_db' ); |
| 196 | + add_option( 'visualizer-activated', true ); | |
| 196 | 197 | } |
| 197 | 198 | |
| 198 | 199 | /** |
| 199 | - * On activation of the plugin | |
| 200 | + * Check if plugin has been activated and then redirect to the correct page. | |
| 200 | 201 | */ |
| 201 | - public function onActivation( $plugin ) { | |
| 202 | + public function adminInit() { | |
| 202 | 203 | if ( defined( 'TI_UNIT_TESTING' ) ) { |
| 203 | 204 | return; |
| 204 | 205 | } |
| 205 | 206 | |
| 206 | - if ( $plugin === VISUALIZER_BASENAME ) { | |
| 207 | - if ( Visualizer_Module::numberOfCharts() > 0 ) { | |
| 208 | - wp_redirect( admin_url( 'admin.php?page=' . Visualizer_Plugin::NAME ) ); | |
| 209 | - } else { | |
| 210 | - wp_redirect( admin_url( 'admin.php?page=viz-support' ) ); | |
| 207 | + if ( get_option( 'visualizer-activated' ) ) { | |
| 208 | + delete_option( 'visualizer-activated' ); | |
| 209 | + if ( ! headers_sent() ) { | |
| 210 | + $page_name = Visualizer_Module::numberOfCharts() > 0 ? Visualizer_Plugin::NAME : 'viz-support'; | |
| 211 | + wp_redirect( add_query_arg( 'page', $page_name, admin_url( 'admin.php' ) ) ); | |
| 212 | + exit(); | |
| 211 | 213 | } |
| 212 | - exit(); | |
| 213 | 214 | } |
| 214 | 215 | } |
| 215 | 216 | |
| 216 | 217 | |
| @@ -218,8 +219,9 @@ | ||
| 218 | 219 | * Deactivate the plugin |
| 219 | 220 | */ |
| 220 | 221 | public function deactivate() { |
| 221 | 222 | wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' ); |
| 223 | + delete_option( 'visualizer-activated', true ); | |
| 222 | 224 | } |
| 223 | 225 | |
| 224 | 226 | /** |
| 225 | 227 | * Refresh the specific chart from the db. |