<?php

/**
 * Fired during plugin activation
 *
 * @link       https://orphic.ca
 * @since      1.0.0
 *
 * @package    Wb_Onboard
 * @subpackage Wb_Onboard/includes
 */

/**
 * Fired during plugin activation.
 *
 * This class defines all code necessary to run during the plugin's activation.
 *
 * @since      1.0.0
 * @package    Wb_Onboard
 * @subpackage Wb_Onboard/includes
 * @author     Orphic Inc. <contact@orphic.ca>
 */
class Wb_Onboard_Activator
{

  /**
   * Short Description. (use period)
   *
   * Long Description.
   *
   * @since    1.0.0
   */
  public static function activate()
  {
    add_option('wb_onboard_form_data', array());
    add_option('wb_onboard_is_initialized', false);

    // Hack to refresh roles
    // $wp_roles = new WP_Roles();
    // $wp_roles->remove_role("wb_onboarding_user");

    // Add onboarding role
    add_role(
      'wb_onboarding_user',
      'WB Onboarding User',
      array(
        'create_sites' => false,
        'delete_sites' => false,
        'manage_network' => false,
        'manage_sites' => false,
        'manage_network_users' => false,
        'manage_network_plugins' => false,
        'manage_network_themes' => false,
        'manage_network_options' => false,
        'upload_plugins' => false,
        'upload_themes' => false,
        'upgrade_network' => false,
        'setup_network' => false,
        'activate_plugins' => false,
        'create_users' => false,
        'delete_plugins' => false,
        'delete_themes' => false,
        'delete_users' => false,
        'edit_files' => false,
        'edit_plugins' => false,
        'edit_theme_options' => false,
        'edit_themes' => false,
        'edit_users' => false,
        'export' => false,
        'import' => false,
        'install_plugins' => false,
        'install_themes' => false,
        'list_users' => false,
        'manage_options' => true,
        'promote_users' => false,
        'remove_users' => false,
        'switch_themes' => false,
        'update_core' => false,
        'update_plugins' => false,
        'update_themes' => false,
        'edit_dashboard' => false,
        'customize' => false,
        'delete_site' => false,
        'moderate_comments' => false,
        'manage_categories' => false,
        'manage_links' => false,
        'edit_others_posts' => false,
        'edit_pages' => false,
        'edit_others_pages' => false,
        'edit_published_pages' => false,
        'publish_pages' => false,
        'delete_pages' => false,
        'delete_others_pages' => false,
        'delete_published_pages' => false,
        'delete_others_posts' => false,
        'delete_private_posts' => false,
        'edit_private_posts' => false,
        'read_private_posts' => false,
        'delete_private_pages' => false,
        'edit_private_pages' => false,
        'read_private_pages' => false,
        'unfiltered_html' => false,
        'edit_published_posts' => false,
        'upload_files' => false,
        'publish_posts' => false,
        'delete_published_posts' => false,
        'edit_posts' => false,
        'delete_posts' => false,
        'read' => true,
      )
    );

    // Programmer la rotation des clés
    if (!wp_next_scheduled('wb_rotate_init_key_event')) {
      wp_schedule_event(time(), 'weekly', 'wb_rotate_init_key_event');
    }

    // Créer la table de backup si elle n'existe pas
    if (!WB_Backup_Service::table_exists()) {
      WB_Backup_Service::create_table();
    }
  }
}
