gocodebox / gocodebox/lifterlms

New Hide Content Shortcode

Open
#1,261 0 comments 0 reactions 0 assignees View on GitHub
good first issue hacktoberfest help wanted Type: Feature Request
Dominant language
PHP
Stars
212
Forks
140
Avg merge
2d 14h
Merged PRs (30d)
19

Description

**Describe alternatives you've considered**
A shortcode that has an extra indicator to either hide content or show content to members of a certain course/membership:

```get_output()

*

* @since 3.5.1

* @since 3.24.1 Unknown.

*

* @return array

*/

protected function get_default_attributes() {

return array(

'membership' => '', // For backwards compat, use id moving forward/

'message' => '',

'id' => get_the_ID(),

'relation' => 'all',

'reverse' => 'no',

);

}

/**

* Retrieve the actual content of the shortcode

*

* $atts & $content are both filtered before being passed to get_output()

* output is filtered so the return of get_output() doesn't need its own filter

*

* @since 3.5.1

* @since 3.24.1 Unknown.

*

* @return string

*/

protected function get_output() {

// Backwards compatibility, get membership if set and fallback to the id.

$ids = $this->get_attribute( 'membership' ) ? $this->get_attribute( 'membership' ) : $this->get_attribute( 'id' );

// Explode, trim whitespace and remove empty values.

$ids = (array) array_map( 'trim', array_filter( explode( ',', $ids ) ) );

// Assume content is hidden.

if ( 'yes' === $this->get_attribute( 'reverse' )){

$hidden = false;

}

if ( 'no' === $this->get_attribute( 'reverse' )){

$hidden = true;

}

if ( 'any' === $this->get_attribute( 'relation' ) && ! empty( $ids ) ) {

foreach ( $ids as $id ) {

if ( llms_is_user_enrolled( get_current_user_id(), $id ) ) {

if ( 'yes' === $this->get_attribute( 'reverse' )){

$hidden = true;

}

if ( 'no' === $this->get_attribute( 'reverse' )){

$hidden = false;

}

break;

}

}

} elseif ( 'all' === $this->get_attribute( 'relation' ) && ! empty( $ids ) ) {

$inc = 0;

foreach ( $ids as $id ) {

if ( llms_is_user_enrolled( get_current_user_id(), $id ) ) {

$inc++;

}

}

if ( count( $ids ) === $inc ) {

if ( 'yes' === $this->get_attribute( 'reverse' )){

$hidden = true;

}

if ( 'no' === $this->get_attribute( 'reverse' )){

$hidden = false;

}

}

}

return ! $hidden ? do_shortcode( $this->get_content() ) : $this->get_attribute( 'message' );

}

}

return LLMS_Shortcode_Hide_Content::instance();```

Contributor guide

Open the contributing guide

Research direction

Start with the proposed LLMS_Shortcode_Hide_Content class and its lifterlms_hide_content tag. Verify the membership/id, relation, reverse, and message behavior against the supplied examples, including matching enrollment access. No test file or repository path is identified, so locate the existing shortcode tests before implementing and use them to confirm the finished behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
authorization, backend, content
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.