verygoodplugins

Untitled

Mar 19th, 2021 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2.  
  3. function shortcode_docs_nav() {
  4.  
  5.     ob_start();
  6.  
  7.     global $post;
  8.  
  9.     // Required version
  10.  
  11.     $category      = get_query_var( 'documentation_category' );
  12.     $category_term = get_term_by( 'slug', $category, 'documentation_category' );
  13.  
  14.     if ( ! empty( $category_term ) ) {
  15.  
  16.         if ( 15 == $category_term->parent || 37 == $category_term->term_id ) {
  17.  
  18.             // Show Personal license required for Integrations + Webhooks
  19.  
  20.             echo do_shortcode( '[elementor-template id="37591"]' );
  21.  
  22.         } elseif ( 29 == $category_term->parent ) {
  23.  
  24.             // Show Plus license required for Addons
  25.  
  26.             echo do_shortcode( '[elementor-template id="37599"]' );
  27.  
  28.         }
  29.  
  30.     }
  31.  
  32.     // On this page
  33.  
  34.     $depth = 4;
  35.  
  36.     $pattern  = '/<h[2-' . $depth . ']*[^>]*>.*?<\/h[2-' . $depth . ']>/';
  37.     $whocares = preg_match_all( $pattern, $post->post_content, $winners );
  38.  
  39.     foreach ( $winners[0] as $i => $winner ) {
  40.  
  41.         $winners[0][ $i ] = str_replace( '<h4>', '<h4><a href="#' . sanitize_title( $winner ) . '">', $winners[0][ $i ] );
  42.         $winners[0][ $i ] = str_replace( '</h4>', '</a></h4>', $winners[0][ $i ] );
  43.  
  44.         $winners[0][ $i ] = str_replace( '<h3>', '<h3><a href="#' . sanitize_title( $winner ) . '">', $winners[0][ $i ] );
  45.         $winners[0][ $i ] = str_replace( '</h3>', '</a></h3>', $winners[0][ $i ] );
  46.  
  47.     }
  48.  
  49.     //reformat the results to be more usable
  50.     $heads = implode( "\n", $winners[0] );
  51.     $heads = preg_replace( '/<h([1-' . $depth . '])>/', '<li class="toc$1">', $heads );
  52.     $heads = preg_replace( '/<\/h[1-' . $depth . ']>/', '</li>', $heads );
  53.  
  54.     ?>
  55.  
  56.     <div id="nav-sidebar" class="sidebar line-top">
  57.  
  58.         <hr style="border-bottom: 4px solid #0b328e;" />
  59.  
  60.         <h3>On this page</h3>
  61.  
  62.         <ul><?php echo $heads; ?></ul>
  63.  
  64.     </div>
  65.  
  66.     <?php
  67.  
  68.     return ob_get_clean();
  69. }
  70.  
  71. add_shortcode( 'wpf_docs_nav', 'shortcode_docs_nav' );
Add Comment
Please, Sign In to add comment