| 1 |
<?php |
| 2 |
/** |
| 3 |
* PayPal Payment Buttons block. |
| 4 |
* |
| 5 |
* @since 14.9 |
| 6 |
* |
| 7 |
* @package automattic/jetpack |
| 8 |
*/ |
| 9 |
|
| 10 |
use Automattic\Jetpack\PaypalPayments\PayPal_Payment_Buttons; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit( 0 ); |
| 14 |
} |
| 15 |
|
| 16 |
// The API-managed buttons ship behind a flag; register it before anything reads it. |
| 17 |
PayPal_Payment_Buttons::register_feature_flags(); |
| 18 |
add_filter( 'jetpack_block_editor_feature_flags', array( PayPal_Payment_Buttons::class, 'add_editor_feature_flags' ) ); |
| 19 |
|
| 20 |
// Register the block. |
| 21 |
add_action( 'init', array( PayPal_Payment_Buttons::class, 'register_block' ), 9 ); |
| 22 |
|
| 23 |
/* |
| 24 |
* Register the PayPal REST routes (wpcom/v2/paypal/*) that the block editor calls |
| 25 |
* to connect an account and manage payment links. Without them the block renders |
| 26 |
* but every request the editor makes -- onboarding, connect, button CRUD -- 404s. |
| 27 |
* |
| 28 |
* Only the routes: init_api() also hooks sharing and the email sender, neither of |
| 29 |
* which is wired up on Jetpack today. Both this and init_admin() no-op while the |
| 30 |
* flag is off. |
| 31 |
*/ |
| 32 |
PayPal_Payment_Buttons::init_rest_api(); |
| 33 |
|
| 34 |
/* |
| 35 |
* Register the Payment Links admin page. The standalone plugin wires this up in |
| 36 |
* its own bootstrap; the Jetpack loader has to do the same or PayPal_Admin_Page |
| 37 |
* never runs and the page does not exist in wp-admin. |
| 38 |
*/ |
| 39 |
if ( is_admin() ) { |
| 40 |
PayPal_Payment_Buttons::init_admin(); |
| 41 |
} |
| 42 |
|
| 43 |
// Load scripts for the editing interface |
| 44 |
add_action( 'enqueue_block_editor_assets', array( PayPal_Payment_Buttons::class, 'load_editor_scripts' ), 9 ); |
| 45 |
|
| 46 |
// Load styles in the editor iframe context |
| 47 |
if ( is_admin() ) { |
| 48 |
add_action( 'enqueue_block_assets', array( PayPal_Payment_Buttons::class, 'load_editor_styles' ), 9 ); |
| 49 |
} |
| 50 |
|