Completed
Branch BUG-10236-FIX-RESET-CAPABILITI... (cbd980)
by
unknown
26:22 queued 14:04
created
core/db_models/fields/EE_Primary_Key_Int_Field.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 block discarded – undo
4 4
 class EE_Primary_Key_Int_Field extends EE_Primary_Key_Field_Base
5 5
 {
6 6
 
7
-    public function __construct($table_column, $nicename)
8
-    {
9
-        parent::__construct($table_column, $nicename, 0);
10
-        $this->setSchemaType('integer');
11
-    }
7
+	public function __construct($table_column, $nicename)
8
+	{
9
+		parent::__construct($table_column, $nicename, 0);
10
+		$this->setSchemaType('integer');
11
+	}
12 12
 
13
-    function prepare_for_set($value_inputted_for_field_on_model_object)
14
-    {
15
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
16
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
17
-        }
18
-        return absint($value_inputted_for_field_on_model_object);
19
-    }
13
+	function prepare_for_set($value_inputted_for_field_on_model_object)
14
+	{
15
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
16
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
17
+		}
18
+		return absint($value_inputted_for_field_on_model_object);
19
+	}
20 20
 
21
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
22
-    {
23
-        return intval($value_found_in_db_for_model_object);
24
-    }
21
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
22
+	{
23
+		return intval($value_found_in_db_for_model_object);
24
+	}
25 25
 
26
-    function is_auto_increment()
27
-    {
28
-        return true;
29
-    }
26
+	function is_auto_increment()
27
+	{
28
+		return true;
29
+	}
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -4,6 +4,9 @@
 block discarded – undo
4 4
 class EE_Primary_Key_Int_Field extends EE_Primary_Key_Field_Base
5 5
 {
6 6
 
7
+    /**
8
+     * @param string $table_column
9
+     */
7 10
     public function __construct($table_column, $nicename)
8 11
     {
9 12
         parent::__construct($table_column, $nicename, 0);
Please login to merge, or discard this patch.
core/db_models/fields/EE_Enum_Text_Field.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -12,131 +12,131 @@
 block discarded – undo
12 12
 class EE_Enum_Text_Field extends EE_Text_Field_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @var array $_allowed_enum_values
17
-     */
18
-    public $_allowed_enum_values;
19
-
20
-    /**
21
-     * @param string  $table_column
22
-     * @param string  $nice_name
23
-     * @param boolean $nullable
24
-     * @param mixed   $default_value
25
-     * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
26
-     */
27
-    function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
28
-    {
29
-        $this->_allowed_enum_values = $allowed_enum_values;
30
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
31
-        $this->setSchemaType('object');
32
-    }
33
-
34
-
35
-
36
-    /**
37
-     * Returns the list of allowed enum options, but filterable.
38
-     * This is used internally
39
-     *
40
-     * @return array
41
-     */
42
-    protected function _allowed_enum_values()
43
-    {
44
-        return apply_filters(
45
-            'FHEE__EE_Enum_Text_Field___allowed_enum_options',
46
-            $this->_allowed_enum_values,
47
-            $this
48
-        );
49
-    }
50
-
51
-
52
-
53
-    /**
54
-     * When setting, just verify that the value being used matches what we've defined as allowable enum values.
55
-     * If not, throw an error (but if WP_DEBUG is false, just set the value to default).
56
-     *
57
-     * @param string $value_inputted_for_field_on_model_object
58
-     * @return string
59
-     * @throws EE_Error
60
-     */
61
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
62
-    {
63
-        if (
64
-            $value_inputted_for_field_on_model_object !== null
65
-            && ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values())
66
-        ) {
67
-            if (defined('WP_DEBUG') && WP_DEBUG) {
68
-                $msg = sprintf(
69
-                    __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
70
-                    $value_inputted_for_field_on_model_object,
71
-                    $this->_name
72
-                );
73
-                $msg2 = sprintf(
74
-                    __('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'),
75
-                    $this->_name,
76
-                    implode(', ', array_keys($this->_allowed_enum_values())),
77
-                    $value_inputted_for_field_on_model_object
78
-                );
79
-                EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
80
-            }
81
-            return $this->get_default_value();
82
-        }
83
-        return $value_inputted_for_field_on_model_object;
84
-    }
85
-
86
-
87
-    /**
88
-     * Gets the pretty version of the enum's value.
89
-     *
90
-     * @param     int |string $value_on_field_to_be_outputted
91
-     * @param    null         $schema
92
-     * @return    string
93
-     */
94
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
95
-    {
96
-        $options = $this->_allowed_enum_values();
97
-        if (isset($options[$value_on_field_to_be_outputted])) {
98
-            return $options[$value_on_field_to_be_outputted];
99
-        } else {
100
-            return $value_on_field_to_be_outputted;
101
-        }
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * When retrieving something from the DB, don't enforce the enum's options. If it's in the DB, we just have to live
108
-     * with that. Note also: when we're saving to the DB again, we also don't enforce the enum options. It's ONLY
109
-     * when we're receiving USER input from prepare_for_set() that we enforce the enum options.
110
-     *
111
-     * @param mixed $value_in_db
112
-     * @return mixed
113
-     */
114
-    public function prepare_for_set_from_db($value_in_db)
115
-    {
116
-        return $value_in_db;
117
-    }
118
-
119
-
120
-    public function getSchemaProperties()
121
-    {
122
-        return array(
123
-            'raw' => array(
124
-                'description' =>  sprintf(
125
-                    __('%s - the value in the database.', 'event_espresso'),
126
-                    $this->get_nicename()
127
-                ),
128
-                'type' => 'string',
129
-                'enum' => array_keys($this->_allowed_enum_values)
130
-            ),
131
-            'pretty' => array(
132
-                'description' =>  sprintf(
133
-                    __('%s - the value for display.', 'event_espresso'),
134
-                    $this->get_nicename()
135
-                ),
136
-                'type' => 'string',
137
-                'enum' => array_values($this->_allowed_enum_values),
138
-                'read_only' => true
139
-            )
140
-        );
141
-    }
15
+	/**
16
+	 * @var array $_allowed_enum_values
17
+	 */
18
+	public $_allowed_enum_values;
19
+
20
+	/**
21
+	 * @param string  $table_column
22
+	 * @param string  $nice_name
23
+	 * @param boolean $nullable
24
+	 * @param mixed   $default_value
25
+	 * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
26
+	 */
27
+	function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
28
+	{
29
+		$this->_allowed_enum_values = $allowed_enum_values;
30
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
31
+		$this->setSchemaType('object');
32
+	}
33
+
34
+
35
+
36
+	/**
37
+	 * Returns the list of allowed enum options, but filterable.
38
+	 * This is used internally
39
+	 *
40
+	 * @return array
41
+	 */
42
+	protected function _allowed_enum_values()
43
+	{
44
+		return apply_filters(
45
+			'FHEE__EE_Enum_Text_Field___allowed_enum_options',
46
+			$this->_allowed_enum_values,
47
+			$this
48
+		);
49
+	}
50
+
51
+
52
+
53
+	/**
54
+	 * When setting, just verify that the value being used matches what we've defined as allowable enum values.
55
+	 * If not, throw an error (but if WP_DEBUG is false, just set the value to default).
56
+	 *
57
+	 * @param string $value_inputted_for_field_on_model_object
58
+	 * @return string
59
+	 * @throws EE_Error
60
+	 */
61
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
62
+	{
63
+		if (
64
+			$value_inputted_for_field_on_model_object !== null
65
+			&& ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values())
66
+		) {
67
+			if (defined('WP_DEBUG') && WP_DEBUG) {
68
+				$msg = sprintf(
69
+					__('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
70
+					$value_inputted_for_field_on_model_object,
71
+					$this->_name
72
+				);
73
+				$msg2 = sprintf(
74
+					__('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'),
75
+					$this->_name,
76
+					implode(', ', array_keys($this->_allowed_enum_values())),
77
+					$value_inputted_for_field_on_model_object
78
+				);
79
+				EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
80
+			}
81
+			return $this->get_default_value();
82
+		}
83
+		return $value_inputted_for_field_on_model_object;
84
+	}
85
+
86
+
87
+	/**
88
+	 * Gets the pretty version of the enum's value.
89
+	 *
90
+	 * @param     int |string $value_on_field_to_be_outputted
91
+	 * @param    null         $schema
92
+	 * @return    string
93
+	 */
94
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
95
+	{
96
+		$options = $this->_allowed_enum_values();
97
+		if (isset($options[$value_on_field_to_be_outputted])) {
98
+			return $options[$value_on_field_to_be_outputted];
99
+		} else {
100
+			return $value_on_field_to_be_outputted;
101
+		}
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * When retrieving something from the DB, don't enforce the enum's options. If it's in the DB, we just have to live
108
+	 * with that. Note also: when we're saving to the DB again, we also don't enforce the enum options. It's ONLY
109
+	 * when we're receiving USER input from prepare_for_set() that we enforce the enum options.
110
+	 *
111
+	 * @param mixed $value_in_db
112
+	 * @return mixed
113
+	 */
114
+	public function prepare_for_set_from_db($value_in_db)
115
+	{
116
+		return $value_in_db;
117
+	}
118
+
119
+
120
+	public function getSchemaProperties()
121
+	{
122
+		return array(
123
+			'raw' => array(
124
+				'description' =>  sprintf(
125
+					__('%s - the value in the database.', 'event_espresso'),
126
+					$this->get_nicename()
127
+				),
128
+				'type' => 'string',
129
+				'enum' => array_keys($this->_allowed_enum_values)
130
+			),
131
+			'pretty' => array(
132
+				'description' =>  sprintf(
133
+					__('%s - the value for display.', 'event_espresso'),
134
+					$this->get_nicename()
135
+				),
136
+				'type' => 'string',
137
+				'enum' => array_values($this->_allowed_enum_values),
138
+				'read_only' => true
139
+			)
140
+		);
141
+	}
142 142
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Full_HTML_Field.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -15,57 +15,57 @@
 block discarded – undo
15 15
 class EE_Full_HTML_Field extends EE_Text_Field_Base
16 16
 {
17 17
 
18
-    /**
19
-     * @param string $table_column
20
-     * @param string $nicename
21
-     * @param bool   $nullable
22
-     * @param null   $default_value
23
-     */
24
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
25
-    {
26
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
27
-        $this->setSchemaType('object');
28
-    }
18
+	/**
19
+	 * @param string $table_column
20
+	 * @param string $nicename
21
+	 * @param bool   $nullable
22
+	 * @param null   $default_value
23
+	 */
24
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
25
+	{
26
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
27
+		$this->setSchemaType('object');
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
33
-     *
34
-     * @param type $value_on_field_to_be_outputted
35
-     * @param type $schema
36
-     * @return string
37
-     */
38
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
39
-    {
40
-        if ($schema == 'form_input') {
41
-            return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
42
-        } elseif ($schema == 'no_wpautop') {
43
-            return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
44
-        } else {
45
-            return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
46
-        }
47
-    }
31
+	/**
32
+	 * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
33
+	 *
34
+	 * @param type $value_on_field_to_be_outputted
35
+	 * @param type $schema
36
+	 * @return string
37
+	 */
38
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
39
+	{
40
+		if ($schema == 'form_input') {
41
+			return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
42
+		} elseif ($schema == 'no_wpautop') {
43
+			return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
44
+		} else {
45
+			return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
46
+		}
47
+	}
48 48
 
49 49
 
50 50
 
51
-    public function getSchemaProperties()
52
-    {
53
-        return array(
54
-            'raw' => array(
55
-                'description' =>  sprintf(
56
-                    __('%s - the value in the database.', 'event_espresso'),
57
-                    $this->get_nicename()
58
-                ),
59
-                'type' => 'string'
60
-            ),
61
-            'rendered' => array(
62
-                'description' =>  sprintf(
63
-                    __('%s - transformed for display.', 'event_espresso'),
64
-                    $this->get_nicename()
65
-                ),
66
-                'type' => 'string',
67
-                'readonly' => true
68
-            )
69
-        );
70
-    }
51
+	public function getSchemaProperties()
52
+	{
53
+		return array(
54
+			'raw' => array(
55
+				'description' =>  sprintf(
56
+					__('%s - the value in the database.', 'event_espresso'),
57
+					$this->get_nicename()
58
+				),
59
+				'type' => 'string'
60
+			),
61
+			'rendered' => array(
62
+				'description' =>  sprintf(
63
+					__('%s - transformed for display.', 'event_espresso'),
64
+					$this->get_nicename()
65
+				),
66
+				'type' => 'string',
67
+				'readonly' => true
68
+			)
69
+		);
70
+	}
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      * @param string $table_column
14 14
      * @param string $nicename
15 15
      * @param bool   $nullable
16
-     * @param null   $default_value
16
+     * @param string   $default_value
17 17
      */
18 18
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
19 19
     {
Please login to merge, or discard this patch.
core/EE_Request_Handler.core.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	 *    remove param
343 343
 	 *
344 344
 	 * @access    public
345
-	 * @param $key
345
+	 * @param string $key
346 346
 	 * @return    void
347 347
 	 */
348 348
 	public function un_set( $key ) {
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	 *    add_output
383 383
 	 *
384 384
 	 * @access    public
385
-	 * @param $string
385
+	 * @param string $string
386 386
 	 * @return    void
387 387
 	 */
388 388
 	public function add_output( $string ) {
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -238,8 +238,8 @@  discard block
 block discarded – undo
238 238
 				if ( ! $this->get( 'post_name' ) ) {
239 239
 					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
240 240
 					$post_name = isset( $post_type_CPT_endpoints[ $this->get( 'post_type' ) ] )
241
-                        ? $post_type_CPT_endpoints[ $this->get( 'post_type' ) ]
242
-                        : '';
241
+						? $post_type_CPT_endpoints[ $this->get( 'post_type' ) ]
242
+						: '';
243 243
 					// if the post type matches on of our then set the endpoint
244 244
 					if ( $post_name ) {
245 245
 						$this->set( 'post_name', $post_name );
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 * @return    void
262 262
 	 */
263 263
 	public function set_espresso_page( $value = null ) {
264
-        $this->_params['is_espresso_page'] = ! empty($value) ? $value : $this->test_for_espresso_page();
264
+		$this->_params['is_espresso_page'] = ! empty($value) ? $value : $this->test_for_espresso_page();
265 265
 	}
266 266
 
267 267
 
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
2 2
 /**
3 3
  * class EE_Request_Handler
4 4
  *
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 * @access public
50 50
 	 * @param  EE_Request $request
51 51
 	 */
52
-	public function __construct( EE_Request $request ) {
52
+	public function __construct(EE_Request $request) {
53 53
 		// grab request vars
54 54
 		$this->_params = $request->params();
55 55
 		// AJAX ???
56
-		$this->ajax = defined( 'DOING_AJAX' ) && DOING_AJAX ? true : false;
57
-		$this->front_ajax = defined( 'EE_FRONT_AJAX' ) && EE_FRONT_AJAX ? true : false;
58
-		do_action( 'AHEE__EE_Request_Handler__construct__complete' );
56
+		$this->ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false;
57
+		$this->front_ajax = defined('EE_FRONT_AJAX') && EE_FRONT_AJAX ? true : false;
58
+		do_action('AHEE__EE_Request_Handler__construct__complete');
59 59
 	}
60 60
 
61 61
 
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
 	 * @param WP $wp
68 68
 	 * @return void
69 69
 	 */
70
-	public function parse_request( $wp = null ) {
70
+	public function parse_request($wp = null) {
71 71
 		//if somebody forgot to provide us with WP, that's ok because its global
72
-		if ( ! $wp instanceof WP ) {
72
+		if ( ! $wp instanceof WP) {
73 73
 			global $wp;
74 74
 		}
75
-		$this->set_request_vars( $wp );
75
+		$this->set_request_vars($wp);
76 76
 	}
77 77
 
78 78
 
@@ -84,14 +84,14 @@  discard block
 block discarded – undo
84 84
 	 * @param WP $wp
85 85
 	 * @return void
86 86
 	 */
87
-	public function set_request_vars( $wp = null ) {
88
-		if ( ! is_admin() ) {
87
+	public function set_request_vars($wp = null) {
88
+		if ( ! is_admin()) {
89 89
 			// set request post_id
90
-			$this->set( 'post_id', $this->get_post_id_from_request( $wp ));
90
+			$this->set('post_id', $this->get_post_id_from_request($wp));
91 91
 			// set request post name
92
-			$this->set( 'post_name', $this->get_post_name_from_request( $wp ));
92
+			$this->set('post_name', $this->get_post_name_from_request($wp));
93 93
 			// set request post_type
94
-			$this->set( 'post_type', $this->get_post_type_from_request( $wp ));
94
+			$this->set('post_type', $this->get_post_type_from_request($wp));
95 95
 			// true or false ? is this page being used by EE ?
96 96
 			$this->set_espresso_page();
97 97
 		}
@@ -106,19 +106,19 @@  discard block
 block discarded – undo
106 106
 	 * @param WP $wp
107 107
 	 * @return int
108 108
 	 */
109
-	public function get_post_id_from_request( $wp = null ) {
110
-		if ( ! $wp instanceof WP ){
109
+	public function get_post_id_from_request($wp = null) {
110
+		if ( ! $wp instanceof WP) {
111 111
 			global $wp;
112 112
 		}
113 113
 		$post_id = null;
114
-		if ( isset( $wp->query_vars['p'] )) {
114
+		if (isset($wp->query_vars['p'])) {
115 115
 			$post_id = $wp->query_vars['p'];
116 116
 		}
117
-		if ( ! $post_id && isset( $wp->query_vars['page_id'] )) {
117
+		if ( ! $post_id && isset($wp->query_vars['page_id'])) {
118 118
 			$post_id = $wp->query_vars['page_id'];
119 119
 		}
120
-		if ( ! $post_id && isset( $wp->request ) && is_numeric( basename( $wp->request ))) {
121
-			$post_id = basename( $wp->request );
120
+		if ( ! $post_id && isset($wp->request) && is_numeric(basename($wp->request))) {
121
+			$post_id = basename($wp->request);
122 122
 		}
123 123
 		return $post_id;
124 124
 	}
@@ -132,35 +132,35 @@  discard block
 block discarded – undo
132 132
 	 * @param WP $wp
133 133
 	 * @return string
134 134
 	 */
135
-	public function get_post_name_from_request( $wp = null ) {
136
-		if ( ! $wp instanceof WP ){
135
+	public function get_post_name_from_request($wp = null) {
136
+		if ( ! $wp instanceof WP) {
137 137
 			global $wp;
138 138
 		}
139 139
 		$post_name = null;
140
-		if ( isset( $wp->query_vars['name'] ) && ! empty( $wp->query_vars['name'] )) {
140
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
141 141
 			$post_name = $wp->query_vars['name'];
142 142
 		}
143
-		if ( ! $post_name && isset( $wp->query_vars['pagename'] ) && ! empty( $wp->query_vars['pagename'] )) {
143
+		if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
144 144
 			$post_name = $wp->query_vars['pagename'];
145 145
 		}
146
-		if ( ! $post_name && isset( $wp->request ) && ! empty( $wp->request )) {
147
-			$possible_post_name = basename( $wp->request );
148
-			if ( ! is_numeric( $possible_post_name )) {
146
+		if ( ! $post_name && isset($wp->request) && ! empty($wp->request)) {
147
+			$possible_post_name = basename($wp->request);
148
+			if ( ! is_numeric($possible_post_name)) {
149 149
 				/** @type WPDB $wpdb */
150 150
 				global $wpdb;
151 151
 				$SQL = "SELECT ID from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s";
152
-				$possible_post_name = $wpdb->get_var( $wpdb->prepare( $SQL, $possible_post_name ));
153
-				if ( $possible_post_name ) {
152
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
153
+				if ($possible_post_name) {
154 154
 					$post_name = $possible_post_name;
155 155
 				}
156 156
 			}
157 157
 		}
158
-		if ( ! $post_name && $this->get( 'post_id' )) {
158
+		if ( ! $post_name && $this->get('post_id')) {
159 159
 			/** @type WPDB $wpdb */
160 160
 			global $wpdb;
161 161
 			$SQL = "SELECT post_name from {$wpdb->posts} WHERE post_status='publish' AND ID=%d";
162
-			$possible_post_name = $wpdb->get_var( $wpdb->prepare( $SQL, $this->get( 'post_id' )));
163
-			if( $possible_post_name ) {
162
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
163
+			if ($possible_post_name) {
164 164
 				$post_name = $possible_post_name;
165 165
 			}
166 166
 		}
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 * @param WP $wp
177 177
 	 * @return mixed
178 178
 	 */
179
-	public function get_post_type_from_request( $wp = null ) {
180
-		if ( ! $wp instanceof WP ){
179
+	public function get_post_type_from_request($wp = null) {
180
+		if ( ! $wp instanceof WP) {
181 181
 			global $wp;
182 182
 		}
183
-		return isset( $wp->query_vars['post_type'] ) ? $wp->query_vars['post_type'] : null;
183
+		return isset($wp->query_vars['post_type']) ? $wp->query_vars['post_type'] : null;
184 184
 	}
185 185
 
186 186
 
@@ -190,18 +190,18 @@  discard block
 block discarded – undo
190 190
 	 * @param  WP $wp
191 191
 	 * @return string
192 192
 	 */
193
-	public function get_current_page_permalink( $wp = null ) {
194
-		$post_id = $this->get_post_id_from_request( $wp );
195
-		if ( $post_id ) {
196
-			$current_page_permalink = get_permalink( $post_id );
193
+	public function get_current_page_permalink($wp = null) {
194
+		$post_id = $this->get_post_id_from_request($wp);
195
+		if ($post_id) {
196
+			$current_page_permalink = get_permalink($post_id);
197 197
 		} else {
198
-			if ( ! $wp instanceof WP ) {
198
+			if ( ! $wp instanceof WP) {
199 199
 				global $wp;
200 200
 			}
201
-			if ( $wp->request ) {
202
-				$current_page_permalink = site_url( $wp->request );
201
+			if ($wp->request) {
202
+				$current_page_permalink = site_url($wp->request);
203 203
 			} else {
204
-				$current_page_permalink = esc_url( site_url( $_SERVER[ 'REQUEST_URI' ] ) );
204
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
205 205
 			}
206 206
 		}
207 207
 		return $current_page_permalink;
@@ -218,31 +218,31 @@  discard block
 block discarded – undo
218 218
 	public function test_for_espresso_page() {
219 219
 		global $wp;
220 220
 		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
221
-		$EE_CPT_Strategy = EE_Registry::instance()->load_core( 'CPT_Strategy' );
221
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
222 222
 		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
223
-		if ( is_array( $espresso_CPT_taxonomies ) ) {
224
-			foreach ( $espresso_CPT_taxonomies as $espresso_CPT_taxonomy =>$details ) {
225
-				if ( isset( $wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ] ) ) {
223
+		if (is_array($espresso_CPT_taxonomies)) {
224
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy =>$details) {
225
+				if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
226 226
 					return true;
227 227
 				}
228 228
 			}
229 229
 		}
230 230
 		// load espresso CPT endpoints
231 231
 		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
232
-		$post_type_CPT_endpoints = array_flip( $espresso_CPT_endpoints );
233
-		$post_types = (array)$this->get( 'post_type' );
234
-		foreach ( $post_types as $post_type ) {
232
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
233
+		$post_types = (array) $this->get('post_type');
234
+		foreach ($post_types as $post_type) {
235 235
 			// was a post name passed ?
236
-			if ( isset( $post_type_CPT_endpoints[ $post_type ] ) ) {
236
+			if (isset($post_type_CPT_endpoints[$post_type])) {
237 237
 				// kk we know this is an espresso page, but is it a specific post ?
238
-				if ( ! $this->get( 'post_name' ) ) {
238
+				if ( ! $this->get('post_name')) {
239 239
 					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
240
-					$post_name = isset( $post_type_CPT_endpoints[ $this->get( 'post_type' ) ] )
241
-                        ? $post_type_CPT_endpoints[ $this->get( 'post_type' ) ]
240
+					$post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
241
+                        ? $post_type_CPT_endpoints[$this->get('post_type')]
242 242
                         : '';
243 243
 					// if the post type matches on of our then set the endpoint
244
-					if ( $post_name ) {
245
-						$this->set( 'post_name', $post_name );
244
+					if ($post_name) {
245
+						$this->set('post_name', $post_name);
246 246
 					}
247 247
 				}
248 248
 				return true;
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * @param null|bool $value
261 261
 	 * @return    void
262 262
 	 */
263
-	public function set_espresso_page( $value = null ) {
263
+	public function set_espresso_page($value = null) {
264 264
         $this->_params['is_espresso_page'] = ! empty($value) ? $value : $this->test_for_espresso_page();
265 265
 	}
266 266
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 *  @return 	mixed
274 274
 	 */
275 275
 	public function is_espresso_page() {
276
-		return isset( $this->_params['is_espresso_page'] ) ? $this->_params['is_espresso_page'] : false;
276
+		return isset($this->_params['is_espresso_page']) ? $this->_params['is_espresso_page'] : false;
277 277
 	}
278 278
 
279 279
 
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
 	 * @param bool $override_ee
298 298
 	 * @return    void
299 299
 	 */
300
-	public function set( $key, $value, $override_ee = false ) {
300
+	public function set($key, $value, $override_ee = false) {
301 301
 		// don't allow "ee" to be overwritten unless explicitly instructed to do so
302 302
 		if (
303 303
 			$key !== 'ee' ||
304
-			( $key === 'ee' && empty( $this->_params['ee'] ))
305
-			|| ( $key === 'ee' && ! empty( $this->_params['ee'] ) && $override_ee )
304
+			($key === 'ee' && empty($this->_params['ee']))
305
+			|| ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
306 306
 		) {
307
-			$this->_params[ $key ] = $value;
307
+			$this->_params[$key] = $value;
308 308
 		}
309 309
 	}
310 310
 
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param null $default
319 319
 	 * @return    mixed
320 320
 	 */
321
-	public function get( $key, $default = null ) {
322
-		return isset( $this->_params[ $key ] ) ? $this->_params[ $key ] : $default;
321
+	public function get($key, $default = null) {
322
+		return isset($this->_params[$key]) ? $this->_params[$key] : $default;
323 323
 	}
324 324
 
325 325
 
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
 	 * @param $key
332 332
 	 * @return    boolean
333 333
 	 */
334
-	public function is_set( $key ) {
335
-		return isset( $this->_params[ $key ] ) ? true : false;
334
+	public function is_set($key) {
335
+		return isset($this->_params[$key]) ? true : false;
336 336
 	}
337 337
 
338 338
 
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 	 * @param $key
345 345
 	 * @return    void
346 346
 	 */
347
-	public function un_set( $key ) {
348
-		unset( $this->_params[ $key ] );
347
+	public function un_set($key) {
348
+		unset($this->_params[$key]);
349 349
 	}
350 350
 
351 351
 
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @param $value
359 359
 	 * @return    void
360 360
 	 */
361
-	public function set_notice( $key, $value ) {
362
-		$this->_notice[ $key ] = $value;
361
+	public function set_notice($key, $value) {
362
+		$this->_notice[$key] = $value;
363 363
 	}
364 364
 
365 365
 
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param $key
372 372
 	 * @return    mixed
373 373
 	 */
374
-	public function get_notice( $key ) {
375
-		return isset( $this->_notice[ $key ] ) ? $this->_notice[ $key ] : null;
374
+	public function get_notice($key) {
375
+		return isset($this->_notice[$key]) ? $this->_notice[$key] : null;
376 376
 	}
377 377
 
378 378
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 	 * @param $string
385 385
 	 * @return    void
386 386
 	 */
387
-	public function add_output( $string ) {
387
+	public function add_output($string) {
388 388
 		$this->_output .= $string;
389 389
 	}
390 390
 
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
 	 * @param $item
407 407
 	 * @param $key
408 408
 	 */
409
-	public function sanitize_text_field_for_array_walk( &$item, &$key ) {
410
-		$item = strpos( $item, 'email' ) !== false ? sanitize_email( $item ) : sanitize_text_field( $item );
409
+	public function sanitize_text_field_for_array_walk(&$item, &$key) {
410
+		$item = strpos($item, 'email') !== false ? sanitize_email($item) : sanitize_text_field($item);
411 411
 	}
412 412
 
413 413
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 	 * @param $b
418 418
 	 * @return bool
419 419
 	 */
420
-	public function __set($a,$b) { return false; }
420
+	public function __set($a, $b) { return false; }
421 421
 
422 422
 
423 423
 
Please login to merge, or discard this patch.
widgets/EspressoWidget.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -18,31 +18,31 @@
 block discarded – undo
18 18
 
19 19
 
20 20
 
21
-    /**
22
-     * @param string $name
23
-     * @param array  $widget_options
24
-     * @param array  $control_options
25
-     */
26
-    public function __construct($name = '', array $widget_options = array(), array $control_options = array())
27
-    {
28
-        $id_base = EspressoWidget::getIdBase(get_class($this));
29
-        $control_options['id_base'] = $id_base;
30
-        $control_options['height'] = isset($control_options['height']) ? $control_options['height'] : 300;
31
-        $control_options['width'] = isset($control_options['width']) ? $control_options['width'] : 350;
32
-        // Register widget with WordPress
33
-        parent::__construct($id_base, $name, $widget_options, $control_options);
34
-    }
35
-
36
-
37
-
38
-    /**
39
-     * @param string $widget_class
40
-     * @return string
41
-     */
42
-    public static function getIdBase($widget_class)
43
-    {
44
-        return sanitize_title(str_replace(array('EEW_', '_'), array('EE_', '-'), $widget_class)) . '-widget';
45
-    }
21
+	/**
22
+	 * @param string $name
23
+	 * @param array  $widget_options
24
+	 * @param array  $control_options
25
+	 */
26
+	public function __construct($name = '', array $widget_options = array(), array $control_options = array())
27
+	{
28
+		$id_base = EspressoWidget::getIdBase(get_class($this));
29
+		$control_options['id_base'] = $id_base;
30
+		$control_options['height'] = isset($control_options['height']) ? $control_options['height'] : 300;
31
+		$control_options['width'] = isset($control_options['width']) ? $control_options['width'] : 350;
32
+		// Register widget with WordPress
33
+		parent::__construct($id_base, $name, $widget_options, $control_options);
34
+	}
35
+
36
+
37
+
38
+	/**
39
+	 * @param string $widget_class
40
+	 * @return string
41
+	 */
42
+	public static function getIdBase($widget_class)
43
+	{
44
+		return sanitize_title(str_replace(array('EEW_', '_'), array('EE_', '-'), $widget_class)) . '-widget';
45
+	}
46 46
 
47 47
 
48 48
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
      */
42 42
     public static function getIdBase($widget_class)
43 43
     {
44
-        return sanitize_title(str_replace(array('EEW_', '_'), array('EE_', '-'), $widget_class)) . '-widget';
44
+        return sanitize_title(str_replace(array('EEW_', '_'), array('EE_', '-'), $widget_class)).'-widget';
45 45
     }
46 46
 
47 47
 
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_shortcodes.dmsstage.php 2 patches
Indentation   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,7 @@
 block discarded – undo
2 2
 
3 3
 /**
4 4
  * Goes through all the posts and pages, and converts old shortcodes to new ones
5
-
6
-*/
5
+ */
7 6
 
8 7
 class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage{
9 8
 	function __construct() {
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 
6 6
 */
7 7
 
8
-class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage{
8
+class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage {
9 9
 	function __construct() {
10 10
 		global $wpdb;
11 11
 		$this->_pretty_name = __("Shortcodes", "event_espresso");
@@ -15,27 +15,27 @@  discard block
 block discarded – undo
15 15
 	protected function _migrate_old_row($old_row) {
16 16
 		$new_post_content = $this->_change_event_list_shortcode($old_row['post_content']);
17 17
 		global $wpdb;
18
-		$wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d",$new_post_content,$old_row['ID']));
18
+		$wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID']));
19 19
 	}
20 20
 
21 21
 	/**
22 22
 	 * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...]
23 23
 	 * @param string $old_content
24 24
 	 */
25
-	private function _change_event_list_shortcode($old_content){
26
-		return str_replace("[EVENT_LIST","[ESPRESSO_EVENTS",$old_content);
25
+	private function _change_event_list_shortcode($old_content) {
26
+		return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content);
27 27
 	}
28 28
 
29
-	function _migration_step($num_items=50){
29
+	function _migration_step($num_items = 50) {
30 30
 		global $wpdb;
31 31
 		$start_at_record = $this->count_records_migrated();
32
-		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d",$start_at_record,$num_items),ARRAY_A);
32
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
33 33
 		$items_actually_migrated = 0;
34
-		foreach($rows as $old_row){
34
+		foreach ($rows as $old_row) {
35 35
 			$this->_migrate_old_row($old_row);
36 36
 			$items_actually_migrated++;
37 37
 		}
38
-		if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){
38
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
39 39
 			$this->set_completed();
40 40
 		}
41 41
 		return $items_actually_migrated;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		return $count;
47 47
 	}
48 48
 
49
-	private function _sql_to_only_select_non_drafts(){
49
+	private function _sql_to_only_select_non_drafts() {
50 50
 		return " WHERE post_type NOT IN ('revision','auto-draft') ";
51 51
 	}
52 52
 
Please login to merge, or discard this patch.
core/admin/PostShortcodeTracking.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -13,150 +13,150 @@
 block discarded – undo
13 13
 class PostShortcodeTracking
14 14
 {
15 15
 
16
-    /**
17
-     * @deprecated 4.9.26
18
-     * @return    void
19
-     */
20
-    public static function set_hooks_admin()
21
-    {
22
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
23
-    }
24
-
25
-
26
-
27
-    /**
28
-     * @deprecated 4.9.26
29
-     * @param $post_ID
30
-     * @param $post
31
-     * @return void
32
-     */
33
-    public static function parse_post_content_on_save( $post_ID, $post )
34
-    {
35
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
36
-    }
37
-
38
-
39
-
40
-    /**
41
-     * @deprecated 4.9.26
42
-     * @param $page_for_posts
43
-     * @return void
44
-     */
45
-    protected static function set_post_shortcodes_for_posts_page( $page_for_posts )
46
-    {
47
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * @deprecated 4.9.26
54
-     * @param $page_for_posts
55
-     * @param $EES_Shortcode
56
-     * @param $post_ID
57
-     * @return void
58
-     */
59
-    protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID )
60
-    {
61
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @deprecated 4.9.26
68
-     * @param $ID
69
-     * @return void
70
-     */
71
-    public static function unset_post_shortcodes_on_delete( $ID )
72
-    {
73
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * @deprecated 4.9.26
80
-     * @param      $ID
81
-     * @param      $shortcode_class
82
-     * @param      $shortcode_posts
83
-     * @param      $page_for_posts
84
-     * @param bool $update_post_shortcodes
85
-     * @return void
86
-     */
87
-    protected static function unset_posts_page_shortcode_for_post(
88
-        $ID,
89
-        $shortcode_class,
90
-        $shortcode_posts,
91
-        $page_for_posts,
92
-        $update_post_shortcodes = false
93
-    ) {
94
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * @deprecated 4.9.26
101
-     * @param string $page_for_posts
102
-     * @return void
103
-     */
104
-    public static function update_post_shortcodes( $page_for_posts = '' )
105
-    {
106
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * @deprecated 4.9.26
113
-     * @param $option
114
-     * @param $value
115
-     * @return void
116
-     */
117
-    public static function reset_page_for_posts_on_initial_set( $option, $value )
118
-    {
119
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * @deprecated 4.9.26
126
-     * @param        $option
127
-     * @param string $old_value
128
-     * @param string $value
129
-     * @return void
130
-     */
131
-    public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' )
132
-    {
133
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * @deprecated 4.9.26
140
-     * @param $option
141
-     * @return void
142
-     */
143
-    public static function reset_page_for_posts_on_delete( $option )
144
-    {
145
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @deprecated 4.9.26
152
-     * @param      $shortcodes
153
-     * @param bool $index_results
154
-     * @return void
155
-     */
156
-    public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true )
157
-    {
158
-        \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
159
-    }
16
+	/**
17
+	 * @deprecated 4.9.26
18
+	 * @return    void
19
+	 */
20
+	public static function set_hooks_admin()
21
+	{
22
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
23
+	}
24
+
25
+
26
+
27
+	/**
28
+	 * @deprecated 4.9.26
29
+	 * @param $post_ID
30
+	 * @param $post
31
+	 * @return void
32
+	 */
33
+	public static function parse_post_content_on_save( $post_ID, $post )
34
+	{
35
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
36
+	}
37
+
38
+
39
+
40
+	/**
41
+	 * @deprecated 4.9.26
42
+	 * @param $page_for_posts
43
+	 * @return void
44
+	 */
45
+	protected static function set_post_shortcodes_for_posts_page( $page_for_posts )
46
+	{
47
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * @deprecated 4.9.26
54
+	 * @param $page_for_posts
55
+	 * @param $EES_Shortcode
56
+	 * @param $post_ID
57
+	 * @return void
58
+	 */
59
+	protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID )
60
+	{
61
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @deprecated 4.9.26
68
+	 * @param $ID
69
+	 * @return void
70
+	 */
71
+	public static function unset_post_shortcodes_on_delete( $ID )
72
+	{
73
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * @deprecated 4.9.26
80
+	 * @param      $ID
81
+	 * @param      $shortcode_class
82
+	 * @param      $shortcode_posts
83
+	 * @param      $page_for_posts
84
+	 * @param bool $update_post_shortcodes
85
+	 * @return void
86
+	 */
87
+	protected static function unset_posts_page_shortcode_for_post(
88
+		$ID,
89
+		$shortcode_class,
90
+		$shortcode_posts,
91
+		$page_for_posts,
92
+		$update_post_shortcodes = false
93
+	) {
94
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * @deprecated 4.9.26
101
+	 * @param string $page_for_posts
102
+	 * @return void
103
+	 */
104
+	public static function update_post_shortcodes( $page_for_posts = '' )
105
+	{
106
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * @deprecated 4.9.26
113
+	 * @param $option
114
+	 * @param $value
115
+	 * @return void
116
+	 */
117
+	public static function reset_page_for_posts_on_initial_set( $option, $value )
118
+	{
119
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * @deprecated 4.9.26
126
+	 * @param        $option
127
+	 * @param string $old_value
128
+	 * @param string $value
129
+	 * @return void
130
+	 */
131
+	public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' )
132
+	{
133
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * @deprecated 4.9.26
140
+	 * @param $option
141
+	 * @return void
142
+	 */
143
+	public static function reset_page_for_posts_on_delete( $option )
144
+	{
145
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @deprecated 4.9.26
152
+	 * @param      $shortcodes
153
+	 * @param bool $index_results
154
+	 * @return void
155
+	 */
156
+	public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true )
157
+	{
158
+		\EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
159
+	}
160 160
 
161 161
 
162 162
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\admin;
3 3
 
4
-defined( 'EVENT_ESPRESSO_VERSION' ) || exit();
4
+defined('EVENT_ESPRESSO_VERSION') || exit();
5 5
 
6 6
 
7 7
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param $post
31 31
      * @return void
32 32
      */
33
-    public static function parse_post_content_on_save( $post_ID, $post )
33
+    public static function parse_post_content_on_save($post_ID, $post)
34 34
     {
35 35
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
36 36
     }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      * @param $page_for_posts
43 43
      * @return void
44 44
      */
45
-    protected static function set_post_shortcodes_for_posts_page( $page_for_posts )
45
+    protected static function set_post_shortcodes_for_posts_page($page_for_posts)
46 46
     {
47 47
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
48 48
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      * @param $post_ID
57 57
      * @return void
58 58
      */
59
-    protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID )
59
+    protected static function set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID)
60 60
     {
61 61
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
62 62
     }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      * @param $ID
69 69
      * @return void
70 70
      */
71
-    public static function unset_post_shortcodes_on_delete( $ID )
71
+    public static function unset_post_shortcodes_on_delete($ID)
72 72
     {
73 73
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
74 74
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      * @param string $page_for_posts
102 102
      * @return void
103 103
      */
104
-    public static function update_post_shortcodes( $page_for_posts = '' )
104
+    public static function update_post_shortcodes($page_for_posts = '')
105 105
     {
106 106
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
107 107
     }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @param $value
115 115
      * @return void
116 116
      */
117
-    public static function reset_page_for_posts_on_initial_set( $option, $value )
117
+    public static function reset_page_for_posts_on_initial_set($option, $value)
118 118
     {
119 119
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
120 120
     }
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      * @param string $value
129 129
      * @return void
130 130
      */
131
-    public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' )
131
+    public static function reset_page_for_posts_on_change($option, $old_value = '', $value = '')
132 132
     {
133 133
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
134 134
     }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      * @param $option
141 141
      * @return void
142 142
      */
143
-    public static function reset_page_for_posts_on_delete( $option )
143
+    public static function reset_page_for_posts_on_delete($option)
144 144
     {
145 145
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
146 146
     }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      * @param bool $index_results
154 154
      * @return void
155 155
      */
156
-    public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true )
156
+    public static function get_post_ids_for_shortcode($shortcodes, $index_results = true)
157 157
     {
158 158
         \EE_Error::doing_it_wrong(__METHOD__, __('Usage is deprecated.', 'event_espresso'), '4.9.26');
159 159
     }
Please login to merge, or discard this patch.
core/CPTs/EE_Register_CPTs.core.php 2 patches
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,602 +14,602 @@  discard block
 block discarded – undo
14 14
 class EE_Register_CPTs
15 15
 {
16 16
 
17
-    /**
18
-     * This property is used to hold an array of EE_default_term objects assigned to a custom post type when the post
19
-     * for that post type is published with no terms set for the taxonomy.
20
-     *
21
-     * @var array of EE_Default_Term objects
22
-     */
23
-    protected $_default_terms = array();
24
-
25
-
26
-
27
-    /**
28
-     *    constructor
29
-     * instantiated at init priority 5
30
-     */
31
-    public function __construct()
32
-    {
33
-        // register taxonomies
34
-        $taxonomies = self::get_taxonomies();
35
-        foreach ($taxonomies as $taxonomy => $tax) {
36
-            $this->register_taxonomy($taxonomy, $tax['singular_name'], $tax['plural_name'], $tax['args']);
37
-        }
38
-        // register CPTs
39
-        $CPTs = self::get_CPTs();
40
-        foreach ($CPTs as $CPT_name => $CPT) {
41
-            $this->register_CPT($CPT_name, $CPT['singular_name'], $CPT['plural_name'], $CPT['args'],
42
-                $CPT['singular_slug'], $CPT['plural_slug']);
43
-        }
44
-        // setup default terms in any of our taxonomies (but only if we're in admin).
45
-        // Why not added via register_activation_hook?
46
-        // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies
47
-        // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin.
48
-        // Keep in mind that this will READ these terms if they are deleted by the user.  Hence MUST use terms.
49
-        // if ( is_admin() ) {
50
-        // 	$this->set_must_use_event_types();
51
-        // }
52
-        //set default terms
53
-        $this->set_default_term('espresso_event_type', 'single-event', array('espresso_events'));
54
-        add_action('AHEE__EE_System__initialize_last', array(__CLASS__, 'maybe_flush_rewrite_rules'), 10);
55
-        // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts
56
-        // IF they don't have a term for that taxonomy set.
57
-        add_action('save_post', array($this, 'save_default_term'), 100, 2);
58
-        // remove no html restrictions from core wp saving of term descriptions.
59
-        // Note. this will affect only registered EE taxonomies.
60
-        $this->_allow_html_descriptions_for_ee_taxonomies();
61
-        do_action('AHEE__EE_Register_CPTs__construct_end', $this);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
68
-     *
69
-     * @since 4.5.0
70
-     * @return void
71
-     */
72
-    public static function maybe_flush_rewrite_rules()
73
-    {
74
-        if (get_option('ee_flush_rewrite_rules', true)) {
75
-            flush_rewrite_rules();
76
-            update_option('ee_flush_rewrite_rules', false);
77
-        }
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * By default, WordPress strips all html from term taxonomy description content.  The purpose of this method is to
84
-     * remove that restriction and ensure that we still run ee term taxonomy descriptions through some full html
85
-     * sanitization equivalent to the post content field.
86
-     *
87
-     * @since 4.7.8
88
-     */
89
-    protected function _allow_html_descriptions_for_ee_taxonomies()
90
-    {
91
-        // first remove default filter for term description but we have to do this earlier
92
-        // before wp sets their own filter
93
-        // because they just set a global filter on all term descriptions before the custom term description filter.
94
-        // Really sux.
95
-        add_filter('pre_term_description', array($this, 'ee_filter_ee_term_description_not_wp'), 1, 2);
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Callback for pre_term_description hook.
102
-     *
103
-     * @param string $description The description content.
104
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
105
-     * @return string
106
-     */
107
-    public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
108
-    {
109
-        //get a list of EE taxonomies
110
-        $ee_taxonomies = array_keys(self::get_taxonomies());
111
-        //only do our own thing if the taxonomy listed is an ee taxonomy.
112
-        if (in_array($taxonomy, $ee_taxonomies, true)) {
113
-            //remove default wp filter
114
-            remove_filter('pre_term_description', 'wp_filter_kses');
115
-            //sanitize THIS content.
116
-            $description = wp_kses($description, wp_kses_allowed_html('post'));
117
-        }
118
-        return $description;
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     *    get_taxonomies
125
-     *
126
-     * @access    public
127
-     * @return    array
128
-     */
129
-    public static function get_taxonomies()
130
-    {
131
-        // define taxonomies
132
-        return apply_filters('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array(
133
-            'espresso_event_categories' => array(
134
-                'singular_name' => __("Event Category", "event_espresso"),
135
-                'plural_name'   => __("Event Categories", "event_espresso"),
136
-                'args'          => array(
137
-                    'public'            => true,
138
-                    'show_in_nav_menus' => true,
139
-                    'show_in_rest'      => true,
140
-                    'capabilities'      => array(
141
-                        'manage_terms' => 'ee_manage_event_categories',
142
-                        'edit_terms'   => 'ee_edit_event_category',
143
-                        'delete_terms' => 'ee_delete_event_category',
144
-                        'assign_terms' => 'ee_assign_event_category',
145
-                    ),
146
-                    'rewrite'           => array('slug' => __('event-category', 'event_espresso')),
147
-                ),
148
-            ),
149
-            'espresso_venue_categories' => array(
150
-                'singular_name' => __("Venue Category", "event_espresso"),
151
-                'plural_name'   => __("Venue Categories", "event_espresso"),
152
-                'args'          => array(
153
-                    'public'            => true,
154
-                    'show_in_nav_menus' => false, //by default this doesn't show for decaf
155
-                    'show_in_rest'      => true,
156
-                    'capabilities'      => array(
157
-                        'manage_terms' => 'ee_manage_venue_categories',
158
-                        'edit_terms'   => 'ee_edit_venue_category',
159
-                        'delete_terms' => 'ee_delete_venue_category',
160
-                        'assign_terms' => 'ee_assign_venue_category',
161
-                    ),
162
-                    'rewrite'           => array('slug' => __('venue-category', 'event_espresso')),
163
-                ),
164
-            ),
165
-            'espresso_event_type'       => array(
166
-                'singular_name' => __("Event Type", "event_espresso"),
167
-                'plural_name'   => __("Event Types", "event_espresso"),
168
-                'args'          => array(
169
-                    'public'       => true,
170
-                    'show_ui'      => false,
171
-                    'show_in_rest' => true,
172
-                    'capabilities' => array(
173
-                        'manage_terms' => 'ee_read_event_type',
174
-                        'edit_terms'   => 'ee_edit_event_type',
175
-                        'delete_terms' => 'ee_delete_event_type',
176
-                        'assign_terms' => 'ee_assign_event_type',
177
-                    ),
178
-                    'rewrite'      => array('slug' => __('event-type', 'event_espresso')),
179
-                    'hierarchical' => true,
180
-                ),
181
-            ),
182
-        ));
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * This returns the corresponding model name for cpts registered by EE.
189
-     *
190
-     * @since 4.6.16.rc.000
191
-     * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
192
-     *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
193
-     *                                            model names for cpts registered in EE.
194
-     * @return array           Empty array if no matching model names for the given slug or an array of model
195
-     *                                            names indexed by post type slug.
196
-     */
197
-    public static function get_cpt_model_names($post_type_slug = '')
198
-    {
199
-        $cpts = self::get_CPTs();
200
-        //first if slug passed in...
201
-        if ( ! empty($post_type_slug)) {
202
-            //match?
203
-            if (
204
-                ! isset($cpts[$post_type_slug])
205
-                || (isset($cpts[$post_type_slug]) && empty($cpts[$post_type_slug]['class_name']))
206
-            ) {
207
-                return array();
208
-            }
209
-            //k let's get the model name for this cpt.
210
-            return array($post_type_slug => str_replace('EE', 'EEM', $cpts[$post_type_slug]['class_name']));
211
-        }
212
-        //if we made it here then we're returning an array of cpt model names indexed by post_type_slug.
213
-        $cpt_models = array();
214
-        foreach ($cpts as $slug => $args) {
215
-            if ( ! empty($args['class_name'])) {
216
-                $cpt_models[$slug] = str_replace('EE', 'EEM', $args['class_name']);
217
-            }
218
-        }
219
-        return $cpt_models;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * This instantiates cpt models related to the cpts registered via EE.
226
-     *
227
-     * @since 4.6.16.rc.000
228
-     * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
229
-     *                               the cpt matching the given slug.  Otherwise all cpt models will be
230
-     *                               instantiated (if possible).
231
-     * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
232
-     *                               EEM models indexed by post slug.
233
-     */
234
-    public static function instantiate_cpt_models($post_type_slug = '')
235
-    {
236
-        $cpt_model_names = self::get_cpt_model_names($post_type_slug);
237
-        $instantiated = array();
238
-        foreach ($cpt_model_names as $slug => $model_name) {
239
-            $instance = EE_Registry::instance()->load_model(str_replace('EEM_', '', $model_name));
240
-            if ($instance instanceof EEM_CPT_Base) {
241
-                $instantiated[$slug] = $instance;
242
-            }
243
-        }
244
-        return $instantiated;
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     *    get_CPTs
251
-     *
252
-     * @access    public
253
-     * @return    array
254
-     */
255
-    public static function get_CPTs()
256
-    {
257
-        // define CPTs
258
-        // NOTE the ['args']['page_templates'] array index is something specific to our CPTs
259
-        // and not part of the WP custom post type api.
260
-        return apply_filters('FHEE__EE_Register_CPTs__get_CPTs__cpts', array(
261
-            'espresso_events'    => array(
262
-                'singular_name' => __("Event", "event_espresso"),
263
-                'plural_name'   => __("Events", "event_espresso"),
264
-                'singular_slug' => __("event", "event_espresso"),
265
-                'plural_slug'   => EE_Registry::instance()->CFG->core->event_cpt_slug,
266
-                'class_name'    => 'EE_Event',
267
-                'args'          => array(
268
-                    'public'            => true,
269
-                    'show_in_nav_menus' => true,
270
-                    'capability_type'   => 'event',
271
-                    'capabilities'      => array(
272
-                        'edit_post'              => 'ee_edit_event',
273
-                        'read_post'              => 'ee_read_event',
274
-                        'delete_post'            => 'ee_delete_event',
275
-                        'edit_posts'             => 'ee_edit_events',
276
-                        'edit_others_posts'      => 'ee_edit_others_events',
277
-                        'publish_posts'          => 'ee_publish_events',
278
-                        'read_private_posts'     => 'ee_read_private_events',
279
-                        'delete_posts'           => 'ee_delete_events',
280
-                        'delete_private_posts'   => 'ee_delete_private_events',
281
-                        'delete_published_posts' => 'ee_delete_published_events',
282
-                        'delete_others_posts'    => 'ee_delete_others_events',
283
-                        'edit_private_posts'     => 'ee_edit_private_events',
284
-                        'edit_published_posts'   => 'ee_edit_published_events',
285
-                    ),
286
-                    'taxonomies'        => array(
287
-                        'espresso_event_categories',
288
-                        'espresso_event_type',
289
-                        'post_tag',
290
-                    ),
291
-                    'page_templates'    => true,
292
-                ),
293
-            ),
294
-            'espresso_venues'    => array(
295
-                'singular_name' => __("Venue", "event_espresso"),
296
-                'plural_name'   => __("Venues", "event_espresso"),
297
-                'singular_slug' => __("venue", "event_espresso"),
298
-                'plural_slug'   => __("venues", "event_espresso"),
299
-                'class_name'    => 'EE_Venue',
300
-                'args'          => array(
301
-                    'public'            => true,
302
-                    'show_in_nav_menus' => false, //by default this doesn't show for decaf,
303
-                    'capability_type'   => 'venue',
304
-                    'capabilities'      => array(
305
-                        'edit_post'              => 'ee_edit_venue',
306
-                        'read_post'              => 'ee_read_venue',
307
-                        'delete_post'            => 'ee_delete_venue',
308
-                        'edit_posts'             => 'ee_edit_venues',
309
-                        'edit_others_posts'      => 'ee_edit_others_venues',
310
-                        'publish_posts'          => 'ee_publish_venues',
311
-                        'read_private_posts'     => 'ee_read_private_venues',
312
-                        'delete_posts'           => 'ee_delete_venues',
313
-                        'delete_private_posts'   => 'ee_delete_private_venues',
314
-                        'delete_published_posts' => 'ee_delete_published_venues',
315
-                        'delete_others_posts'    => 'ee_edit_others_venues',
316
-                        'edit_private_posts'     => 'ee_edit_private_venues',
317
-                        'edit_published_posts'   => 'ee_edit_published_venues',
318
-                    ),
319
-                    'taxonomies'        => array(
320
-                        'espresso_venue_categories',
321
-                        'post_tag',
322
-                    ),
323
-                    'page_templates'    => true,
324
-                ),
325
-            ),
326
-            'espresso_attendees' => array(
327
-                'singular_name' => __("Contact", "event_espresso"),
328
-                'plural_name'   => __("Contacts", "event_espresso"),
329
-                'singular_slug' => __("contact", "event_espresso"),
330
-                'plural_slug'   => __("contacts", "event_espresso"),
331
-                'class_name'    => 'EE_Attendee',
332
-                'args'          => array(
333
-                    'public'             => false,
334
-                    'publicly_queryable' => false,
335
-                    'hierarchical'       => false,
336
-                    'has_archive'        => false,
337
-                    'taxonomies'         => array('post_tag'),
338
-                    'capability_type'    => 'contact',
339
-                    'capabilities'       => array(
340
-                        'edit_post'              => 'ee_edit_contact',
341
-                        'read_post'              => 'ee_read_contact',
342
-                        'delete_post'            => 'ee_delete_contact',
343
-                        'edit_posts'             => 'ee_edit_contacts',
344
-                        'edit_others_posts'      => 'ee_edit_contacts',
345
-                        'publish_posts'          => 'ee_edit_contacts',
346
-                        'read_private_posts'     => 'ee_edit_contacts',
347
-                        'delete_posts'           => 'ee_delete_contacts',
348
-                        'delete_private_posts'   => 'ee_delete_contacts',
349
-                        'delete_published_posts' => 'ee_delete_contacts',
350
-                        'delete_others_posts'    => 'ee_delete_contacts',
351
-                        'edit_private_posts'     => 'ee_edit_contacts',
352
-                        'edit_published_posts'   => 'ee_edit_contacts',
353
-                    ),
354
-                    'supports'           => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments'),
355
-                ),
356
-            ),
357
-        ));
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * This basically goes through the CPT array and returns only CPT's
364
-     * that have the ['args']['public'] option set as false
365
-     *
366
-     * @return array
367
-     */
368
-    public static function get_private_CPTs()
369
-    {
370
-        $CPTs = self::get_CPTs();
371
-        $private_CPTs = array();
372
-        foreach ($CPTs as $CPT => $details) {
373
-            if (empty($details['args']['public'])) {
374
-                $private_CPTs[$CPT] = $details;
375
-            }
376
-        }
377
-        return $private_CPTs;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Registers a custom taxonomy. Should be called before registering custom post types,
384
-     * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
385
-     *
386
-     * @param string $taxonomy_name , eg 'books'
387
-     * @param string $singular_name internationalized singular name
388
-     * @param string $plural_name   internationalized plural name
389
-     * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
390
-     */
391
-    public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
392
-    {
393
-        $args = array(
394
-            'hierarchical'      => true,
395
-            'labels'            => array(
396
-                'name'          => $plural_name,
397
-                'singular_name' => $singular_name,
398
-            ),
399
-            'show_ui'           => true,
400
-            'show_ee_ui'        => true,
401
-            'show_admin_column' => true,
402
-            'query_var'         => true,
403
-            'show_in_nav_menus' => false,
404
-            'map_meta_cap'      => true
405
-            //'rewrite'           => array( 'slug' => 'genre' ),
406
-        );
407
-        if ($override_args) {
408
-            if (isset($override_args['labels'])) {
409
-                $labels = array_merge($args['labels'], $override_args['labels']);
410
-                $args['labels'] = $labels;
411
-            }
412
-            $args = array_merge($args, $override_args);
413
-        }
414
-        register_taxonomy($taxonomy_name, null, $args);
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * Registers a new custom post type. Sets default settings given only the following params.
421
-     *
422
-     * @param string $post_type     the actual post type name
423
-     *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
424
-     *                              cpt Also any models must use this slug as well)
425
-     * @param string $singular_name a pre-internationalized string for the singular name of the objects
426
-     * @param string $plural_name   a pre-internalized string for the plural name of the objects
427
-     * @param array  $override_args exactly like $args as described in
428
-     *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
429
-     *                              set in this function will be overridden by whatever you set in $override_args
430
-     * @param string $singular_slug
431
-     * @param string $plural_slug
432
-     * @return void , but registers the custom post type
433
-     */
434
-    public function register_CPT(
435
-        $post_type,
436
-        $singular_name,
437
-        $plural_name,
438
-        $override_args = array(),
439
-        $singular_slug = '',
440
-        $plural_slug = ''
441
-    ) {
442
-        $labels = array(
443
-            'name'               => $plural_name,
444
-            'singular_name'      => $singular_name,
445
-            'add_new'            => sprintf(__("Add %s", "event_espresso"), $singular_name),
446
-            'add_new_item'       => sprintf(__("Add New %s", "event_espresso"), $singular_name),
447
-            'edit_item'          => sprintf(__("Edit %s", "event_espresso"), $singular_name),
448
-            'new_item'           => sprintf(__("New %s", "event_espresso"), $singular_name),
449
-            'all_items'          => sprintf(__("All %s", "event_espresso"), $plural_name),
450
-            'view_item'          => sprintf(__("View %s", "event_espresso"), $singular_name),
451
-            'search_items'       => sprintf(__("Search %s", "event_espresso"), $plural_name),
452
-            'not_found'          => sprintf(__("No %s found", "event_espresso"), $plural_name),
453
-            'not_found_in_trash' => sprintf(__("No %s found in Trash", "event_espresso"), $plural_name),
454
-            'parent_item_colon'  => '',
455
-            'menu_name'          => sprintf(__("%s", "event_espresso"), $plural_name),
456
-        );
457
-        //verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name
458
-        // $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name;
459
-        $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name;
460
-        //note the page_templates arg in the supports index is something specific to EE.
461
-        //  WordPress doesn't actually have that in their register_post_type api.
462
-        $args = array(
463
-            'labels'             => $labels,
464
-            'public'             => true,
465
-            'publicly_queryable' => true,
466
-            'show_ui'            => false,
467
-            'show_ee_ui'         => true,
468
-            'show_in_menu'       => false,
469
-            'show_in_nav_menus'  => false,
470
-            'query_var'          => true,
471
-            'rewrite'            => apply_filters(
472
-                'FHEE__EE_Register_CPTs__register_CPT__rewrite',
473
-                array('slug' => $plural_slug),
474
-                $post_type
475
-            ),
476
-            'capability_type'    => 'post',
477
-            'map_meta_cap'       => true,
478
-            'has_archive'        => true,
479
-            'hierarchical'       => false,
480
-            'menu_position'      => null,
481
-            'supports'           => array(
482
-                'title',
483
-                'editor',
484
-                'author',
485
-                'thumbnail',
486
-                'excerpt',
487
-                'custom-fields',
488
-                'comments',
489
-            ),
490
-        );
491
-        if ($override_args) {
492
-            if (isset($override_args['labels'])) {
493
-                $labels = array_merge($args['labels'], $override_args['labels']);
494
-            }
495
-            $args = array_merge($args, $override_args);
496
-            $args['labels'] = $labels;
497
-        }
498
-        register_post_type($post_type, $args);
499
-    }
500
-
501
-
502
-
503
-    public function set_must_use_event_types()
504
-    {
505
-        $term_details = array(
506
-            //Attendee's register for the first date-time only
507
-            'single-event'    => array(
508
-                __('Single Event', 'event_espresso'),
509
-                __('A single event that spans one or more consecutive days.', 'event_espresso'),
510
-            ),
511
-            //example: a party or two-day long workshop
512
-            //Attendee's can register for any of the date-times
513
-            'multi-event'     => array(
514
-                __('Multi Event', 'event_espresso'),
515
-                __('Multiple, separate, but related events that occur on consecutive days.', 'event_espresso'),
516
-            ),
517
-            //example: a three day music festival or week long conference
518
-            //Attendee's register for the first date-time only
519
-            'event-series'    => array(
520
-                __('Event Series', 'event_espresso'),
521
-                __(' Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
522
-            ),
523
-            //example: an 8 week introduction to basket weaving course
524
-            //Attendee's can register for any of the date-times.
525
-            'recurring-event' => array(
526
-                __('Recurring Event', 'event_espresso'),
527
-                __('Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
528
-            ),
529
-            //example: a yoga class
530
-            'ongoing' => array(
531
-                __('Ongoing Event', 'event_espresso'),
532
-                __('An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event',
533
-                    'event_espresso'),
534
-            )
535
-            //example: access to a museum
536
-            //'walk-in' => array( __('Walk In', 'event_espresso'), __('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ),
537
-            //'reservation' => array( __('Reservation', 'event_espresso'), __('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
538
-            // 'multiple-session' => array( __('Multiple Session', 'event_espresso'), __('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
539
-            //'appointment' => array( __('Appointments', 'event_espresso'), __('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') )
540
-        );
541
-        $this->set_must_use_terms('espresso_event_type', $term_details);
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     * wrapper method for handling the setting up of initial terms in the db (if they don't already exist).
548
-     * Note this should ONLY be used for terms that always must be present.  Be aware that if an initial term is
549
-     * deleted then it WILL be recreated.
550
-     *
551
-     * @param string $taxonomy     The name of the taxonomy
552
-     * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
553
-     *                             description as the elements in the array
554
-     * @return void
555
-     */
556
-    public function set_must_use_terms($taxonomy, $term_details)
557
-    {
558
-        $term_details = (array)$term_details;
559
-        foreach ($term_details as $slug => $details) {
560
-            if ( ! term_exists($slug, $taxonomy)) {
561
-                $insert_arr = array(
562
-                    'slug'        => $slug,
563
-                    'description' => $details[1],
564
-                );
565
-                wp_insert_term($details[0], $taxonomy, $insert_arr);
566
-            }
567
-        }
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     * Allows us to set what the default will be for terms when a cpt is PUBLISHED.
574
-     *
575
-     * @param string $taxonomy  The taxonomy we're using for the default term
576
-     * @param string $term_slug The slug of the term that will be the default.
577
-     * @param array  $cpt_slugs An array of custom post types we want the default assigned to
578
-     */
579
-    public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
580
-    {
581
-        $this->_default_terms[][$term_slug] = new EE_Default_Term($taxonomy, $term_slug, $cpt_slugs);
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property
588
-     *
589
-     * @param  int    $post_id ID of CPT being saved
590
-     * @param  object $post    Post object
591
-     * @return void
592
-     */
593
-    public function save_default_term($post_id, $post)
594
-    {
595
-        if (empty($this->_default_terms)) {
596
-            return;
597
-        } //no default terms set so lets just exit.
598
-        foreach ($this->_default_terms as $defaults) {
599
-            foreach ($defaults as $default_obj) {
600
-                if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) {
601
-                    //note some error proofing going on here to save unnecessary db queries
602
-                    $taxonomies = get_object_taxonomies($post->post_type);
603
-                    foreach ((array)$taxonomies as $taxonomy) {
604
-                        $terms = wp_get_post_terms($post_id, $taxonomy);
605
-                        if (empty($terms) && $taxonomy === $default_obj->taxonomy) {
606
-                            wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy);
607
-                        }
608
-                    }
609
-                }
610
-            }
611
-        }
612
-    }
17
+	/**
18
+	 * This property is used to hold an array of EE_default_term objects assigned to a custom post type when the post
19
+	 * for that post type is published with no terms set for the taxonomy.
20
+	 *
21
+	 * @var array of EE_Default_Term objects
22
+	 */
23
+	protected $_default_terms = array();
24
+
25
+
26
+
27
+	/**
28
+	 *    constructor
29
+	 * instantiated at init priority 5
30
+	 */
31
+	public function __construct()
32
+	{
33
+		// register taxonomies
34
+		$taxonomies = self::get_taxonomies();
35
+		foreach ($taxonomies as $taxonomy => $tax) {
36
+			$this->register_taxonomy($taxonomy, $tax['singular_name'], $tax['plural_name'], $tax['args']);
37
+		}
38
+		// register CPTs
39
+		$CPTs = self::get_CPTs();
40
+		foreach ($CPTs as $CPT_name => $CPT) {
41
+			$this->register_CPT($CPT_name, $CPT['singular_name'], $CPT['plural_name'], $CPT['args'],
42
+				$CPT['singular_slug'], $CPT['plural_slug']);
43
+		}
44
+		// setup default terms in any of our taxonomies (but only if we're in admin).
45
+		// Why not added via register_activation_hook?
46
+		// Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies
47
+		// (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin.
48
+		// Keep in mind that this will READ these terms if they are deleted by the user.  Hence MUST use terms.
49
+		// if ( is_admin() ) {
50
+		// 	$this->set_must_use_event_types();
51
+		// }
52
+		//set default terms
53
+		$this->set_default_term('espresso_event_type', 'single-event', array('espresso_events'));
54
+		add_action('AHEE__EE_System__initialize_last', array(__CLASS__, 'maybe_flush_rewrite_rules'), 10);
55
+		// hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts
56
+		// IF they don't have a term for that taxonomy set.
57
+		add_action('save_post', array($this, 'save_default_term'), 100, 2);
58
+		// remove no html restrictions from core wp saving of term descriptions.
59
+		// Note. this will affect only registered EE taxonomies.
60
+		$this->_allow_html_descriptions_for_ee_taxonomies();
61
+		do_action('AHEE__EE_Register_CPTs__construct_end', $this);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
68
+	 *
69
+	 * @since 4.5.0
70
+	 * @return void
71
+	 */
72
+	public static function maybe_flush_rewrite_rules()
73
+	{
74
+		if (get_option('ee_flush_rewrite_rules', true)) {
75
+			flush_rewrite_rules();
76
+			update_option('ee_flush_rewrite_rules', false);
77
+		}
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * By default, WordPress strips all html from term taxonomy description content.  The purpose of this method is to
84
+	 * remove that restriction and ensure that we still run ee term taxonomy descriptions through some full html
85
+	 * sanitization equivalent to the post content field.
86
+	 *
87
+	 * @since 4.7.8
88
+	 */
89
+	protected function _allow_html_descriptions_for_ee_taxonomies()
90
+	{
91
+		// first remove default filter for term description but we have to do this earlier
92
+		// before wp sets their own filter
93
+		// because they just set a global filter on all term descriptions before the custom term description filter.
94
+		// Really sux.
95
+		add_filter('pre_term_description', array($this, 'ee_filter_ee_term_description_not_wp'), 1, 2);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Callback for pre_term_description hook.
102
+	 *
103
+	 * @param string $description The description content.
104
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
105
+	 * @return string
106
+	 */
107
+	public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
108
+	{
109
+		//get a list of EE taxonomies
110
+		$ee_taxonomies = array_keys(self::get_taxonomies());
111
+		//only do our own thing if the taxonomy listed is an ee taxonomy.
112
+		if (in_array($taxonomy, $ee_taxonomies, true)) {
113
+			//remove default wp filter
114
+			remove_filter('pre_term_description', 'wp_filter_kses');
115
+			//sanitize THIS content.
116
+			$description = wp_kses($description, wp_kses_allowed_html('post'));
117
+		}
118
+		return $description;
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 *    get_taxonomies
125
+	 *
126
+	 * @access    public
127
+	 * @return    array
128
+	 */
129
+	public static function get_taxonomies()
130
+	{
131
+		// define taxonomies
132
+		return apply_filters('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array(
133
+			'espresso_event_categories' => array(
134
+				'singular_name' => __("Event Category", "event_espresso"),
135
+				'plural_name'   => __("Event Categories", "event_espresso"),
136
+				'args'          => array(
137
+					'public'            => true,
138
+					'show_in_nav_menus' => true,
139
+					'show_in_rest'      => true,
140
+					'capabilities'      => array(
141
+						'manage_terms' => 'ee_manage_event_categories',
142
+						'edit_terms'   => 'ee_edit_event_category',
143
+						'delete_terms' => 'ee_delete_event_category',
144
+						'assign_terms' => 'ee_assign_event_category',
145
+					),
146
+					'rewrite'           => array('slug' => __('event-category', 'event_espresso')),
147
+				),
148
+			),
149
+			'espresso_venue_categories' => array(
150
+				'singular_name' => __("Venue Category", "event_espresso"),
151
+				'plural_name'   => __("Venue Categories", "event_espresso"),
152
+				'args'          => array(
153
+					'public'            => true,
154
+					'show_in_nav_menus' => false, //by default this doesn't show for decaf
155
+					'show_in_rest'      => true,
156
+					'capabilities'      => array(
157
+						'manage_terms' => 'ee_manage_venue_categories',
158
+						'edit_terms'   => 'ee_edit_venue_category',
159
+						'delete_terms' => 'ee_delete_venue_category',
160
+						'assign_terms' => 'ee_assign_venue_category',
161
+					),
162
+					'rewrite'           => array('slug' => __('venue-category', 'event_espresso')),
163
+				),
164
+			),
165
+			'espresso_event_type'       => array(
166
+				'singular_name' => __("Event Type", "event_espresso"),
167
+				'plural_name'   => __("Event Types", "event_espresso"),
168
+				'args'          => array(
169
+					'public'       => true,
170
+					'show_ui'      => false,
171
+					'show_in_rest' => true,
172
+					'capabilities' => array(
173
+						'manage_terms' => 'ee_read_event_type',
174
+						'edit_terms'   => 'ee_edit_event_type',
175
+						'delete_terms' => 'ee_delete_event_type',
176
+						'assign_terms' => 'ee_assign_event_type',
177
+					),
178
+					'rewrite'      => array('slug' => __('event-type', 'event_espresso')),
179
+					'hierarchical' => true,
180
+				),
181
+			),
182
+		));
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * This returns the corresponding model name for cpts registered by EE.
189
+	 *
190
+	 * @since 4.6.16.rc.000
191
+	 * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
192
+	 *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
193
+	 *                                            model names for cpts registered in EE.
194
+	 * @return array           Empty array if no matching model names for the given slug or an array of model
195
+	 *                                            names indexed by post type slug.
196
+	 */
197
+	public static function get_cpt_model_names($post_type_slug = '')
198
+	{
199
+		$cpts = self::get_CPTs();
200
+		//first if slug passed in...
201
+		if ( ! empty($post_type_slug)) {
202
+			//match?
203
+			if (
204
+				! isset($cpts[$post_type_slug])
205
+				|| (isset($cpts[$post_type_slug]) && empty($cpts[$post_type_slug]['class_name']))
206
+			) {
207
+				return array();
208
+			}
209
+			//k let's get the model name for this cpt.
210
+			return array($post_type_slug => str_replace('EE', 'EEM', $cpts[$post_type_slug]['class_name']));
211
+		}
212
+		//if we made it here then we're returning an array of cpt model names indexed by post_type_slug.
213
+		$cpt_models = array();
214
+		foreach ($cpts as $slug => $args) {
215
+			if ( ! empty($args['class_name'])) {
216
+				$cpt_models[$slug] = str_replace('EE', 'EEM', $args['class_name']);
217
+			}
218
+		}
219
+		return $cpt_models;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * This instantiates cpt models related to the cpts registered via EE.
226
+	 *
227
+	 * @since 4.6.16.rc.000
228
+	 * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
229
+	 *                               the cpt matching the given slug.  Otherwise all cpt models will be
230
+	 *                               instantiated (if possible).
231
+	 * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
232
+	 *                               EEM models indexed by post slug.
233
+	 */
234
+	public static function instantiate_cpt_models($post_type_slug = '')
235
+	{
236
+		$cpt_model_names = self::get_cpt_model_names($post_type_slug);
237
+		$instantiated = array();
238
+		foreach ($cpt_model_names as $slug => $model_name) {
239
+			$instance = EE_Registry::instance()->load_model(str_replace('EEM_', '', $model_name));
240
+			if ($instance instanceof EEM_CPT_Base) {
241
+				$instantiated[$slug] = $instance;
242
+			}
243
+		}
244
+		return $instantiated;
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 *    get_CPTs
251
+	 *
252
+	 * @access    public
253
+	 * @return    array
254
+	 */
255
+	public static function get_CPTs()
256
+	{
257
+		// define CPTs
258
+		// NOTE the ['args']['page_templates'] array index is something specific to our CPTs
259
+		// and not part of the WP custom post type api.
260
+		return apply_filters('FHEE__EE_Register_CPTs__get_CPTs__cpts', array(
261
+			'espresso_events'    => array(
262
+				'singular_name' => __("Event", "event_espresso"),
263
+				'plural_name'   => __("Events", "event_espresso"),
264
+				'singular_slug' => __("event", "event_espresso"),
265
+				'plural_slug'   => EE_Registry::instance()->CFG->core->event_cpt_slug,
266
+				'class_name'    => 'EE_Event',
267
+				'args'          => array(
268
+					'public'            => true,
269
+					'show_in_nav_menus' => true,
270
+					'capability_type'   => 'event',
271
+					'capabilities'      => array(
272
+						'edit_post'              => 'ee_edit_event',
273
+						'read_post'              => 'ee_read_event',
274
+						'delete_post'            => 'ee_delete_event',
275
+						'edit_posts'             => 'ee_edit_events',
276
+						'edit_others_posts'      => 'ee_edit_others_events',
277
+						'publish_posts'          => 'ee_publish_events',
278
+						'read_private_posts'     => 'ee_read_private_events',
279
+						'delete_posts'           => 'ee_delete_events',
280
+						'delete_private_posts'   => 'ee_delete_private_events',
281
+						'delete_published_posts' => 'ee_delete_published_events',
282
+						'delete_others_posts'    => 'ee_delete_others_events',
283
+						'edit_private_posts'     => 'ee_edit_private_events',
284
+						'edit_published_posts'   => 'ee_edit_published_events',
285
+					),
286
+					'taxonomies'        => array(
287
+						'espresso_event_categories',
288
+						'espresso_event_type',
289
+						'post_tag',
290
+					),
291
+					'page_templates'    => true,
292
+				),
293
+			),
294
+			'espresso_venues'    => array(
295
+				'singular_name' => __("Venue", "event_espresso"),
296
+				'plural_name'   => __("Venues", "event_espresso"),
297
+				'singular_slug' => __("venue", "event_espresso"),
298
+				'plural_slug'   => __("venues", "event_espresso"),
299
+				'class_name'    => 'EE_Venue',
300
+				'args'          => array(
301
+					'public'            => true,
302
+					'show_in_nav_menus' => false, //by default this doesn't show for decaf,
303
+					'capability_type'   => 'venue',
304
+					'capabilities'      => array(
305
+						'edit_post'              => 'ee_edit_venue',
306
+						'read_post'              => 'ee_read_venue',
307
+						'delete_post'            => 'ee_delete_venue',
308
+						'edit_posts'             => 'ee_edit_venues',
309
+						'edit_others_posts'      => 'ee_edit_others_venues',
310
+						'publish_posts'          => 'ee_publish_venues',
311
+						'read_private_posts'     => 'ee_read_private_venues',
312
+						'delete_posts'           => 'ee_delete_venues',
313
+						'delete_private_posts'   => 'ee_delete_private_venues',
314
+						'delete_published_posts' => 'ee_delete_published_venues',
315
+						'delete_others_posts'    => 'ee_edit_others_venues',
316
+						'edit_private_posts'     => 'ee_edit_private_venues',
317
+						'edit_published_posts'   => 'ee_edit_published_venues',
318
+					),
319
+					'taxonomies'        => array(
320
+						'espresso_venue_categories',
321
+						'post_tag',
322
+					),
323
+					'page_templates'    => true,
324
+				),
325
+			),
326
+			'espresso_attendees' => array(
327
+				'singular_name' => __("Contact", "event_espresso"),
328
+				'plural_name'   => __("Contacts", "event_espresso"),
329
+				'singular_slug' => __("contact", "event_espresso"),
330
+				'plural_slug'   => __("contacts", "event_espresso"),
331
+				'class_name'    => 'EE_Attendee',
332
+				'args'          => array(
333
+					'public'             => false,
334
+					'publicly_queryable' => false,
335
+					'hierarchical'       => false,
336
+					'has_archive'        => false,
337
+					'taxonomies'         => array('post_tag'),
338
+					'capability_type'    => 'contact',
339
+					'capabilities'       => array(
340
+						'edit_post'              => 'ee_edit_contact',
341
+						'read_post'              => 'ee_read_contact',
342
+						'delete_post'            => 'ee_delete_contact',
343
+						'edit_posts'             => 'ee_edit_contacts',
344
+						'edit_others_posts'      => 'ee_edit_contacts',
345
+						'publish_posts'          => 'ee_edit_contacts',
346
+						'read_private_posts'     => 'ee_edit_contacts',
347
+						'delete_posts'           => 'ee_delete_contacts',
348
+						'delete_private_posts'   => 'ee_delete_contacts',
349
+						'delete_published_posts' => 'ee_delete_contacts',
350
+						'delete_others_posts'    => 'ee_delete_contacts',
351
+						'edit_private_posts'     => 'ee_edit_contacts',
352
+						'edit_published_posts'   => 'ee_edit_contacts',
353
+					),
354
+					'supports'           => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments'),
355
+				),
356
+			),
357
+		));
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * This basically goes through the CPT array and returns only CPT's
364
+	 * that have the ['args']['public'] option set as false
365
+	 *
366
+	 * @return array
367
+	 */
368
+	public static function get_private_CPTs()
369
+	{
370
+		$CPTs = self::get_CPTs();
371
+		$private_CPTs = array();
372
+		foreach ($CPTs as $CPT => $details) {
373
+			if (empty($details['args']['public'])) {
374
+				$private_CPTs[$CPT] = $details;
375
+			}
376
+		}
377
+		return $private_CPTs;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Registers a custom taxonomy. Should be called before registering custom post types,
384
+	 * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
385
+	 *
386
+	 * @param string $taxonomy_name , eg 'books'
387
+	 * @param string $singular_name internationalized singular name
388
+	 * @param string $plural_name   internationalized plural name
389
+	 * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
390
+	 */
391
+	public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
392
+	{
393
+		$args = array(
394
+			'hierarchical'      => true,
395
+			'labels'            => array(
396
+				'name'          => $plural_name,
397
+				'singular_name' => $singular_name,
398
+			),
399
+			'show_ui'           => true,
400
+			'show_ee_ui'        => true,
401
+			'show_admin_column' => true,
402
+			'query_var'         => true,
403
+			'show_in_nav_menus' => false,
404
+			'map_meta_cap'      => true
405
+			//'rewrite'           => array( 'slug' => 'genre' ),
406
+		);
407
+		if ($override_args) {
408
+			if (isset($override_args['labels'])) {
409
+				$labels = array_merge($args['labels'], $override_args['labels']);
410
+				$args['labels'] = $labels;
411
+			}
412
+			$args = array_merge($args, $override_args);
413
+		}
414
+		register_taxonomy($taxonomy_name, null, $args);
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * Registers a new custom post type. Sets default settings given only the following params.
421
+	 *
422
+	 * @param string $post_type     the actual post type name
423
+	 *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
424
+	 *                              cpt Also any models must use this slug as well)
425
+	 * @param string $singular_name a pre-internationalized string for the singular name of the objects
426
+	 * @param string $plural_name   a pre-internalized string for the plural name of the objects
427
+	 * @param array  $override_args exactly like $args as described in
428
+	 *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
429
+	 *                              set in this function will be overridden by whatever you set in $override_args
430
+	 * @param string $singular_slug
431
+	 * @param string $plural_slug
432
+	 * @return void , but registers the custom post type
433
+	 */
434
+	public function register_CPT(
435
+		$post_type,
436
+		$singular_name,
437
+		$plural_name,
438
+		$override_args = array(),
439
+		$singular_slug = '',
440
+		$plural_slug = ''
441
+	) {
442
+		$labels = array(
443
+			'name'               => $plural_name,
444
+			'singular_name'      => $singular_name,
445
+			'add_new'            => sprintf(__("Add %s", "event_espresso"), $singular_name),
446
+			'add_new_item'       => sprintf(__("Add New %s", "event_espresso"), $singular_name),
447
+			'edit_item'          => sprintf(__("Edit %s", "event_espresso"), $singular_name),
448
+			'new_item'           => sprintf(__("New %s", "event_espresso"), $singular_name),
449
+			'all_items'          => sprintf(__("All %s", "event_espresso"), $plural_name),
450
+			'view_item'          => sprintf(__("View %s", "event_espresso"), $singular_name),
451
+			'search_items'       => sprintf(__("Search %s", "event_espresso"), $plural_name),
452
+			'not_found'          => sprintf(__("No %s found", "event_espresso"), $plural_name),
453
+			'not_found_in_trash' => sprintf(__("No %s found in Trash", "event_espresso"), $plural_name),
454
+			'parent_item_colon'  => '',
455
+			'menu_name'          => sprintf(__("%s", "event_espresso"), $plural_name),
456
+		);
457
+		//verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name
458
+		// $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name;
459
+		$plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name;
460
+		//note the page_templates arg in the supports index is something specific to EE.
461
+		//  WordPress doesn't actually have that in their register_post_type api.
462
+		$args = array(
463
+			'labels'             => $labels,
464
+			'public'             => true,
465
+			'publicly_queryable' => true,
466
+			'show_ui'            => false,
467
+			'show_ee_ui'         => true,
468
+			'show_in_menu'       => false,
469
+			'show_in_nav_menus'  => false,
470
+			'query_var'          => true,
471
+			'rewrite'            => apply_filters(
472
+				'FHEE__EE_Register_CPTs__register_CPT__rewrite',
473
+				array('slug' => $plural_slug),
474
+				$post_type
475
+			),
476
+			'capability_type'    => 'post',
477
+			'map_meta_cap'       => true,
478
+			'has_archive'        => true,
479
+			'hierarchical'       => false,
480
+			'menu_position'      => null,
481
+			'supports'           => array(
482
+				'title',
483
+				'editor',
484
+				'author',
485
+				'thumbnail',
486
+				'excerpt',
487
+				'custom-fields',
488
+				'comments',
489
+			),
490
+		);
491
+		if ($override_args) {
492
+			if (isset($override_args['labels'])) {
493
+				$labels = array_merge($args['labels'], $override_args['labels']);
494
+			}
495
+			$args = array_merge($args, $override_args);
496
+			$args['labels'] = $labels;
497
+		}
498
+		register_post_type($post_type, $args);
499
+	}
500
+
501
+
502
+
503
+	public function set_must_use_event_types()
504
+	{
505
+		$term_details = array(
506
+			//Attendee's register for the first date-time only
507
+			'single-event'    => array(
508
+				__('Single Event', 'event_espresso'),
509
+				__('A single event that spans one or more consecutive days.', 'event_espresso'),
510
+			),
511
+			//example: a party or two-day long workshop
512
+			//Attendee's can register for any of the date-times
513
+			'multi-event'     => array(
514
+				__('Multi Event', 'event_espresso'),
515
+				__('Multiple, separate, but related events that occur on consecutive days.', 'event_espresso'),
516
+			),
517
+			//example: a three day music festival or week long conference
518
+			//Attendee's register for the first date-time only
519
+			'event-series'    => array(
520
+				__('Event Series', 'event_espresso'),
521
+				__(' Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
522
+			),
523
+			//example: an 8 week introduction to basket weaving course
524
+			//Attendee's can register for any of the date-times.
525
+			'recurring-event' => array(
526
+				__('Recurring Event', 'event_espresso'),
527
+				__('Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
528
+			),
529
+			//example: a yoga class
530
+			'ongoing' => array(
531
+				__('Ongoing Event', 'event_espresso'),
532
+				__('An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event',
533
+					'event_espresso'),
534
+			)
535
+			//example: access to a museum
536
+			//'walk-in' => array( __('Walk In', 'event_espresso'), __('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ),
537
+			//'reservation' => array( __('Reservation', 'event_espresso'), __('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
538
+			// 'multiple-session' => array( __('Multiple Session', 'event_espresso'), __('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
539
+			//'appointment' => array( __('Appointments', 'event_espresso'), __('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') )
540
+		);
541
+		$this->set_must_use_terms('espresso_event_type', $term_details);
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 * wrapper method for handling the setting up of initial terms in the db (if they don't already exist).
548
+	 * Note this should ONLY be used for terms that always must be present.  Be aware that if an initial term is
549
+	 * deleted then it WILL be recreated.
550
+	 *
551
+	 * @param string $taxonomy     The name of the taxonomy
552
+	 * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
553
+	 *                             description as the elements in the array
554
+	 * @return void
555
+	 */
556
+	public function set_must_use_terms($taxonomy, $term_details)
557
+	{
558
+		$term_details = (array)$term_details;
559
+		foreach ($term_details as $slug => $details) {
560
+			if ( ! term_exists($slug, $taxonomy)) {
561
+				$insert_arr = array(
562
+					'slug'        => $slug,
563
+					'description' => $details[1],
564
+				);
565
+				wp_insert_term($details[0], $taxonomy, $insert_arr);
566
+			}
567
+		}
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 * Allows us to set what the default will be for terms when a cpt is PUBLISHED.
574
+	 *
575
+	 * @param string $taxonomy  The taxonomy we're using for the default term
576
+	 * @param string $term_slug The slug of the term that will be the default.
577
+	 * @param array  $cpt_slugs An array of custom post types we want the default assigned to
578
+	 */
579
+	public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
580
+	{
581
+		$this->_default_terms[][$term_slug] = new EE_Default_Term($taxonomy, $term_slug, $cpt_slugs);
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property
588
+	 *
589
+	 * @param  int    $post_id ID of CPT being saved
590
+	 * @param  object $post    Post object
591
+	 * @return void
592
+	 */
593
+	public function save_default_term($post_id, $post)
594
+	{
595
+		if (empty($this->_default_terms)) {
596
+			return;
597
+		} //no default terms set so lets just exit.
598
+		foreach ($this->_default_terms as $defaults) {
599
+			foreach ($defaults as $default_obj) {
600
+				if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) {
601
+					//note some error proofing going on here to save unnecessary db queries
602
+					$taxonomies = get_object_taxonomies($post->post_type);
603
+					foreach ((array)$taxonomies as $taxonomy) {
604
+						$terms = wp_get_post_terms($post_id, $taxonomy);
605
+						if (empty($terms) && $taxonomy === $default_obj->taxonomy) {
606
+							wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy);
607
+						}
608
+					}
609
+				}
610
+			}
611
+		}
612
+	}
613 613
 
614 614
 }
615 615
 
@@ -623,27 +623,27 @@  discard block
 block discarded – undo
623 623
 {
624 624
 
625 625
 
626
-    //props holding the items
627
-    public $taxonomy  = '';
626
+	//props holding the items
627
+	public $taxonomy  = '';
628 628
 
629
-    public $cpt_slugs = array();
629
+	public $cpt_slugs = array();
630 630
 
631
-    public $term_slug = '';
631
+	public $term_slug = '';
632 632
 
633 633
 
634 634
 
635
-    /**
636
-     * constructor
637
-     *
638
-     * @param string $taxonomy  The taxonomy the default term belongs to
639
-     * @param string $term_slug The slug of the term that will be the default.
640
-     * @param array  $cpt_slugs The custom post type the default term gets saved with
641
-     */
642
-    public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
643
-    {
644
-        $this->taxonomy = $taxonomy;
645
-        $this->cpt_slugs = (array)$cpt_slugs;
646
-        $this->term_slug = $term_slug;
647
-    }
635
+	/**
636
+	 * constructor
637
+	 *
638
+	 * @param string $taxonomy  The taxonomy the default term belongs to
639
+	 * @param string $term_slug The slug of the term that will be the default.
640
+	 * @param array  $cpt_slugs The custom post type the default term gets saved with
641
+	 */
642
+	public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
643
+	{
644
+		$this->taxonomy = $taxonomy;
645
+		$this->cpt_slugs = (array)$cpt_slugs;
646
+		$this->term_slug = $term_slug;
647
+	}
648 648
 
649 649
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
      */
556 556
     public function set_must_use_terms($taxonomy, $term_details)
557 557
     {
558
-        $term_details = (array)$term_details;
558
+        $term_details = (array) $term_details;
559 559
         foreach ($term_details as $slug => $details) {
560 560
             if ( ! term_exists($slug, $taxonomy)) {
561 561
                 $insert_arr = array(
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
                 if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) {
601 601
                     //note some error proofing going on here to save unnecessary db queries
602 602
                     $taxonomies = get_object_taxonomies($post->post_type);
603
-                    foreach ((array)$taxonomies as $taxonomy) {
603
+                    foreach ((array) $taxonomies as $taxonomy) {
604 604
                         $terms = wp_get_post_terms($post_id, $taxonomy);
605 605
                         if (empty($terms) && $taxonomy === $default_obj->taxonomy) {
606 606
                             wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy);
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
     public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
643 643
     {
644 644
         $this->taxonomy = $taxonomy;
645
-        $this->cpt_slugs = (array)$cpt_slugs;
645
+        $this->cpt_slugs = (array) $cpt_slugs;
646 646
         $this->term_slug = $term_slug;
647 647
     }
648 648
 
Please login to merge, or discard this patch.
modules/ticket_selector/ProcessTicketSelector.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     /**
33 33
      * cancelTicketSelections
34 34
      *
35
-     * @return        string
35
+     * @return        false|null
36 36
      */
37 37
     public function cancelTicketSelections()
38 38
     {
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     /**
100 100
      * process_ticket_selections
101 101
      *
102
-     * @return array|bool
102
+     * @return boolean|null
103 103
      * @throws \EE_Error
104 104
      */
105 105
     public function processTicketSelections()
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      * validate_post_data
274 274
      *
275 275
      * @param int $id
276
-     * @return array|FALSE
276
+     * @return string
277 277
      */
278 278
     private function validatePostData($id = 0)
279 279
     {
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
      *
391 391
      * @param \EE_Ticket $ticket
392 392
      * @param int        $qty
393
-     * @return TRUE on success, FALSE on fail
393
+     * @return boolean on success, FALSE on fail
394 394
      * @throws \EE_Error
395 395
      */
396 396
     private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1)
Please login to merge, or discard this patch.
Indentation   +569 added lines, -569 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\modules\ticket_selector;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,574 +19,574 @@  discard block
 block discarded – undo
19 19
 class ProcessTicketSelector
20 20
 {
21 21
 
22
-    /**
23
-     * array of datetimes and the spaces available for them
24
-     *
25
-     * @access private
26
-     * @var array
27
-     */
28
-    private static $_available_spaces = array();
29
-
30
-
31
-
32
-    /**
33
-     * cancelTicketSelections
34
-     *
35
-     * @return        string
36
-     */
37
-    public function cancelTicketSelections()
38
-    {
39
-        // check nonce
40
-        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
41
-            return false;
42
-        }
43
-        \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
44
-        if (\EE_Registry::instance()->REQ->is_set('event_id')) {
45
-            wp_safe_redirect(
46
-                \EEH_Event_View::event_link_url(
47
-                    \EE_Registry::instance()->REQ->get('event_id')
48
-                )
49
-            );
50
-        } else {
51
-            wp_safe_redirect(
52
-                site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
53
-            );
54
-        }
55
-        exit();
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * processTicketSelectorNonce
62
-     *
63
-     * @param  string $nonce_name
64
-     * @param string  $id
65
-     * @return bool
66
-     */
67
-    private function processTicketSelectorNonce($nonce_name, $id = '')
68
-    {
69
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
70
-        if (
71
-            ! is_admin()
72
-            && (
73
-                ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id)
74
-                || ! wp_verify_nonce(
75
-                    \EE_Registry::instance()->REQ->get($nonce_name_with_id),
76
-                    $nonce_name
77
-                )
78
-            )
79
-        ) {
80
-            \EE_Error::add_error(
81
-                sprintf(
82
-                    __(
83
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
84
-                        'event_espresso'
85
-                    ),
86
-                    '<br/>'
87
-                ),
88
-                __FILE__,
89
-                __FUNCTION__,
90
-                __LINE__
91
-            );
92
-            return false;
93
-        }
94
-        return true;
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * process_ticket_selections
101
-     *
102
-     * @return array|bool
103
-     * @throws \EE_Error
104
-     */
105
-    public function processTicketSelections()
106
-    {
107
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
108
-        // do we have an event id?
109
-        if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) {
110
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
111
-            \EE_Error::add_error(
112
-                sprintf(
113
-                    __(
114
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
115
-                        'event_espresso'
116
-                    ),
117
-                    '<br/>'
118
-                ),
119
-                __FILE__,
120
-                __FUNCTION__,
121
-                __LINE__
122
-            );
123
-        }
124
-        //if event id is valid
125
-        $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id'));
126
-        // check nonce
127
-        if ( ! $this->processTicketSelectorNonce('process_ticket_selections', $id)) {
128
-            return false;
129
-        }
130
-        //		d( \EE_Registry::instance()->REQ );
131
-        self::$_available_spaces = array(
132
-            'tickets'   => array(),
133
-            'datetimes' => array(),
134
-        );
135
-        //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart.
136
-        // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc.
137
-        \EE_Registry::instance()->load_core('Session');
138
-        // unless otherwise requested, clear the session
139
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
140
-            \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
141
-        }
142
-        //d( \EE_Registry::instance()->SSN );
143
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
144
-        // validate/sanitize data
145
-        $valid = $this->validatePostData($id);
146
-        //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
147
-        //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ );
148
-        //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ );
149
-        //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ );
150
-        //check total tickets ordered vs max number of attendees that can register
151
-        if ($valid['total_tickets'] > $valid['max_atndz']) {
152
-            // ordering too many tickets !!!
153
-            $total_tickets_string = _n(
154
-                'You have attempted to purchase %s ticket.',
155
-                'You have attempted to purchase %s tickets.',
156
-                $valid['total_tickets'],
157
-                'event_espresso'
158
-            );
159
-            $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
160
-            // dev only message
161
-            $max_atndz_string = _n(
162
-                'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
163
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
164
-                $valid['max_atndz'],
165
-                'event_espresso'
166
-            );
167
-            $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
168
-            \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
169
-        } else {
170
-            // all data appears to be valid
171
-            $tckts_slctd = false;
172
-            $tickets_added = 0;
173
-            $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid);
174
-            if ($valid['total_tickets'] > 0) {
175
-                // load cart
176
-                \EE_Registry::instance()->load_core('Cart');
177
-                // cycle thru the number of data rows sent from the event listing
178
-                for ($x = 0; $x < $valid['rows']; $x++) {
179
-                    // does this row actually contain a ticket quantity?
180
-                    if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
181
-                        // YES we have a ticket quantity
182
-                        $tckts_slctd = true;
183
-                        //						d( $valid['ticket_obj'][$x] );
184
-                        if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) {
185
-                            // then add ticket to cart
186
-                            $tickets_added += $this->addTicketToCart(
187
-                                $valid['ticket_obj'][$x],
188
-                                $valid['qty'][$x]
189
-                            );
190
-                            if (\EE_Error::has_error()) {
191
-                                break;
192
-                            }
193
-                        } else {
194
-                            // nothing added to cart retrieved
195
-                            \EE_Error::add_error(
196
-                                sprintf(
197
-                                    __(
198
-                                        'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
199
-                                        'event_espresso'
200
-                                    ),
201
-                                    '<br/>'
202
-                                ),
203
-                                __FILE__, __FUNCTION__, __LINE__
204
-                            );
205
-                        }
206
-                    }
207
-                }
208
-            }
209
-            do_action(
210
-                'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
211
-                \EE_Registry::instance()->CART,
212
-                $this
213
-            );
214
-            //d( \EE_Registry::instance()->CART );
215
-            //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
216
-            if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) {
217
-                if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
218
-                    do_action(
219
-                        'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
220
-                        \EE_Registry::instance()->CART,
221
-                        $this
222
-                    );
223
-                    \EE_Registry::instance()->CART->recalculate_all_cart_totals();
224
-                    \EE_Registry::instance()->CART->save_cart(false);
225
-                    // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
226
-                    // just return TRUE for registrations being made from admin
227
-                    if (is_admin()) {
228
-                        return true;
229
-                    }
230
-                    \EE_Error::get_notices(false, true);
231
-                    wp_safe_redirect(
232
-                        apply_filters(
233
-                            'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
234
-                            \EE_Registry::instance()->CFG->core->reg_page_url()
235
-                        )
236
-                    );
237
-                    exit();
238
-                } else {
239
-                    if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) {
240
-                        // nothing added to cart
241
-                        \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'),
242
-                            __FILE__, __FUNCTION__, __LINE__);
243
-                    }
244
-                }
245
-            } else {
246
-                // no ticket quantities were selected
247
-                \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.',
248
-                    'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
249
-            }
250
-        }
251
-        //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
252
-        // at this point, just return if registration is being made from admin
253
-        if (is_admin()) {
254
-            return false;
255
-        }
256
-        if ($valid['return_url']) {
257
-            \EE_Error::get_notices(false, true);
258
-            wp_safe_redirect($valid['return_url']);
259
-            exit();
260
-        } elseif (isset($event_to_add['id'])) {
261
-            \EE_Error::get_notices(false, true);
262
-            wp_safe_redirect(get_permalink($event_to_add['id']));
263
-            exit();
264
-        } else {
265
-            echo \EE_Error::get_notices();
266
-        }
267
-        return false;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * validate_post_data
274
-     *
275
-     * @param int $id
276
-     * @return array|FALSE
277
-     */
278
-    private function validatePostData($id = 0)
279
-    {
280
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
281
-        if ( ! $id) {
282
-            \EE_Error::add_error(
283
-                __('The event id provided was not valid.', 'event_espresso'),
284
-                __FILE__,
285
-                __FUNCTION__,
286
-                __LINE__
287
-            );
288
-            return false;
289
-        }
290
-        // start with an empty array()
291
-        $valid_data = array();
292
-        // grab valid id
293
-        $valid_data['id'] = $id;
294
-        // array of other form names
295
-        $inputs_to_clean = array(
296
-            'event_id'   => 'tkt-slctr-event-id',
297
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
298
-            'rows'       => 'tkt-slctr-rows-',
299
-            'qty'        => 'tkt-slctr-qty-',
300
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
301
-            'return_url' => 'tkt-slctr-return-url-',
302
-        );
303
-        // let's track the total number of tickets ordered.'
304
-        $valid_data['total_tickets'] = 0;
305
-        // cycle through $inputs_to_clean array
306
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
307
-            // check for POST data
308
-            if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
309
-                // grab value
310
-                $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id);
311
-                switch ($what) {
312
-                    // integers
313
-                    case 'event_id':
314
-                        $valid_data[$what] = absint($input_value);
315
-                        // get event via the event id we put in the form
316
-                        $valid_data['event'] = \EE_Registry::instance()
317
-                                                           ->load_model('Event')
318
-                                                           ->get_one_by_ID($valid_data['event_id']);
319
-                        break;
320
-                    case 'rows':
321
-                    case 'max_atndz':
322
-                        $valid_data[$what] = absint($input_value);
323
-                        break;
324
-                    // arrays of integers
325
-                    case 'qty':
326
-                        /** @var array $row_qty */
327
-                        $row_qty = $input_value;
328
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
329
-                        if ( ! is_array($row_qty)) {
330
-                            // get number of rows
331
-                            $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
332
-                                ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
333
-                                : 1;
334
-                            // explode ints by the dash
335
-                            $row_qty = explode('-', $row_qty);
336
-                            $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
337
-                            $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
338
-                            $row_qty = array($row => $qty);
339
-                            for ($x = 1; $x <= $rows; $x++) {
340
-                                if ( ! isset($row_qty[$x])) {
341
-                                    $row_qty[$x] = 0;
342
-                                }
343
-                            }
344
-                        }
345
-                        ksort($row_qty);
346
-                        // cycle thru values
347
-                        foreach ($row_qty as $qty) {
348
-                            $qty = absint($qty);
349
-                            // sanitize as integers
350
-                            $valid_data[$what][] = $qty;
351
-                            $valid_data['total_tickets'] += $qty;
352
-                        }
353
-                        break;
354
-                    // array of integers
355
-                    case 'ticket_id':
356
-                        $value_array = array();
357
-                        // cycle thru values
358
-                        foreach ((array)$input_value as $key => $value) {
359
-                            // allow only numbers, letters,  spaces, commas and dashes
360
-                            $value_array[$key] = wp_strip_all_tags($value);
361
-                            // get ticket via the ticket id we put in the form
362
-                            $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value);
363
-                            $valid_data['ticket_obj'][$key] = $ticket_obj;
364
-                        }
365
-                        $valid_data[$what] = $value_array;
366
-                        break;
367
-                    case 'return_url' :
368
-                        // grab and sanitize return-url
369
-                        $input_value = esc_url_raw($input_value);
370
-                        // was the request coming from an iframe ? if so, then:
371
-                        if (strpos($input_value, 'event_list=iframe')) {
372
-                            // get anchor fragment
373
-                            $input_value = explode('#', $input_value);
374
-                            $input_value = end($input_value);
375
-                            // use event list url instead, but append anchor
376
-                            $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value;
377
-                        }
378
-                        $valid_data[$what] = $input_value;
379
-                        break;
380
-                }    // end switch $what
381
-            }
382
-        }    // end foreach $inputs_to_clean
383
-        return $valid_data;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * adds a ticket to the cart
390
-     *
391
-     * @param \EE_Ticket $ticket
392
-     * @param int        $qty
393
-     * @return TRUE on success, FALSE on fail
394
-     * @throws \EE_Error
395
-     */
396
-    private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1)
397
-    {
398
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
399
-        // get the number of spaces left for this datetime ticket
400
-        $available_spaces = $this->ticketDatetimeAvailability($ticket);
401
-        // compare available spaces against the number of tickets being purchased
402
-        if ($available_spaces >= $qty) {
403
-            // allow addons to prevent a ticket from being added to cart
404
-            if (
405
-            ! apply_filters(
406
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
407
-                true,
408
-                $ticket,
409
-                $qty,
410
-                $available_spaces
411
-            )
412
-            ) {
413
-                return false;
414
-            }
415
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
416
-            // add event to cart
417
-            if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) {
418
-                $this->recalculateTicketDatetimeAvailability($ticket, $qty);
419
-                return true;
420
-            }
421
-            return false;
422
-        }
423
-        // tickets can not be purchased but let's find the exact number left
424
-        // for the last ticket selected PRIOR to subtracting tickets
425
-        $available_spaces = $this->ticketDatetimeAvailability($ticket, true);
426
-        // greedy greedy greedy eh?
427
-        if ($available_spaces > 0) {
428
-            if (
429
-            apply_filters(
430
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error',
431
-                true,
432
-                $ticket,
433
-                $qty,
434
-                $available_spaces
435
-            )
436
-            ) {
437
-                $this->displayAvailabilityError($available_spaces);
438
-            }
439
-        } else {
440
-            \EE_Error::add_error(
441
-                __(
442
-                    'We\'re sorry, but there are no available spaces left for this event at this particular date and time.',
443
-                    'event_espresso'
444
-                ),
445
-                __FILE__, __FUNCTION__, __LINE__
446
-            );
447
-        }
448
-        return false;
449
-    }
450
-
451
-
452
-
453
-    /**
454
-     * @param int $available_spaces
455
-     * @throws \EE_Error
456
-     */
457
-    private function displayAvailabilityError($available_spaces = 1)
458
-    {
459
-        // add error messaging - we're using the _n function that will generate
460
-        // the appropriate singular or plural message based on the number of $available_spaces
461
-        if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) {
462
-            $msg = sprintf(
463
-                _n(
464
-                    'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
465
-                    'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
466
-                    $available_spaces,
467
-                    'event_espresso'
468
-                ),
469
-                $available_spaces,
470
-                '<br />'
471
-            );
472
-        } else {
473
-            $msg = sprintf(
474
-                _n(
475
-                    'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
476
-                    'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
477
-                    $available_spaces,
478
-                    'event_espresso'
479
-                ),
480
-                $available_spaces,
481
-                '<br />'
482
-            );
483
-        }
484
-        \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     * ticketDatetimeAvailability
491
-     * creates an array of tickets plus all of the datetimes available to each ticket
492
-     * and tracks the spaces remaining for each of those datetimes
493
-     *
494
-     * @param \EE_Ticket $ticket - selected ticket
495
-     * @param bool       $get_original_ticket_spaces
496
-     * @return int
497
-     * @throws \EE_Error
498
-     */
499
-    private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false)
500
-    {
501
-        // if the $_available_spaces array has not been set up yet...
502
-        if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
503
-            $this->setInitialTicketDatetimeAvailability($ticket);
504
-        }
505
-        $available_spaces = $ticket->qty() - $ticket->sold();
506
-        if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
507
-            // loop thru tickets, which will ALSO include individual ticket records AND a total
508
-            foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
509
-                // if we want the original datetime availability BEFORE we started subtracting tickets ?
510
-                if ($get_original_ticket_spaces) {
511
-                    // then grab the available spaces from the "tickets" array
512
-                    // and compare with the above to get the lowest number
513
-                    $available_spaces = min(
514
-                        $available_spaces,
515
-                        self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]
516
-                    );
517
-                } else {
518
-                    // we want the updated ticket availability as stored in the "datetimes" array
519
-                    $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]);
520
-                }
521
-            }
522
-        }
523
-        return $available_spaces;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * @param \EE_Ticket $ticket
530
-     * @return void
531
-     * @throws \EE_Error
532
-     */
533
-    private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket)
534
-    {
535
-        // first, get all of the datetimes that are available to this ticket
536
-        $datetimes = $ticket->get_many_related(
537
-            'Datetime',
538
-            array(
539
-                array(
540
-                    'DTT_EVT_end' => array(
541
-                        '>=',
542
-                        \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
543
-                    ),
544
-                ),
545
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
546
-            )
547
-        );
548
-        if ( ! empty($datetimes)) {
549
-            // now loop thru all of the datetimes
550
-            foreach ($datetimes as $datetime) {
551
-                if ($datetime instanceof \EE_Datetime) {
552
-                    // the number of spaces available for the datetime without considering individual ticket quantities
553
-                    $spaces_remaining = $datetime->spaces_remaining();
554
-                    // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold
555
-                    // or the datetime spaces remaining) to this ticket using the datetime ID as the key
556
-                    self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(
557
-                        $ticket->qty() - $ticket->sold(),
558
-                        $spaces_remaining
559
-                    );
560
-                    // if the remaining spaces for this datetime is already set,
561
-                    // then compare that against the datetime spaces remaining, and take the lowest number,
562
-                    // else just take the datetime spaces remaining, and assign to the datetimes array
563
-                    self::$_available_spaces['datetimes'][$datetime->ID()] = isset(
564
-                        self::$_available_spaces['datetimes'][$datetime->ID()]
565
-                    )
566
-                        ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining)
567
-                        : $spaces_remaining;
568
-                }
569
-            }
570
-        }
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * @param    \EE_Ticket $ticket
577
-     * @param    int        $qty
578
-     * @return    void
579
-     */
580
-    private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0)
581
-    {
582
-        if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
583
-            // loop thru tickets, which will ALSO include individual ticket records AND a total
584
-            foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
585
-                // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
586
-                self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
587
-            }
588
-        }
589
-    }
22
+	/**
23
+	 * array of datetimes and the spaces available for them
24
+	 *
25
+	 * @access private
26
+	 * @var array
27
+	 */
28
+	private static $_available_spaces = array();
29
+
30
+
31
+
32
+	/**
33
+	 * cancelTicketSelections
34
+	 *
35
+	 * @return        string
36
+	 */
37
+	public function cancelTicketSelections()
38
+	{
39
+		// check nonce
40
+		if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
41
+			return false;
42
+		}
43
+		\EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
44
+		if (\EE_Registry::instance()->REQ->is_set('event_id')) {
45
+			wp_safe_redirect(
46
+				\EEH_Event_View::event_link_url(
47
+					\EE_Registry::instance()->REQ->get('event_id')
48
+				)
49
+			);
50
+		} else {
51
+			wp_safe_redirect(
52
+				site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
53
+			);
54
+		}
55
+		exit();
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * processTicketSelectorNonce
62
+	 *
63
+	 * @param  string $nonce_name
64
+	 * @param string  $id
65
+	 * @return bool
66
+	 */
67
+	private function processTicketSelectorNonce($nonce_name, $id = '')
68
+	{
69
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
70
+		if (
71
+			! is_admin()
72
+			&& (
73
+				! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id)
74
+				|| ! wp_verify_nonce(
75
+					\EE_Registry::instance()->REQ->get($nonce_name_with_id),
76
+					$nonce_name
77
+				)
78
+			)
79
+		) {
80
+			\EE_Error::add_error(
81
+				sprintf(
82
+					__(
83
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
84
+						'event_espresso'
85
+					),
86
+					'<br/>'
87
+				),
88
+				__FILE__,
89
+				__FUNCTION__,
90
+				__LINE__
91
+			);
92
+			return false;
93
+		}
94
+		return true;
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * process_ticket_selections
101
+	 *
102
+	 * @return array|bool
103
+	 * @throws \EE_Error
104
+	 */
105
+	public function processTicketSelections()
106
+	{
107
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
108
+		// do we have an event id?
109
+		if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) {
110
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
111
+			\EE_Error::add_error(
112
+				sprintf(
113
+					__(
114
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
115
+						'event_espresso'
116
+					),
117
+					'<br/>'
118
+				),
119
+				__FILE__,
120
+				__FUNCTION__,
121
+				__LINE__
122
+			);
123
+		}
124
+		//if event id is valid
125
+		$id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id'));
126
+		// check nonce
127
+		if ( ! $this->processTicketSelectorNonce('process_ticket_selections', $id)) {
128
+			return false;
129
+		}
130
+		//		d( \EE_Registry::instance()->REQ );
131
+		self::$_available_spaces = array(
132
+			'tickets'   => array(),
133
+			'datetimes' => array(),
134
+		);
135
+		//we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart.
136
+		// When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc.
137
+		\EE_Registry::instance()->load_core('Session');
138
+		// unless otherwise requested, clear the session
139
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
140
+			\EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
141
+		}
142
+		//d( \EE_Registry::instance()->SSN );
143
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
144
+		// validate/sanitize data
145
+		$valid = $this->validatePostData($id);
146
+		//EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
147
+		//EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ );
148
+		//EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ );
149
+		//EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ );
150
+		//check total tickets ordered vs max number of attendees that can register
151
+		if ($valid['total_tickets'] > $valid['max_atndz']) {
152
+			// ordering too many tickets !!!
153
+			$total_tickets_string = _n(
154
+				'You have attempted to purchase %s ticket.',
155
+				'You have attempted to purchase %s tickets.',
156
+				$valid['total_tickets'],
157
+				'event_espresso'
158
+			);
159
+			$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
160
+			// dev only message
161
+			$max_atndz_string = _n(
162
+				'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
163
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
164
+				$valid['max_atndz'],
165
+				'event_espresso'
166
+			);
167
+			$limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
168
+			\EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
169
+		} else {
170
+			// all data appears to be valid
171
+			$tckts_slctd = false;
172
+			$tickets_added = 0;
173
+			$valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid);
174
+			if ($valid['total_tickets'] > 0) {
175
+				// load cart
176
+				\EE_Registry::instance()->load_core('Cart');
177
+				// cycle thru the number of data rows sent from the event listing
178
+				for ($x = 0; $x < $valid['rows']; $x++) {
179
+					// does this row actually contain a ticket quantity?
180
+					if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
181
+						// YES we have a ticket quantity
182
+						$tckts_slctd = true;
183
+						//						d( $valid['ticket_obj'][$x] );
184
+						if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) {
185
+							// then add ticket to cart
186
+							$tickets_added += $this->addTicketToCart(
187
+								$valid['ticket_obj'][$x],
188
+								$valid['qty'][$x]
189
+							);
190
+							if (\EE_Error::has_error()) {
191
+								break;
192
+							}
193
+						} else {
194
+							// nothing added to cart retrieved
195
+							\EE_Error::add_error(
196
+								sprintf(
197
+									__(
198
+										'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
199
+										'event_espresso'
200
+									),
201
+									'<br/>'
202
+								),
203
+								__FILE__, __FUNCTION__, __LINE__
204
+							);
205
+						}
206
+					}
207
+				}
208
+			}
209
+			do_action(
210
+				'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
211
+				\EE_Registry::instance()->CART,
212
+				$this
213
+			);
214
+			//d( \EE_Registry::instance()->CART );
215
+			//die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
216
+			if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) {
217
+				if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
218
+					do_action(
219
+						'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
220
+						\EE_Registry::instance()->CART,
221
+						$this
222
+					);
223
+					\EE_Registry::instance()->CART->recalculate_all_cart_totals();
224
+					\EE_Registry::instance()->CART->save_cart(false);
225
+					// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
226
+					// just return TRUE for registrations being made from admin
227
+					if (is_admin()) {
228
+						return true;
229
+					}
230
+					\EE_Error::get_notices(false, true);
231
+					wp_safe_redirect(
232
+						apply_filters(
233
+							'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
234
+							\EE_Registry::instance()->CFG->core->reg_page_url()
235
+						)
236
+					);
237
+					exit();
238
+				} else {
239
+					if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) {
240
+						// nothing added to cart
241
+						\EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'),
242
+							__FILE__, __FUNCTION__, __LINE__);
243
+					}
244
+				}
245
+			} else {
246
+				// no ticket quantities were selected
247
+				\EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.',
248
+					'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
249
+			}
250
+		}
251
+		//die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
252
+		// at this point, just return if registration is being made from admin
253
+		if (is_admin()) {
254
+			return false;
255
+		}
256
+		if ($valid['return_url']) {
257
+			\EE_Error::get_notices(false, true);
258
+			wp_safe_redirect($valid['return_url']);
259
+			exit();
260
+		} elseif (isset($event_to_add['id'])) {
261
+			\EE_Error::get_notices(false, true);
262
+			wp_safe_redirect(get_permalink($event_to_add['id']));
263
+			exit();
264
+		} else {
265
+			echo \EE_Error::get_notices();
266
+		}
267
+		return false;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * validate_post_data
274
+	 *
275
+	 * @param int $id
276
+	 * @return array|FALSE
277
+	 */
278
+	private function validatePostData($id = 0)
279
+	{
280
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
281
+		if ( ! $id) {
282
+			\EE_Error::add_error(
283
+				__('The event id provided was not valid.', 'event_espresso'),
284
+				__FILE__,
285
+				__FUNCTION__,
286
+				__LINE__
287
+			);
288
+			return false;
289
+		}
290
+		// start with an empty array()
291
+		$valid_data = array();
292
+		// grab valid id
293
+		$valid_data['id'] = $id;
294
+		// array of other form names
295
+		$inputs_to_clean = array(
296
+			'event_id'   => 'tkt-slctr-event-id',
297
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
298
+			'rows'       => 'tkt-slctr-rows-',
299
+			'qty'        => 'tkt-slctr-qty-',
300
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
301
+			'return_url' => 'tkt-slctr-return-url-',
302
+		);
303
+		// let's track the total number of tickets ordered.'
304
+		$valid_data['total_tickets'] = 0;
305
+		// cycle through $inputs_to_clean array
306
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
307
+			// check for POST data
308
+			if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
309
+				// grab value
310
+				$input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id);
311
+				switch ($what) {
312
+					// integers
313
+					case 'event_id':
314
+						$valid_data[$what] = absint($input_value);
315
+						// get event via the event id we put in the form
316
+						$valid_data['event'] = \EE_Registry::instance()
317
+														   ->load_model('Event')
318
+														   ->get_one_by_ID($valid_data['event_id']);
319
+						break;
320
+					case 'rows':
321
+					case 'max_atndz':
322
+						$valid_data[$what] = absint($input_value);
323
+						break;
324
+					// arrays of integers
325
+					case 'qty':
326
+						/** @var array $row_qty */
327
+						$row_qty = $input_value;
328
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
329
+						if ( ! is_array($row_qty)) {
330
+							// get number of rows
331
+							$rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
332
+								? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
333
+								: 1;
334
+							// explode ints by the dash
335
+							$row_qty = explode('-', $row_qty);
336
+							$row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
337
+							$qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
338
+							$row_qty = array($row => $qty);
339
+							for ($x = 1; $x <= $rows; $x++) {
340
+								if ( ! isset($row_qty[$x])) {
341
+									$row_qty[$x] = 0;
342
+								}
343
+							}
344
+						}
345
+						ksort($row_qty);
346
+						// cycle thru values
347
+						foreach ($row_qty as $qty) {
348
+							$qty = absint($qty);
349
+							// sanitize as integers
350
+							$valid_data[$what][] = $qty;
351
+							$valid_data['total_tickets'] += $qty;
352
+						}
353
+						break;
354
+					// array of integers
355
+					case 'ticket_id':
356
+						$value_array = array();
357
+						// cycle thru values
358
+						foreach ((array)$input_value as $key => $value) {
359
+							// allow only numbers, letters,  spaces, commas and dashes
360
+							$value_array[$key] = wp_strip_all_tags($value);
361
+							// get ticket via the ticket id we put in the form
362
+							$ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value);
363
+							$valid_data['ticket_obj'][$key] = $ticket_obj;
364
+						}
365
+						$valid_data[$what] = $value_array;
366
+						break;
367
+					case 'return_url' :
368
+						// grab and sanitize return-url
369
+						$input_value = esc_url_raw($input_value);
370
+						// was the request coming from an iframe ? if so, then:
371
+						if (strpos($input_value, 'event_list=iframe')) {
372
+							// get anchor fragment
373
+							$input_value = explode('#', $input_value);
374
+							$input_value = end($input_value);
375
+							// use event list url instead, but append anchor
376
+							$input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value;
377
+						}
378
+						$valid_data[$what] = $input_value;
379
+						break;
380
+				}    // end switch $what
381
+			}
382
+		}    // end foreach $inputs_to_clean
383
+		return $valid_data;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * adds a ticket to the cart
390
+	 *
391
+	 * @param \EE_Ticket $ticket
392
+	 * @param int        $qty
393
+	 * @return TRUE on success, FALSE on fail
394
+	 * @throws \EE_Error
395
+	 */
396
+	private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1)
397
+	{
398
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
399
+		// get the number of spaces left for this datetime ticket
400
+		$available_spaces = $this->ticketDatetimeAvailability($ticket);
401
+		// compare available spaces against the number of tickets being purchased
402
+		if ($available_spaces >= $qty) {
403
+			// allow addons to prevent a ticket from being added to cart
404
+			if (
405
+			! apply_filters(
406
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
407
+				true,
408
+				$ticket,
409
+				$qty,
410
+				$available_spaces
411
+			)
412
+			) {
413
+				return false;
414
+			}
415
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
416
+			// add event to cart
417
+			if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) {
418
+				$this->recalculateTicketDatetimeAvailability($ticket, $qty);
419
+				return true;
420
+			}
421
+			return false;
422
+		}
423
+		// tickets can not be purchased but let's find the exact number left
424
+		// for the last ticket selected PRIOR to subtracting tickets
425
+		$available_spaces = $this->ticketDatetimeAvailability($ticket, true);
426
+		// greedy greedy greedy eh?
427
+		if ($available_spaces > 0) {
428
+			if (
429
+			apply_filters(
430
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error',
431
+				true,
432
+				$ticket,
433
+				$qty,
434
+				$available_spaces
435
+			)
436
+			) {
437
+				$this->displayAvailabilityError($available_spaces);
438
+			}
439
+		} else {
440
+			\EE_Error::add_error(
441
+				__(
442
+					'We\'re sorry, but there are no available spaces left for this event at this particular date and time.',
443
+					'event_espresso'
444
+				),
445
+				__FILE__, __FUNCTION__, __LINE__
446
+			);
447
+		}
448
+		return false;
449
+	}
450
+
451
+
452
+
453
+	/**
454
+	 * @param int $available_spaces
455
+	 * @throws \EE_Error
456
+	 */
457
+	private function displayAvailabilityError($available_spaces = 1)
458
+	{
459
+		// add error messaging - we're using the _n function that will generate
460
+		// the appropriate singular or plural message based on the number of $available_spaces
461
+		if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) {
462
+			$msg = sprintf(
463
+				_n(
464
+					'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
465
+					'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
466
+					$available_spaces,
467
+					'event_espresso'
468
+				),
469
+				$available_spaces,
470
+				'<br />'
471
+			);
472
+		} else {
473
+			$msg = sprintf(
474
+				_n(
475
+					'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
476
+					'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
477
+					$available_spaces,
478
+					'event_espresso'
479
+				),
480
+				$available_spaces,
481
+				'<br />'
482
+			);
483
+		}
484
+		\EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 * ticketDatetimeAvailability
491
+	 * creates an array of tickets plus all of the datetimes available to each ticket
492
+	 * and tracks the spaces remaining for each of those datetimes
493
+	 *
494
+	 * @param \EE_Ticket $ticket - selected ticket
495
+	 * @param bool       $get_original_ticket_spaces
496
+	 * @return int
497
+	 * @throws \EE_Error
498
+	 */
499
+	private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false)
500
+	{
501
+		// if the $_available_spaces array has not been set up yet...
502
+		if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
503
+			$this->setInitialTicketDatetimeAvailability($ticket);
504
+		}
505
+		$available_spaces = $ticket->qty() - $ticket->sold();
506
+		if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
507
+			// loop thru tickets, which will ALSO include individual ticket records AND a total
508
+			foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
509
+				// if we want the original datetime availability BEFORE we started subtracting tickets ?
510
+				if ($get_original_ticket_spaces) {
511
+					// then grab the available spaces from the "tickets" array
512
+					// and compare with the above to get the lowest number
513
+					$available_spaces = min(
514
+						$available_spaces,
515
+						self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]
516
+					);
517
+				} else {
518
+					// we want the updated ticket availability as stored in the "datetimes" array
519
+					$available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]);
520
+				}
521
+			}
522
+		}
523
+		return $available_spaces;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * @param \EE_Ticket $ticket
530
+	 * @return void
531
+	 * @throws \EE_Error
532
+	 */
533
+	private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket)
534
+	{
535
+		// first, get all of the datetimes that are available to this ticket
536
+		$datetimes = $ticket->get_many_related(
537
+			'Datetime',
538
+			array(
539
+				array(
540
+					'DTT_EVT_end' => array(
541
+						'>=',
542
+						\EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
543
+					),
544
+				),
545
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
546
+			)
547
+		);
548
+		if ( ! empty($datetimes)) {
549
+			// now loop thru all of the datetimes
550
+			foreach ($datetimes as $datetime) {
551
+				if ($datetime instanceof \EE_Datetime) {
552
+					// the number of spaces available for the datetime without considering individual ticket quantities
553
+					$spaces_remaining = $datetime->spaces_remaining();
554
+					// save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold
555
+					// or the datetime spaces remaining) to this ticket using the datetime ID as the key
556
+					self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(
557
+						$ticket->qty() - $ticket->sold(),
558
+						$spaces_remaining
559
+					);
560
+					// if the remaining spaces for this datetime is already set,
561
+					// then compare that against the datetime spaces remaining, and take the lowest number,
562
+					// else just take the datetime spaces remaining, and assign to the datetimes array
563
+					self::$_available_spaces['datetimes'][$datetime->ID()] = isset(
564
+						self::$_available_spaces['datetimes'][$datetime->ID()]
565
+					)
566
+						? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining)
567
+						: $spaces_remaining;
568
+				}
569
+			}
570
+		}
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * @param    \EE_Ticket $ticket
577
+	 * @param    int        $qty
578
+	 * @return    void
579
+	 */
580
+	private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0)
581
+	{
582
+		if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
583
+			// loop thru tickets, which will ALSO include individual ticket records AND a total
584
+			foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
585
+				// subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
586
+				self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
587
+			}
588
+		}
589
+	}
590 590
 
591 591
 
592 592
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
             );
50 50
         } else {
51 51
             wp_safe_redirect(
52
-                site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
52
+                site_url('/'.\EE_Registry::instance()->CFG->core->event_cpt_slug.'/')
53 53
             );
54 54
         }
55 55
         exit();
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                 'event_espresso'
166 166
             );
167 167
             $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
168
-            \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
168
+            \EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
169 169
         } else {
170 170
             // all data appears to be valid
171 171
             $tckts_slctd = false;
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
         // cycle through $inputs_to_clean array
306 306
         foreach ($inputs_to_clean as $what => $input_to_clean) {
307 307
             // check for POST data
308
-            if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
308
+            if (\EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) {
309 309
                 // grab value
310
-                $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id);
310
+                $input_value = \EE_Registry::instance()->REQ->get($input_to_clean.$id);
311 311
                 switch ($what) {
312 312
                     // integers
313 313
                     case 'event_id':
@@ -328,8 +328,8 @@  discard block
 block discarded – undo
328 328
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
329 329
                         if ( ! is_array($row_qty)) {
330 330
                             // get number of rows
331
-                            $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
332
-                                ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
331
+                            $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id)
332
+                                ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id))
333 333
                                 : 1;
334 334
                             // explode ints by the dash
335 335
                             $row_qty = explode('-', $row_qty);
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
                     case 'ticket_id':
356 356
                         $value_array = array();
357 357
                         // cycle thru values
358
-                        foreach ((array)$input_value as $key => $value) {
358
+                        foreach ((array) $input_value as $key => $value) {
359 359
                             // allow only numbers, letters,  spaces, commas and dashes
360 360
                             $value_array[$key] = wp_strip_all_tags($value);
361 361
                             // get ticket via the ticket id we put in the form
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
                             $input_value = explode('#', $input_value);
374 374
                             $input_value = end($input_value);
375 375
                             // use event list url instead, but append anchor
376
-                            $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value;
376
+                            $input_value = \EEH_Event_View::event_archive_url().'#'.$input_value;
377 377
                         }
378 378
                         $valid_data[$what] = $input_value;
379 379
                         break;
Please login to merge, or discard this patch.