| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The public-facing template functionality of the plugin. |
| 5 |
* |
| 6 |
* @package Wpfnl |
| 7 |
* @subpackage Wpfnl/public |
| 8 |
*/ |
| 9 |
|
| 10 |
|
| 11 |
/** |
| 12 |
* The public-facing template functionality of the plugin. |
| 13 |
* |
| 14 |
* @link https://rextheme.com |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @package Wpfnl |
| 18 |
* @subpackage Wpfnl/public |
| 19 |
*/ |
| 20 |
|
| 21 |
class Wpfnl_Step_Template |
| 22 |
{ |
| 23 |
public function init() |
| 24 |
{ |
| 25 |
add_filter('template_include', [ $this, 'wpfnl_include_step_template' ]); |
| 26 |
} |
| 27 |
|
| 28 |
public function wpfnl_include_step_template($template) |
| 29 |
{ |
| 30 |
//try and get the query var we registered in our query_vars() function |
| 31 |
$step_page = get_query_var('funnel_step'); |
| 32 |
|
| 33 |
//if the query var has data, we must be on the right page, load our custom template |
| 34 |
if ($step_page) { |
| 35 |
return plugin_dir_path(__FILE__) . 'template/step-view.php'; |
| 36 |
} |
| 37 |
|
| 38 |
return $template; |
| 39 |
} |
| 40 |
|
| 41 |
public function flush_rules() |
| 42 |
{ |
| 43 |
$this->rewrite_rules(); |
| 44 |
|
| 45 |
flush_rewrite_rules(); |
| 46 |
} |
| 47 |
|
| 48 |
public function rewrite_rules() |
| 49 |
{ |
| 50 |
add_rewrite_rule('funnel/(.+?)/?$', 'index.php?funnel_step=$matches[1]', 'top'); |
| 51 |
add_rewrite_tag('%funnel_step%', '([^&]+)'); |
| 52 |
} |
| 53 |
|
| 54 |
public function get_next_step($order, $current) |
| 55 |
{ |
| 56 |
$current_key = array_search($current, array_column($order, 'id')); |
| 57 |
if (isset($order[$current_key + 1])) { |
| 58 |
$next_key = $order[$current_key + 1]; |
| 59 |
$next_id = $next_key['id']; |
| 60 |
return $next_id; |
| 61 |
} else { |
| 62 |
return false; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|