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 Block: Add fallback code blocks for different contexts. #17161

Closed
kwight opened this issue Sep 14, 2020 · 1 comment · Fixed by #17256
Closed

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

kwight opened this issue Sep 14, 2020 · 1 comment · Fixed by #17256
Assignees
Labels
[Block] Pay With Paypal aka Simple Payments [Feature] Pay with PayPal aka Simple Payments [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it

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.

Email Reader Notifs
Screen Shot 2020-09-14 at 2 48 22 PM Screen Shot 2020-09-14 at 2 47 45 PM Screen Shot 2020-09-14 at 2 30 43 PM

In email, we could keep the same layout and styling, and have the PayPal button image just link to the post. We can do the same with notifications, but due to their fixed narrow width, also make any product image full-width (as already happens). It feels like the Reader block can stay just the featured image in the list view, but should be fully functional in the single view (which would require a way to enqueue its necessary front-end JS).

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 kwight added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it Pay with Paypal labels Sep 14, 2020
@mmtr
Copy link
Member

mmtr commented Sep 16, 2020

As I noted in paYKcK-FI-p2#comment-813 the Pay with PayPal block is a special case since the block saves a shortcode into the post content, so neither the render_callback function nor the render_block filter are fired (shortcodes bypass the whole block rendering flow).

The alternative for this block would be to implement the fallback as part of the shortcode output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Pay With Paypal aka Simple Payments [Feature] Pay with PayPal aka Simple Payments [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants