Issues (4138)

classes/frontend/class-endpoints.php (30 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes\frontend;
3
4
/**
5
 * Contains the endpoints
6
 *
7
 * @package lsx-health-plan
8
 */
9
class Endpoints {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @var      object \lsx_health_plan\classes\frontend\Endpoints()
17
	 */
18
	protected static $instance = null;
19
20
	/**
21
	 * Constructor
22
	 */
23
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
24
		add_action( 'init', array( $this, 'setup' ) );
25
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
26
27
	/**
28
	 * Return an instance of this class.
29
	 *
30
	 * @since 1.0.0
31
	 *
32
	 * @return    object \lsx_health_plan\classes\frontend\Endpoints()    A single instance of this class.
33
	 */
34
	public static function get_instance() {
35
		// If the single instance hasn't been set, set it now.
36
		if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
37
			self::$instance = new self();
38
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
39
		return self::$instance;
40
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
41
42
	/**
43
	 * Runs on init
44
	 */
45
	public function setup() {
46
		$this->add_rewrite_rules();
47
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
48
49
	/**
50
	 * Registers the rewrites.
51
	 */
52
	public function add_rewrite_rules() {
53
		// Here is where we add in the rewrite rules above the normal WP ones.
54
		add_rewrite_tag( '%endpoint%', '([^&]+)' );
55
		add_rewrite_tag( '%section%', '([^&]+)' );
56
57
		// Plan Sections.
58
		add_rewrite_rule( 'plan/([^/]+)/([^/]+)/?$', 'index.php?plan=$matches[1]&section=$matches[2]', 'top' );
59
60
		// Warm up.
61
		$warm_up = \lsx_health_plan\functions\get_option( 'endpoint_warm_up', false );
62
		if ( false === $warm_up ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
63
			$warm_up = 'warm-up';
64
		}
65
66
		add_rewrite_rule( 'plan/([^/]+)/([^/]+)/' . $warm_up . '/?$', 'index.php?plan=$matches[1]&section=$matches[2]&endpoint=warm-up', 'top' );
67
68
		// Workout.
69
		if ( post_type_exists( 'workout' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
70
			$workout = \lsx_health_plan\functions\get_option( 'endpoint_workout', false );
71
			if ( false === $workout ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
72
				$workout = 'workout';
73
			}
74
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
75
		add_rewrite_rule( 'plan/([^/]+)/([^/]+)/' . $workout . '/?$', 'index.php?plan=$matches[1]&section=$matches[2]&endpoint=workout', 'top' );
76
77
		// Meal.
78
		if ( post_type_exists( 'meal' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
79
			$meal = \lsx_health_plan\functions\get_option( 'endpoint_meal', false );
80
			if ( false === $meal ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
81
				$meal = 'meal';
82
			}
83
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
84
		add_rewrite_rule( 'plan/([^/]+)/([^/]+)/' . $meal . '/?$', 'index.php?plan=$matches[1]&section=$matches[2]&endpoint=meal', 'top' );
85
86
		// Recipe.
87
		if ( post_type_exists( 'recipe' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
88
			$recipe = \lsx_health_plan\functions\get_option( 'endpoint_recipe', false );
89
			if ( false === $recipe ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
90
				$recipe = 'recipes';
91
			}
92
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
93
		add_rewrite_rule( 'plan/([^/]+)/([^/]+)/' . $recipe . '/?$', 'index.php?plan=$matches[1]&section=$matches[2]&endpoint=recipes', 'top' );
94
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
95
}
96