Created
October 19, 2017 16:35
-
-
Save wpmudev-sls/3851835e50621f2ffa7e06fe9330361b to your computer and use it in GitHub Desktop.
[Incsub Support] - Redirects to custom thank you page after new ticket submit.
This file contains 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 | |
/** | |
* Plugin Name: [Incsub Support] - Custom redirect | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Redirects to custom thank you page after ticket submit. | |
* Author: Panos Lyrakis @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
if ( ! class_exists( 'WPMUDEV_PS_Sites_Options' ) ) { | |
class WPMUDEV_PS_Sites_Options { | |
private static $_instance = null; | |
private static $_thank_you_page = null; | |
public static function get_instance() { | |
if( is_null( self::$_instance ) ){ | |
self::$_instance = new WPMUDEV_PS_Sites_Options(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
self::$_thank_you_page = 2746; | |
add_action( 'support_system_insert_ticket', array( $this, 'custom_redirect' ), 10 ); | |
add_shortcode( 'wpmudev_support_ticket_link', array( $this, 'ticket_link_sh' ) ); | |
add_filter( 'query_vars', array( $this, 'query_vars' ), 10 ); | |
} | |
public function custom_redirect(){ | |
wp_redirect( add_query_arg( 'tid', $ticket_id, get_permalink( self::$_thank_you_page ) ) ); | |
exit; | |
} | |
public function ticket_link_sh( $atts ){ | |
$atts = shortcode_atts( | |
array( | |
'tid' => null | |
), $atts, 'wpmudev_support_ticket_link_sc' ); | |
if( is_null( $tid ) ){ | |
$tid = get_query_var('tid'); | |
} | |
$out = ''; | |
$redirect_to = incsub_support_get_support_page_url(); | |
if ( $redirect_to ) { | |
$out = sprintf( '<a href="%1s">%2s</a>', | |
add_query_arg( 'tid', $tid, $redirect_to ), | |
__( 'View ticket' ) ); | |
} | |
return $out; | |
} | |
public function query_vars( $vars ){ | |
$vars[] = 'tid'; | |
return $vars; | |
} | |
} | |
add_action( 'plugins_loaded', function(){ | |
$GLOBALS['WPMUDEV_PS_Sites_Options'] = WPMUDEV_PS_Sites_Options::get_instance(); | |
}, 10 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment