mode ? esc_html__( 'Live Mode', 'surecart' ) : esc_html__( 'Test Mode', 'surecart' ); ?>
•
mode === $mode ? ' ✓' : ''; ?>
getFormPost( get_post() );
if ( empty( $form_post->post_content ) ) {
return;
}
// Get the checkout form block.
$checkout_form_block = wp_get_first_block( parse_blocks( $form_post->post_content ), 'surecart/form' );
if ( empty( $checkout_form_block ) ) {
return;
}
// get the mode from the block.
$this->mode = $checkout_form_block['attrs']['mode'] ?? 'live';
// build the url to change the mode.
$url = add_query_arg(
[
'sc_checkout_change_mode' => $form_post->ID,
'sc_checkout_post' => get_the_ID(),
'nonce' => wp_create_nonce( 'update_checkout_mode' ),
],
get_home_url( null, 'surecart/change-checkout-mode' )
);
// add the top level menu item.
$wp_admin_bar->add_menu(
[
'id' => 'sc_change_checkout_mode',
'title' => $this->getMenuTitle(),
]
);
// add the live mode menu item.
$wp_admin_bar->add_menu(
[
'parent' => 'sc_change_checkout_mode',
'id' => 'sc_live_mode',
'title' => $this->getMenuItem( 'live' ),
'href' => 'live' === $this->mode ? '#' : $url,
]
);
// add the test mode menu item.
$wp_admin_bar->add_menu(
[
'parent' => 'sc_change_checkout_mode',
'id' => 'sc_test_mode',
'title' => $this->getMenuItem( 'test' ),
'href' => 'test' === $this->mode ? '#' : $url,
],
);
// Mark as rendered.
$this->rendered = true;
}
/**
* Confirm script.
*
* @return void
*/
public function confirmScript() {
if ( ! $this->rendered ) {
return;
}
$mode = 'test' === $this->mode ? esc_html__( 'live mode', 'surecart' ) : esc_html__( 'test mode', 'surecart' );
// translators: %s: live mode or test mode.
$message = sprintf( esc_html__( "Are you sure you want to change this form to %1\$s? \n\nThis will change the form to %2\$s for EVERYONE, and %3\$s cart contents will be used - your cart contents may not transfer.", 'surecart' ), $mode, $mode, $mode );
?>
post_content );
if ( ! has_block( 'surecart/checkout-form', $post ) ) {
return null;
}
$checkout_form_block = wp_get_first_block( $blocks, 'surecart/checkout-form' );
// Get the form post id.
$checkout_form_post_id = $checkout_form_block['attrs']['id'] ?? null;
if ( ! $checkout_form_post_id ) {
return null;
}
return get_post( $checkout_form_post_id ) ?? null;
}
/**
* Get block from post.
*
* @param \WP_Post $checkout_form_post The checkout form post.
*
* @return array|null
*/
public function getBlockFromPost( $checkout_form_post ) {
if ( ! $checkout_form_post ) {
return null;
}
$checkout_form_inner_block = parse_blocks( $checkout_form_post->post_content );
// Find the surecart/form block.
return wp_get_first_block( $checkout_form_inner_block, 'surecart/form' );
}
}