Skip to content

Commit

Permalink
Merge pull request #2 from pressbooks/feat/support-new-shortcodes
Browse files Browse the repository at this point in the history
feat: Support new shortcodes
  • Loading branch information
SteelWagstaff authored Oct 5, 2023
2 parents 9fee621 + 4dafc0f commit 900a8e9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "steelwagstaff/pressbooks-shortcode-handler",
"name": "pressbooks/pressbooks-shortcode-handler",
"description": "A plugin for Pressbooks which handles additional shortcodes used by Lumen Learning",
"type": "wordpress-plugin",
"minimum-stability": "stable",
Expand Down
79 changes: 67 additions & 12 deletions pressbooks-shortcode-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
Plugin Name: Pressbooks Shortcode Handler
Plugin URI: https://github.com/SteelWagstaff/pressbooks-shortcode-handler
Description: Plugin for Pressbooks to handle additional shortcodes used by Lumen Learning.
Version: 0.1
Version: 1.1.0
Author: Steel Wagstaff
Author URI: https://steelwagstaff.info
License: GPL 3.0
*/

add_shortcode( 'reveal-answer', 'revealAnswerShortCodeHandler' );
add_shortcode( 'hidden-answer', 'hiddenAnswerShortCodeHandler' );
add_shortcode( 'glossary-page', 'glossary_page_shortcode' );
add_shortcode( 'glossary-term', 'glossary_term_shortcode' );
add_shortcode( 'glossary-definition', 'glossary_definition_shortcode' );
add_shortcode( 'glossary-page', 'glossaryPageShortcodeHandler' );
add_shortcode( 'glossary-term', 'glossaryTermShortcodeHandler' );
add_shortcode( 'glossary-definition', 'glossaryDefinitionShortcodeHandler' );
add_shortcode( 'videopicker', 'videopickerShortcodeHandler' );
add_shortcode( 'ohm', 'ohmQuestionShortcodeHandler' );
add_shortcode( 'ohm2_question', 'ohmQuestionShortcodeHandler' );
add_shortcode( 'choosedataset', 'choosedatasetShortcodeHandler' );

/**
* Shortcode handler for [reveal-answer].
Expand All @@ -25,7 +29,7 @@
* @return string
*/
function revealAnswerShortCodeHandler( $atts = [], $content = null ) {
return '<details><summary>' . do_shortcode( $content ) . '</summary>';
return '<details><summary>' . do_shortcode( $content ) . '</summary>';
}

/**
Expand All @@ -38,7 +42,7 @@ function revealAnswerShortCodeHandler( $atts = [], $content = null ) {
*/

function hiddenAnswerShortCodeHandler( $atts = [], $content = null ) {
return do_shortcode( $content ) . '</details>';
return do_shortcode( $content ) . '</details>';
}

/**
Expand All @@ -49,8 +53,8 @@ function hiddenAnswerShortCodeHandler( $atts = [], $content = null ) {
*
* @return string
*/
function glossary_page_shortcode( $atts = [], $content = null ) {
return '<div class="lumen-glossary"><dl>' . do_shortcode( $content ) . '</dl></div>';
function glossaryPageShortcodeHandler( $atts = [], $content = null ) {
return '<div class="lumen-glossary"><dl>' . do_shortcode( $content ) . '</dl></div>';
}

/**
Expand All @@ -61,8 +65,8 @@ function glossary_page_shortcode( $atts = [], $content = null ) {
*
* @return string
*/
function glossary_term_shortcode( $atts = [], $content = null ) {
return '<dt>' . do_shortcode( $content ) . '</dt>';
function glossaryTermShortcodeHandler( $atts = [], $content = null ) {
return '<dt>' . do_shortcode( $content ) . '</dt>';
}

/**
Expand All @@ -72,6 +76,57 @@ function glossary_term_shortcode( $atts = [], $content = null ) {
*
* @return string
*/
function glossary_definition_shortcode( $atts = [], $content = null ) {
return '<dd>' . do_shortcode( $content ) . '</dd>';
function glossaryDefinitionShortcodeHandler( $atts = [], $content = null ) {
return '<dd>' . do_shortcode( $content ) . '</dd>';
}

/**
* Shortcode that displays a fallback message for excluded interactive video picker elements used by Lumen Learning
* @param string $content Shortcode content.
*
* @return string
*/
function videopickerShortcodeHandler( $atts = [], $content = null ) {
return '<div class="textbox interactive-content">
<p><span class="interactive-content__icon"></span>An interactive video picker element has been excluded from the printed version of the text. To see the interactive element that was excluded, please visit the courseware online.</p>
</div>';
}

/**
* Shortcode that displays the title, label, and brief fallback message for excluded interactive dataset picker elements
* @param string $content Shortcode content.
*
* @return string
*/
function choosedatasetShortcodeHandler( $atts = [], $content = null ) {
$header = '';
if ( $atts['title'] ) {
$header .= '<h3>' . $atts['title'] . '</h3>';
}
if ( $atts['label'] ) {
$header .= '<h4>' . $atts['label'] . '</h4>';
}
$options = '';
if ( $atts['default'] ) {
$options .= '<option value="">' . $atts['default'] . '</option>';
}
$id = $atts['divid'] ? $atts['divid'] : 'tnh-choose-dataset';

return '<div id="' . $id . '" class="chooseDataset">
' . $header . '
<div class="textbox interactive-content">
<p><span class="interactive-content__icon"></span>An interactive dataset picker element has been excluded from the printed version of the text. To see the interactive element that was excluded, please visit the courseware online.</p>
</div></div>';
}

/**
* Shortcode that displays a brief fallback message for excluded OHM & OHM 2 questions used by Lumen Learning
* @param string $content Shortcode content.
*
* @return string
*/
function ohmQuestionShortcodeHandler( $atts = [], $content = null ) {
return '<div class="textbox interactive-content">
<p><span class="interactive-content__icon"></span>An interactive online homework element has been excluded from the printed version of the text. To see the interactive element that was excluded, please visit the courseware online.</p>
</div>';
}

0 comments on commit 900a8e9

Please sign in to comment.