Skip to content

Commit

Permalink
- added uninstall hook
Browse files Browse the repository at this point in the history
- moved function from deactivator to uninstaller.php
- deactivator.php only unsets user field instead of deleting all options.
  • Loading branch information
Levdbas committed Sep 27, 2017
1 parent 9d9405b commit 2bba3e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
25 changes: 12 additions & 13 deletions admin/partials/support-hours-functions.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php
function hoursToMinutes($hours)
{


function hoursToMinutes($hours){
$minutes = 0;
if (strpos($hours, ':') !== false)
{
list($hours, $minutes) = explode(':', $hours);
}
return $hours * 60 + $minutes;
}
function minuszeros($hours2)
{


function minuszeros($hours2) {
$minutes = 0;
if (preg_match("/0+([1-9]:)/", $hours2) == true) {
$hours2 = ltrim($hours2, '0');
Expand All @@ -21,6 +23,8 @@ function minuszeros($hours2)
}
return $hours2;
}


/*
Checks the workfields for the time fields. Adds all timefields and returns them.
If no workfields and therefore no time fields are filled, returns 00:00
Expand Down Expand Up @@ -51,19 +55,14 @@ function AddTime($workFields) {
$workFields = $options['workFields'];

$used_hours_calc = hoursToMinutes(AddTime($workFields));
$used_hours = new DateTime(AddTime($workFields));
$used_hours = $used_hours->format('H:i');
$used_hours = AddTime($workFields);
$used_hours= minuszeros($used_hours);

$bought_hours_calc = hoursToMinutes($options['bought_hours']);

// TODO: hier een nieuwe functie voor vinden die ook meer uren dan 24 toelaat. @3:59 pakt het systeem wel. 24 uur, pakt ie wel maar geen error. Vanaf boven de 24 uur een error.

$bought_hours = new DateTime($options['bought_hours']);
$bought_hours = $bought_hours->format('H:i');
$bought_hours = $options['bought_hours'];
$bought_hours = minuszeros($bought_hours);

$current_color = get_user_option( 'admin_color' );


if (strpos($used_hours, ':') !== false){
$size = 'small';
} else{
Expand Down
9 changes: 6 additions & 3 deletions includes/class-support-hours-deactivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ class Support_Hours_Deactivator {
* @since 1.0.0
*/
public static function deactivate() {
//delete_option('support-hours');
// TODO: checken of deze functie goed werkt met het verwijderen van de user accounts.
delete_option('support-hours','support-hours["users"]');
//Get entire array
$SupportHourOptions = get_option('support-hours');
//Alter the options array appropriately
$SupportHourOptions['users'] = '';
//Update entire array
update_option('support-hours', $SupportHourOptions);
}

}
6 changes: 3 additions & 3 deletions includes/class-support-hours-uninstaller.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Fired during plugin deactivation
* Fired during plugin uninstall
*
* @link http://basedonline.nl
* @since 1.0.0
Expand All @@ -11,9 +11,9 @@
*/

/**
* Fired during plugin deactivation.
* Fired during plugin uninstall.
*
* This class defines all code necessary to run during the plugin's deactivation.
* This class defines all code necessary to run during the plugin's uninstall.
*
* @since 1.0.0
* @package Support_Hours
Expand Down
2 changes: 1 addition & 1 deletion support-hours.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function uninstall_support_hours() {

register_activation_hook( __FILE__, 'activate_support_hours' );
register_deactivation_hook( __FILE__, 'deactivate_support_hours' );
//register_uninstall_hook(__FILE__, 'uninstall_support_hours');
register_uninstall_hook(__FILE__, 'uninstall_support_hours');


function supportHours_plugin_notice() {
Expand Down

0 comments on commit 2bba3e2

Please # to comment.