Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/regeneratorRuntime-undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
donnapep authored Apr 22, 2024
2 parents e7cedbc + e337f4c commit fccf710
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 300 deletions.
90 changes: 0 additions & 90 deletions assets/admin/emails/email-preview-button/email-preview-button.js

This file was deleted.

This file was deleted.

118 changes: 0 additions & 118 deletions assets/admin/emails/email-preview-button/email-preview-button.test.js

This file was deleted.

13 changes: 0 additions & 13 deletions assets/admin/emails/email-preview-button/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions changelog/fix-email-preview-link
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix preview email button and links
45 changes: 21 additions & 24 deletions includes/internal/emails/class-email-preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function __construct( Email_Sender $email_sender, Sensei_Assets $assets )
*/
public function init(): void {
add_action( 'template_redirect', [ $this, 'render_preview' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'register_admin_scripts' ] );
add_filter( 'preview_post_link', [ $this, 'filter_preview_link' ], 10, 2 );
add_filter( 'post_type_link', [ $this, 'filter_preview_link' ], 10, 2 );
}

/**
Expand All @@ -83,29 +84,6 @@ public function render_preview(): void {
}
}

/**
* Register and enqueue scripts and styles that are needed in the backend.
*
* @internal
*/
public function register_admin_scripts(): void {
$screen = get_current_screen();
if ( ! $screen || Email_Post_Type::POST_TYPE !== $screen->id ) {
return;
}

$this->assets->enqueue( 'sensei-email-preview-button', 'admin/emails/email-preview-button/index.js', [], true );
$this->assets->enqueue( 'sensei-email-preview-button', 'admin/emails/email-preview-button/email-preview-button.css' );

wp_localize_script(
'sensei-email-preview-button',
'sensei_email_preview',
[
'link' => self::get_preview_link( get_the_ID() ),
]
);
}

/**
* Get the preview link.
*
Expand Down Expand Up @@ -217,10 +195,29 @@ private function validate_request(): void {
wp_die( esc_html__( 'Invalid request', 'sensei-lms' ) );
}

// phpcs:ignore WordPress.WP.Capabilities.Unknown
if ( ! current_user_can( 'manage_sensei' ) ) {
wp_die( esc_html__( 'Insufficient permissions', 'sensei-lms' ) );
}

check_admin_referer( 'preview-email-post_' . $post->ID );
}

/**
* Filter the preview link.
*
* @internal
*
* @param string $link The preview link.
* @param WP_Post $post The post object.
*
* @return string
*/
public function filter_preview_link( $link, $post ): string {
if ( Email_Post_Type::POST_TYPE !== $post->post_type ) {
return $link;
}

return str_replace( '&', '&', $this->get_preview_link( $post->ID ) );
}
}
Loading

0 comments on commit fccf710

Please sign in to comment.