set_basename( false, __FILE__ ); } else { /** * DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE * `function_exists` CALL ABOVE TO PROPERLY WORK. */ define( 'ABB_VERSION', isset( $_SERVER['HTTP_HOST'] ) && 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '2.1.0' ); define( 'ABB_DIR_URL', plugin_dir_url( __FILE__ ) ); define( 'ABB_DIR_PATH', plugin_dir_path( __FILE__ ) ); define( 'ABB_HAS_PRO', file_exists( dirname(__FILE__) . '/vendor/freemius/start.php' ) ); if ( ABB_HAS_PRO ) { require_once ABB_DIR_PATH . 'includes/fs.php'; }else{ require_once ABB_DIR_PATH . 'includes/fs-lite.php'; } function alertboxblock_is_premium(){ return ABB_HAS_PRO ? alertboxblock_fs()->can_use_premium_code() : false; } // Admin URL of the "Help & Demos" dashboard, optionally on a tab (welcome, pricing, ...). function alertboxblock_dashboard_url( $tab = 'welcome' ){ return admin_url( 'edit.php?post_type=alert-box-block&page=alert-box-block-dashboard#/' . $tab ); } // ... Your plugin's main file logic ... if (ABB_HAS_PRO) { require_once ABB_DIR_PATH . 'includes/LicenseActivation.php'; } if( !class_exists( 'ABBAlertBoxPlugin' ) ){ class ABBAlertBoxPlugin{ public function __construct(){ add_action( 'init', [$this, 'onInit'] ); add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); add_action('enqueue_block_editor_assets', [$this, "enqueueBlockEditorAssets"]); add_filter( 'default_title', [$this, 'defaultTitle'], 10, 2 ); add_filter( 'default_content', [$this, 'defaultContent'], 10, 2 ); add_action( 'wp_enqueue_scripts', [ $this, 'pricingUrlForAdmins' ] ); add_filter( 'block_categories_all', [ $this, 'registerBlockCategory' ], 10, 2 ); } /** * Register the "Alert Box Blocks" category so every abb/* block groups * under it in the inserter (block.json `"category": "alert-box-blocks"`). */ function registerBlockCategory( $categories, $context ) { foreach ( $categories as $cat ) { if ( isset( $cat['slug'] ) && 'alert-box-blocks' === $cat['slug'] ) { return $categories; // already registered } } return array_merge( [ [ 'slug' => 'alert-box-blocks', 'title' => __( 'Alert Box Blocks', 'alert-box-block' ), 'icon' => null, ], ], $categories ); } // The front-end "Upgrade Now" overlay links admins to the dashboard // pricing tab; other visitors fall back to the public pricing page. function pricingUrlForAdmins() { if ( current_user_can( 'manage_options' ) ) { wp_add_inline_script( 'abb-alert-box-view-script', 'window.abbPricingUrl = ' . wp_json_encode( alertboxblock_dashboard_url( 'pricing' ) ) . ';', 'before' ); } } function defaultTitle( $title, $post ) { if ( 'page' !== $post->post_type || ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['nonce'] ) ), 'psbCreatePage' ) ) { return $title; } if ( isset( $_GET['title'] ) ) { return sanitize_text_field( wp_unslash( $_GET['title'] ) ); } return $title; } function defaultContent( $content, $post ) { if ( 'page' !== $post->post_type || ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['nonce'] ) ), 'psbCreatePage' ) ) { return $content; } if ( isset( $_GET['content'] ) ) { // Value is block markup whose HTML comment delimiters (e.g. ) // would be destroyed by kses/text sanitizers. The nonce is verified above, this only // pre-fills the editor for a page the current user is creating, and core sanitizes it // again on save for users without the unfiltered_html capability. return wp_unslash( $_GET['content'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- block markup, nonce verified, sanitized by core on save. } return $content; } function enqueueBlockEditorAssets() { wp_add_inline_script( 'abb-alert-box-editor-script', 'const abbpipecheck = ' . wp_json_encode(alertboxblock_is_premium()).'; window.abbPricingUrl = ' . wp_json_encode( alertboxblock_dashboard_url( 'pricing' ) ) . ';', 'before'); } function enqueueBlockAssets(){ global $post; // $post is null in many contexts where this hook fires (archives, search, // 404, REST, the site editor, widget areas), so bail out when unavailable. if ( ! $post instanceof WP_Post ) { return; } $blocks = parse_blocks($post->post_content); foreach ($blocks as $block) { if ($block['blockName'] === 'abb/alert-box') { $icon = isset($block['attrs']['icon']) ? $block['attrs']['icon'] : null; $svg = isset($icon['svg']) ? trim($icon['svg']) : ''; if (empty($svg)) { wp_enqueue_style( 'fontAwesome', ABB_DIR_URL . 'public/css/font-awesome.min.css', [], '6.4.2' ); } } } } function onInit(){ $disabled = class_exists( 'ABB_DisabledBlocks' ) ? ABB_DisabledBlocks::get() : []; // Core block — always available (marked "required" in the dashboard). register_block_type( __DIR__ . '/build' ); // Pro-only blocks: registered (and therefore available in the // inserter and in shortcodes) only for licensed users and only when // not toggled off from the dashboard Blocks page. A new Pro block // also needs its webpack entries and a row in src/admin/utils/data.js. $abb_pro_blocks = [ 'announcement-bar', 'countdown-alert', 'popup-alert', 'toast-notification', 'news-ticker' ]; if ( alertboxblock_is_premium() ) { foreach ( $abb_pro_blocks as $abb_slug ) { if ( ! in_array( 'abb/' . $abb_slug, $disabled, true ) && file_exists( __DIR__ . '/build/blocks/' . $abb_slug . '/block.json' ) ) { register_block_type( __DIR__ . '/build/blocks/' . $abb_slug ); } } } } } new ABBAlertBoxPlugin(); } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), function( $links ) { if ( current_user_can( 'manage_options' ) ) { $links[] = '' . esc_html__( 'Help & Demos', 'alert-box-block' ) . ''; } return $links; } ); // Shortcode generator: a locked single-block CPT that outputs a reusable // [alert_box id=N] shortcode (mirrors the Video Player Block architecture). require_once ABB_DIR_PATH . 'includes/PostType.php'; require_once ABB_DIR_PATH . 'includes/ShortCode.php'; require_once ABB_DIR_PATH . 'includes/CustomColumn.php'; require_once ABB_DIR_PATH . 'includes/Enqueue.php'; require_once ABB_DIR_PATH . 'includes/DisabledBlocks.php'; new ABB_PostType(); new ABB_ShortCode(); new ABB_CustomColumn(); new ABB_Enqueue(); new ABB_DisabledBlocks(); } require_once ABB_DIR_PATH . '/includes/Menu.php'; // Constant old codes