<?php

function endurance_setup() {
    if ( function_exists( 'get_option' ) && function_exists( 'update_option' ) ) {
        #PLUGINS
        #_____________________________________________________________________
        $active_plugins = (array) get_option( 'active_plugins', array() );
        $active_plugins[] = 'jetpack/jetpack.php';
        $active_plugins[] = 'mojo-marketplace-wp-plugin/mojo-marketplace.php';
        update_option( 'active_plugins', array_unique( $active_plugins ) );
        update_option( 'jetpack_activated',   3 );
        update_option( 'jetpack_do_activate', 1 );

        #OPTIMIZATIONS
        #_____________________________________________________________________
        update_option( 'close_comments_for_old_posts', 1 );
        update_option( 'close_comments_days_old', 28 );
        update_option( 'comments_per_page', 20 );
        update_option( 'endurance_cache_level', 2 );

        #UPDATE SETTINGS
        #_____________________________________________________________________
        update_option( 'allow_major_auto_core_updates', 'true' );
        update_option( 'allow_minor_auto_core_updates', 'true' );
        update_option( 'auto_update_plugin', 'true' );
        update_option( 'auto_update_theme', 'true' );
        update_option( 'auto_update_translation', 'true' );

        #SETUP
        #_____________________________________________________________________
        update_option( 'mm_coming_soon', 'true' );
        update_option( 'mm_install_date', date( 'M d, Y' ) );
        $event = array(
            't'        => 'event',
            'ec'    => 'plugin_status',
            'ea'    => 'installed',
            'el'    => 'Install date: ' . date( 'M d, Y' ),
            'keep'    => false,
        );
        $events = get_option( 'mm_cron', array() );
        $events['hourly'][ $event['ea'] ] = $event;
        update_option( 'mm_cron', $events );

        #PARTNER SETTINGS
        #_____________________________________________________________________
        update_option( 'wpforms_constant_contact', 'show' );
        update_option( 'optinmonster_trial_id', '1258907' );
        update_option( 'monsterinsights_shareasale_id', '1258907' );
    }
    # if ( stripos( @exec( 'hostname' ), 'bluehost' ) || true ) {
    #     $source = 'https://raw.githubusercontent.com/bluehost/endurance-php-edge/production/endurance-php-edge.php';
    #     $destination = WP_CONTENT_DIR . '/mu-plugins/endurance-php-edge.php';
    #     $request = wp_remote_get( $source );
    #     if ( ! is_wp_error( $request ) ) {
    #         file_put_contents( $destination, $request['body'] );
    #     }
    # }
    if ( function_exists( 'save_mod_rewrite_rules' ) ) {
        save_mod_rewrite_rules();
    }
    delete_option('rewrite_rules');
    unlink( __FILE__ );
}
add_action( 'shutdown', 'endurance_setup' );
