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 ) ) {
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(
'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' ) ) {