<?php
/*
Plugin Name: Generator Razer Gold Pin Store
Description: Generator Razer Gold Pin Store
Version: 1.0.0
Author: Saul Morales Pacheco
Author URI: https://saulmoralespa.com
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Text Domain: generator-razer-gold-pin-store
Domain Path: /languages/
*/

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if(!defined('RAZER_GOLD_PIN_STORE_GENERATE_RGPS_VERSION')){
    define('RAZER_GOLD_PIN_STORE_GENERATE_RGPS_VERSION', '1.0.0');
}

add_action( 'plugins_loaded', 'razer_gold_pin_store_generate_rgps_init');


function razer_gold_pin_store_generate_rgps_init(){
    if (!razer_gold_pin_store_generate_rgps_requirements()) return;

    razer_gold_pin_store_generate_rgps()->run_razer();
}

function razer_gold_pin_store_generate_rgps_notices($notice){
    ?>
    <div class="error notice is-dismissible">
        <p><?php echo esc_html($notice); ?></p>
    </div>
    <?php
}

function razer_gold_pin_store_generate_rgps_requirements(){

    if ( ! extension_loaded( 'xml' ) ){
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            add_action(
                'admin_notices',
                function() {
                    razer_gold_pin_store_generate_rgps_notices( 'Razer Gold Pin Store Generate: Requiere la extensión xml se encuentre instalada' );
                }
            );
        }
        return false;
    }

    if ( ! extension_loaded( 'simplexml' ) ){
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            add_action(
                'admin_notices',
                function() {
                    razer_gold_pin_store_generate_rgps_notices( 'Razer Gold Pin Store Generate: Requiere la extensión simplexml se encuentre instalada' );
                }
            );
        }
        return false;
    }

    return true;
}

function razer_gold_pin_store_generate_rgps(){
    static $plugin;
    if(!isset($plugin)){
        require_once("includes/class-razer-gold-pin-store-rgps-plugin.php");
        $plugin = new Razer_Gold_Pin_Store_Plugin_RGPS(__FILE__, RAZER_GOLD_PIN_STORE_GENERATE_RGPS_VERSION);
    }
    return $plugin;
}