Advertisement
Guest User

PRG-2

a guest
Nov 25th, 2018
11,495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. $use_prg = new prg_pattern();
  2.  
  3. class prg_pattern {
  4.     public function __construct() {
  5.         add_action( 'template_redirect', array( $this, 'prg_get_and_redirect' ) );
  6.         add_shortcode( 'prgpattern', array( $this, 'prg_pattern_form' ) );
  7.     }
  8.  
  9.  
  10.     public function prg_pattern_form( $atts ){
  11.         $atts = shortcode_atts(
  12.             array(
  13.                 'slug' => 'noFoo',
  14.                 'title' => 'noBob',
  15.                 'extern' => 'false'
  16.             ), $atts, 'prgpattern' );
  17.  
  18.         if ( $atts['extern'] == 'true' ) {
  19.             $redirect_slug = esc_url( $atts['slug'] );
  20.         } else {
  21.             $redirect_slug = esc_url( home_url() . '/' . strtolower( $atts['slug'] ) );
  22.         }
  23.  
  24.         ob_start();
  25.         ?>
  26.             <form method="POST">
  27.                 <button class="noLink" type="submit" name="prgpattern" value="<?php echo $redirect_slug; ?>"><?php echo $atts['title']; ?></button>
  28.             </form>
  29.         <?php
  30.         return ob_get_clean();
  31.     }
  32.  
  33.  
  34.     public function prg_get_and_redirect(){
  35.         if ( isset( $_POST['prgpattern'] ) ) {
  36.             $slug = esc_url( $_POST['prgpattern'] );
  37.             wp_redirect( $slug );
  38.             exit();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement