Sindbad~EG File Manager
<?php
namespace TierPricingTable;
use Automattic\WooCommerce\Utilities\FeaturesUtil ;
use TierPricingTable\Addons\Addons ;
use TierPricingTable\Admin\Admin ;
use TierPricingTable\Blocks\GutenbergBlocks ;
use TierPricingTable\Core\AdminNotifier ;
use TierPricingTable\Core\Cache ;
use TierPricingTable\Core\FileManager ;
use TierPricingTable\Core\ServiceContainerTrait ;
use TierPricingTable\Frontend\Frontend ;
use TierPricingTable\Services\API\WooCommerceRESTAPIService ;
use TierPricingTable\Services\CartUpsellsService ;
use TierPricingTable\Services\CatalogPricesService ;
use TierPricingTable\Services\DebugService ;
use TierPricingTable\Services\ImportExport\WoocommerceExportService ;
use TierPricingTable\Services\ImportExport\WoocommerceImportService ;
use TierPricingTable\Services\LegacyHooksService ;
use TierPricingTable\Services\ProductPageService ;
use TierPricingTable\Services\RegularPricingService ;
use TierPricingTable\Services\TieredPricingCartService ;
use TierPricingTable\Services\YouSaveService ;
use TierPricingTable\Settings\Settings ;
use WC_Product ;
use WP_User ;
/**
* Class TierPricingTablePlugin
*
* @package TierPricingTable
*/
class TierPricingTablePlugin
{
use ServiceContainerTrait ;
/**
* License instance
*
* @var Freemius
*/
private $licence ;
const VERSION = '4.1.0' ;
/**
* TierPricingTablePlugin constructor.
*
* @param string $mainFile
*/
public function __construct( string $mainFile )
{
// Core
$this->getContainer()->add( 'fileManager', new FileManager( $mainFile ) );
$this->getContainer()->add( 'adminNotifier', new AdminNotifier() );
$this->getContainer()->add( 'settings', new Settings() );
$this->getContainer()->add( 'cache', new Cache() );
$this->licence = new Freemius( $mainFile );
add_action( 'init', array( $this, 'loadTextDomain' ), -999 );
add_filter(
'plugin_action_links_' . plugin_basename( $this->getContainer()->getFileManager()->getMainFile() ),
array( $this, 'addPluginActions' ),
10,
4
);
add_filter(
'plugin_row_meta',
array( $this, 'addPluginsMeta' ),
10,
2
);
add_action( 'before_woocommerce_init', function () use( $mainFile ) {
if ( class_exists( FeaturesUtil::class ) ) {
FeaturesUtil::declare_compatibility( 'custom_order_tables', $mainFile, true );
FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $mainFile, true );
}
} );
}
public function checkRequirements() : bool
{
if ( !function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
// Check if WooCommerce is active
if ( !(is_plugin_active( 'woocommerce/woocommerce.php' ) || is_plugin_active_for_network( 'woocommerce/woocommerce.php' )) ) {
/* translators: %s: required plugin */
$message = sprintf( __( '<b>Tiered Pricing Table</b> plugin requires %s to be installed and activated.', 'tier-pricing-table' ), '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">WooCommerce</a>' );
$this->getContainer()->getAdminNotifier()->push( $message, AdminNotifier::ERROR, false );
return false;
}
// Check license
if ( !$this->licence->isValid() ) {
return false;
}
return true;
}
/**
* Entry point when every requirement is passed
*/
public function run()
{
new Frontend();
new Admin();
new Addons();
new Integrations\Integrations();
// Init Services
add_action( 'init', function () {
$this->getContainer()->add( LegacyHooksService::class, new LegacyHooksService() );
$this->getContainer()->add( DebugService::class, new DebugService() );
$this->getContainer()->add( RegularPricingService::class, new RegularPricingService() );
$this->getContainer()->add( TieredPricingCartService::class, new TieredPricingCartService() );
$this->getContainer()->add( YouSaveService::class, new YouSaveService() );
$this->getContainer()->add( ProductPageService::class, new ProductPageService() );
$this->getContainer()->add( WooCommerceRESTAPIService::class, new WooCommerceRESTAPIService() );
$this->getContainer()->add( WoocommerceImportService::class, new WoocommerceImportService() );
$this->getContainer()->add( WoocommerceExportService::class, new WoocommerceExportService() );
$this->getContainer()->add( GutenbergBlocks::class, new GutenbergBlocks() );
} );
}
/**
* Add setting to plugin actions at plugins list
*
* @param array $actions
*
* @return array
*/
public function addPluginActions( array $actions ) : array
{
$actions[] = '<a href="' . $this->getContainer()->getSettings()->getLink() . '">' . __( 'Settings', 'tier-pricing-table' ) . '</a>';
if ( !tpt_fs()->is_premium() ) {
$actions[] = '<a href="' . tpt_fs_activation_url() . '"><b style="color: red">' . __( 'Go Premium', 'tier-pricing-table' ) . '</b></a>';
}
return $actions;
}
public function addPluginsMeta( $links, $file )
{
if ( strpos( $file, 'tier-pricing-table' ) === false ) {
return $links;
}
$links['docs'] = '<a target="_blank" href="' . self::getDocumentationURL() . '">' . __( 'Documentation', 'tier-pricing-table' ) . '</a>';
$links['contact-us'] = '<a href="' . self::getContactUsURL() . '"><b style="color: green">' . __( 'Contact Us', 'tier-pricing-table' ) . '</b></a>';
if ( !tpt_fs()->is_anonymous() && tpt_fs()->is_installed_on_site() ) {
$links['account'] = '<a href="' . self::getAccountPageURL() . '"><b>' . __( 'Account', 'tier-pricing-table' ) . '</b></a>';
}
return $links;
}
/**
* Load plugin translations
*/
public function loadTextDomain()
{
$name = $this->getContainer()->getFileManager()->getPluginName();
load_plugin_textdomain( 'tier-pricing-table', false, $name . '/languages/' );
}
/**
* Fired during plugin uninstall
*/
public static function uninstall()
{
Settings::deleteOptions();
}
public static function getSupportedSimpleProductTypes()
{
return apply_filters( 'tiered_pricing_table/supported_simple_product_types', array( 'simple', 'subscription', 'variation' ) );
}
public static function getSupportedVariableProductTypes()
{
return apply_filters( 'tiered_pricing_table/supported_variable_product_types', array( 'variable', 'variable-subscription' ) );
}
public static function getSupportedVariationProductTypes()
{
return apply_filters( 'tiered_pricing_table/supported_variable_product_types', array( 'variation', 'subscription-variation' ) );
}
public static function isSimpleProductSupported( WC_Product $product ) : bool
{
return in_array( $product->get_type(), self::getSupportedSimpleProductTypes() );
}
public static function isVariableProductSupported( WC_Product $product ) : bool
{
return in_array( $product->get_type(), self::getSupportedVariableProductTypes() );
}
public static function isVariationProductSupported( WC_Product $product ) : bool
{
return in_array( $product->get_type(), self::getSupportedVariationProductTypes() );
}
/**
* Plugin activation
*/
public function activate()
{
set_transient( 'tiered_pricing_table_activated', 'yes', 100 );
}
public static function getDocumentationURL() : string
{
return 'https://woocommerce.com/document/tiered-pricing-table/';
}
public static function getContactUsURL() : string
{
return admin_url( 'admin.php?page=tiered-pricing-table-contact-us' );
}
public static function getAccountPageURL() : string
{
return admin_url( 'admin.php?page=tired-pricing-table-account' );
}
/**
* Uses for separate rules during the import
*
* @return string
*/
public static function getRulesSeparator() : string
{
return apply_filters( 'tiered_pricing_table/rules_separator', ',' );
}
/**
* Get current user the prices calculate for. Sometimes current user can be different from the logged-in user.
* For example, when admin creates an order for customer in administration panel
*
* @return WP_User
*/
public static function getCurrentUser() : WP_User
{
if ( !empty($GLOBALS['tpt_current_user_id']) ) {
$user = new WP_User( intval( $GLOBALS['tpt_current_user_id'] ) );
} else {
$user = wp_get_current_user();
}
return apply_filters( 'tiered_pricing_table/current_user', $user );
}
/**
* Get current user roles
*
* @return array
*/
public static function getCurrentUserRoles() : array
{
$user = self::getCurrentUser();
return apply_filters( 'tiered_pricing_table/current_user_roles', $user->roles, get_current_user_id() );
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists