Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created
core/services/notices/NoticeConverter.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -17,79 +17,79 @@
 block discarded – undo
17 17
 abstract class NoticeConverter implements NoticeConverterInterface
18 18
 {
19 19
 
20
-    /**
21
-     * @var NoticesContainerInterface $notices
22
-     */
23
-    private $notices;
20
+	/**
21
+	 * @var NoticesContainerInterface $notices
22
+	 */
23
+	private $notices;
24 24
 
25
-    /**
26
-     * if set to true, then errors will be thrown as exceptions
27
-     *
28
-     * @var boolean $throw_exceptions
29
-     */
30
-    private $throw_exceptions;
25
+	/**
26
+	 * if set to true, then errors will be thrown as exceptions
27
+	 *
28
+	 * @var boolean $throw_exceptions
29
+	 */
30
+	private $throw_exceptions;
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * NoticeConverter constructor.
36
-     *
37
-     * @param bool                      $throw_exceptions
38
-     */
39
-    public function __construct($throw_exceptions = false)
40
-    {
41
-        $this->throw_exceptions = $throw_exceptions;
42
-    }
34
+	/**
35
+	 * NoticeConverter constructor.
36
+	 *
37
+	 * @param bool                      $throw_exceptions
38
+	 */
39
+	public function __construct($throw_exceptions = false)
40
+	{
41
+		$this->throw_exceptions = $throw_exceptions;
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * @return NoticesContainerInterface
48
-     */
49
-    public function getNotices()
50
-    {
51
-        return $this->notices;
52
-    }
46
+	/**
47
+	 * @return NoticesContainerInterface
48
+	 */
49
+	public function getNotices()
50
+	{
51
+		return $this->notices;
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @param NoticesContainerInterface $notices
58
-     */
59
-    protected function setNotices(NoticesContainerInterface $notices)
60
-    {
61
-        $this->notices = $notices;
62
-    }
56
+	/**
57
+	 * @param NoticesContainerInterface $notices
58
+	 */
59
+	protected function setNotices(NoticesContainerInterface $notices)
60
+	{
61
+		$this->notices = $notices;
62
+	}
63 63
 
64 64
 
65 65
 
66
-    /**
67
-     * @return bool
68
-     */
69
-    public function getThrowExceptions()
70
-    {
71
-        return $this->throw_exceptions;
72
-    }
66
+	/**
67
+	 * @return bool
68
+	 */
69
+	public function getThrowExceptions()
70
+	{
71
+		return $this->throw_exceptions;
72
+	}
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     * @param bool $throw_exceptions
78
-     */
79
-    public function setThrowExceptions($throw_exceptions)
80
-    {
81
-        $this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN);
82
-    }
76
+	/**
77
+	 * @param bool $throw_exceptions
78
+	 */
79
+	public function setThrowExceptions($throw_exceptions)
80
+	{
81
+		$this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN);
82
+	}
83 83
 
84 84
 
85 85
 
86
-    /**
87
-     * @return void;
88
-     */
89
-    public function clearNotices()
90
-    {
91
-        $this->notices = null;
92
-    }
86
+	/**
87
+	 * @return void;
88
+	 */
89
+	public function clearNotices()
90
+	{
91
+		$this->notices = null;
92
+	}
93 93
 
94 94
 
95 95
 }
Please login to merge, or discard this patch.
core/db_models/EEM_WP_User.model.php 2 patches
Indentation   +115 added lines, -115 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
 
@@ -15,129 +15,129 @@  discard block
 block discarded – undo
15 15
 class EEM_WP_User extends EEM_Base
16 16
 {
17 17
 
18
-    /**
19
-     * private instance of the EEM_WP_User object
20
-     *
21
-     * @type EEM_WP_User
22
-     */
23
-    protected static $_instance = null;
18
+	/**
19
+	 * private instance of the EEM_WP_User object
20
+	 *
21
+	 * @type EEM_WP_User
22
+	 */
23
+	protected static $_instance = null;
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     *    constructor
29
-     *
30
-     * @param null $timezone
31
-     * @throws \EE_Error
32
-     */
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('WP_User', 'event_espresso');
36
-        $this->plural_item = __('WP_Users', 'event_espresso');
37
-        global $wpdb;
38
-        $this->_tables = array(
39
-            'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
40
-        );
41
-        $this->_fields = array(
42
-            'WP_User' => array(
43
-                'ID'                  => new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')),
44
-                'user_login'          => new EE_Plain_Text_Field(
45
-                    'user_login',
46
-                    __('User Login', 'event_espresso'),
47
-                    false,
48
-                    ''
49
-                ),
50
-                'user_pass'           => new EE_Plain_Text_Field(
51
-                    'user_pass',
52
-                    __('User Password', 'event_espresso'),
53
-                    false,
54
-                    ''
55
-                ),
56
-                'user_nicename'       => new EE_Plain_Text_Field(
57
-                    'user_nicename',
58
-                    __(' User Nice Name', 'event_espresso'),
59
-                    false,
60
-                    ''
61
-                ),
62
-                'user_email'          => new EE_Email_Field(
63
-                    'user_email',
64
-                    __('User Email', 'event_espresso'),
65
-                    false
66
-                ),
67
-                'user_registered'     => new EE_Datetime_Field(
68
-                    'user_registered',
69
-                    __('Date User Registered', 'event_espresso'),
70
-                    false,
71
-                    EE_Datetime_Field::now,
72
-                    $timezone
73
-                ),
74
-                'user_activation_key' => new EE_Plain_Text_Field(
75
-                    'user_activation_key',
76
-                    __('User Activation Key', 'event_espresso'),
77
-                    false,
78
-                    ''
79
-                ),
80
-                'user_status'         => new EE_Integer_Field(
81
-                    'user_status',
82
-                    __('User Status', 'event_espresso'),
83
-                    false,
84
-                    0
85
-                ),
86
-                'display_name'        => new EE_Plain_Text_Field(
87
-                    'display_name',
88
-                    __('Display Name', 'event_espresso'),
89
-                    false,
90
-                    ''
91
-                ),
92
-            ),
93
-        );
94
-        $this->_model_relations = array(
95
-            'Attendee'       => new EE_Has_Many_Relation(),
96
-            'Change_Log'     => new EE_Has_Many_Relation(),
97
-            'Event'          => new EE_Has_Many_Relation(),
98
-            'Payment_Method' => new EE_Has_Many_Relation(),
99
-            'Price'          => new EE_Has_Many_Relation(),
100
-            'Price_Type'     => new EE_Has_Many_Relation(),
101
-            'Question'       => new EE_Has_Many_Relation(),
102
-            'Question_Group' => new EE_Has_Many_Relation(),
103
-            'Ticket'         => new EE_Has_Many_Relation(),
104
-            'Venue'          => new EE_Has_Many_Relation(),
105
-            'Message'        => new EE_Has_Many_Relation(),
106
-        );
107
-        $this->_wp_core_model = true;
108
-        $this->_caps_slug = 'users';
109
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
110
-        $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
111
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
112
-            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
113
-        }
114
-        //@todo: account for create_users controls whether they can create users at all
115
-        parent::__construct($timezone);
116
-    }
27
+	/**
28
+	 *    constructor
29
+	 *
30
+	 * @param null $timezone
31
+	 * @throws \EE_Error
32
+	 */
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('WP_User', 'event_espresso');
36
+		$this->plural_item = __('WP_Users', 'event_espresso');
37
+		global $wpdb;
38
+		$this->_tables = array(
39
+			'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true),
40
+		);
41
+		$this->_fields = array(
42
+			'WP_User' => array(
43
+				'ID'                  => new EE_Primary_Key_Int_Field('ID', __('WP_User ID', 'event_espresso')),
44
+				'user_login'          => new EE_Plain_Text_Field(
45
+					'user_login',
46
+					__('User Login', 'event_espresso'),
47
+					false,
48
+					''
49
+				),
50
+				'user_pass'           => new EE_Plain_Text_Field(
51
+					'user_pass',
52
+					__('User Password', 'event_espresso'),
53
+					false,
54
+					''
55
+				),
56
+				'user_nicename'       => new EE_Plain_Text_Field(
57
+					'user_nicename',
58
+					__(' User Nice Name', 'event_espresso'),
59
+					false,
60
+					''
61
+				),
62
+				'user_email'          => new EE_Email_Field(
63
+					'user_email',
64
+					__('User Email', 'event_espresso'),
65
+					false
66
+				),
67
+				'user_registered'     => new EE_Datetime_Field(
68
+					'user_registered',
69
+					__('Date User Registered', 'event_espresso'),
70
+					false,
71
+					EE_Datetime_Field::now,
72
+					$timezone
73
+				),
74
+				'user_activation_key' => new EE_Plain_Text_Field(
75
+					'user_activation_key',
76
+					__('User Activation Key', 'event_espresso'),
77
+					false,
78
+					''
79
+				),
80
+				'user_status'         => new EE_Integer_Field(
81
+					'user_status',
82
+					__('User Status', 'event_espresso'),
83
+					false,
84
+					0
85
+				),
86
+				'display_name'        => new EE_Plain_Text_Field(
87
+					'display_name',
88
+					__('Display Name', 'event_espresso'),
89
+					false,
90
+					''
91
+				),
92
+			),
93
+		);
94
+		$this->_model_relations = array(
95
+			'Attendee'       => new EE_Has_Many_Relation(),
96
+			'Change_Log'     => new EE_Has_Many_Relation(),
97
+			'Event'          => new EE_Has_Many_Relation(),
98
+			'Payment_Method' => new EE_Has_Many_Relation(),
99
+			'Price'          => new EE_Has_Many_Relation(),
100
+			'Price_Type'     => new EE_Has_Many_Relation(),
101
+			'Question'       => new EE_Has_Many_Relation(),
102
+			'Question_Group' => new EE_Has_Many_Relation(),
103
+			'Ticket'         => new EE_Has_Many_Relation(),
104
+			'Venue'          => new EE_Has_Many_Relation(),
105
+			'Message'        => new EE_Has_Many_Relation(),
106
+		);
107
+		$this->_wp_core_model = true;
108
+		$this->_caps_slug = 'users';
109
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list';
110
+		$this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list';
111
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
112
+			$this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User();
113
+		}
114
+		//@todo: account for create_users controls whether they can create users at all
115
+		parent::__construct($timezone);
116
+	}
117 117
 
118 118
 
119 119
 
120
-    /**
121
-     * We don't need a foreign key to the WP_User model, we just need its primary key
122
-     *
123
-     * @return string
124
-     */
125
-    public function wp_user_field_name()
126
-    {
127
-        return $this->primary_key_name();
128
-    }
120
+	/**
121
+	 * We don't need a foreign key to the WP_User model, we just need its primary key
122
+	 *
123
+	 * @return string
124
+	 */
125
+	public function wp_user_field_name()
126
+	{
127
+		return $this->primary_key_name();
128
+	}
129 129
 
130 130
 
131 131
 
132
-    /**
133
-     * This WP_User model IS owned, even though it doesn't have a foreign key to itself
134
-     *
135
-     * @return boolean
136
-     */
137
-    public function is_owned()
138
-    {
139
-        return true;
140
-    }
132
+	/**
133
+	 * This WP_User model IS owned, even though it doesn't have a foreign key to itself
134
+	 *
135
+	 * @return boolean
136
+	 */
137
+	public function is_owned()
138
+	{
139
+		return true;
140
+	}
141 141
 }
142 142
 // End of file EEM_WP_User.model.php
143 143
 // Location: /core/db_models/EEM_WP_User.model.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Taxonomy.model.php 2 patches
Indentation   +116 added lines, -116 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
  * Event Espresso
