From 8394a89599635d1900cc69c74b7b1401789aa0f3 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Tue, 20 Aug 2024 10:28:19 -0400 Subject: [PATCH] Fix lifterlms_membership_link outputting draft or trashed content (#2732) * Check post status before outputting content. --- ...s-membership-link-outputs-draft-or-trashed-content.yml | 6 ++++++ .../shortcodes/class.llms.shortcode.membership.link.php | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changelogs/fix_lifterlms-membership-link-outputs-draft-or-trashed-content.yml diff --git a/.changelogs/fix_lifterlms-membership-link-outputs-draft-or-trashed-content.yml b/.changelogs/fix_lifterlms-membership-link-outputs-draft-or-trashed-content.yml new file mode 100644 index 0000000000..a5765cadfc --- /dev/null +++ b/.changelogs/fix_lifterlms-membership-link-outputs-draft-or-trashed-content.yml @@ -0,0 +1,6 @@ +significance: patch +type: fixed +links: + - "#2724" +entry: Avoid outputting lifterlms_membership_link content if the membership is + not published. diff --git a/includes/shortcodes/class.llms.shortcode.membership.link.php b/includes/shortcodes/class.llms.shortcode.membership.link.php index bfcc8030c5..f5860f095b 100644 --- a/includes/shortcodes/class.llms.shortcode.membership.link.php +++ b/includes/shortcodes/class.llms.shortcode.membership.link.php @@ -40,6 +40,10 @@ class LLMS_Shortcode_Membership_Link extends LLMS_Shortcode { * @version 3.4.3 */ protected function get_output() { + if ( 'publish' !== get_post_status( $this->get_attribute( 'id' ) ) ) { + return ''; + } + return '' . $this->get_content() . ''; } @@ -65,9 +69,9 @@ protected function get_default_attributes() { * @version 3.4.3 */ protected function get_default_content( $atts = array() ) { - return apply_filters( 'lifterlms_membership_link_text', get_the_title( $this->get_attribute( 'id' ) ), $this->get_attribute( 'id' ) ); + $default_content = 'publish' === get_post_status( $this->get_attribute( 'id' ) ) ? get_the_title( $this->get_attribute( 'id' ) ) : ''; + return apply_filters( 'lifterlms_membership_link_text', $default_content, $this->get_attribute( 'id' ) ); } - } return LLMS_Shortcode_Membership_Link::instance();