post_type ) { return; } if ( ! current_user_can( 'edit_posts' ) ) { return; } // Free sites get the upsell (→ pricing); licensed sites get a "your Pro // blocks" showcase instead (→ the dashboard's blocks page), since the // pricing route doesn't exist for them. $is_pro = alertboxblock_is_premium(); if ( ! apply_filters( 'alertboxblock_show_pro_promo', true, $is_pro ) ) { return; } $asset = $this->asset( 'admin-promo' ); wp_enqueue_script( 'abb-admin-promo', ABB_DIR_URL . 'build/admin-promo.js', $asset['dependencies'], $asset['version'], true ); wp_enqueue_style( 'abb-admin-promo', ABB_DIR_URL . 'build/admin-promo.css', [], $asset['version'] ); wp_set_script_translations( 'abb-admin-promo', 'alert-box-block', ABB_DIR_PATH . 'languages' ); wp_add_inline_script( 'abb-admin-promo', 'window.abbPromo = ' . wp_json_encode( [ 'isPro' => (bool) $is_pro, // The showcase / upsell is for people who can buy + install plugins; // the Pro "Alert Block" picker is for anyone editing the shortcode. 'showPromo' => current_user_can( 'activate_plugins' ), 'pricing' => esc_url_raw( alertboxblock_dashboard_url( 'pricing' ) ), 'blocks' => esc_url_raw( alertboxblock_dashboard_url( 'blocks' ) ), ] ) . ';', 'before' ); } public function enqueue( $hook ) { global $typenow; if ( ABB_PostType::POST_TYPE !== $typenow ) { return; } $asset = $this->asset( 'admin-post' ); wp_enqueue_script( 'abb-admin-post', ABB_DIR_URL . 'build/admin-post.js', $asset['dependencies'], $asset['version'], true ); wp_enqueue_style( 'abb-admin-post', ABB_DIR_URL . 'build/admin-post.css', [], $asset['version'] ); wp_set_script_translations( 'abb-admin-post', 'alert-box-block', ABB_DIR_PATH . 'languages' ); } /** * Read a webpack-generated *.asset.php so script dependencies and the * content-hash version stay in sync with the actual bundle. */ private function asset( $name ) { $file = ABB_DIR_PATH . 'build/' . $name . '.asset.php'; return file_exists( $file ) ? require $file : [ 'dependencies' => [], 'version' => ABB_VERSION ]; } } }