Last active
September 7, 2018 21:32
-
-
Save iansvo/3b08be9118e7dff9133036f8eabb8047 to your computer and use it in GitHub Desktop.
This WordPress PHP snippet creates a metabox for all pages/posts that contains definitions for user entered shortcodes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Enqueue Thickbox Assets | |
| add_thickbox(); | |
| // Define shortcodes | |
| // Setup array | |
| $shortcodes = array(); | |
| // Add a shortcode to the shortcodes array | |
| $shortcodes[] = array( | |
| 'code' => '[faqs category="all"]', | |
| 'description' => 'Displays FAQs created in the dashboard on the frontend of the site, optionally filtered by category.', | |
| 'params' => array( | |
| 'category' => array( | |
| 'type' => 'string', | |
| 'definition' => '(Optional) The name of the category.', | |
| 'default' => '"all"' | |
| ) | |
| ) | |
| ); | |
| ?> | |
| <div id="shortcode-definitions-metabox" class="shortcode-definitions-metabox" style="display:none;"> | |
| <?php if( $shortcodes ) : ?> | |
| <h1 style="margin-bottom: 2em;">Shortcodes</h1> | |
| <dl class="shortcode-definitions-metabox_list"> | |
| <?php foreach( $shortcodes as $shortcode ) : ?> | |
| <dt> | |
| <code> | |
| <?php echo $shortcode['code']; ?> | |
| </code> | |
| <p> | |
| <?php echo $shortcode['description']; ?> | |
| </p> | |
| </dt> | |
| <dd> | |
| <h3> | |
| Parameters | |
| </h3> | |
| <?php if( $shortcode['params'] ) : ?> | |
| <?php foreach( $shortcode['params'] as $param => $details ) : ?> | |
| <div style="margin-bottom: 1em;"> | |
| <code> | |
| <?php echo $param; ?> | |
| </code> | |
| <div> | |
| (<?php echo $details['type']; ?>) - <?php echo $details['definition']; ?> | |
| </div> | |
| <em> | |
| Default: <?php echo $details['default'] ? $details['default'] : 'None'; ?> | |
| </em> | |
| </div> | |
| <?php endforeach; ?> | |
| <?php else : ?> | |
| None | |
| <?php endif; ?> | |
| </dd> | |
| <?php endforeach; ?> | |
| </dl> | |
| <?php else : ?> | |
| <p>No shortcodes found</p> | |
| <?php endif; ?> | |
| </div> | |
| <a href="#TB_inline?width=600&height=550&inlineId=shortcode-definitions-metabox" class="thickbox">View Shortcodes</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Outputs the metabox in the dashboard | |
| function iansvo_shortcode_metabox() { | |
| add_meta_box( | |
| 'shortcode-definitions', | |
| __( 'Shortcode Definitions', 'fabent-parent' ), | |
| 'iansvo_shortcode_metabox_content', | |
| array('post', 'page'), | |
| 'side', | |
| 'high' | |
| ); | |
| } | |
| add_action( 'add_meta_boxes', 'iansvo_shortcode_metabox' ); | |
| function iansvo_shortcode_metabox_content() { | |
| ob_start(); | |
| include get_template_directory() . '/inc/shortcode-metabox-content.php'; | |
| echo ob_get_clean(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment