PHP code example of storepress / admin-utils

1. Go to this page and download the library: Download storepress/admin-utils library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

storepress / admin-utils example snippets



  /**
  Plugin Name: Plugin Example
  Plugin URI: https://storepress.com/plugins/plugin-example/
  Description: Example Plugin.
  Author: Emran Ahmed
  Version: 1.0.0
  Tested up to: 6.3
  Author URI: https://storepress.com/emran/
  Update URI: https://update.example.com/
  */
  
  defined( 'ABSPATH' ) || die( 'Keep Silent' );
  
  use StorePress\Example\Plugin;
  
  define('EXAMPLE_PLUGIN_FILE', __FILE__);
  
  // Include the main class.
  if ( ! class_exists( Plugin::class, false ) ) {
    


	namespace StorePress\Example;
	
	use StorePress\Example\Containers\Container;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	function get_container(): Container {
		return Container::instance();
	}
	
	function get_plugin_file(): string {
		return constant( 'EXAMPLE_PLUGIN_FILE' );
	}
	
	function get_pro_plugin_file(): string {
		
		if( defined( 'EXAMPLE_PLUGIN_PRO_FILE' ) ) {
			return constant( 'EXAMPLE_PLUGIN_PRO_FILE' );
		}
		
		return 'example-plugin-pro/example-plugin-pro.php';
	}




	/**
	 * Plugin Initialization Class File.
	 *
	 * Handles plugin bootstrap, dependency loading, and service provider initialization.
	 *
	 * @package    StorePress/Example
	 * @since      1.0.0
	 * @version    1.0.0
	 */

	declare( strict_types=1 );

	namespace StorePress\Example;

	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\Example\ServiceProviders\ProCompatibilityServiceProvider;
	use StorePress\Example\ServiceProviders\ServiceProviders;
	use StorePress\Example\ServiceProviders\SettingsServiceProvider;
	use StorePress\Example\ServiceProviders\DeactivationServiceProvider;
	use StorePress\Example\ServiceProviders\UpdaterServiceProvider;
	
	/**
	 * Plugin Initialization Class.
	 *
	 * Bootstraps the plugin by loading vendor autoloaders, registering the service provider,
	 * and initializing hooks. Uses the singleton pattern to ensure only one instance exists.
	 *
	 * @name Plugin
	 */
	class Plugin {

		// =====================================================================
		// Properties
		// =====================================================================

		/**
		 * Plugin file path.
		 *
		 * Stores the absolute path to the main plugin file.
		 *
		 * @var string
		 */
		protected string $plugin_file;

		// =====================================================================
		// Singleton Instance
		// =====================================================================

		/**
		 * Return singleton instance of the Init class.
		 *
		 * The instance will be created if it does not exist yet.
		 *
		 * @param string $plugin_file The absolute path to the main plugin file.
		 *
		 * @return self The singleton instance.
		 *
		 * @since 1.0.0
		 *
		 * @example
		 * // Get or create the singleton instance.
		 * $init = Init::instance( __FILE__ );
		 *
		 * @example
		 * // Access from global function.
		 * function plugin_b(): Init {
		 *     return Init::instance( __FILE__ );
		 * }
		 */
		public static function instance(): self {
			static $instance = null;
			return $instance ??= new self();
		}

		// =====================================================================
		// Constructor
		// =====================================================================

		/**
		 * Initialize the plugin.
		 *
		 * Loads vendor autoloaders and functions, registers the service provider,
		 * boots the service provider, and runs initialization hooks.
		 *
		 */
		public function __construct() {

			$this->includes();

			$this->hooks();
			
			$this->init();
		}

		// =====================================================================
		// File Loading Methods
		// =====================================================================

		/**
		 * Load n array(
				UpdaterServiceProvider::class=>UpdaterServiceProvider::class,
				DeactivationServiceProvider::class=>DeactivationServiceProvider::class,
				SettingsServiceProvider::class=>SettingsServiceProvider::class,
				ProCompatibilityServiceProvider::class=>ProCompatibilityServiceProvider::class
			);
		}

		public function service_providers(): ServiceProviders {
			return ServiceProviders::instance( $this->get_service_providers() );
		}
	}


	
	declare( strict_types=1 );
	
	namespace StorePress\Example\Integrations;
	
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use StorePress\AdminUtils\ServiceProviders\ServiceProviderLoader;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	class ServiceProviders extends ServiceProviderLoader {
		
		use SingletonTrait;
	}


	
	namespace StorePress\Example\Integrations;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\AdminUtils\Abstracts\AbstractSettings;
	
	class AdminPage extends AbstractSettings {
		
		public function settings_id(): string {
			return 'example-plugin-settings';
		}
		
		public function get_default_sidebar(): void {
			echo 'Hello from default sidebar';
			
			// ge_text'     => 'Settings not saved',
				'settings_updated_message_text'   => 'Settings Saved',
				'settings_deleted_message_text'   => 'Settings Reset',
				'settings_tab_not_available_text' => 'Settings Tab is not available.',
				'method_called_before_init'       => 'This method should not be called before init.',
			);
		}
		

		// Adding custom scripts.
    public function enqueue_scripts(): void {
        parent::enqueue_scripts();
        if ( $this->has_field_type( 'wc-enhanced-select' ) ) {
            wp_enqueue_style( 'woocommerce_admin_styles' );
            wp_enqueue_script( 'wc-enhanced-select' );
        }
    }
    
    // Adding Custom TASK: 
    public function get_custom_action_uri(): string {
       return wp_nonce_url( $this->get_settings_uri( array( 'action' => 'custom-action' ) ), $this->get_nonce_action() );
    }
    
    // Task: 02
    public function process_actions($current_action): void{
    
        parent::process_actions($current_action);
      
        if ( 'custom-action' === $current_action ) {
          $this->process_action_custom();
        }
    }
    
    // Task: 03
    public function process_action_custom(): void{
        check_admin_referer( $this->get_nonce_action() );
        
        
        
        // Process your task.
        
        
        
        wp_safe_redirect( $this->get_action_uri( array( 'message' => 'custom-action-done' ) ) ); 
        exit;
    }
    
    // Task: 04
    public function settings_messages(): void{
      
      parent::settings_messages();
      
      $message = $this->get_message_query_arg_value();
      
      if ( 'custom-action-done' === $message ) {
          $this->add_settings_message( 'Custom action done successfully.' );
      }
      
      if ( 'custom-action-fail' === $message ) {
          $this->add_settings_message( 'Custom action failed.', 'error' );
      }
    }
	}


	
	namespace StorePress\Example\Services;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use StorePress\Example\Integrations\AdminPage;
	
	/**
	 * Admin Menu Class.
	 *
	 * @name Settings
	 */
	
	class Settings extends AdminPage {
		
		use SingletonTrait;
		
		public function add_settings(): array {
			return array(
				'general' => 'General',
				
				//'pure' => 'Pure',
				'basic'   => array(
					'name'     => 'Basic',
					'sidebar'  => 25,
				),
				
				'advance' => array(
					'name'     => 'Advanced',
					'icon'     => 'dashicons dashicons-analytics',
					'sidebar'  => false,
					'hidden'   => false,
					'external' => false,
				),
				'rest' => 'Rest',
			);
		}
		
		// Naming Convention: add_<TAB ID>_settings_page()
    public function add_basic_settings_page() {
        echo 'custom page ui';
    }
		
		public function add_general_settings_fields() {
			return array(
				array(
					'type'        => 'section',
					'title'       => 'Section title',
					'description' => 'Section description',
				),
				
				array(
					'id'          => 'field-text-mn',
					'type'        => 'text',
					'title'       => 'Input Type text',
					'description' => 'Input Description',
					'placeholder' => 'Placeholder',
					'default'     => 'text field default',
					'suffix'      => 'px',
					'		
						array(
							'id'          => 'field-color',
							'type'        => 'color',
							'title'       => 'Input Type Color',
							'description' => 'Input Type Color',
							'placeholder' => 'Placeholder',
							'default'     => '#ffccff',
							'html_datalist'=>array('#dddddd','#eeeeee'),
							'tooltip'      => 'Textarea Help tooltip',
							'type'            => 'textarea',
							'title'           => 'Width',
							'description'     => 'Input desc of 01',
							'placeholder'     => 'Abcd',
							'default'         => '100',
							'suffix'          => 'x',
							'html_attributes' => array( 'min' => 10 ),
							'tooltip'      => 'Textarea Help tooltip',
							'		//'suffix'       => 'px',
					'tle'       => 'Input Type Radio',
					'description' => 'Input Type Radio',
					'placeholder' => 'Placeholder',
					'default'     => 'y',
					'options'     => array(
						'x' => 'Home X',
						'y' => 'Home Y',
						'z' => 'Home Z',
					)
					// '    => array(
						'home1' => 'Home One',
						'home3' => 'Home 3',
						'home2' => 'Home 2',
					)
				),
				
				array(
					'id'              => 'inputse',
					'type'            => 'wc-enhanced-select',
					'title'           => '2 Input text 01 general single selectbox',
					'description'     => 'Input desc of 01<code>xxx</code>',
					// 'default'     => array( 'home3', 'home1' ),
					// 'multiple'    => true,
					'default'         => 'home3',
					'class'=>array('x', 'y'),
					'html_attributes' => array( 'data-demo' => true ),
					'options'         => array(
						'home1' => 'Home One',
						'home3' => 'Home 3',
						'home2' => 'Home 2',
					)
				),
				
				array(
					'id'              => 'inputse2xx',
					'type'            => 'wc-enhanced-select',
					'title'           => 'Int value',
					'description'     => 'Input desc of 01<code>rxxx</code>',
					// 'default'     => array( 'home3', 'home1' ),
					// 'multiple'    => true,
					'default'         => '2',
					'class'=>array('x', 'y'),
					'html_attributes' => array( 'data-demo' => true ),
					'options'         => array(
						'1' => 'Home One',
						'2' => 'Home Two',
						'3' => 'Home three',
					)
				),
				
				array(
					'id'          => 'input2',
					'type'        => 'text',
					'title'       => 'Input text 02',
					'description' => 'Input desc of 02',
					'default'     => '',
					'placeholder' => 'Abcd 02'
				),
				
				array(
					'id'          => 'inputunit',
					'type'        => 'unit',
					'title'       => 'Input text unit',
					'description' => 'Input desc of unit',
					'default'     => '10px',
					'html_attributes' => array( 'min' => 0, 'max'=>100, 'step'=>5 ),
					'units'=>array('px', '%', 'em', 'rem'),
					'condition'=>array('selector'=>$this->get_field_selector('input2')),
				),
				
				array(
					'type'        => 'section',
					'title'       => 'Section 02',
					'description' => 'Section of 02',
				),
			);
		}
		
		public function add_rest_settings_fields() {
			return array(
				array(
					'type'        => 'section',
					'title'       => 'Section rest',
					'description' => 'Section description',
				),
				
				array(
					'id'           => 'field-textarea-x',
					'type'         => 'textarea',
					'title'        => 'Input Type text',
					'description'  => 'Input Description',
					'placeholder'  => 'Placeholder',
					'default'      => 'text field default',
					'suffix'       => 'px',
					'


	
	declare( strict_types=1 );

	namespace StorePress\Example\ServiceProviders;

	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\AdminUtils\Abstracts\AbstractServiceProvider;
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use StorePress\Example\Containers\Container;
	use StorePress\Example\Services\Settings;
	
	class SettingsServiceProvider extends AbstractServiceProvider {
		
		use SingletonTrait;
		
		public function get_container(): Container {
			return Container::instance();
		}
		
		public function register(): void {
			
			$this->get_container()->register(
				Settings::class,
				function () {
					return Settings::instance();
				}
			);
		}
		
		public function boot(): void {
			$this->get_container()->get( Settings::class );
		}
	}

public function get_menu_slug(): string {
		return 'edit.php?post_type=wporg_product';
}


array(
    'type'        => 'section',
    'title'       => 'Section Title',
    'description' => 'Section Description',
)


  
  array(
      'id'          => 'input3', // Field ID.
      'type'        => 'text', // text, unit, password, toggle, code, small-text, tiny-text, large-text, textarea, email, url, number, color, select, wc-enhanced-select, radio, checkbox
      'title'       => 'Input Label',
      
      // Optional.
      'full_width' => true, // To make field full width. Just remove this key if do not want to use.
      
      'add_tag' => "PRO", // Add TAG
      'add_tag' => array("PRO", 'BACKGROUND COLOR HEX CODE'), // Add PRO Label
      'add_tag' => array("BETA", 'BACKGROUND COLOR HEX CODE', 'TEXT COLOR HEX CODE'), // Add PRO Label
      
      'description' => 'Input field description',
      
      'default'       => 'Hello World', //  default value can be string or array
      'default'       => array('x','y'), //  default value can be string or array
      
      'placeholder' => '' // Placeholder
      'suffix'      => '' // Field suffix.
      'html_attributes' => array('min' => 10) // Custom html attributes.
      'html_datalist'   => array('value 1', 'value 2') // HTML Datalist for suggestion.
      'ema/
      // Options array for select, radio and checkbox [key=>value]
      // If checkbox have no options or value, default will be yes|no
      'options' => array(
          'x' => 'Home X',
          'y' => 'Home Y',
          'z' => 'Home Z',
          'new'   => array(
              'label' => 'New',
              'description' => 'New Item',
          ),
      )
  ),


	
	namespace StorePress\Example\Integrations;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\AdminUtils\Abstracts\AbstractProPluginInCompatibility;
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use function StorePress\Example\get_pro_plugin_file;
	
	class ProPluginInCompatibility extends AbstractProPluginInCompatibility {
		
		use SingletonTrait;
		
		public function compatible_version(): string {
			return '3.0.0';
		}
		
		public function pro_plugin_file(): string {
			return get_pro_plugin_file(); // OR FILE CONSTANCE OF PRO PLUGIN FILE.
		}
		
		public function localize_notice_format(): string {
			// translators: 1: Extended Plugin Name. 2: Extended Plugin Version. 3: Extended Plugin Compatible Version.
			return 'You are using an incompatible version of <strong>%1$s - (%2$s)</strong>. Please upgrade to version <strong>%3$s</strong> or upper.';
		}
	}


/**
 * Plugin Name: Plugin Example
 * Tested up to: 6.4.1
 * Update URI: https://update.example.com/
*/



	
	namespace StorePress\Example\Integrations;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\AdminUtils\Abstracts\AbstractUpdater;
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use function StorePress\Example\get_container;
	
	
	/**
	 * Updater Class.
	 *
	 * @name Updater
	 */
	
	class Updater extends AbstractUpdater {
		
		use SingletonTrait;
		
		public function license_key(): string {
			// return get_container()->get( Settings::class )->get_option( 'license' );
			return 'hello';
		}
		
		public function product_id(): int {
			return 123450;
		}
		
		public function update_server_path(): string {
			return '/wp-json/plugin-updater/v1/check-update';
		}
		
		public function localize_strings(): array {
			
			$name = $this->get_plugin_name();
			
			return array(
				'license_key_empty_message'     => 'License key is not available.',
				'check_update_link_text'        => sprintf('Check Update %s', $name),
				'rollback_changelog_title'      => 'Changelog',
				'rollback_action_running'       => 'Rolling back',
				'rollback_action_button'        => sprintf('Rollback %s', $name),
				'rollback_cancel_button'        => 'Cancel',
				'rollback_current_version'      => 'Current version',
				'rollback_last_updated'         => 'Last updated %s ago.',
				'rollback_view_changelog'       => sprintf('View Changelog for %s', $name),
				'rollback_page_title'           => sprintf( 'Rollback Plugin %s', $name),
				'rollback_link_text'            => sprintf('Rollback %s', $name),
				'rollback_failed'               => 'Rollback failed.',
				'rollback_success'              => 'Rollback success: %s rolled back to version %s.',
				'rollback_plugin_not_available' => 'Plugin is not available.',
				'rollback_no_access'            => 'Sorry, you are not allowed to rollback plugins for this site.',
				'rollback_not_available'        => 'Rollback is not available for plugin: %s',
				'rollback_no_target_version'    => 'Plugin version not selected.',
			);
		}
		
		// If you need to send additional arguments to update server.
		// Check get_request_args() method.
		public function additional_request_args(): array {
			return array( 'custom_args'=> 'args_value' );
		}
	}


	
	namespace StorePress\Example\Integrations;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\AdminUtils\Abstracts\AbstractDeactivationFeedback;
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use function StorePress\Example\get_container;
	
	/**
	 * Changelog Dialog Class.
	 *
	 * @name DeactivationFeedback
	 */
	
	class DeactivationFeedback extends AbstractDeactivationFeedback {
		
		use SingletonTrait;
		
		/**
		 * Get deactivation title.
		 *
		 * @return string
		 */
		public function title(): string {
			return 'QUICK FEEDBACK';
		}
		
		public function sub_title(): string {
			return 'May we have a little info about why you are deactivating?';
		}
		
		/**
		 * Set API URL to send feedback.
		 *
		 * @return string
		 * @example https://example.com/wp-json/__NAMESPACE__/v1/deactivate
		 */
		public function api_url(): string {
			return 'http://sites.local/storepress-admin-utils/wp-json/feedback/v1/deactivate';
		}
		
		/**
		 * Get saved settings data.
		 *
		 * @return array<string, mixed>
		 */
		public function options(): array {
			// return get_container()->get( Settings::class )->get_options();
			return array();
		}
		
		public function get_buttons(): array {
			
			return array(
				array(
					'type'       => 'button',
					'label'      => __( 'Send feedback & Deactivate' ),
					'attributes' => array(
						'disabled'        => true,
						'type'            => 'submit',
						'data-action'     => 'submit',
						'data-label'      => __( 'Send feedback & Deactivate' ),
						'data-processing' => __( 'Deactivate...' ),
						'class'           => array( 'button', 'button-primary' ),
					),
					'spinner'    => true,
				),
				array(
					'type'       => 'link',
					'label'      => __( 'Skip & Deactivate' ),
					'attributes' => array(
						'href'  => '#',
						'class' => array( 'skip-deactivate' ),
					),
				),
			);
		}
		
		public function get_reasons(): array {
			$current_user = wp_get_current_user();
			$name = $this->get_plugin_name();
			
			return array(
				'temporary_deactivation' => array(
					'title'             => esc_html__( 'It\'s a temporary deactivation.', 'woo-variation-swatches' ),
				),
				
				'dont_know_about' => array(
					'title'             => esc_html__( 'I couldn\'t understand how to make it work.', 'woo-variation-swatches' ),
					'message'             => sprintf( 'Its Plugin %s.', $name),
				),
				
				'no_longer_needed' => array(
					'title'             => esc_html__( 'I no longer need the plugin.', 'woo-variation-swatches' ),
				),
				
				'found_a_better_plugin' => array(
					'title'             => esc_html__( 'I found a better plugin.', 'woo-variation-swatches' ),
					'input' => array(
						'placeholder'=>esc_html__( 'Please let us know which one', 'woo-variation-swatches' ),
					),
				),
				
				'broke_site_layout' => array(
					'title'             => __( 'The plugin <strong>broke my layout</strong> or some functionality.', 'woo-variation-swatches' ),
					'message'           => __( '<a target="_blank" href="https://getwooplugins.com/tickets/">Please open a support ticket</a>, we will fix it immediately.', 'woo-variation-swatches' ),
				),
				
				'plugin_setup_help' => array(
					'title'             => __( 'I need someone to <strong>setup this plugin.</strong>', 'woo-variation-swatches' ),
					'input' => array(
						'placeholder'=>esc_html__( 'Your email address.', 'woo-variation-swatches' ),
						'value'=>sanitize_email( $current_user->user_email )
					),
					'message'             => __( 'Please provide your email address to contact with you <br>and help you to set up and configure this plugin.', 'woo-variation-swatches' ),
				),
				
				'plugin_config_too_complicated' => array(
					'title'             => __( 'The plugin is <strong>too complicated to configure.</strong>', 'woo-variation-swatches' ),
					'message'             => __( '<a target="_blank" href="https://getwooplugins.com/documentation/woocommerce-variation-swatches/">Have you checked our documentation?</a>.', 'woo-variation-swatches' ),
				),
				
				'need_specific_feature' => array(
					'title'             => esc_html__( 'I need specific feature that you don\'t support.', 'woo-variation-swatches' ),
					
					'input' => array(
						'placeholder'=>esc_html__( 'Please share with us.', 'woo-variation-swatches' ),
					),
				),
				
				'other' => array(
					'title'             => esc_html__( 'Other', 'woo-variation-swatches' ),
					'input' => array(
						'placeholder'=>esc_html__( 'Please share the reason', 'woo-variation-swatches' ),
					),
				)
			);
		}
		
		/**
		 * Dialog width.  - Optional.
		 *
		 * @return string
		 */
		/*public function get_dialog_width(): string {
			return ''; // 600px
		}*/
	}



	declare( strict_types=1 );

	namespace StorePress\Example\Containers;

	defined( 'ABSPATH' ) || die( 'Keep Silent' );

	use StorePress\AdminUtils\ServiceContainers\ServiceContainer;
	use StorePress\AdminUtils\Traits\SingletonTrait;

	/**
	 * Dependency Injection Container Class.
	 *
	 *
	 * @name Container
	 */
	class Container extends ServiceContainer {
		use SingletonTrait;
	}


	
	declare( strict_types=1 );
	
	namespace StorePress\Example\Integrations;
	
	use StorePress\AdminUtils\Traits\SingletonTrait;
	use StorePress\AdminUtils\Abstracts\AbstractCache;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	class Cache extends AbstractCache {
		
		use SingletonTrait;
	}

$cache = Cache::instance();

// Store for 1 hour.
$cache->set( 'api_response', $data, HOUR_IN_SECONDS );

// Retrieve.
$data = $cache->get( 'api_response' );



$value = $cache->get( 'api_response' );

if ( $cache->has( $value ) ) {
	// Cache hit — use $value.
} else {
	// Cache miss — regenerate and store.
	$value = my_expensive_lookup();
	$cache->set( 'api_response', $value );
}


$cache->delete( 'api_response' );


// Invalidate all cached data for this plugin.
$cache->clear();

// Same effect; flush_all() also clears the whole object cache when no group flush is supported.
$cache->flush();


$args = array(
  'x'=>1,
  'a'=>2,
);

// Generate cache key by array or object.
$key = $cache->create_key($args);

$cache->add( 'api_response_with_' . $key, $data, HOUR_IN_SECONDS );


add_action( 'my_plugin_data_updated', function () {
  $cache = Cache::instance();
	$cache->flush();
} );


	/*
	Plugin Name: Plugin Example Pro
	Plugin URI: https://storepress.com/plugins/plugin-example-pro/
	Description: This is not a plugin for test admin utilities.
	Author: Emran Ahmed
	Version: 1.0.0
	Tested up to: 6.3
	Author URI: https://storepress.com/emran/
	Update URI: https://update.example.com/
	*/
	
	/**
	 * Bootstrap the plugin.
	 */
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	use StorePress\Example\PluginPro;
	
	define('PLUGIN_EXAMPLE_PRO_FILE', __FILE__);
	
	function plugin_example_pro() {
		
		// Include the main class.
		if ( ! class_exists( PluginPro::class, false ) ) {
			



	declare( strict_types=1 );

	namespace StorePress\Example;
	
	use StorePress\Example\ServiceProviders\DeactivationServiceProviderPro;
	use StorePress\Example\ServiceProviders\SettingsServiceProvider;
	use StorePress\Example\ServiceProviders\SettingsServiceProviderPro;
	
	defined( 'ABSPATH' ) || die( 'Keep Silent' );
	
	class PluginPro extends Plugin {
		
		public static function instance(): self {
			static $instance = null;
			return $instance ??= new self();
		}

		public function includes(): void {
			
			parent::includes();
			
			$vendor_path = untrailingslashit( plugin_dir_path( $this->get_pro_plugin_file() ) ) . '/vendor';

			if ( file_exists( $vendor_path . '/autoload_packages.php' ) ) {
				



// Based on Plugin Header Update URI:  
// https://update.example.com/wp-json/plugin-updater/v1/check-update
add_action( 'rest_api_init', function () {
    register_rest_route( 'plugin-updater/v1', '/check-update', [
        'methods'             => WP_REST_Server::READABLE,
        'callback'            => 'updater_get_plugin',
        'permission_callback' => '__return_true',
    ] );
} );

/**
 * @param WP_REST_Request $request REST request instance.
 *
 * @return WP_REST_Response|WP_Error WP_REST_Response instance if the plugin was found,
 *                                    WP_Error if the plugin isn't found.
 *                                   
 */
function updater_get_plugin( WP_REST_Request $request ) {
    
    $params = $request->get_params();
            
    $source          = $request->get_param( 'source' );                  // upgrade
    $type            = $request->get_param( 'type' );                    // plugins
    $mode            = $request->get_param( 'mode' );                    // dev | prod
    $plugin_name     = $request->get_param( 'name' );                    // plugin-dir/plugin-name.php
    $plugin_slug     = $request->get_param( 'slug' );                    // plugin-dir
    $license_key     = $request->get_param( 'license_key' );             // license key
    $product_id      = $request->get_param( 'product_id' );              // product id
    $domain          = $request->get_param( 'domain' );                  // example.com
    $current_version = $request->get_param( 'current_version' );         // current_version
    $additional_args = (array) $request->get_param( 'additional_args' ); // plugin additional arguments.
    
    
    /**
     * $data [
     *
     *     'description'=>'',
     * 
     *     'active_installs'=>'1000',
     *
     *     'faq'=>'',
     * 
     *     'changelog'=>'',
     *
     *     'new_version'=>'x.x.x', // * REQUIRED
     * 
		 *     'banners'=>['low'=>'https://ps.w.org/woocommerce/assets/banner-772x250.png', 'high'=>'https://ps.w.org/woocommerce/assets/banner-1544x500.png'],
		 *
		 *     'banners_rtl'=>[],
		 *
		 *     Using SVG Icon Recommended.
		 *
		 *     'icons'=>[ 'svg' => 'https://ps.w.org/woocommerce/assets/icon.svg', '2x'  => 'https://ps.w.org/woocommerce/assets/icon-256x256.png', '1x'  => 'https://ps.w.org/woocommerce/assets/icon-128x128.png' ], // icons.
		 *  
		 *     'screenshots'=>[['src'=>'', 'caption'=>'' ], ['src'=>'', 'caption'=>''], ['src'=>'', 'caption'=>'']],
     *
     *     'last_updated'=>'2023-11-11 3:24pm GMT+6',
     *
     *     'upgrade_notice'=>'',
     * 
     *     'upgrade_notice'=>['1.1.0'=>'Notice for this version', '1.2.0'=>'Notice for 1.2.0 version'],
     *
     *     'package'=>'https://plugin-server.com/plugin-2.0.0.zip', // * REQUIRED ABSOLUTE URL
     *
     *     'tested'=>'x.x.x', // WP testes Version
     *
     *     '



// Sample API:  
// https://state.example.com/wp-json/feedback/v1/deactivate
add_action( 'rest_api_init', function () {
    register_rest_route( 'feedback/v1', '/deactivate', [
        'methods'             => WP_REST_Server::CREATABLE,
        'callback'            => 'store_deactivate_data',
        'permission_callback' => '__return_true',
    ] );
} );

/**
 * @param WP_REST_Request $request REST request instance.
 *
 * @return WP_REST_Response|WP_Error WP_REST_Response instance if the plugin was found,
 *                                    WP_Error if the plugin isn't found.
 *                                   
 */
 
function store_deactivate_data( WP_REST_Request $request ) {
    
    $params = $request->get_params();
            
    $feedback  = (array) $request->get_param( 'feedback' );
    $wordpress = (array) $request->get_param( 'wordpress' );
    $theme     = (array) $request->get_param( 'theme' );
    $plugins   = (array) $request->get_param( 'plugins' );
    $server    = (array) $request->get_param( 'server' );
    
    // Save data
    
    return rest_ensure_response( true );
}