*/ function tk_pricing_page_get_config() { $defaults = array( 'heading' => '', 'subheading' => '', 'bundle' => array( 'product_id' => '', 'plan_id' => '', 'public_key' => '', 'name' => '', ), 'tiers' => array(), ); $config = wp_parse_args( apply_filters( 'tk_pricing_page_config', $defaults ), $defaults ); $config['bundle'] = wp_parse_args( (array) $config['bundle'], $defaults['bundle'] ); $config['tiers'] = array_map( static function ( $tier ) { return wp_parse_args( $tier, array( 'id' => '', 'name' => '', 'sites' => '', 'licenses' => '1', 'price' => '', 'currency' => '$', 'period' => '/year', 'highlight' => false, 'bullets' => array(), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- this submodule ships its own `tk-pricing-page` text domain by design; each host plugin embeds the same Pricing UI so the strings are localized once at the submodule layer rather than per host. 'cta_label' => __( 'Get Started', 'tk-pricing-page' ), ) ); }, (array) $config['tiers'] ); return $config; } } if ( ! function_exists( 'tk_pricing_page_color_menu_link' ) ) { /** * Color the host plugin's "Go Pro!" submenu link orange so it pops in the * admin sidebar. Matches any link whose `href` ends in `_bundle_screen`, * which is the convention every host plugin uses for its Go Pro page slug. */ function tk_pricing_page_color_menu_link() { echo ''; } } add_action( 'admin_print_styles', 'tk_pricing_page_color_menu_link' ); if ( ! function_exists( 'tk_pricing_page_enqueue_assets' ) ) { /** * Enqueue Freemius checkout + pricing-page assets on any admin screen * whose id contains `bundle_screen` (the convention used across host plugins). */ function tk_pricing_page_enqueue_assets() { $screen = get_current_screen(); if ( ! $screen || ! str_contains( $screen->id, 'bundle_screen' ) ) { return; } $base_path = plugin_dir_path( __FILE__ ); $base_url = plugin_dir_url( __FILE__ ); $js_path = $base_path . 'build/js/pricing-page.js'; $css_path = $base_path . 'build/css/pricing-page.css'; wp_enqueue_script( 'freemius-checkout', 'https://checkout.freemius.com/js/v1/', array(), '1', true ); wp_enqueue_script( 'tk-pricing-page', $base_url . 'build/js/pricing-page.js', array( 'freemius-checkout' ), file_exists( $js_path ) ? filemtime( $js_path ) : false, true ); wp_enqueue_style( 'tk-pricing-page', $base_url . 'build/css/pricing-page.css', array(), file_exists( $css_path ) ? filemtime( $css_path ) : false ); wp_localize_script( 'tk-pricing-page', 'tkPricingPageConfig', tk_pricing_page_get_config() ); } } add_action( 'admin_enqueue_scripts', 'tk_pricing_page_enqueue_assets' ); if ( ! function_exists( 'tk_pricing_page_render' ) ) { /** * Render the pricing page. Use as the callback for `add_submenu_page()` in each host plugin. */ function tk_pricing_page_render() { $config = tk_pricing_page_get_config(); if ( empty( $config['tiers'] ) || empty( $config['bundle']['product_id'] ) ) { echo '
'; // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch -- submodule's own `tk-pricing-page` text domain (see top-of-file note). esc_html_e( 'Pricing page is not fully configured. The host plugin must register the `tk_pricing_page_config` filter with `bundle` credentials and at least one `tiers` entry.', 'tk-pricing-page' ); echo '