licence = new Freemius($mainFile); // Core $this->getContainer()->add( 'fileManager', new FileManager($mainFile, 'tiered-pricing-table') ); $this->getContainer()->add( 'adminNotifier', new AdminNotifier() ); $this->saveActivationTime(); $this->declareCompatibilities(); } public function declareCompatibilities() { add_action( 'before_woocommerce_init', function () { if ( class_exists( FeaturesUtil::class ) ) { $mainFile = $this->getContainer()->getFileManager()->getMainFile(); FeaturesUtil::declare_compatibility( 'custom_order_tables', $mainFile ); FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', $mainFile ); FeaturesUtil::declare_compatibility( 'product_block_editor', $mainFile ); } } ); } public function initializationHooks() { add_action( 'init', array($this, 'loadTextDomain'), -999 ); add_filter( 'plugin_row_meta', array($this, 'addPluginsMeta'), 10, 2 ); add_filter( 'plugin_action_links_' . plugin_basename( $this->getContainer()->getFileManager()->getMainFile() ), array($this, 'addPluginActions'), 10, 4 ); } 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( __( 'Tiered Pricing Table plugin requires %s to be installed and activated.', 'tier-pricing-table' ), 'WooCommerce' ); $this->getContainer()->getAdminNotifier()->push( $message, AdminNotifier::ERROR ); return false; } // Check license if ( !$this->licence->isValid() ) { return false; } return true; } /** * Entry point when every requirement is passed */ public function run() { $this->getContainer()->add( 'settings', new Settings() ); $this->getContainer()->add( 'cache', new Cache() ); $this->initializationHooks(); new Frontend(); new Admin(); new Addons(); new Integrations(); $this->getContainer()->initService( Notifications::class ); // Init Services add_action( 'init', function () { $this->getContainer()->initService( DebugService::class ); $this->getContainer()->initService( SystemStatusReportService::class ); $this->getContainer()->initService( RegularPricingService::class ); $this->getContainer()->initService( TieredPricingCartService::class ); $this->getContainer()->initService( YouSaveService::class ); $this->getContainer()->initService( ProductPageService::class ); $this->getContainer()->initService( WooCommerceRestAPI::class ); $this->getContainer()->initService( WoocommerceImportService::class ); $this->getContainer()->initService( WoocommerceExportService::class ); $this->getContainer()->initService( GutenbergBlocks::class ); } ); } /** * Add setting to plugin actions at plugins list * * @param array $actions * * @return array */ public function addPluginActions( array $actions ) : array { $actions[] = '' . __( 'Settings', 'tier-pricing-table' ) . ''; if ( !tpt_fs()->can_use_premium_code() ) { $actions[] = '' . __( 'Go Premium', 'tier-pricing-table' ) . ''; } return $actions; } public function addPluginsMeta( $links, $file ) { if ( strpos( $file, 'tier-pricing-table' ) === false ) { return $links; } $links['docs'] = '' . __( 'Documentation', 'tier-pricing-table' ) . ''; $links['contact-us'] = '' . __( 'Contact Us', 'tier-pricing-table' ) . ''; if ( !tpt_fs()->is_anonymous() && tpt_fs()->is_installed_on_site() ) { $links['account'] = '' . __( 'Account', 'tier-pricing-table' ) . ''; } return $links; } /** * Load plugin translations */ public function loadTextDomain() { $name = $this->getContainer()->getFileManager()->getPluginName(); load_plugin_textdomain( 'tier-pricing-table', false, $name . '/languages/' ); } /** * Fired after plugin uninstallation. * This function is used to remove the activation timestamp option. */ public static function uninstall() { delete_option( 'tpt_plugin_activation_timestamp' ); } public static function getSupportedSimpleProductTypes() : array { return (array) apply_filters( 'tiered_pricing_table/supported_simple_product_types', array( 'simple', 'variation', 'subscription', 'subscription-variation' ) ); } public static function getSupportedVariableProductTypes() : array { return (array) apply_filters( 'tiered_pricing_table/supported_variable_product_types', array('variable', 'variable-subscription') ); } public static function getSupportedVariationProductTypes() : array { return (array) apply_filters( 'tiered_pricing_table/supported_variation_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() { } public static function getDocumentationURL() : string { return 'https://tiered-pricing.com/documentation/user/'; } 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=tiered-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 ); } public static function getAvailablePricingLayouts() { return apply_filters( 'tiered_pricing_table/pricing_layouts', array( 'table' => __( 'Table', 'tier-pricing-table' ), 'blocks' => __( 'Blocks', 'tier-pricing-table' ), 'options' => __( 'Options', 'tier-pricing-table' ), 'dropdown' => __( 'Dropdown', 'tier-pricing-table' ), 'horizontal-table' => __( 'Horizontal table', 'tier-pricing-table' ), 'plain-text' => __( 'Plain text', 'tier-pricing-table' ), 'tooltip' => __( 'Tooltip', 'tier-pricing-table' ), ) ); } /** * 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() ); } public function saveActivationTime() { if ( !get_option( 'tpt_plugin_activation_timestamp', false ) ) { update_option( 'tpt_plugin_activation_timestamp', time() ); } } public static function getPluginActivationDate() : ?int { return intval( get_option( 'tpt_plugin_activation_timestamp', 0 ) ); } }