<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

/**
 * Fired during plugin activation
 *
 * @link       #
 * @since      1.0.0
 *
 * @package    commenting-feature
 *
 */

/**
 * Fired during plugin activation.
 *
 * This class defines all code necessary to run during the plugin's activation.
 *
 * @since      1.0.0
 * @package    commenting-feature
 *
 * @author     multidots
 */
class Commenting_block_Activator {

    /**
     * Short Description. (use period)
     *
     * Long Description.
     *
     * @since    1.0.0
     */
    public static function activate() {

        // Set default websocket when plugin activates.
        // Get multicollab plan details.

        // Set default permissions (only when the option has never been stored; add_option no-ops if it exists).
        global $wp_roles;
        $default_data     = array();
        $all_roles        = $wp_roles->roles;
        $editable_roles   = apply_filters( 'editable_roles', $all_roles ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core WP filter; hook name cannot be prefixed.
        if ( ( is_array( $editable_roles ) && ! empty( $editable_roles ) ) || ( is_object( $editable_roles ) && ! empty( (array) $editable_roles ) ) ) {
            foreach ( $editable_roles as $key => $role ) {
                if ( isset( $role['capabilities']['edit_posts'] ) || isset( $role['capabilities']['edit_pages'] ) ) {
                    $default_data[ $key ]['add_comment']         = 1;
                    $default_data[ $key ]['resolved_comment']    = 1;
                    $default_data[ $key ]['resolved_suggestion'] = 1;
                }
            }
        }
        add_option( 'multicollab_permissions', $default_data, '', 'no' );
    }
}
