Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $use_prg = new prg_pattern();
- class prg_pattern {
- public function __construct() {
- add_action( 'template_redirect', array( $this, 'prg_get_and_redirect' ) );
- add_shortcode( 'prgpattern', array( $this, 'prg_pattern_form' ) );
- }
- public function prg_pattern_form( $atts ){
- $atts = shortcode_atts(
- array(
- 'slug' => 'noFoo',
- 'title' => 'noBob',
- 'extern' => 'false'
- ), $atts, 'prgpattern' );
- if ( $atts['extern'] == 'true' ) {
- $redirect_slug = esc_url( $atts['slug'] );
- } else {
- $redirect_slug = esc_url( home_url() . '/' . strtolower( $atts['slug'] ) );
- }
- ob_start();
- ?>
- <form method="POST">
- <button class="noLink" type="submit" name="prgpattern" value="<?php echo $redirect_slug; ?>"><?php echo $atts['title']; ?></button>
- </form>
- <?php
- return ob_get_clean();
- }
- public function prg_get_and_redirect(){
- if ( isset( $_POST['prgpattern'] ) ) {
- $slug = esc_url( $_POST['prgpattern'] );
- wp_redirect( $slug );
- exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement