Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pay With Paypal: Add fallback code blocks for different contexts. #45654

Closed
kwight opened this issue Sep 14, 2020 · 1 comment
Closed

Pay With Paypal: Add fallback code blocks for different contexts. #45654

kwight opened this issue Sep 14, 2020 · 1 comment

Comments

@kwight
Copy link
Contributor

kwight commented Sep 14, 2020

On WordPress.com, the Reader, Masterbar notifications, and email notifications are all different contexts in which Gutenberg blocks can be viewed, and they've each got their own limitations and issues with what to render (for example, iframes and other elements are impossible in email, while certain interactions like PayPal purchase buttons are inappropriate in notifications). Blocks need to be able to produce fallback markup when displaying in these different contexts.

The render_callback property can be used directly in blocks we control to define these fallbacks. Let's add context identifiers and code blocks for the Pay With PayPal block, which will also stand as an example for how to handle other blocks.

register_block_type( 'namespace/my-block', [
  'render_callback' => 'render_block',
] );
 
function render_block( $attributes, $content ) {
  if ( $is_email_context ) {
    // Return email fallback.
  }
  if ( $is_reader_context ) {
    // Return reader fallback.
  }
  if ( $is_notifications_context ) {
    // Return notifications fallback.
  }
 
  return $content;
}

See: paYKcK-FI-p2
See: 217-gh-dotcom-manage

@kwight
Copy link
Contributor Author

kwight commented Sep 14, 2020

Oops, duplicate of Automattic/jetpack#17161

@kwight kwight closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant