Last active
March 28, 2021 21:02
-
-
Save sirbrillig/4c45b14ac57dc7d448b47334e5ab966d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Checkout Experiment | |
Description: An experimental WordPress.com checkout inside wp-admin | |
Author: Automattic | |
Version: 1.0 | |
Author URI: http://automattic.com | |
*/ | |
class CheckoutExperiment { | |
public static function init(): void { | |
$checkout = new self(); | |
add_action( 'admin_menu', [ $checkout, 'add_menu' ] ); | |
add_action( 'admin_enqueue_scripts', [ $checkout, 'add_scripts' ] ); | |
} | |
public function add_menu(): void { | |
add_menu_page( 'Checkout Experiment', 'Checkout Experiment', 'manage_options', 'checkout-experiment', [ $this, 'render_checkout' ] ); | |
} | |
public function add_scripts( string $hook_suffix ): void { | |
if ( $hook_suffix !== 'toplevel_page_checkout-experiment' ) { | |
return; | |
} | |
$version = '5'; | |
wp_enqueue_script( 'react' ); | |
wp_enqueue_script( 'react-dom' ); | |
wp_register_script( 'checkout-experiment', plugin_dir_url( __FILE__ ) . 'checkout-experiment-app/dist/bundle.js', [ 'react', 'react-dom' ], $version, true ); | |
wp_localize_script( 'checkout-experiment', 'checkout_data', [ 'blog_id' => get_current_blog_id() ] ); | |
wp_enqueue_script( 'checkout-experiment' ); | |
} | |
public function render_checkout(): void { | |
echo '<div id="checkout-experiment-app">js goes here</div>'; | |
} | |
} | |
add_action( 'init', array( 'CheckoutExperiment', 'init' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment