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.0.2' ); 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; } // ... 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 ); } 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()).';', '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(){ register_block_type( __DIR__ . '/build' ); } } new ABBAlertBoxPlugin(); } } require_once ABB_DIR_PATH . '/includes/Menu.php'; // Constant old codes