@@ -25,127 +25,127 @@  discard block
 block discarded – undo
25 25
 class EEM_Term_Taxonomy extends EEM_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32 32
 
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('Term Taxonomy', 'event_espresso');
36
-        $this->plural_item = __('Term Taxonomy', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
39
-        );
40
-        $this->_fields = array(
41
-            'Term_Taxonomy' => array(
42
-                'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
43
-                    'term_taxonomy_id',
44
-                    __('Term-Taxonomy ID', 'event_espresso')
45
-                ),
46
-                'term_id'          => new EE_Foreign_Key_Int_Field(
47
-                    'term_id',
48
-                    __("Term Id", "event_espresso"),
49
-                    false,
50
-                    0,
51
-                    'Term'
52
-                ),
53
-                'taxonomy'         => new EE_Plain_Text_Field(
54
-                    'taxonomy',
55
-                    __('Taxonomy Name', 'event_espresso'),
56
-                    false,
57
-                    'category'
58
-                ),
59
-                'description'      => new EE_Post_Content_Field(
60
-                    'description',
61
-                    __("Description of Term", "event_espresso"),
62
-                    false,
63
-                    ''
64
-                ),
65
-                'parent'           => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0),
66
-                'term_count'       => new EE_Integer_Field(
67
-                    'count',
68
-                    __("Count of Objects attached", 'event_espresso'),
69
-                    false,
70
-                    0
71
-                ),
72
-            ),
73
-        );
74
-        $this->_model_relations = array(
75
-            'Term_Relationship' => new EE_Has_Many_Relation(),
76
-            'Term'              => new EE_Belongs_To_Relation(),
77
-        );
78
-        $cpt_models = array_keys(EE_Registry::instance()->cpt_models());
79
-        foreach ($cpt_models as $model_name) {
80
-            $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship');
81
-        }
82
-        $this->_indexes = array(
83
-            'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')),
84
-        );
85
-        $path_to_tax_model = '';
86
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
87
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected(
88
-            $path_to_tax_model
89
-        );
90
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = false;
91
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = false;
92
-        //add cap restrictions for editing relating to the "ee_edit_*"
93
-        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
94
-            array(
95
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
96
-            )
97
-        );
98
-        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
99
-            array(
100
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
101
-            )
102
-        );
103
-        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
104
-            array(
105
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
106
-            )
107
-        );
108
-        //add cap restrictions for deleting relating to the "ee_deleting_*"
109
-        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
110
-            array(
111
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
112
-            )
113
-        );
114
-        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
115
-            array(
116
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
117
-            )
118
-        );
119
-        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
120
-            array(
121
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
122
-            )
123
-        );
124
-        parent::__construct($timezone);
125
-        add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3);
126
-    }
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('Term Taxonomy', 'event_espresso');
36
+		$this->plural_item = __('Term Taxonomy', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
39
+		);
40
+		$this->_fields = array(
41
+			'Term_Taxonomy' => array(
42
+				'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
43
+					'term_taxonomy_id',
44
+					__('Term-Taxonomy ID', 'event_espresso')
45
+				),
46
+				'term_id'          => new EE_Foreign_Key_Int_Field(
47
+					'term_id',
48
+					__("Term Id", "event_espresso"),
49
+					false,
50
+					0,
51
+					'Term'
52
+				),
53
+				'taxonomy'         => new EE_Plain_Text_Field(
54
+					'taxonomy',
55
+					__('Taxonomy Name', 'event_espresso'),
56
+					false,
57
+					'category'
58
+				),
59
+				'description'      => new EE_Post_Content_Field(
60
+					'description',
61
+					__("Description of Term", "event_espresso"),
62
+					false,
63
+					''
64
+				),
65
+				'parent'           => new EE_Integer_Field('parent', __("Parent Term ID", "event_espresso"), false, 0),
66
+				'term_count'       => new EE_Integer_Field(
67
+					'count',
68
+					__("Count of Objects attached", 'event_espresso'),
69
+					false,
70
+					0
71
+				),
72
+			),
73
+		);
74
+		$this->_model_relations = array(
75
+			'Term_Relationship' => new EE_Has_Many_Relation(),
76
+			'Term'              => new EE_Belongs_To_Relation(),
77
+		);
78
+		$cpt_models = array_keys(EE_Registry::instance()->cpt_models());
79
+		foreach ($cpt_models as $model_name) {
80
+			$this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship');
81
+		}
82
+		$this->_indexes = array(
83
+			'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')),
84
+		);
85
+		$path_to_tax_model = '';
86
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
87
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected(
88
+			$path_to_tax_model
89
+		);
90
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = false;
91
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = false;
92
+		//add cap restrictions for editing relating to the "ee_edit_*"
93
+		$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
94
+			array(
95
+				$path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
96
+			)
97
+		);
98
+		$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
99
+			array(
100
+				$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
101
+			)
102
+		);
103
+		$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
104
+			array(
105
+				$path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
106
+			)
107
+		);
108
+		//add cap restrictions for deleting relating to the "ee_deleting_*"
109
+		$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
110
+			array(
111
+				$path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
112
+			)
113
+		);
114
+		$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
115
+			array(
116
+				$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
117
+			)
118
+		);
119
+		$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
120
+			array(
121
+				$path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
122
+			)
123
+		);
124
+		parent::__construct($timezone);
125
+		add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3);
126
+	}
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * Makes sure that during REST API queries, we only return term-taxonomies
132
-     * for term taxonomies which should be shown in the rest api
133
-     *
134
-     * @param array    $model_query_params
135
-     * @param array    $querystring_query_params
136
-     * @param EEM_Base $model
137
-     * @return array
138
-     */
139
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
140
-    {
141
-        if ($model === EEM_Term_Taxonomy::instance()) {
142
-            $taxonomies = get_taxonomies(array('show_in_rest' => true));
143
-            if (! empty($taxonomies)) {
144
-                $model_query_params[0]['taxonomy'] = array('IN', $taxonomies);
145
-            }
146
-        }
147
-        return $model_query_params;
148
-    }
130
+	/**
131
+	 * Makes sure that during REST API queries, we only return term-taxonomies
132
+	 * for term taxonomies which should be shown in the rest api
133
+	 *
134
+	 * @param array    $model_query_params
135
+	 * @param array    $querystring_query_params
136
+	 * @param EEM_Base $model
137
+	 * @return array
138
+	 */
139
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
140
+	{
141
+		if ($model === EEM_Term_Taxonomy::instance()) {
142
+			$taxonomies = get_taxonomies(array('show_in_rest' => true));
143
+			if (! empty($taxonomies)) {
144
+				$model_query_params[0]['taxonomy'] = array('IN', $taxonomies);
145
+			}
146
+		}
147
+		return $model_query_params;
148
+	}
149 149
 }
150 150
 // End of file EEM_Term_Taxonomy.model.php
151 151
 // Location: /includes/models/EEM_Term_Taxonomy.model.php
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * @author                Michael Nelson
19 19
  * ------------------------------------------------------------------------
20 20
  */
21
-require_once(EE_MODELS . 'EEM_Base.model.php');
21
+require_once(EE_MODELS.'EEM_Base.model.php');
22 22
 
23 23
 
24 24
 
@@ -92,33 +92,33 @@  discard block
 block discarded – undo
92 92
         //add cap restrictions for editing relating to the "ee_edit_*"
93 93
         $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
94 94
             array(
95
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
95
+                $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
96 96
             )
97 97
         );
98 98
         $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
99 99
             array(
100
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
100
+                $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
101 101
             )
102 102
         );
103 103
         $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
104 104
             array(
105
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
105
+                $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
106 106
             )
107 107
         );
108 108
         //add cap restrictions for deleting relating to the "ee_deleting_*"
109 109
         $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
110 110
             array(
111
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
111
+                $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
112 112
             )
113 113
         );
114 114
         $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
115 115
             array(
116
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
116
+                $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
117 117
             )
118 118
         );
119 119
         $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
120 120
             array(
121
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
121
+                $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
122 122
             )
123 123
         );
124 124
         parent::__construct($timezone);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     {
141 141
         if ($model === EEM_Term_Taxonomy::instance()) {
142 142
             $taxonomies = get_taxonomies(array('show_in_rest' => true));
143
-            if (! empty($taxonomies)) {
143
+            if ( ! empty($taxonomies)) {
144 144
                 $model_query_params[0]['taxonomy'] = array('IN', $taxonomies);
145 145
             }
146 146
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Term.model.php 2 patches
Indentation   +201 added lines, -201 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
 
@@ -15,206 +15,206 @@  discard block
 block discarded – undo
15 15
 class EEM_Term extends EEM_Base
16 16
 {
17 17
 
18
-    // private instance of the Attendee object
19
-    protected static $_instance = null;
20
-
21
-
22
-
23
-    /**
24
-     *__construct
25
-     *
26
-     * @param string $timezone
27
-     */
28
-    protected function __construct($timezone = null)
29
-    {
30
-        $this->singular_item = __('Term', 'event_espresso');
31
-        $this->plural_item = __('Terms', 'event_espresso');
32
-        $this->_tables = array(
33
-            'Term' => new EE_Primary_Table('terms', 'term_id'),
34
-        );
35
-        $this->_fields = array(
36
-            'Term' => array(
37
-                'term_id'    => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')),
38
-                'name'       => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''),
39
-                'slug'       => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false),
40
-                'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0),
41
-            ),
42
-        );
43
-        $this->_model_relations = array(
44
-            'Term_Taxonomy' => new EE_Has_Many_Relation(),
45
-        );
46
-        $path_to_tax_model = 'Term_Taxonomy';
47
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
48
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected(
49
-            $path_to_tax_model
50
-        );
51
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = false;
52
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = false;
53
-        $path_to_tax_model = $path_to_tax_model . '.';
54
-        //add cap restrictions for editing relating to the "ee_edit_*"
55
-        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
56
-            array(
57
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
58
-            )
59
-        );
60
-        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
61
-            array(
62
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
63
-            )
64
-        );
65
-        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
66
-            array(
67
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
68
-            )
69
-        );
70
-        //add cap restrictions for deleting relating to the "ee_deleting_*"
71
-        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
72
-            array(
73
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
74
-            )
75
-        );
76
-        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
77
-            array(
78
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
79
-            )
80
-        );
81
-        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
82
-            array(
83
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
84
-            )
85
-        );
86
-        parent::__construct($timezone);
87
-        add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3);
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * retrieves a list of all EE event categories
94
-     *
95
-     * @access public
96
-     * @param bool $show_uncategorized
97
-     * @return \EE_Base_Class[]
98
-     */
99
-    public function get_all_ee_categories($show_uncategorized = false)
100
-    {
101
-        $where_params = array(
102
-            'Term_Taxonomy.taxonomy' => 'espresso_event_categories',
103
-            'NOT'                    => array('name' => __('Uncategorized', 'event_espresso')),
104
-        );
105
-        if ($show_uncategorized) {
106
-            unset($where_params['NOT']);
107
-        }
108
-        return EEM_Term::instance()->get_all(
109
-            array(
110
-                $where_params,
111
-                'order_by' => array('name' => 'ASC'),
112
-            )
113
-        );
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * retrieves a list of all post_tags associated with an EE CPT
120
-     *
121
-     * @access public
122
-     * @param string $post_type
123
-     * @return array
124
-     */
125
-    public function get_all_CPT_post_tags($post_type = '')
126
-    {
127
-        switch ($post_type) {
128
-            case 'espresso_events':
129
-                return $this->get_all_event_post_tags();
130
-                break;
131
-            case 'espresso_venues':
132
-                return $this->get_all_venue_post_tags();
133
-                break;
134
-            default:
135
-                $event_tags = $this->get_all_event_post_tags();
136
-                $venue_tags = $this->get_all_venue_post_tags();
137
-                return array_merge($event_tags, $venue_tags);
138
-        }
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * get_all_event_post_tags
145
-     *
146
-     * @return EE_Base_Class[]
147
-     */
148
-    public function get_all_event_post_tags()
149
-    {
150
-        $post_tags = EEM_Term::instance()->get_all(
151
-            array(
152
-                array(
153
-                    'Term_Taxonomy.taxonomy'        => 'post_tag',
154
-                    'Term_Taxonomy.Event.post_type' => 'espresso_events',
155
-                ),
156
-                'order_by'   => array('name' => 'ASC'),
157
-                'force_join' => array('Term_Taxonomy.Event'),
158
-            )
159
-        );
160
-        foreach ($post_tags as $key => $post_tag) {
161
-            if (! isset($post_tags[$key]->post_type)) {
162
-                $post_tags[$key]->post_type = array();
163
-            }
164
-            $post_tags[$key]->post_type[] = 'espresso_events';
165
-        }
166
-        return $post_tags;
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * get_all_venue_post_tags
173
-     *
174
-     * @return EE_Base_Class[]
175
-     */
176
-    public function get_all_venue_post_tags()
177
-    {
178
-        $post_tags = EEM_Term::instance()->get_all(
179
-            array(
180
-                array(
181
-                    'Term_Taxonomy.taxonomy'        => 'post_tag',
182
-                    'Term_Taxonomy.Venue.post_type' => 'espresso_venues',
183
-                ),
184
-                'order_by'   => array('name' => 'ASC'),
185
-                'force_join' => array('Term_Taxonomy'),
186
-            )
187
-        );
188
-        foreach ($post_tags as $key => $post_tag) {
189
-            if (! isset($post_tags[$key]->post_type)) {
190
-                $post_tags[$key]->post_type = array();
191
-            }
192
-            $post_tags[$key]->post_type[] = 'espresso_venues';
193
-        }
194
-        return $post_tags;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * Makes sure that during REST API queries, we only return terms
201
-     * for term taxonomies which should be shown in the rest api
202
-     *
203
-     * @param array    $model_query_params
204
-     * @param array    $querystring_query_params
205
-     * @param EEM_Base $model
206
-     * @return array
207
-     */
208
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
209
-    {
210
-        if ($model === EEM_Term::instance()) {
211
-            $taxonomies = get_taxonomies(array('show_in_rest' => true));
212
-            if (! empty($taxonomies)) {
213
-                $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
214
-            }
215
-        }
216
-        return $model_query_params;
217
-    }
18
+	// private instance of the Attendee object
19
+	protected static $_instance = null;
20
+
21
+
22
+
23
+	/**
24
+	 *__construct
25
+	 *
26
+	 * @param string $timezone
27
+	 */
28
+	protected function __construct($timezone = null)
29
+	{
30
+		$this->singular_item = __('Term', 'event_espresso');
31
+		$this->plural_item = __('Terms', 'event_espresso');
32
+		$this->_tables = array(
33
+			'Term' => new EE_Primary_Table('terms', 'term_id'),
34
+		);
35
+		$this->_fields = array(
36
+			'Term' => array(
37
+				'term_id'    => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')),
38
+				'name'       => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''),
39
+				'slug'       => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false),
40
+				'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0),
41
+			),
42
+		);
43
+		$this->_model_relations = array(
44
+			'Term_Taxonomy' => new EE_Has_Many_Relation(),
45
+		);
46
+		$path_to_tax_model = 'Term_Taxonomy';
47
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
48
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected(
49
+			$path_to_tax_model
50
+		);
51
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = false;
52
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = false;
53
+		$path_to_tax_model = $path_to_tax_model . '.';
54
+		//add cap restrictions for editing relating to the "ee_edit_*"
55
+		$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
56
+			array(
57
+				$path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
58
+			)
59
+		);
60
+		$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
61
+			array(
62
+				$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
63
+			)
64
+		);
65
+		$this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
66
+			array(
67
+				$path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
68
+			)
69
+		);
70
+		//add cap restrictions for deleting relating to the "ee_deleting_*"
71
+		$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
72
+			array(
73
+				$path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
74
+			)
75
+		);
76
+		$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
77
+			array(
78
+				$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
79
+			)
80
+		);
81
+		$this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
82
+			array(
83
+				$path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
84
+			)
85
+		);
86
+		parent::__construct($timezone);
87
+		add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3);
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * retrieves a list of all EE event categories
94
+	 *
95
+	 * @access public
96
+	 * @param bool $show_uncategorized
97
+	 * @return \EE_Base_Class[]
98
+	 */
99
+	public function get_all_ee_categories($show_uncategorized = false)
100
+	{
101
+		$where_params = array(
102
+			'Term_Taxonomy.taxonomy' => 'espresso_event_categories',
103
+			'NOT'                    => array('name' => __('Uncategorized', 'event_espresso')),
104
+		);
105
+		if ($show_uncategorized) {
106
+			unset($where_params['NOT']);
107
+		}
108
+		return EEM_Term::instance()->get_all(
109
+			array(
110
+				$where_params,
111
+				'order_by' => array('name' => 'ASC'),
112
+			)
113
+		);
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * retrieves a list of all post_tags associated with an EE CPT
120
+	 *
121
+	 * @access public
122
+	 * @param string $post_type
123
+	 * @return array
124
+	 */
125
+	public function get_all_CPT_post_tags($post_type = '')
126
+	{
127
+		switch ($post_type) {
128
+			case 'espresso_events':
129
+				return $this->get_all_event_post_tags();
130
+				break;
131
+			case 'espresso_venues':
132
+				return $this->get_all_venue_post_tags();
133
+				break;
134
+			default:
135
+				$event_tags = $this->get_all_event_post_tags();
136
+				$venue_tags = $this->get_all_venue_post_tags();
137
+				return array_merge($event_tags, $venue_tags);
138
+		}
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * get_all_event_post_tags
145
+	 *
146
+	 * @return EE_Base_Class[]
147
+	 */
148
+	public function get_all_event_post_tags()
149
+	{
150
+		$post_tags = EEM_Term::instance()->get_all(
151
+			array(
152
+				array(
153
+					'Term_Taxonomy.taxonomy'        => 'post_tag',
154
+					'Term_Taxonomy.Event.post_type' => 'espresso_events',
155
+				),
156
+				'order_by'   => array('name' => 'ASC'),
157
+				'force_join' => array('Term_Taxonomy.Event'),
158
+			)
159
+		);
160
+		foreach ($post_tags as $key => $post_tag) {
161
+			if (! isset($post_tags[$key]->post_type)) {
162
+				$post_tags[$key]->post_type = array();
163
+			}
164
+			$post_tags[$key]->post_type[] = 'espresso_events';
165
+		}
166
+		return $post_tags;
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * get_all_venue_post_tags
173
+	 *
174
+	 * @return EE_Base_Class[]
175
+	 */
176
+	public function get_all_venue_post_tags()
177
+	{
178
+		$post_tags = EEM_Term::instance()->get_all(
179
+			array(
180
+				array(
181
+					'Term_Taxonomy.taxonomy'        => 'post_tag',
182
+					'Term_Taxonomy.Venue.post_type' => 'espresso_venues',
183
+				),
184
+				'order_by'   => array('name' => 'ASC'),
185
+				'force_join' => array('Term_Taxonomy'),
186
+			)
187
+		);
188
+		foreach ($post_tags as $key => $post_tag) {
189
+			if (! isset($post_tags[$key]->post_type)) {
190
+				$post_tags[$key]->post_type = array();
191
+			}
192
+			$post_tags[$key]->post_type[] = 'espresso_venues';
193
+		}
194
+		return $post_tags;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * Makes sure that during REST API queries, we only return terms
201
+	 * for term taxonomies which should be shown in the rest api
202
+	 *
203
+	 * @param array    $model_query_params
204
+	 * @param array    $querystring_query_params
205
+	 * @param EEM_Base $model
206
+	 * @return array
207
+	 */
208
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
209
+	{
210
+		if ($model === EEM_Term::instance()) {
211
+			$taxonomies = get_taxonomies(array('show_in_rest' => true));
212
+			if (! empty($taxonomies)) {
213
+				$model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
214
+			}
215
+		}
216
+		return $model_query_params;
217
+	}
218 218
 
219 219
 
220 220
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -50,37 +50,37 @@  discard block
 block discarded – undo
50 50
         );
51 51
         $this->_cap_restriction_generators[EEM_Base::caps_edit] = false;
52 52
         $this->_cap_restriction_generators[EEM_Base::caps_delete] = false;
53
-        $path_to_tax_model = $path_to_tax_model . '.';
53
+        $path_to_tax_model = $path_to_tax_model.'.';
54 54
         //add cap restrictions for editing relating to the "ee_edit_*"
55 55
         $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
56 56
             array(
57
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
57
+                $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'),
58 58
             )
59 59
         );
60 60
         $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
61 61
             array(
62
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
62
+                $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'),
63 63
             )
64 64
         );
65 65
         $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
66 66
             array(
67
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
67
+                $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'),
68 68
             )
69 69
         );
70 70
         //add cap restrictions for deleting relating to the "ee_deleting_*"
71 71
         $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
72 72
             array(
73
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
73
+                $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'),
74 74
             )
75 75
         );
76 76
         $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
77 77
             array(
78
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
78
+                $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'),
79 79
             )
80 80
         );
81 81
         $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
82 82
             array(
83
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
83
+                $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'),
84 84
             )
85 85
         );
86 86
         parent::__construct($timezone);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             )
159 159
         );
160 160
         foreach ($post_tags as $key => $post_tag) {
161
-            if (! isset($post_tags[$key]->post_type)) {
161
+            if ( ! isset($post_tags[$key]->post_type)) {
162 162
                 $post_tags[$key]->post_type = array();
163 163
             }
164 164
             $post_tags[$key]->post_type[] = 'espresso_events';
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             )
187 187
         );
188 188
         foreach ($post_tags as $key => $post_tag) {
189
-            if (! isset($post_tags[$key]->post_type)) {
189
+            if ( ! isset($post_tags[$key]->post_type)) {
190 190
                 $post_tags[$key]->post_type = array();
191 191
             }
192 192
             $post_tags[$key]->post_type[] = 'espresso_venues';
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     {
210 210
         if ($model === EEM_Term::instance()) {
211 211
             $taxonomies = get_taxonomies(array('show_in_rest' => true));
212
-            if (! empty($taxonomies)) {
212
+            if ( ! empty($taxonomies)) {
213 213
                 $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
214 214
             }
215 215
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Post_Meta.model.php 2 patches
Indentation   +49 added lines, -49 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
  * Event Espresso
@@ -33,57 +33,57 @@  discard block
 block discarded – undo
33 33
 class EEM_Post_Meta extends EEM_Base
34 34
 {
35 35
 
36
-    // private instance of the EE_Post_Meta object
37
-    protected static $_instance = null;
36
+	// private instance of the EE_Post_Meta object
37
+	protected static $_instance = null;
38 38
 
39 39
 
40 40
 
41
-    protected function __construct($timezone = null)
42
-    {
43
-        $this->singular_item = __('Post Meta', 'event_espresso');
44
-        $this->plural_item = __('Post Metas', 'event_espresso');
45
-        $this->_tables = array(
46
-            'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
47
-        );
48
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
49
-        $this->_fields = array(
50
-            'Post_Meta' => array(
51
-                'meta_id'    => new EE_Primary_Key_Int_Field(
52
-                    'meta_id',
53
-                    __("Meta ID", "event_espresso")
54
-                ),
55
-                'post_id'    => new EE_Foreign_Key_Int_Field(
56
-                    'post_id',
57
-                    __("Primary Key of Post", "event_espresso"),
58
-                    false,
59
-                    0,
60
-                    $models_this_can_attach_to
61
-                ),
62
-                'meta_key'   => new EE_Plain_Text_Field(
63
-                    'meta_key',
64
-                    __("Meta Key", "event_espresso"),
65
-                    false,
66
-                    ''
67
-                ),
68
-                'meta_value' => new EE_Maybe_Serialized_Text_Field(
69
-                    'meta_value',
70
-                    __("Meta Value", "event_espresso"),
71
-                    true
72
-                ),
73
-            ),
74
-        );
75
-        $this->_model_relations = array();
76
-        foreach ($models_this_can_attach_to as $model) {
77
-            $this->_model_relations[$model] = new EE_Belongs_To_Relation();
78
-        }
79
-        foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
80
-            $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta(
81
-                'meta_key',
82
-                'meta_value'
83
-            );
84
-        }
85
-        parent::__construct($timezone);
86
-    }
41
+	protected function __construct($timezone = null)
42
+	{
43
+		$this->singular_item = __('Post Meta', 'event_espresso');
44
+		$this->plural_item = __('Post Metas', 'event_espresso');
45
+		$this->_tables = array(
46
+			'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'),
47
+		);
48
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
49
+		$this->_fields = array(
50
+			'Post_Meta' => array(
51
+				'meta_id'    => new EE_Primary_Key_Int_Field(
52
+					'meta_id',
53
+					__("Meta ID", "event_espresso")
54
+				),
55
+				'post_id'    => new EE_Foreign_Key_Int_Field(
56
+					'post_id',
57
+					__("Primary Key of Post", "event_espresso"),
58
+					false,
59
+					0,
60
+					$models_this_can_attach_to
61
+				),
62
+				'meta_key'   => new EE_Plain_Text_Field(
63
+					'meta_key',
64
+					__("Meta Key", "event_espresso"),
65
+					false,
66
+					''
67
+				),
68
+				'meta_value' => new EE_Maybe_Serialized_Text_Field(
69
+					'meta_value',
70
+					__("Meta Value", "event_espresso"),
71
+					true
72
+				),
73
+			),
74
+		);
75
+		$this->_model_relations = array();
76
+		foreach ($models_this_can_attach_to as $model) {
77
+			$this->_model_relations[$model] = new EE_Belongs_To_Relation();
78
+		}
79
+		foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
80
+			$this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta(
81
+				'meta_key',
82
+				'meta_value'
83
+			);
84
+		}
85
+		parent::__construct($timezone);
86
+	}
87 87
 
88 88
 
89 89
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  * @author                Michael Nelson
27 27
  * ------------------------------------------------------------------------
28 28
  */
29
-require_once(EE_MODELS . 'EEM_Base.model.php');
29
+require_once(EE_MODELS.'EEM_Base.model.php');
30 30
 
31 31
 
32 32
 
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Relationship.model.php 2 patches
Indentation   +219 added lines, -219 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
 require_once(EE_MODELS . 'EEM_Base.model.php');
5 5
 
@@ -15,229 +15,229 @@  discard block
 block discarded – undo
15 15
 class EEM_Term_Relationship extends EEM_Base
16 16
 {
17 17
 
18
-    // private instance of the Attendee object
19
-    protected static $_instance = null;
20
-
21
-
22
-
23
-    /**
24
-     * EEM_Term_Relationship constructor.
25
-     *
26
-     * @param string $timezone
27
-     */
28
-    protected function __construct($timezone = null)
29
-    {
30
-        $this->singular_item = __('Term Relationship', 'event_espresso');
31
-        $this->plural_item = __('Term Relationships', 'event_espresso');
32
-        $this->_tables = array(
33
-            'Term_Relationship' => new EE_Primary_Table('term_relationships'),
34
-        );
35
-        $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
36
-        $this->_fields = array(
37
-            'Term_Relationship' => array(
38
-                'object_id'        => new EE_Foreign_Key_Int_Field(
39
-                    'object_id',
40
-                    __('Object(Post) ID', 'event_espresso'),
41
-                    false,
42
-                    0,
43
-                    $models_this_can_attach_to
44
-                ),
45
-                'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
46
-                    'term_taxonomy_id',
47
-                    __(
48
-                        'Term (in context of a taxonomy) ID',
49
-                        'event_espresso'
50
-                    ),
51
-                    false,
52
-                    0,
53
-                    'Term_Taxonomy'
54
-                ),
55
-                'term_order'       => new EE_Integer_Field(
56
-                    'term_order',
57
-                    __('Term Order', 'event_espresso'),
58
-                    false,
59
-                    0
60
-                ),
61
-            ),
62
-        );
63
-        $this->_model_relations = array(
64
-            'Term_Taxonomy' => new EE_Belongs_To_Relation(),
65
-        );
66
-        foreach ($models_this_can_attach_to as $model_name) {
67
-            $this->_model_relations[$model_name] = new EE_Belongs_To_Relation();
68
-        }
69
-        $this->_indexes = array(
70
-            'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
71
-        );
72
-        $path_to_event_model = 'Event.';
73
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public(
74
-            $path_to_event_model
75
-        );
76
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
77
-            new EE_Restriction_Generator_Event_Related_Protected(
78
-                $path_to_event_model
79
-            );
80
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected(
81
-            $path_to_event_model
82
-        );
83
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] =
84
-            new EE_Restriction_Generator_Event_Related_Protected(
85
-                $path_to_event_model,
86
-                EEM_Base::caps_edit
87
-            );
88
-        $path_to_tax_model = 'Term_Taxonomy.';
89
-        //add cap restrictions for editing term relations to the "ee_assign_*"
90
-        //and for deleting term relations too
91
-        $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
92
-        foreach ($cap_contexts_affected as $cap_context_affected) {
93
-            $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] =
94
-                new EE_Default_Where_Conditions(
95
-                    array(
96
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
97
-                            '!=',
98
-                            'espresso_event_categories',
99
-                        ),
100
-                    )
101
-                );
102
-            $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] =
103
-                new EE_Default_Where_Conditions(
104
-                    array(
105
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
106
-                            '!=',
107
-                            'espresso_venue_categories',
108
-                        ),
109
-                    )
110
-                );
111
-            $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
112
-                array(
113
-                    $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
114
-                )
115
-            );
116
-        }
117
-        parent::__construct($timezone);
118
-        add_filter(
119
-            'FHEE__Read__create_model_query_params',
120
-            array('EEM_Term_Relationship', 'rest_api_query_params'),
121
-            10,
122
-            3
123
-        );
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * Makes sure all term-taxonomy counts are correct
130
-     *
131
-     * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
132
-     * @global wpdb $wpdb
133
-     * @return int the number of rows affected
134
-     */
135
-    public function update_term_taxonomy_counts($term_taxonomy_id = null)
136
-    {
137
-        //because this uses a subquery and sometimes assigning to column to be another column's
138
-        //value, we just write the SQL directly.
139
-        global $wpdb;
140
-        if ($term_taxonomy_id) {
141
-            $second_operand = $wpdb->prepare('%d', $term_taxonomy_id);
142
-        } else {
143
-            $second_operand = 'tr.term_taxonomy_id';
144
-        }
145
-        $rows_affected = $this->_do_wpdb_query(
146
-            'query',
147
-            array(
148
-                "
18
+	// private instance of the Attendee object
19
+	protected static $_instance = null;
20
+
21
+
22
+
23
+	/**
24
+	 * EEM_Term_Relationship constructor.
25
+	 *
26
+	 * @param string $timezone
27
+	 */
28
+	protected function __construct($timezone = null)
29
+	{
30
+		$this->singular_item = __('Term Relationship', 'event_espresso');
31
+		$this->plural_item = __('Term Relationships', 'event_espresso');
32
+		$this->_tables = array(
33
+			'Term_Relationship' => new EE_Primary_Table('term_relationships'),
34
+		);
35
+		$models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models());
36
+		$this->_fields = array(
37
+			'Term_Relationship' => array(
38
+				'object_id'        => new EE_Foreign_Key_Int_Field(
39
+					'object_id',
40
+					__('Object(Post) ID', 'event_espresso'),
41
+					false,
42
+					0,
43
+					$models_this_can_attach_to
44
+				),
45
+				'term_taxonomy_id' => new EE_Foreign_Key_Int_Field(
46
+					'term_taxonomy_id',
47
+					__(
48
+						'Term (in context of a taxonomy) ID',
49
+						'event_espresso'
50
+					),
51
+					false,
52
+					0,
53
+					'Term_Taxonomy'
54
+				),
55
+				'term_order'       => new EE_Integer_Field(
56
+					'term_order',
57
+					__('Term Order', 'event_espresso'),
58
+					false,
59
+					0
60
+				),
61
+			),
62
+		);
63
+		$this->_model_relations = array(
64
+			'Term_Taxonomy' => new EE_Belongs_To_Relation(),
65
+		);
66
+		foreach ($models_this_can_attach_to as $model_name) {
67
+			$this->_model_relations[$model_name] = new EE_Belongs_To_Relation();
68
+		}
69
+		$this->_indexes = array(
70
+			'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')),
71
+		);
72
+		$path_to_event_model = 'Event.';
73
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public(
74
+			$path_to_event_model
75
+		);
76
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
77
+			new EE_Restriction_Generator_Event_Related_Protected(
78
+				$path_to_event_model
79
+			);
80
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected(
81
+			$path_to_event_model
82
+		);
83
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] =
84
+			new EE_Restriction_Generator_Event_Related_Protected(
85
+				$path_to_event_model,
86
+				EEM_Base::caps_edit
87
+			);
88
+		$path_to_tax_model = 'Term_Taxonomy.';
89
+		//add cap restrictions for editing term relations to the "ee_assign_*"
90
+		//and for deleting term relations too
91
+		$cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete);
92
+		foreach ($cap_contexts_affected as $cap_context_affected) {
93
+			$this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] =
94
+				new EE_Default_Where_Conditions(
95
+					array(
96
+						$path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
97
+							'!=',
98
+							'espresso_event_categories',
99
+						),
100
+					)
101
+				);
102
+			$this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] =
103
+				new EE_Default_Where_Conditions(
104
+					array(
105
+						$path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
106
+							'!=',
107
+							'espresso_venue_categories',
108
+						),
109
+					)
110
+				);
111
+			$this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
112
+				array(
113
+					$path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
114
+				)
115
+			);
116
+		}
117
+		parent::__construct($timezone);
118
+		add_filter(
119
+			'FHEE__Read__create_model_query_params',
120
+			array('EEM_Term_Relationship', 'rest_api_query_params'),
121
+			10,
122
+			3
123
+		);
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * Makes sure all term-taxonomy counts are correct
130
+	 *
131
+	 * @param int   $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL
132
+	 * @global wpdb $wpdb
133
+	 * @return int the number of rows affected
134
+	 */
135
+	public function update_term_taxonomy_counts($term_taxonomy_id = null)
136
+	{
137
+		//because this uses a subquery and sometimes assigning to column to be another column's
138
+		//value, we just write the SQL directly.
139
+		global $wpdb;
140
+		if ($term_taxonomy_id) {
141
+			$second_operand = $wpdb->prepare('%d', $term_taxonomy_id);
142
+		} else {
143
+			$second_operand = 'tr.term_taxonomy_id';
144
+		}
145
+		$rows_affected = $this->_do_wpdb_query(
146
+			'query',
147
+			array(
148
+				"
149 149
                 UPDATE {$wpdb->term_taxonomy} AS tt 
150 150
                 SET count = (
151 151
                     select count(*) as proper_count from {$wpdb->term_relationships} AS tr 
152 152
                     WHERE tt.term_taxonomy_id = $second_operand
153 153
                 )",
154
-            )
155
-        );
156
-        return $rows_affected;
157
-    }
158
-
159
-
160
-
161
-    /**
162
-     * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
163
-     * inserting
164
-     *
165
-     * @param array $field_n_values @see EEM_Base::insert
166
-     * @return boolean
167
-     */
168
-    public function insert($field_n_values)
169
-    {
170
-        $return = parent::insert($field_n_values);
171
-        if (isset($field_n_values['term_taxonomy_id'])) {
172
-            $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
173
-        }
174
-        return $return;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
-     * all ok
182
-     *
183
-     * @param array   $fields_n_values         see EEM_Base::update
184
-     * @param array   $query_params            @see EEM_Base::get_all
185
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
186
-     *                                         in this model's entity map according to $fields_n_values that match
187
-     *                                         $query_params. This obviously has some overhead, so you can disable it
188
-     *                                         by setting this to FALSE, but be aware that model objects being used
189
-     *                                         could get out-of-sync with the database
190
-     * @return int
191
-     */
192
-    public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
193
-    {
194
-        $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
195
-        if ($count) {
196
-            $this->update_term_taxonomy_counts();
197
-        }
198
-        return $count;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * Overrides parent so that after running this, we also double-check
205
-     * the term taxonomy counts are up-to-date
206
-     *
207
-     * @param array   $query_params @see EEM_Base::get_all
208
-     * @param boolean $allow_blocking
209
-     * @return int @see EEM_Base::delete
210
-     */
211
-    public function delete($query_params, $allow_blocking = true)
212
-    {
213
-        $count = parent::delete($query_params, $allow_blocking);
214
-        if ($count) {
215
-            $this->update_term_taxonomy_counts();
216
-        }
217
-        return $count;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Makes sure that during REST API queries, we only return term relationships
224
-     * for term taxonomies which should be shown in the rest api
225
-     *
226
-     * @param array    $model_query_params
227
-     * @param array    $querystring_query_params
228
-     * @param EEM_Base $model
229
-     * @return array
230
-     */
231
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
232
-    {
233
-        if ($model === EEM_Term_Relationship::instance()) {
234
-            $taxonomies = get_taxonomies(array('show_in_rest' => true));
235
-            if (! empty($taxonomies)) {
236
-                $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237
-            }
238
-        }
239
-        return $model_query_params;
240
-    }
154
+			)
155
+		);
156
+		return $rows_affected;
157
+	}
158
+
159
+
160
+
161
+	/**
162
+	 * Overrides the parent to also make sure term-taxonomy counts are up-to-date after
163
+	 * inserting
164
+	 *
165
+	 * @param array $field_n_values @see EEM_Base::insert
166
+	 * @return boolean
167
+	 */
168
+	public function insert($field_n_values)
169
+	{
170
+		$return = parent::insert($field_n_values);
171
+		if (isset($field_n_values['term_taxonomy_id'])) {
172
+			$this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']);
173
+		}
174
+		return $return;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * Overrides parent so that after an update, we also check the term_taxonomy_counts are
181
+	 * all ok
182
+	 *
183
+	 * @param array   $fields_n_values         see EEM_Base::update
184
+	 * @param array   $query_params            @see EEM_Base::get_all
185
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
186
+	 *                                         in this model's entity map according to $fields_n_values that match
187
+	 *                                         $query_params. This obviously has some overhead, so you can disable it
188
+	 *                                         by setting this to FALSE, but be aware that model objects being used
189
+	 *                                         could get out-of-sync with the database
190
+	 * @return int
191
+	 */
192
+	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
193
+	{
194
+		$count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync);
195
+		if ($count) {
196
+			$this->update_term_taxonomy_counts();
197
+		}
198
+		return $count;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * Overrides parent so that after running this, we also double-check
205
+	 * the term taxonomy counts are up-to-date
206
+	 *
207
+	 * @param array   $query_params @see EEM_Base::get_all
208
+	 * @param boolean $allow_blocking
209
+	 * @return int @see EEM_Base::delete
210
+	 */
211
+	public function delete($query_params, $allow_blocking = true)
212
+	{
213
+		$count = parent::delete($query_params, $allow_blocking);
214
+		if ($count) {
215
+			$this->update_term_taxonomy_counts();
216
+		}
217
+		return $count;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Makes sure that during REST API queries, we only return term relationships
224
+	 * for term taxonomies which should be shown in the rest api
225
+	 *
226
+	 * @param array    $model_query_params
227
+	 * @param array    $querystring_query_params
228
+	 * @param EEM_Base $model
229
+	 * @return array
230
+	 */
231
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
232
+	{
233
+		if ($model === EEM_Term_Relationship::instance()) {
234
+			$taxonomies = get_taxonomies(array('show_in_rest' => true));
235
+			if (! empty($taxonomies)) {
236
+				$model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237
+			}
238
+		}
239
+		return $model_query_params;
240
+	}
241 241
 
242 242
 
243 243
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_Base.model.php');
4
+require_once(EE_MODELS.'EEM_Base.model.php');
5 5
 
6 6
 
7 7
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
             $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] =
94 94
                 new EE_Default_Where_Conditions(
95 95
                     array(
96
-                        $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array(
96
+                        $path_to_tax_model.'taxonomy*ee_assign_event_category' => array(
97 97
                             '!=',
98 98
                             'espresso_event_categories',
99 99
                         ),
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
             $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] =
103 103
                 new EE_Default_Where_Conditions(
104 104
                     array(
105
-                        $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array(
105
+                        $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array(
106 106
                             '!=',
107 107
                             'espresso_venue_categories',
108 108
                         ),
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                 );
111 111
             $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions(
112 112
                 array(
113
-                    $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
113
+                    $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'),
114 114
                 )
115 115
             );
116 116
         }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     {
233 233
         if ($model === EEM_Term_Relationship::instance()) {
234 234
             $taxonomies = get_taxonomies(array('show_in_rest' => true));
235
-            if (! empty($taxonomies)) {
235
+            if ( ! empty($taxonomies)) {
236 236
                 $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies);
237 237
             }
238 238
         }
Please login to merge, or discard this patch.
modules/ticket_selector/templates/simple_ticket_selector.template.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>
12 12
 <?php
13 13
 if ( $ticket instanceof EE_Ticket ) {
14
-    do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
15
-    $ticket_description = $ticket->description();
16
-    $ticket_description .= ! empty( $ticket_description )
17
-        ? '<br />' . $ticket_status_display
18
-        : $ticket_status_display;
19
-    if (strpos( $ticket_description, '<div' ) === false) {
20
-        $ticket_description = "<p>{$ticket_description}</p>";
21
-    }
14
+	do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
15
+	$ticket_description = $ticket->description();
16
+	$ticket_description .= ! empty( $ticket_description )
17
+		? '<br />' . $ticket_status_display
18
+		: $ticket_status_display;
19
+	if (strpos( $ticket_description, '<div' ) === false) {
20
+		$ticket_description = "<p>{$ticket_description}</p>";
21
+	}
22 22
 ?>
23 23
 <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">
24 24
     <div class="no-tkt-slctr-ticket-content-dv">
@@ -28,6 +28,6 @@  discard block
 block discarded – undo
28 28
         <?php } ?>
29 29
     </div><!-- .no-tkt-slctr-ticket-content-dv -->
30 30
 <?php
31
-    do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
31
+	do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
32 32
 }
33 33
 ?>
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,24 +10,24 @@
 block discarded – undo
10 10
 <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/>
11 11
 <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>
12 12
 <?php
13
-if ( $ticket instanceof EE_Ticket ) {
14
-    do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
13
+if ($ticket instanceof EE_Ticket) {
14
+    do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event);
15 15
     $ticket_description = $ticket->description();
16
-    $ticket_description .= ! empty( $ticket_description )
17
-        ? '<br />' . $ticket_status_display
16
+    $ticket_description .= ! empty($ticket_description)
17
+        ? '<br />'.$ticket_status_display
18 18
         : $ticket_status_display;
19
-    if (strpos( $ticket_description, '<div' ) === false) {
19
+    if (strpos($ticket_description, '<div') === false) {
20 20
         $ticket_description = "<p>{$ticket_description}</p>";
21 21
     }
22 22
 ?>
23 23
 <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">
24 24
     <div class="no-tkt-slctr-ticket-content-dv">
25 25
         <h5><?php echo $ticket->name(); ?></h5>
26
-        <?php if ( ! empty( $ticket_description ) ) { ?>
26
+        <?php if ( ! empty($ticket_description)) { ?>
27 27
         <?php echo $ticket_description; ?>
28 28
         <?php } ?>
29 29
     </div><!-- .no-tkt-slctr-ticket-content-dv -->
30 30
 <?php
31
-    do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
31
+    do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event);
32 32
 }
33 33
 ?>
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 
376 376
 
377 377
     /**
378
-     * @param mixed  $var
378
+     * @param string  $var
379 379
      * @param string $var_name
380 380
      * @param string $file
381 381
      * @param int    $line
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 
571 571
     /**
572 572
      * @deprecated 4.9.39.rc.034
573
-     * @param null $timer_name
573
+     * @param string $timer_name
574 574
      */
575 575
     public function start_timer($timer_name = null)
576 576
     {
Please login to merge, or discard this patch.
Indentation   +636 added lines, -636 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,626 +17,626 @@  discard block
 block discarded – undo
17 17
 class EEH_Debug_Tools
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EEH_Autoloader object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $_memory_usage_points = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EEH_Debug_Tools
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * private class constructor
53
-     */
54
-    private function __construct()
55
-    {
56
-        // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
59
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
-            // so we've moved it to our test folder so that it is not included with production releases
62
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
-        }
65
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
-        //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
-        // }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo $priority;
148
-                foreach ($function as $name => $properties) {
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[$hook_name])) {
168
-            $filters[$hook_name] = array();
169
-            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
-                $filters[$hook_name][$priority] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[$hook_name][$priority][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            __(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__, __FUNCTION__, __LINE__
214
-                    );
215
-                }
216
-            } else {
217
-                // old school attempt
218
-                file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
-                    $activation_errors
221
-                );
222
-            }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
-            update_option('ee_plugin_activation_errors', $activation_errors);
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
-     * or we want to make sure they use something the right way.
234
-     *
235
-     * @access public
236
-     * @param string $function      The function that was called
237
-     * @param string $message       A message explaining what has been done incorrectly
238
-     * @param string $version       The version of Event Espresso where the error was added
239
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
-     *                              for a deprecated function. This allows deprecation to occur during one version,
241
-     *                              but not have any notices appear until a later version. This allows developers
242
-     *                              extra time to update their code before notices appear.
243
-     * @param int    $error_type
244
-     * @uses   trigger_error()
245
-     */
246
-    public function doing_it_wrong(
247
-        $function,
248
-        $message,
249
-        $version,
250
-        $applies_when = '',
251
-        $error_type = null
252
-    ) {
253
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
-        // because we swapped the parameter order around for the last two params,
256
-        // let's verify that some third party isn't still passing an error type value for the third param
257
-        if (is_int($applies_when)) {
258
-            $error_type = $applies_when;
259
-            $applies_when = espresso_version();
260
-        }
261
-        // if not displaying notices yet, then just leave
262
-        if (version_compare(espresso_version(), $applies_when, '<')) {
263
-            return;
264
-        }
265
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
-        $version = $version === null
267
-            ? ''
268
-            : sprintf(
269
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
-                $version
271
-            );
272
-        $error_message = sprintf(
273
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
-            $function,
275
-            '<strong>',
276
-            '</strong>',
277
-            $message,
278
-            $version
279
-        );
280
-        // don't trigger error if doing ajax,
281
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
-        if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
284
-                    'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
-                    'event_espresso'
286
-                );
287
-            $error_message .= '<ul><li>';
288
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
-            $error_message .= '</ul>';
290
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
-            //now we set this on the transient so it shows up on the next request.
292
-            EE_Error::get_notices(false, true);
293
-        } else {
294
-            trigger_error($error_message, $error_type);
295
-        }
296
-    }
297
-
298
-
299
-
300
-
301
-    /**
302
-     * Logger helpers
303
-     */
304
-    /**
305
-     * debug
306
-     *
307
-     * @param string $class
308
-     * @param string $func
309
-     * @param string $line
310
-     * @param array  $info
311
-     * @param bool   $display_request
312
-     * @param string $debug_index
313
-     * @param string $debug_key
314
-     * @throws EE_Error
315
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
-     */
317
-    public static function log(
318
-        $class = '',
319
-        $func = '',
320
-        $line = '',
321
-        $info = array(),
322
-        $display_request = false,
323
-        $debug_index = '',
324
-        $debug_key = 'EE_DEBUG_SPCO'
325
-    ) {
326
-        if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
-            $debug_data = get_option($debug_key, array());
329
-            $default_data = array(
330
-                $class => $func . '() : ' . $line,
331
-                'REQ'  => $display_request ? $_REQUEST : '',
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
337
-                $debug_data[$index] = array();
338
-            }
339
-            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[$key] = self::strip_objects($value);
357
-            } else if (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[$object_class] = array();
360
-                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[$object_class]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[$object_class]['status'] = $value->status();
366
-                } else if (method_exists($value, 'status_ID')) {
367
-                    $info[$object_class]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[$key]);
370
-            }
371
-        }
372
-        return (array)$info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed  $var
379
-     * @param string $var_name
380
-     * @param string $file
381
-     * @param int    $line
382
-     * @param int    $heading_tag
383
-     * @param bool   $die
384
-     * @param string $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = __FILE__,
390
-        $line = __LINE__,
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
-        $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
405
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
406
-        if ($die) {
407
-            die($result);
408
-        }
409
-        echo $result;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * @param string $var_name
416
-     * @param string $heading_tag
417
-     * @param string $margin
418
-     * @return string
419
-     */
420
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
-    {
422
-        if (defined('EE_TESTS_DIR')) {
423
-            return "\n\n{$var_name}";
424
-        }
425
-        $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @param string $heading_tag
433
-     * @return string
434
-     */
435
-    protected static function headingX($heading_tag = 'h5')
436
-    {
437
-        if (defined('EE_TESTS_DIR')) {
438
-            return "\n";
439
-        }
440
-        return '</' . $heading_tag . '>';
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * @param string $content
447
-     * @return string
448
-     */
449
-    protected static function grey_span($content = '')
450
-    {
451
-        if (defined('EE_TESTS_DIR')) {
452
-            return $content;
453
-        }
454
-        return '<span style="color:#999">' . $content . '</span>';
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * @param string $file
461
-     * @param int    $line
462
-     * @return string
463
-     */
464
-    protected static function file_and_line($file, $line)
465
-    {
466
-        if (defined('EE_TESTS_DIR')) {
467
-            return "\n (" . $file . ' line no: ' . $line . ' ) ';
468
-        }
469
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
470
-               . $file
471
-               . '<br />line no: '
472
-               . $line
473
-               . '</span>';
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * @param string $content
480
-     * @return string
481
-     */
482
-    protected static function orange_span($content = '')
483
-    {
484
-        if (defined('EE_TESTS_DIR')) {
485
-            return $content;
486
-        }
487
-        return '<span style="color:#E76700">' . $content . '</span>';
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * @param mixed $var
494
-     * @return string
495
-     */
496
-    protected static function pre_span($var)
497
-    {
498
-        ob_start();
499
-        var_dump($var);
500
-        $var = ob_get_clean();
501
-        if (defined('EE_TESTS_DIR')) {
502
-            return "\n" . $var;
503
-        }
504
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
505
-    }
506
-
507
-
508
-
509
-    /**
510
-     * @param mixed  $var
511
-     * @param string $var_name
512
-     * @param string $file
513
-     * @param int    $line
514
-     * @param int    $heading_tag
515
-     * @param bool   $die
516
-     */
517
-    public static function printr(
518
-        $var,
519
-        $var_name = '',
520
-        $file = __FILE__,
521
-        $line = __LINE__,
522
-        $heading_tag = 5,
523
-        $die = false
524
-    ) {
525
-        // return;
526
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
527
-        $margin = is_admin() ? ' 180px' : '0';
528
-        //$print_r = false;
529
-        if (is_string($var)) {
530
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
531
-            return;
532
-        }
533
-        if (is_object($var)) {
534
-            $var_name = ! $var_name ? 'object' : $var_name;
535
-            //$print_r = true;
536
-        } else if (is_array($var)) {
537
-            $var_name = ! $var_name ? 'array' : $var_name;
538
-            //$print_r = true;
539
-        } else if (is_numeric($var)) {
540
-            $var_name = ! $var_name ? 'numeric' : $var_name;
541
-        } else if ($var === null) {
542
-            $var_name = ! $var_name ? 'null' : $var_name;
543
-        }
544
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
545
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
546
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
547
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
548
-                EEH_Debug_Tools::pre_span($var)
549
-            );
550
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
551
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
552
-        if ($die) {
553
-            die($result);
554
-        }
555
-        echo $result;
556
-    }
557
-
558
-
559
-
560
-    /******************** deprecated ********************/
561
-    /**
562
-     * @deprecated 4.9.39.rc.034
563
-     */
564
-    public function reset_times()
565
-    {
566
-        Benchmark::resetTimes();
567
-    }
568
-
569
-
570
-
571
-    /**
572
-     * @deprecated 4.9.39.rc.034
573
-     * @param null $timer_name
574
-     */
575
-    public function start_timer($timer_name = null)
576
-    {
577
-        Benchmark::startTimer($timer_name);
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     * @deprecated 4.9.39.rc.034
584
-     * @param string $timer_name
585
-     */
586
-    public function stop_timer($timer_name = '')
587
-    {
588
-        Benchmark::stopTimer($timer_name);
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     * @deprecated 4.9.39.rc.034
595
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
596
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
597
-     * @return void
598
-     */
599
-    public function measure_memory($label, $output_now = false)
600
-    {
601
-        Benchmark::measureMemory($label, $output_now);
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     * @deprecated 4.9.39.rc.034
608
-     * @param int $size
609
-     * @return string
610
-     */
611
-    public function convert($size)
612
-    {
613
-        return Benchmark::convert($size);
614
-    }
615
-
616
-
617
-
618
-    /**
619
-     * @deprecated 4.9.39.rc.034
620
-     * @param bool $output_now
621
-     * @return string
622
-     */
623
-    public function show_times($output_now = true)
624
-    {
625
-        return Benchmark::displayResults($output_now);
626
-    }
627
-
628
-
629
-
630
-    /**
631
-     * @deprecated 4.9.39.rc.034
632
-     * @param string $timer_name
633
-     * @param float  $total_time
634
-     * @return string
635
-     */
636
-    public function format_time($timer_name, $total_time)
637
-    {
638
-        return Benchmark::formatTime($timer_name, $total_time);
639
-    }
20
+	/**
21
+	 *    instance of the EEH_Autoloader object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $_memory_usage_points = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EEH_Debug_Tools
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * private class constructor
53
+	 */
54
+	private function __construct()
55
+	{
56
+		// load Kint PHP debugging library
57
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
59
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
+			// so we've moved it to our test folder so that it is not included with production releases
62
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
+			require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
+		}
65
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
+		//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
+		// }
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[$tag] = $wp_filter[$tag];
134
+			if (! is_array($hook[$tag])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . $tag . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo $priority;
148
+				foreach ($function as $name => $properties) {
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[$hook_name])) {
168
+			$filters[$hook_name] = array();
169
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+				$filters[$hook_name][$priority] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[$hook_name][$priority][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__, __FUNCTION__, __LINE__
214
+					);
215
+				}
216
+			} else {
217
+				// old school attempt
218
+				file_put_contents(
219
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
+					$activation_errors
221
+				);
222
+			}
223
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
+			update_option('ee_plugin_activation_errors', $activation_errors);
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
+	 * or we want to make sure they use something the right way.
234
+	 *
235
+	 * @access public
236
+	 * @param string $function      The function that was called
237
+	 * @param string $message       A message explaining what has been done incorrectly
238
+	 * @param string $version       The version of Event Espresso where the error was added
239
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
241
+	 *                              but not have any notices appear until a later version. This allows developers
242
+	 *                              extra time to update their code before notices appear.
243
+	 * @param int    $error_type
244
+	 * @uses   trigger_error()
245
+	 */
246
+	public function doing_it_wrong(
247
+		$function,
248
+		$message,
249
+		$version,
250
+		$applies_when = '',
251
+		$error_type = null
252
+	) {
253
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
+		// because we swapped the parameter order around for the last two params,
256
+		// let's verify that some third party isn't still passing an error type value for the third param
257
+		if (is_int($applies_when)) {
258
+			$error_type = $applies_when;
259
+			$applies_when = espresso_version();
260
+		}
261
+		// if not displaying notices yet, then just leave
262
+		if (version_compare(espresso_version(), $applies_when, '<')) {
263
+			return;
264
+		}
265
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
+		$version = $version === null
267
+			? ''
268
+			: sprintf(
269
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
+				$version
271
+			);
272
+		$error_message = sprintf(
273
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
+			$function,
275
+			'<strong>',
276
+			'</strong>',
277
+			$message,
278
+			$version
279
+		);
280
+		// don't trigger error if doing ajax,
281
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
+		if (defined('DOING_AJAX') && DOING_AJAX) {
283
+			$error_message .= ' ' . esc_html__(
284
+					'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
+					'event_espresso'
286
+				);
287
+			$error_message .= '<ul><li>';
288
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
+			$error_message .= '</ul>';
290
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
+			//now we set this on the transient so it shows up on the next request.
292
+			EE_Error::get_notices(false, true);
293
+		} else {
294
+			trigger_error($error_message, $error_type);
295
+		}
296
+	}
297
+
298
+
299
+
300
+
301
+	/**
302
+	 * Logger helpers
303
+	 */
304
+	/**
305
+	 * debug
306
+	 *
307
+	 * @param string $class
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @param array  $info
311
+	 * @param bool   $display_request
312
+	 * @param string $debug_index
313
+	 * @param string $debug_key
314
+	 * @throws EE_Error
315
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
+	 */
317
+	public static function log(
318
+		$class = '',
319
+		$func = '',
320
+		$line = '',
321
+		$info = array(),
322
+		$display_request = false,
323
+		$debug_index = '',
324
+		$debug_key = 'EE_DEBUG_SPCO'
325
+	) {
326
+		if (WP_DEBUG) {
327
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+			$debug_data = get_option($debug_key, array());
329
+			$default_data = array(
330
+				$class => $func . '() : ' . $line,
331
+				'REQ'  => $display_request ? $_REQUEST : '',
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[$index])) {
337
+				$debug_data[$index] = array();
338
+			}
339
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[$key] = self::strip_objects($value);
357
+			} else if (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[$object_class] = array();
360
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[$object_class]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[$object_class]['status'] = $value->status();
366
+				} else if (method_exists($value, 'status_ID')) {
367
+					$info[$object_class]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[$key]);
370
+			}
371
+		}
372
+		return (array)$info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed  $var
379
+	 * @param string $var_name
380
+	 * @param string $file
381
+	 * @param int    $line
382
+	 * @param int    $heading_tag
383
+	 * @param bool   $die
384
+	 * @param string $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = __FILE__,
390
+		$line = __LINE__,
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
+		$result .= $is_method
402
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
405
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
406
+		if ($die) {
407
+			die($result);
408
+		}
409
+		echo $result;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * @param string $var_name
416
+	 * @param string $heading_tag
417
+	 * @param string $margin
418
+	 * @return string
419
+	 */
420
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
+	{
422
+		if (defined('EE_TESTS_DIR')) {
423
+			return "\n\n{$var_name}";
424
+		}
425
+		$margin = "25px 0 0 {$margin}";
426
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @param string $heading_tag
433
+	 * @return string
434
+	 */
435
+	protected static function headingX($heading_tag = 'h5')
436
+	{
437
+		if (defined('EE_TESTS_DIR')) {
438
+			return "\n";
439
+		}
440
+		return '</' . $heading_tag . '>';
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * @param string $content
447
+	 * @return string
448
+	 */
449
+	protected static function grey_span($content = '')
450
+	{
451
+		if (defined('EE_TESTS_DIR')) {
452
+			return $content;
453
+		}
454
+		return '<span style="color:#999">' . $content . '</span>';
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * @param string $file
461
+	 * @param int    $line
462
+	 * @return string
463
+	 */
464
+	protected static function file_and_line($file, $line)
465
+	{
466
+		if (defined('EE_TESTS_DIR')) {
467
+			return "\n (" . $file . ' line no: ' . $line . ' ) ';
468
+		}
469
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
470
+			   . $file
471
+			   . '<br />line no: '
472
+			   . $line
473
+			   . '</span>';
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * @param string $content
480
+	 * @return string
481
+	 */
482
+	protected static function orange_span($content = '')
483
+	{
484
+		if (defined('EE_TESTS_DIR')) {
485
+			return $content;
486
+		}
487
+		return '<span style="color:#E76700">' . $content . '</span>';
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * @param mixed $var
494
+	 * @return string
495
+	 */
496
+	protected static function pre_span($var)
497
+	{
498
+		ob_start();
499
+		var_dump($var);
500
+		$var = ob_get_clean();
501
+		if (defined('EE_TESTS_DIR')) {
502
+			return "\n" . $var;
503
+		}
504
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
505
+	}
506
+
507
+
508
+
509
+	/**
510
+	 * @param mixed  $var
511
+	 * @param string $var_name
512
+	 * @param string $file
513
+	 * @param int    $line
514
+	 * @param int    $heading_tag
515
+	 * @param bool   $die
516
+	 */
517
+	public static function printr(
518
+		$var,
519
+		$var_name = '',
520
+		$file = __FILE__,
521
+		$line = __LINE__,
522
+		$heading_tag = 5,
523
+		$die = false
524
+	) {
525
+		// return;
526
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
527
+		$margin = is_admin() ? ' 180px' : '0';
528
+		//$print_r = false;
529
+		if (is_string($var)) {
530
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
531
+			return;
532
+		}
533
+		if (is_object($var)) {
534
+			$var_name = ! $var_name ? 'object' : $var_name;
535
+			//$print_r = true;
536
+		} else if (is_array($var)) {
537
+			$var_name = ! $var_name ? 'array' : $var_name;
538
+			//$print_r = true;
539
+		} else if (is_numeric($var)) {
540
+			$var_name = ! $var_name ? 'numeric' : $var_name;
541
+		} else if ($var === null) {
542
+			$var_name = ! $var_name ? 'null' : $var_name;
543
+		}
544
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
545
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
546
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
547
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
548
+				EEH_Debug_Tools::pre_span($var)
549
+			);
550
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
551
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
552
+		if ($die) {
553
+			die($result);
554
+		}
555
+		echo $result;
556
+	}
557
+
558
+
559
+
560
+	/******************** deprecated ********************/
561
+	/**
562
+	 * @deprecated 4.9.39.rc.034
563
+	 */
564
+	public function reset_times()
565
+	{
566
+		Benchmark::resetTimes();
567
+	}
568
+
569
+
570
+
571
+	/**
572
+	 * @deprecated 4.9.39.rc.034
573
+	 * @param null $timer_name
574
+	 */
575
+	public function start_timer($timer_name = null)
576
+	{
577
+		Benchmark::startTimer($timer_name);
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 * @deprecated 4.9.39.rc.034
584
+	 * @param string $timer_name
585
+	 */
586
+	public function stop_timer($timer_name = '')
587
+	{
588
+		Benchmark::stopTimer($timer_name);
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 * @deprecated 4.9.39.rc.034
595
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
596
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
597
+	 * @return void
598
+	 */
599
+	public function measure_memory($label, $output_now = false)
600
+	{
601
+		Benchmark::measureMemory($label, $output_now);
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 * @deprecated 4.9.39.rc.034
608
+	 * @param int $size
609
+	 * @return string
610
+	 */
611
+	public function convert($size)
612
+	{
613
+		return Benchmark::convert($size);
614
+	}
615
+
616
+
617
+
618
+	/**
619
+	 * @deprecated 4.9.39.rc.034
620
+	 * @param bool $output_now
621
+	 * @return string
622
+	 */
623
+	public function show_times($output_now = true)
624
+	{
625
+		return Benchmark::displayResults($output_now);
626
+	}
627
+
628
+
629
+
630
+	/**
631
+	 * @deprecated 4.9.39.rc.034
632
+	 * @param string $timer_name
633
+	 * @param float  $total_time
634
+	 * @return string
635
+	 */
636
+	public function format_time($timer_name, $total_time)
637
+	{
638
+		return Benchmark::formatTime($timer_name, $total_time);
639
+	}
640 640
 
641 641
 
642 642
 
@@ -649,31 +649,31 @@  discard block
 block discarded – undo
649 649
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
650 650
  */
651 651
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
652
-    function dump_wp_query()
653
-    {
654
-        global $wp_query;
655
-        d($wp_query);
656
-    }
652
+	function dump_wp_query()
653
+	{
654
+		global $wp_query;
655
+		d($wp_query);
656
+	}
657 657
 }
658 658
 /**
659 659
  * borrowed from Kint Debugger
660 660
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
661 661
  */
662 662
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
663
-    function dump_wp()
664
-    {
665
-        global $wp;
666
-        d($wp);
667
-    }
663
+	function dump_wp()
664
+	{
665
+		global $wp;
666
+		d($wp);
667
+	}
668 668
 }
669 669
 /**
670 670
  * borrowed from Kint Debugger
671 671
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
672 672
  */
673 673
 if (class_exists('Kint') && ! function_exists('dump_post')) {
674
-    function dump_post()
675
-    {
676
-        global $post;
677
-        d($post);
678
-    }
674
+	function dump_post()
675
+	{
676
+		global $post;
677
+		d($post);
678
+	}
679 679
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public static function instance()
41 41
     {
42 42
         // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
     private function __construct()
55 55
     {
56 56
         // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
57
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
58 58
             // despite EE4 having a check for an existing copy of the Kint debugging class,
59 59
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60 60
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61 61
             // so we've moved it to our test folder so that it is not included with production releases
62 62
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
63
+            require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
64 64
         }
65 65
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66 66
         //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function show_db_name()
82 82
     {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84 84
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85 85
                  . DB_NAME
86 86
                  . '</p>';
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132 132
         if ($tag) {
133 133
             $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
134
+            if ( ! is_array($hook[$tag])) {
135 135
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136 136
                 return;
137 137
             }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
138
+            echo '<h5>For Tag: '.$tag.'</h5>';
139 139
         } else {
140 140
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141 141
             ksort($hook);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
             } else {
217 217
                 // old school attempt
218 218
                 file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
219
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
220 220
                     $activation_errors
221 221
                 );
222 222
             }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
224 224
             update_option('ee_plugin_activation_errors', $activation_errors);
225 225
         }
226 226
     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         // don't trigger error if doing ajax,
281 281
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282 282
         if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
283
+            $error_message .= ' '.esc_html__(
284 284
                     'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285 285
                     'event_espresso'
286 286
                 );
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
         $debug_key = 'EE_DEBUG_SPCO'
325 325
     ) {
326 326
         if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
328 328
             $debug_data = get_option($debug_key, array());
329 329
             $default_data = array(
330
-                $class => $func . '() : ' . $line,
330
+                $class => $func.'() : '.$line,
331 331
                 'REQ'  => $display_request ? $_REQUEST : '',
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
336
+            if ( ! isset($debug_data[$index])) {
337 337
                 $debug_data[$index] = array();
338 338
             }
339 339
             $debug_data[$index][microtime()] = array_merge($default_data, $info);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 unset($info[$key]);
370 370
             }
371 371
         }
372
-        return (array)$info;
372
+        return (array) $info;
373 373
     }
374 374
 
375 375
 
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400 400
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401 401
         $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
402
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
403
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
404 404
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
405 405
         $result .= EEH_Debug_Tools::headingX($heading_tag);
406 406
         if ($die) {
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             return "\n\n{$var_name}";
424 424
         }
425 425
         $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
426
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
427 427
     }
428 428
 
429 429
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         if (defined('EE_TESTS_DIR')) {
438 438
             return "\n";
439 439
         }
440
-        return '</' . $heading_tag . '>';
440
+        return '</'.$heading_tag.'>';
441 441
     }
442 442
 
443 443
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         if (defined('EE_TESTS_DIR')) {
452 452
             return $content;
453 453
         }
454
-        return '<span style="color:#999">' . $content . '</span>';
454
+        return '<span style="color:#999">'.$content.'</span>';
455 455
     }
456 456
 
457 457
 
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
     protected static function file_and_line($file, $line)
465 465
     {
466 466
         if (defined('EE_TESTS_DIR')) {
467
-            return "\n (" . $file . ' line no: ' . $line . ' ) ';
467
+            return "\n (".$file.' line no: '.$line.' ) ';
468 468
         }
469 469
         return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
470 470
                . $file
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
         if (defined('EE_TESTS_DIR')) {
485 485
             return $content;
486 486
         }
487
-        return '<span style="color:#E76700">' . $content . '</span>';
487
+        return '<span style="color:#E76700">'.$content.'</span>';
488 488
     }
489 489
 
490 490
 
@@ -499,9 +499,9 @@  discard block
 block discarded – undo
499 499
         var_dump($var);
500 500
         $var = ob_get_clean();
501 501
         if (defined('EE_TESTS_DIR')) {
502
-            return "\n" . $var;
502
+            return "\n".$var;
503 503
         }
504
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
504
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
505 505
     }
506 506
 
507 507
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
545 545
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
546 546
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
547
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
547
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
548 548
                 EEH_Debug_Tools::pre_span($var)
549 549
             );
550 550
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
Please login to merge, or discard this patch.
core/services/Benchmark.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     {
123 123
         add_action(
124 124
             'shutdown',
125
-            function () {
125
+            function() {
126 126
                 Benchmark::displayResults();
127 127
             }
128 128
         );
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
             return '';
143 143
         }
144 144
         $output = '';
145
-        if (! empty(Benchmark::$times)) {
145
+        if ( ! empty(Benchmark::$times)) {
146 146
             $total = 0;
147 147
             $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />';
148 148
             foreach (Benchmark::$times as $timer_name => $total_time) {
149
-                $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />';
149
+                $output .= Benchmark::formatTime($timer_name, $total_time).'<br />';
150 150
                 $total += $total_time;
151 151
             }
152 152
             $output .= '<br />';
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
             $output .= '<span style="color:darkorange">Zoinks!</span><br />';
163 163
             $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
164 164
         }
165
-        if (! empty(Benchmark::$memory_usage)) {
166
-            $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage);
165
+        if ( ! empty(Benchmark::$memory_usage)) {
166
+            $output .= '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage);
167 167
         }
168 168
         if (empty($output)) {
169 169
             return '';
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     public static function convert($size)
193 193
     {
194 194
         $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
195
-        return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)];
195
+        return round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)];
196 196
     }
197 197
 
198 198
 
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -17,229 +17,229 @@
 block discarded – undo
17 17
 class Benchmark
18 18
 {
19 19
 
20
-    /**
21
-     * array containing the start time for the timers
22
-     */
23
-    private static $start_times;
24
-
25
-    /**
26
-     * array containing all the timer'd times, which can be outputted via show_times()
27
-     */
28
-    private static $times = array();
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    protected static $memory_usage = array();
34
-
35
-
36
-
37
-    /**
38
-     * whether to benchmark code or not
39
-     */
40
-    public static function doNotRun()
41
-    {
42
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * resetTimes
49
-     */
50
-    public static function resetTimes()
51
-    {
52
-        Benchmark::$times = array();
53
-    }
54
-
55
-
56
-
57
-    /**
58
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
-     *
60
-     * @param null $timer_name
61
-     */
62
-    public static function startTimer($timer_name = null)
63
-    {
64
-        if (Benchmark::doNotRun()) {
65
-            return;
66
-        }
67
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
-        Benchmark::$start_times[$timer_name] = microtime(true);
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
-     *
76
-     * @param string $timer_name
77
-     */
78
-    public static function stopTimer($timer_name = '')
79
-    {
80
-        if (Benchmark::doNotRun()) {
81
-            return;
82
-        }
83
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
-        if (isset(Benchmark::$start_times[$timer_name])) {
85
-            $start_time = Benchmark::$start_times[$timer_name];
86
-            unset(Benchmark::$start_times[$timer_name]);
87
-        } else {
88
-            $start_time = array_pop(Benchmark::$start_times);
89
-        }
90
-        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * Measure the memory usage by PHP so far.
97
-     *
98
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
-     * @return void
101
-     */
102
-    public static function measureMemory($label, $output_now = false)
103
-    {
104
-        if (Benchmark::doNotRun()) {
105
-            return;
106
-        }
107
-        $memory_used = Benchmark::convert(memory_get_peak_usage(true));
108
-        Benchmark::$memory_usage[$label] = $memory_used;
109
-        if ($output_now) {
110
-            echo "\r\n<br>$label : $memory_used";
111
-        }
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * will display the benchmarking results at shutdown
118
-     *
119
-     * @return void
120
-     */
121
-    public static function displayResultsAtShutdown()
122
-    {
123
-        add_action(
124
-            'shutdown',
125
-            function () {
126
-                Benchmark::displayResults();
127
-            }
128
-        );
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * displayResults
135
-     *
136
-     * @param bool $echo
137
-     * @return string
138
-     */
139
-    public static function displayResults($echo = true)
140
-    {
141
-        if (Benchmark::doNotRun()) {
142
-            return '';
143
-        }
144
-        $output = '';
145
-        if (! empty(Benchmark::$times)) {
146
-            $total = 0;
147
-            $output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />';
148
-            foreach (Benchmark::$times as $timer_name => $total_time) {
149
-                $output .= Benchmark::formatTime($timer_name, $total_time) . '<br />';
150
-                $total += $total_time;
151
-            }
152
-            $output .= '<br />';
153
-            $output .= '<h4>TOTAL TIME</h4>';
154
-            $output .= Benchmark::formatTime('', $total);
155
-            $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
156
-            $output .= '<br />';
157
-            $output .= '<h5>Performance scale (from best to worse)</h5>';
158
-            $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
159
-            $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
160
-            $output .= '<span style="color:limegreen">Like...groovy!</span><br />';
161
-            $output .= '<span style="color:gold">Ruh Oh</span><br />';
162
-            $output .= '<span style="color:darkorange">Zoinks!</span><br />';
163
-            $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
164
-        }
165
-        if (! empty(Benchmark::$memory_usage)) {
166
-            $output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage);
167
-        }
168
-        if (empty($output)) {
169
-            return '';
170
-        }
171
-        $output = '<div style="border:1px solid #dddddd; background-color:#ffffff;'
172
-                  . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;')
173
-                  . ' padding:2em;">'
174
-                  . '<h4>BENCHMARKING</h4>'
175
-                  . $output
176
-                  . '</div>';
177
-        if ($echo) {
178
-            echo $output;
179
-            return '';
180
-        }
181
-        return $output;
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
188
-     *
189
-     * @param int $size
190
-     * @return string
191
-     */
192
-    public static function convert($size)
193
-    {
194
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
195
-        return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)];
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @param string $timer_name
202
-     * @param float  $total_time
203
-     * @return string
204
-     */
205
-    public static function formatTime($timer_name, $total_time)
206
-    {
207
-        $total_time *= 1000;
208
-        switch ($total_time) {
209
-            case $total_time > 12500 :
210
-                $color = 'red';
211
-                $bold = 'bold';
212
-                break;
213
-            case $total_time > 2500 :
214
-                $color = 'darkorange';
215
-                $bold = 'bold';
216
-                break;
217
-            case $total_time > 500 :
218
-                $color = 'gold';
219
-                $bold = 'bold';
220
-                break;
221
-            case $total_time > 100 :
222
-                $color = 'limegreen';
223
-                $bold = 'normal';
224
-                break;
225
-            case $total_time > 20 :
226
-                $color = 'deepskyblue';
227
-                $bold = 'normal';
228
-                break;
229
-            default :
230
-                $color = 'mediumpurple';
231
-                $bold = 'normal';
232
-                break;
233
-        }
234
-        return '<span style="min-width: 10px; margin:0 1em; color:'
235
-               . $color
236
-               . '; font-weight:'
237
-               . $bold
238
-               . '; font-size:1.2em;">'
239
-               . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
240
-               . '</span> '
241
-               . $timer_name;
242
-    }
20
+	/**
21
+	 * array containing the start time for the timers
22
+	 */
23
+	private static $start_times;
24
+
25
+	/**
26
+	 * array containing all the timer'd times, which can be outputted via show_times()
27
+	 */
28
+	private static $times = array();
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	protected static $memory_usage = array();
34
+
35
+
36
+
37
+	/**
38
+	 * whether to benchmark code or not
39
+	 */
40
+	public static function doNotRun()
41
+	{
42
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * resetTimes
49
+	 */
50
+	public static function resetTimes()
51
+	{
52
+		Benchmark::$times = array();
53
+	}
54
+
55
+
56
+
57
+	/**
58
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
59
+	 *
60
+	 * @param null $timer_name
61
+	 */
62
+	public static function startTimer($timer_name = null)
63
+	{
64
+		if (Benchmark::doNotRun()) {
65
+			return;
66
+		}
67
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
68
+		Benchmark::$start_times[$timer_name] = microtime(true);
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
75
+	 *
76
+	 * @param string $timer_name
77
+	 */
78
+	public static function stopTimer($timer_name = '')
79
+	{
80
+		if (Benchmark::doNotRun()) {
81
+			return;
82
+		}
83
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
84
+		if (isset(Benchmark::$start_times[$timer_name])) {
85
+			$start_time = Benchmark::$start_times[$timer_name];
86
+			unset(Benchmark::$start_times[$timer_name]);
87
+		} else {
88
+			$start_time = array_pop(Benchmark::$start_times);
89
+		}
90
+		Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * Measure the memory usage by PHP so far.
97
+	 *
98
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
99
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
100
+	 * @return void
101
+	 */
102
+	public static function measureMemory($label, $output_now = false)
103
+	{
104
+		if (Benchmark::doNotRun()) {
105
+			return;
106
+		}
107
+		$memory_used = Benchmark::convert(memory_get_peak_usage(true));
108
+		Benchmark::$memory_usage[$label] = $memory_used;
109
+		if ($output_now) {
110
+			echo "\r\n<br>$label : $memory_used";
111
+		}
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * will display the benchmarking results at shutdown
118
+	 *
119
+	 * @return void
120
+	 */
121
+	public static function displayResultsAtShutdown()
122
+	{
123
+		add_action(
124
+			'shutdown',
125
+			function () {
126
+				Benchmark::displayResults();
127
+			}
128
+		);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * displayResults
135
+	 *
136
+	 * @param bool $echo
137
+	 * @return string
138
+	 */
139
+	public static function displayResults($echo = true)
140
+	{
141
+		if (Benchmark::doNotRun()) {
142
+			return '';
143
+		}
144
+		$output = '';
145
+		if (! empty(Benchmark::$times)) {
146
+			$total = 0;
147
+			$output .= '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />';
148
+			foreach (Benchmark::$times as $timer_name => $total_time) {
149
+				$output .= Benchmark::formatTime($timer_name, $total_time) . '<br />';
150
+				$total += $total_time;
151
+			}
152
+			$output .= '<br />';
153
+			$output .= '<h4>TOTAL TIME</h4>';
154
+			$output .= Benchmark::formatTime('', $total);
155
+			$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
156
+			$output .= '<br />';
157
+			$output .= '<h5>Performance scale (from best to worse)</h5>';
158
+			$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
159
+			$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
160
+			$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
161
+			$output .= '<span style="color:gold">Ruh Oh</span><br />';
162
+			$output .= '<span style="color:darkorange">Zoinks!</span><br />';
163
+			$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
164
+		}
165
+		if (! empty(Benchmark::$memory_usage)) {
166
+			$output .= '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage);
167
+		}
168
+		if (empty($output)) {
169
+			return '';
170
+		}
171
+		$output = '<div style="border:1px solid #dddddd; background-color:#ffffff;'
172
+				  . (is_admin() ? ' margin:2em 2em 2em 180px;' : ' margin:2em;')
173
+				  . ' padding:2em;">'
174
+				  . '<h4>BENCHMARKING</h4>'
175
+				  . $output
176
+				  . '</div>';
177
+		if ($echo) {
178
+			echo $output;
179
+			return '';
180
+		}
181
+		return $output;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
188
+	 *
189
+	 * @param int $size
190
+	 * @return string
191
+	 */
192
+	public static function convert($size)
193
+	{
194
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
195
+		return round($size / pow(1024, $i = floor(log($size, 1024))), 2) . ' ' . $unit[absint($i)];
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @param string $timer_name
202
+	 * @param float  $total_time
203
+	 * @return string
204
+	 */
205
+	public static function formatTime($timer_name, $total_time)
206
+	{
207
+		$total_time *= 1000;
208
+		switch ($total_time) {
209
+			case $total_time > 12500 :
210
+				$color = 'red';
211
+				$bold = 'bold';
212
+				break;
213
+			case $total_time > 2500 :
214
+				$color = 'darkorange';
215
+				$bold = 'bold';
216
+				break;
217
+			case $total_time > 500 :
218
+				$color = 'gold';
219
+				$bold = 'bold';
220
+				break;
221
+			case $total_time > 100 :
222
+				$color = 'limegreen';
223
+				$bold = 'normal';
224
+				break;
225
+			case $total_time > 20 :
226
+				$color = 'deepskyblue';
227
+				$bold = 'normal';
228
+				break;
229
+			default :
230
+				$color = 'mediumpurple';
231
+				$bold = 'normal';
232
+				break;
233
+		}
234
+		return '<span style="min-width: 10px; margin:0 1em; color:'
235
+			   . $color
236
+			   . '; font-weight:'
237
+			   . $bold
238
+			   . '; font-size:1.2em;">'
239
+			   . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
240
+			   . '</span> '
241
+			   . $timer_name;
242
+	}
243 243
 
244 244
 
245 245
 
Please login to merge, or discard this patch.