Esempio n. 1
0
 /**
  * Uninstall plugin method
  *
  * @param  none
  * @return void
  */
 public static function uninstall()
 {
     global $wpdb;
     // PHPLeague tables
     $tables = array($wpdb->fixture, $wpdb->league, $wpdb->club, $wpdb->country, $wpdb->match, $wpdb->table_cache, $wpdb->team, $wpdb->player, $wpdb->player_team, $wpdb->player_data, $wpdb->table_chart, $wpdb->table_predi);
     // Delete each table one by one
     foreach ($tables as $table) {
         $wpdb->query('DROP TABLE IF EXISTS ' . $table . ';');
     }
     // Delete the versions in the options table
     delete_option('phpleague_version');
     delete_option('phpleague_db_version');
     // Delete the PHPLeague directory and sub-directories
     PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH, 'delete');
     PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH . 'logo_big/', 'delete');
     PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH . 'logo_mini/', 'delete');
     PHPLeague_Tools::manage_directory(WP_PHPLEAGUE_UPLOADS_PATH . 'players/', 'delete');
 }
 /**
  * Manage a directory (Create/Delete).
  *
  * @param   string $path
  * @param   string $action
  * @return  mixed
  */
 public static function manage_directory($path = NULL, $action = '')
 {
     // Create directory
     if ($action === 'create') {
         // Path does not exist
         if (!is_dir($path)) {
             // Create the directory
             mkdir($path, 0755, TRUE);
             // Set permissions (must be manually set to fix umask issues)
             chmod($path, 0755);
         }
     } elseif ($action === 'delete') {
         // Path exists
         if (is_dir($path)) {
             $dir_handle = opendir($path);
             if (!$dir_handle) {
                 return FALSE;
             }
             while ($file = readdir($dir_handle)) {
                 if ($file != '.' && $file != '..') {
                     if (!is_dir($path . '/' . $file)) {
                         unlink($path . '/' . $file);
                     } else {
                         PHPLeague_Tools::manage_directory($path . '/' . $file, 'delete');
                     }
                 }
             }
             closedir($dir_handle);
             rmdir($path);
             return TRUE;
         }
     } else {
         return;
     }
 }