css
3 months ago
docs
3 months ago
img
3 months ago
js
3 months ago
tabs
3 months ago
api.php
3 months ago
cleanup.php
3 months ago
colors.php
3 months ago
deprecated.php
3 months ago
header.php
3 months ago
helpers.php
3 months ago
index.php
3 months ago
menu.php
3 months ago
plugins-page.php
3 months ago
post-type-help-doc-imports.php
3 months ago
post-type-help-docs.php
3 months ago
shortcodes.php
3 months ago
taxonomy-folders.php
3 months ago
shortcodes.php
88 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Shortcodes |
| 4 | */ |
| 5 | |
| 6 | namespace PluginRx\AdminHelpDocs; |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 9 | |
| 10 | class Shortcodes { |
| 11 | |
| 12 | /** |
| 13 | * The single instance of the class |
| 14 | * |
| 15 | * @var self|null |
| 16 | */ |
| 17 | private static ?Shortcodes $instance = null; |
| 18 | |
| 19 | |
| 20 | /** |
| 21 | * Get the singleton instance |
| 22 | * |
| 23 | * @return self |
| 24 | */ |
| 25 | public static function instance() : self { |
| 26 | return self::$instance ??= new self(); |
| 27 | } // End instance() |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * Constructor |
| 32 | */ |
| 33 | private function __construct() { |
| 34 | |
| 35 | // Display shortcodes without executing them |
| 36 | add_shortcode( 'dont_do_shortcode', [ $this, 'dont_do_shortcode' ] ); |
| 37 | |
| 38 | // Deprecated: Add custom CSS to documents |
| 39 | add_shortcode( 'helpdocs_css', [ $this, 'helpdocs_css' ] ); |
| 40 | |
| 41 | } // End __construct() |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * Display shortcodes without executing them |
| 46 | * USAGE: [dont_do_shortcode click_to_copy="false" code="false"][your_shortcode_here][/dont_do_shortcode] |
| 47 | * |
| 48 | * @param array $atts |
| 49 | * @return string |
| 50 | */ |
| 51 | public function dont_do_shortcode( $atts, $content = null ) : string { |
| 52 | $atts = shortcode_atts( [ |
| 53 | 'content' => '', |
| 54 | 'code' => true, |
| 55 | 'click_to_copy' => true |
| 56 | ], $atts ); |
| 57 | |
| 58 | $wrapper = ( strtolower( sanitize_text_field( $atts[ 'code' ] ) ) == 'false' ) ? 'span' : 'code'; |
| 59 | $click_to_copy = ( strtolower( sanitize_text_field( $atts[ 'click_to_copy' ] ) ) == 'false' ) ? false : true; |
| 60 | |
| 61 | // Support legacy method of passing content as an attribute with curly braces instead of square brackets |
| 62 | if ( empty( $content ) && ! empty( $atts[ 'content' ] ) ) { |
| 63 | $content = $atts[ 'content' ]; |
| 64 | $content = str_replace( '{', '[[', $content ); |
| 65 | $content = str_replace( '}', ']]', $content ); |
| 66 | } |
| 67 | |
| 68 | $click_to_copy_class = $click_to_copy ? ' helpdocs-click-to-copy' : ''; |
| 69 | |
| 70 | return '<' . $wrapper . ' class="helpdocs_dont_do_shortcode' . $click_to_copy_class . '">' . $content . '</' . $wrapper . '>'; |
| 71 | } // End dont_do_shortcode() |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * Add custom CSS (External or Inline) to the document |
| 76 | * |
| 77 | * @deprecated Add CSS to main docs page from the settings page now. |
| 78 | * @return string |
| 79 | */ |
| 80 | public function helpdocs_css() : string { |
| 81 | _deprecated_function( __FUNCTION__, '2.0', 'Add CSS to main docs page from the settings page now.' ); |
| 82 | return ''; |
| 83 | } // End helpdocs_css() |
| 84 | |
| 85 | } |
| 86 | |
| 87 | |
| 88 | Shortcodes::instance(); |