Completed
Branch FET-10486-add-timestamp-checki... (786b14)
by
unknown
79:06 queued 65:28
created
core/db_models/relations/EE_Belongs_To_Relation.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -13,128 +13,128 @@
 block discarded – undo
13 13
 class EE_Belongs_To_Relation extends EE_Model_Relation_Base
14 14
 {
15 15
 
16
-    /**
17
-     * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
18
-     * to the other model. This knows how to join the models,
19
-     * get related models across the relation, and add-and-remove the relationships.
20
-     *
21
-     * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
22
-     *                                                              default. if there are related models across this
23
-     *                                                              relation, block (prevent and add an error) the
24
-     *                                                              deletion of this model
25
-     * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
26
-     *                                                              instead of the default
27
-     */
28
-    public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
29
-    {
30
-        parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
31
-    }
16
+	/**
17
+	 * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
18
+	 * to the other model. This knows how to join the models,
19
+	 * get related models across the relation, and add-and-remove the relationships.
20
+	 *
21
+	 * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
22
+	 *                                                              default. if there are related models across this
23
+	 *                                                              relation, block (prevent and add an error) the
24
+	 *                                                              deletion of this model
25
+	 * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
26
+	 *                                                              instead of the default
27
+	 */
28
+	public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
29
+	{
30
+		parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * get_join_statement
36
-     *
37
-     * @param string $model_relation_chain
38
-     * @return string
39
-     * @throws \EE_Error
40
-     */
41
-    public function get_join_statement($model_relation_chain)
42
-    {
43
-        //create the sql string like
44
-        $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
47
-                $this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
48
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
50
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
51
-        return $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
52
-                $this_table_alias,
53
-                $this_table_fk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
54
-    }
34
+	/**
35
+	 * get_join_statement
36
+	 *
37
+	 * @param string $model_relation_chain
38
+	 * @return string
39
+	 * @throws \EE_Error
40
+	 */
41
+	public function get_join_statement($model_relation_chain)
42
+	{
43
+		//create the sql string like
44
+		$this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
47
+				$this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
48
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
+				$this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
50
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
51
+		return $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
52
+				$this_table_alias,
53
+				$this_table_fk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
59
-     * you like.
60
-     *
61
-     * @param EE_Base_Class|int $this_obj_or_id
62
-     * @param EE_Base_Class|int $other_obj_or_id
63
-     * @param array             $extra_join_model_fields_n_values
64
-     * @return \EE_Base_Class
65
-     * @throws \EE_Error
66
-     */
67
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
68
-    {
69
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
70
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
71
-        //find the field on the other model which is a foreign key to this model
72
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
73
-        if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
74
-            //set that field on the other model to this model's ID
75
-            $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
76
-            $this_model_obj->save();
77
-        }
78
-        return $other_model_obj;
79
-    }
57
+	/**
58
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
59
+	 * you like.
60
+	 *
61
+	 * @param EE_Base_Class|int $this_obj_or_id
62
+	 * @param EE_Base_Class|int $other_obj_or_id
63
+	 * @param array             $extra_join_model_fields_n_values
64
+	 * @return \EE_Base_Class
65
+	 * @throws \EE_Error
66
+	 */
67
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
68
+	{
69
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
70
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
71
+		//find the field on the other model which is a foreign key to this model
72
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
73
+		if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
74
+			//set that field on the other model to this model's ID
75
+			$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
76
+			$this_model_obj->save();
77
+		}
78
+		return $other_model_obj;
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
84
-     *
85
-     * @param EE_Base_Class|int $this_obj_or_id
86
-     * @param EE_Base_Class|int $other_obj_or_id
87
-     * @param array             $where_query
88
-     * @return \EE_Base_Class
89
-     * @throws \EE_Error
90
-     */
91
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
92
-    {
93
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
94
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
95
-        //find the field on the other model which is a foreign key to this model
96
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
97
-        //set that field on the other model to this model's ID
98
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
99
-        $this_model_obj->save();
100
-        return $other_model_obj;
101
-    }
82
+	/**
83
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
84
+	 *
85
+	 * @param EE_Base_Class|int $this_obj_or_id
86
+	 * @param EE_Base_Class|int $other_obj_or_id
87
+	 * @param array             $where_query
88
+	 * @return \EE_Base_Class
89
+	 * @throws \EE_Error
90
+	 */
91
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
92
+	{
93
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
94
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
95
+		//find the field on the other model which is a foreign key to this model
96
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
97
+		//set that field on the other model to this model's ID
98
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
99
+		$this_model_obj->save();
100
+		return $other_model_obj;
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
106
-     *
107
-     * @param EE_Base_Class $model_obj_or_id
108
-     * @param array         $query_params                            like EEM_Base::get_all's $query_params
109
-     * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
110
-     * @return EE_Base_Class[]
111
-     * @throws \EE_Error
112
-     */
113
-    public function get_all_related(
114
-        $model_obj_or_id,
115
-        $query_params = array(),
116
-        $values_already_prepared_by_model_object = false
117
-    ) {
118
-        if ($values_already_prepared_by_model_object !== false) {
119
-            EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related',
120
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
121
-                '4.8.1');
122
-        }
123
-        //get column on this model object which is a foreign key to the other model
124
-        $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
125
-        //get its value
126
-        if ($model_obj_or_id instanceof EE_Base_Class) {
127
-            $model_obj = $model_obj_or_id;
128
-        } else {
129
-            $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
130
-        }
131
-        $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
132
-        //get all where their PK matches that value
133
-        $query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
134
-        $query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
104
+	/**
105
+	 * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
106
+	 *
107
+	 * @param EE_Base_Class $model_obj_or_id
108
+	 * @param array         $query_params                            like EEM_Base::get_all's $query_params
109
+	 * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
110
+	 * @return EE_Base_Class[]
111
+	 * @throws \EE_Error
112
+	 */
113
+	public function get_all_related(
114
+		$model_obj_or_id,
115
+		$query_params = array(),
116
+		$values_already_prepared_by_model_object = false
117
+	) {
118
+		if ($values_already_prepared_by_model_object !== false) {
119
+			EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related',
120
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
121
+				'4.8.1');
122
+		}
123
+		//get column on this model object which is a foreign key to the other model
124
+		$fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
125
+		//get its value
126
+		if ($model_obj_or_id instanceof EE_Base_Class) {
127
+			$model_obj = $model_obj_or_id;
128
+		} else {
129
+			$model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
130
+		}
131
+		$ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
132
+		//get all where their PK matches that value
133
+		$query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
134
+		$query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
135 135
 //		echo '$query_params';
136 136
 //		var_dump($query_params);
137
-        return $this->get_other_model()->get_all($query_params);
138
-    }
137
+		return $this->get_other_model()->get_all($query_params);
138
+	}
139 139
 
140 140
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'relations/EE_Model_Relation_Base.php');
2
+require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php');
3 3
 
4 4
 /**
5 5
  * Class EE_Belongs_To_Relation
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
         $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
45 45
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
46 46
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
47
-                $this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias();
47
+                $this->get_this_model()->get_this_model_name()).$this_table_fk_field->get_table_alias();
48 48
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,
49
-                $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias();
49
+                $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias();
50 50
         $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
51 51
         return $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(),
52 52
                 $this_table_alias,
53
-                $this_table_fk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53
+                $this_table_fk_field->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
54 54
     }
55 55
 
56 56
 
Please login to merge, or discard this patch.
core/EE_Data_Migration_Manager.core.php 3 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	protected $_table_analysis;
128 128
 
129 129
 	/**
130
-     * 	@var EE_Data_Migration_Manager $_instance
130
+	 * 	@var EE_Data_Migration_Manager $_instance
131 131
 	 * 	@access 	private
132
-     */
132
+	 */
133 133
 	private static $_instance = NULL;
134 134
 
135 135
 
@@ -720,18 +720,18 @@  discard block
 block discarded – undo
720 720
 
721 721
 
722 722
 
723
-    /**
724
-     * Gets all the data migration scripts available in the core folder and folders
725
-     * in addons. Has the side effect of adding them for autoloading
726
-     *
727
-     * @return array keys are expected classnames, values are their filepaths
728
-     * @throws \EE_Error
729
-     */
723
+	/**
724
+	 * Gets all the data migration scripts available in the core folder and folders
725
+	 * in addons. Has the side effect of adding them for autoloading
726
+	 *
727
+	 * @return array keys are expected classnames, values are their filepaths
728
+	 * @throws \EE_Error
729
+	 */
730 730
 	public function get_all_data_migration_scripts_available(){
731 731
 		if( ! $this->_data_migration_class_to_filepath_map){
732 732
 			$this->_data_migration_class_to_filepath_map = array();
733 733
 			foreach($this->get_data_migration_script_folders() as $folder_path){
734
-                $folder_path = EEH_File::end_with_directory_separator($folder_path);
734
+				$folder_path = EEH_File::end_with_directory_separator($folder_path);
735 735
 				$files = glob( $folder_path. '*.dms.php' );
736 736
 
737 737
 				if ( empty( $files ) ) {
@@ -748,15 +748,15 @@  discard block
 block discarded – undo
748 748
 					if( $slug !== 'Core' ){
749 749
 						if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) {
750 750
 							EE_Error::doing_it_wrong(
751
-							    __FUNCTION__,
752
-                                sprintf(
753
-                                    __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ),
754
-                                    $classname,
755
-                                    $slug,
756
-                                    implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) )
757
-                                ),
758
-                                '4.3.0.alpha.019'
759
-                            );
751
+								__FUNCTION__,
752
+								sprintf(
753
+									__( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ),
754
+									$classname,
755
+									$slug,
756
+									implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) )
757
+								),
758
+								'4.3.0.alpha.019'
759
+							);
760 760
 						}
761 761
 					}
762 762
 					$this->_data_migration_class_to_filepath_map[$classname] = $file;
@@ -939,12 +939,12 @@  discard block
 block discarded – undo
939 939
 	}
940 940
 
941 941
 /**
942
-	 * Resets the borked data migration scripts so they're no longer borked
943
-	 * so we can again attempt to migrate
944
-	 *
945
-	 * @return bool
946
-	 * @throws \EE_Error
947
-	 */
942
+ * Resets the borked data migration scripts so they're no longer borked
943
+ * so we can again attempt to migrate
944
+ *
945
+ * @return bool
946
+ * @throws \EE_Error
947
+ */
948 948
 	public function reattempt(){
949 949
 		//find if the last-ran script was borked
950 950
 		//set it as being non-borked (we shouldn't ever get DMSs that we don't recognize)
Please login to merge, or discard this patch.
Spacing   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  * to indicate it successfully migrate some data, and has nothing left to do; or EE_Data_Migration_Manager::status_fatal_error to indicate
25 25
  * an error occurred which means the ajax script should probably stop executing.
26 26
  */
27
-class EE_Data_Migration_Manager{
27
+class EE_Data_Migration_Manager {
28 28
 
29 29
 	/**
30 30
 	 *
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * of this EE installation. Keys should be the name of the version the script upgraded to
82 82
 	 * @var EE_Data_Migration_Script_Base[]
83 83
 	 */
84
-	private $_data_migrations_ran =null;
84
+	private $_data_migrations_ran = null;
85 85
 	/**
86 86
 	 * The last ran script. It's nice to store this somewhere accessible, as its easiest
87 87
 	 * to know which was the last run by which is the newest wp option; but in most of the code
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	public static function instance() {
143 143
 		// check if class object is instantiated
144
-		if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) {
144
+		if ( ! self::$_instance instanceof EE_Data_Migration_Manager) {
145 145
 			self::$_instance = new self();
146 146
 		}
147 147
 		return self::$_instance;
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * all new usages of the singleton should be made with Classname::instance()) and returns it
152 152
 	 * @return EE_Data_Migration_Manager
153 153
 	 */
154
-	public static function reset(){
154
+	public static function reset() {
155 155
 		self::$_instance = NULL;
156 156
 		return self::instance();
157 157
 	}
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	/**
162 162
 	 * constructor
163 163
 	 */
164
-	private function __construct(){
164
+	private function __construct() {
165 165
 		$this->stati_that_indicate_to_continue_migrations = array(
166 166
 			self::status_continue,
167 167
 			self::status_completed
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
 		);
181 181
 		//make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class
182 182
 		//to be defined, because right now it doesn't get autoloaded on its own
183
-		EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE );
184
-		EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE );
185
-		EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE );
186
-		EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE );
187
-		EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE );
188
-		$this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true );
189
-		$this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true );
183
+		EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE);
184
+		EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE);
185
+		EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE);
186
+		EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE);
187
+		EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE);
188
+		$this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true);
189
+		$this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
190 190
 	}
191 191
 
192 192
 
@@ -199,21 +199,21 @@  discard block
 block discarded – undo
199 199
 	 * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set)
200 200
 	 * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0')
201 201
 	 */
202
-	private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){
202
+	private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) {
203 203
 		$plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name);
204 204
 		//check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style)
205
-		$parts = explode(".",$plugin_slug_and_version_string);
205
+		$parts = explode(".", $plugin_slug_and_version_string);
206 206
 
207
-		if(count($parts) == 4){
207
+		if (count($parts) == 4) {
208 208
 			//it's 4.2-style.eg Core.4.1.0
209
-			$plugin_slug = $parts[0];//eg Core
209
+			$plugin_slug = $parts[0]; //eg Core
210 210
 			$version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0
211
-		}else{
211
+		} else {
212 212
 			//it's 4.1-style: eg 4.1.0
213 213
 			$plugin_slug = 'Core';
214
-			$version_string = $plugin_slug_and_version_string;//eg 4.1.0
214
+			$version_string = $plugin_slug_and_version_string; //eg 4.1.0
215 215
 		}
216
-		return array($plugin_slug,$version_string);
216
+		return array($plugin_slug, $version_string);
217 217
 	}
218 218
 
219 219
 	/**
@@ -224,21 +224,21 @@  discard block
 block discarded – undo
224 224
 	 * @return EE_Data_Migration_Script_Base
225 225
 	 * @throws EE_Error
226 226
 	 */
227
-	private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){
227
+	private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) {
228 228
 		$data_migration_data = maybe_unserialize($dms_option_value);
229
-		if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){
229
+		if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) {
230 230
 			$class = new $data_migration_data['class'];
231
-			if($class instanceof EE_Data_Migration_Script_Base){
231
+			if ($class instanceof EE_Data_Migration_Script_Base) {
232 232
 				$class->instantiate_from_array_of_properties($data_migration_data);
233 233
 				return $class;
234
-			}else{
234
+			} else {
235 235
 				//huh, so its an object but not a data migration script?? that shouldn't happen
236 236
 				//just leave it as an array (which will probably just get ignored)
237
-				throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class']));
237
+				throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class']));
238 238
 			}
239
-		}else{
239
+		} else {
240 240
 			//so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists
241
-			throw new EE_Error(sprintf(__("The wp option  with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name));
241
+			throw new EE_Error(sprintf(__("The wp option  with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name));
242 242
 		}
243 243
 	}
244 244
 	/**
@@ -246,34 +246,34 @@  discard block
 block discarded – undo
246 246
 	 * the last ran which hasn't finished yet
247 247
 	 * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored)
248 248
 	 */
249
-	public function get_data_migrations_ran(){
250
-		if( ! $this->_data_migrations_ran ){
249
+	public function get_data_migrations_ran() {
250
+		if ( ! $this->_data_migrations_ran) {
251 251
 			//setup autoloaders for each of the scripts in there
252 252
 			$this->get_all_data_migration_scripts_available();
253
-			$data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array()));
253
+			$data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array()));
254 254
 
255 255
 			$data_migrations_ran = array();
256 256
 			//convert into data migration script classes where possible
257
-			foreach($data_migrations_options as $data_migration_option){
258
-				list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']);
257
+			foreach ($data_migrations_options as $data_migration_option) {
258
+				list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']);
259 259
 
260
-				try{
261
-					$class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']);
260
+				try {
261
+					$class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']);
262 262
 					$data_migrations_ran[$plugin_slug][$version_string] = $class;
263 263
 					//ok so far THIS is the 'last-ran-script'... unless we find another on next iteration
264 264
 					$this->_last_ran_script = $class;
265
-					if( ! $class->is_completed()){
265
+					if ( ! $class->is_completed()) {
266 266
 						//sometimes we also like to know which was the last incomplete script (or if there are any at all)
267 267
 						$this->_last_ran_incomplete_script = $class;
268 268
 					}
269
-				}catch(EE_Error $e){
269
+				} catch (EE_Error $e) {
270 270
 					//ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs
271 271
 					$data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']);
272 272
 				}
273 273
 			}
274 274
 			//so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays
275 275
 			$this->_data_migrations_ran = $data_migrations_ran;
276
-			 if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){
276
+			 if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) {
277 277
 				$this->_data_migrations_ran = array();
278 278
 			}
279 279
 		}
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @param        $new_table
291 291
 	 * @return mixed string or int
292 292
 	 */
293
-	public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){
293
+	public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) {
294 294
 		$script = EE_Registry::instance()->load_dms($script_name);
295 295
 		$mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table);
296 296
 		return $mapping;
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
 	 * option returned in this array is the most-recently ran DMS option
302 302
 	 * @return array
303 303
 	 */
304
-	 public function get_all_migration_script_options(){
304
+	 public function get_all_migration_script_options() {
305 305
 		global $wpdb;
306
-		return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A);
306
+		return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A);
307 307
 	}
308 308
 
309 309
 	/**
@@ -311,8 +311,8 @@  discard block
 block discarded – undo
311 311
 	 * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the
312 312
 	 * folder name.
313 313
 	 */
314
-	public function get_data_migration_script_folders(){
315
-		return  apply_filters( 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',array(EE_CORE.'data_migration_scripts') );
314
+	public function get_data_migration_script_folders() {
315
+		return  apply_filters('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', array(EE_CORE.'data_migration_scripts'));
316 316
 	}
317 317
 
318 318
 	/**
@@ -324,11 +324,11 @@  discard block
 block discarded – undo
324 324
 	 * }
325 325
 	 * @throws EE_Error
326 326
 	 */
327
-	public function script_migrates_to_version($migration_script_name){
327
+	public function script_migrates_to_version($migration_script_name) {
328 328
 		$dms_info = $this->parse_dms_classname($migration_script_name);
329 329
 		return array(
330
-			'slug'=> $dms_info[ 'slug' ],
331
-			'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] );
330
+			'slug'=> $dms_info['slug'],
331
+			'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] );
332 332
 	}
333 333
 
334 334
 	/**
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
 	 * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints)
338 338
 	 * @throws EE_Error
339 339
 	 */
340
-	public function parse_dms_classname($classname){
340
+	public function parse_dms_classname($classname) {
341 341
 		$matches = array();
342
-		preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches);
343
-		if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){
344
-				throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname));
342
+		preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches);
343
+		if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) {
344
+				throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname));
345 345
 		}
346
-		return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4]));
346
+		return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4]));
347 347
 	}
348 348
 	/**
349 349
 	 * Ensures that the option indicating the current DB version is set. This should only be
@@ -352,33 +352,33 @@  discard block
 block discarded – undo
352 352
 	 * to 4.1.x.
353 353
 	 * @return string of current db state
354 354
 	 */
355
-	public function ensure_current_database_state_is_set(){
356
-		$espresso_db_core_updates = get_option( 'espresso_db_update', array() );
355
+	public function ensure_current_database_state_is_set() {
356
+		$espresso_db_core_updates = get_option('espresso_db_update', array());
357 357
 		$db_state = get_option(EE_Data_Migration_Manager::current_database_state);
358
-		if( ! $db_state ){
358
+		if ( ! $db_state) {
359 359
 			//mark the DB as being in the state as the last version in there.
360 360
 			//this is done to trigger maintenance mode and do data migration scripts
361 361
 			//if the admin installed this version of EE over 3.1.x or 4.0.x
362 362
 			//otherwise, the normal maintenance mode code is fine
363 363
 			$previous_versions_installed = array_keys($espresso_db_core_updates);
364 364
 			$previous_version_installed = end($previous_versions_installed);
365
-			if(version_compare('4.1.0', $previous_version_installed)){
365
+			if (version_compare('4.1.0', $previous_version_installed)) {
366 366
 				//last installed version was less than 4.1
367 367
 				//so we want the data migrations to happen. SO, we're going to say the DB is at that state
368 368
 //				echo "4.1.0 is greater than $previous_version_installed! update the option";
369 369
 				$db_state = array('Core'=>$previous_version_installed);
370
-			}else{
370
+			} else {
371 371
 //					echo "4.1.0 is SMALLER than $previous_version_installed";
372 372
 					$db_state = array('Core'=>EVENT_ESPRESSO_VERSION);
373 373
 			}
374
-			update_option(EE_Data_Migration_Manager::current_database_state,$db_state);
374
+			update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
375 375
 		}
376 376
 		//in 4.1, $db_state would have only been a simple string like '4.1.0',
377 377
 		//but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's
378 378
 		//db, and possibly other keys for other addons like 'Calendar','Permissions',etc
379
-		if( ! is_array($db_state)){
379
+		if ( ! is_array($db_state)) {
380 380
 			$db_state = array('Core'=>$db_state);
381
-			update_option(EE_Data_Migration_Manager::current_database_state,$db_state);
381
+			update_option(EE_Data_Migration_Manager::current_database_state, $db_state);
382 382
 		}
383 383
 		return $db_state;
384 384
 	}
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	 * or they don't apply), returns an empty array
390 390
 	 * @return EE_Data_Migration_Script_Base[]
391 391
 	 */
392
-	public function check_for_applicable_data_migration_scripts(){
392
+	public function check_for_applicable_data_migration_scripts() {
393 393
 		//get the option describing what options have already run
394 394
 		$scripts_ran = $this->get_data_migrations_ran();
395 395
 		//$scripts_ran = array('4.1.0.core'=>array('monkey'=>null));
@@ -402,62 +402,62 @@  discard block
 block discarded – undo
402 402
 		$iteration = 0;
403 403
 		$next_database_state_to_consider = $current_database_state;
404 404
 		$theoretical_database_state = NULL;
405
-		do{
405
+		do {
406 406
 			//the next state after the currently-considered one will start off looking the same as the current, but we may make additions...
407 407
 			$theoretical_database_state = $next_database_state_to_consider;
408 408
 			//the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?)
409
-			foreach($script_class_and_filepaths_available as $classname => $filepath){
409
+			foreach ($script_class_and_filepaths_available as $classname => $filepath) {
410 410
 
411 411
 				$migrates_to_version = $this->script_migrates_to_version($classname);
412
-				$script_converts_plugin_slug = $migrates_to_version[ 'slug' ];
413
-				$script_converts_to_version = $migrates_to_version[ 'version' ];
412
+				$script_converts_plugin_slug = $migrates_to_version['slug'];
413
+				$script_converts_to_version = $migrates_to_version['version'];
414 414
 				//check if this version script is DONE or not; or if it's never been ran
415
-				if(		! $scripts_ran ||
415
+				if ( ! $scripts_ran ||
416 416
 						! isset($scripts_ran[$script_converts_plugin_slug]) ||
417
-						! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){
417
+						! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) {
418 418
 					//we haven't ran this conversion script before
419 419
 					//now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available
420
-					$script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() );
420
+					$script = new $classname($this->_get_table_manager(), $this->_get_table_analysis());
421 421
 					/* @var $script EE_Data_Migration_Script_Base */
422 422
 					$can_migrate = $script->can_migrate_from_version($theoretical_database_state);
423
-					if($can_migrate){
423
+					if ($can_migrate) {
424 424
 						$script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script;
425 425
 						$migrates_to_version = $script->migrates_to_version();
426
-						$next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ];
426
+						$next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version'];
427 427
 						unset($script_class_and_filepaths_available[$classname]);
428 428
 					}
429
-				} elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){
429
+				} elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) {
430 430
 					//this script has been ran, or at least started
431 431
 					$script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version];
432
-					if( $script->get_status() != self::status_completed){
432
+					if ($script->get_status() != self::status_completed) {
433 433
 						//this script is already underway... keep going with it
434 434
 						$script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script;
435 435
 						$migrates_to_version = $script->migrates_to_version();
436
-						$next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ];
436
+						$next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version'];
437 437
 						unset($script_class_and_filepaths_available[$classname]);
438
-					}else{
438
+					} else {
439 439
 						//it must have a status that indicates it has finished, so we don't want to try and run it again
440 440
 					}
441
-				}else{
441
+				} else {
442 442
 					//it exists but it's not  a proper data migration script
443 443
 					//maybe the script got renamed? or was simply removed from EE?
444 444
 					//either way, its certainly not runnable!
445 445
 				}
446 446
 			}
447 447
 			$iteration++;
448
-		}while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6);
448
+		}while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6);
449 449
 		//ok we have all the scripts that should run, now let's make them into flat array
450 450
 		$scripts_that_should_run = array();
451
-		foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){
451
+		foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) {
452 452
 			ksort($scripts_at_priority);
453
-			foreach($scripts_at_priority as $scripts){
454
-				foreach($scripts as $script){
453
+			foreach ($scripts_at_priority as $scripts) {
454
+				foreach ($scripts as $script) {
455 455
 					$scripts_that_should_run[get_class($script)] = $script;
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 
460
-		do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run );
460
+		do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run);
461 461
 		return $scripts_that_should_run;
462 462
 	}
463 463
 
@@ -471,14 +471,14 @@  discard block
 block discarded – undo
471 471
 	 * @param bool $include_completed_scripts
472 472
 	 * @return EE_Data_Migration_Script_Base
473 473
 	 */
474
-	public function get_last_ran_script($include_completed_scripts = false){
474
+	public function get_last_ran_script($include_completed_scripts = false) {
475 475
 		//make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script
476
-		if( ! $this->_data_migrations_ran){
476
+		if ( ! $this->_data_migrations_ran) {
477 477
 			$this->get_data_migrations_ran();
478 478
 		}
479
-		if($include_completed_scripts){
479
+		if ($include_completed_scripts) {
480 480
 			return $this->_last_ran_script;
481
-		}else{
481
+		} else {
482 482
 			return $this->_last_ran_incomplete_script;
483 483
 		}
484 484
 	}
@@ -501,19 +501,19 @@  discard block
 block discarded – undo
501 501
 	 * 		@type string $message string describing what was done during this step
502 502
 	 * }
503 503
 	 */
504
-	public function migration_step( $step_size = 0 ){
504
+	public function migration_step($step_size = 0) {
505 505
 
506 506
 		//bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535
507
-		if ( class_exists( 'EE_CPT_Strategy' ) ) {
508
-			remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 );
507
+		if (class_exists('EE_CPT_Strategy')) {
508
+			remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5);
509 509
 		}
510 510
 
511
-		try{
511
+		try {
512 512
 			$currently_executing_script = $this->get_last_ran_script();
513
-			if( ! $currently_executing_script){
513
+			if ( ! $currently_executing_script) {
514 514
 				//Find the next script that needs to execute
515 515
 				$scripts = $this->check_for_applicable_data_migration_scripts();
516
-				if( ! $scripts ){
516
+				if ( ! $scripts) {
517 517
 					//huh, no more scripts to run... apparently we're done!
518 518
 					//but dont forget to make sure initial data is there
519 519
 					//we should be good to allow them to exit maintenance mode now
@@ -534,18 +534,18 @@  discard block
 block discarded – undo
534 534
 				//and add to the array/wp option showing the scripts ran
535 535
 //				$this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script;
536 536
 				$migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script));
537
-				$plugin_slug = $migrates_to[ 'slug' ];
538
-				$version = $migrates_to[ 'version' ];
537
+				$plugin_slug = $migrates_to['slug'];
538
+				$version = $migrates_to['version'];
539 539
 				$this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script;
540 540
 			}
541 541
 			$current_script_name = get_class($currently_executing_script);
542
-		}catch(Exception $e){
542
+		} catch (Exception $e) {
543 543
 			//an exception occurred while trying to get migration scripts
544 544
 
545
-			$message =  sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() );
545
+			$message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString());
546 546
 			//record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations
547 547
 			//but that's ok-- it's just an FYI to support that we couldn't even run any data migrations
548
-			$this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message));
548
+			$this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message));
549 549
 			return array(
550 550
 				'records_to_migrate'=>1,
551 551
 				'records_migrated'=>0,
@@ -555,16 +555,16 @@  discard block
 block discarded – undo
555 555
 			);
556 556
 		}
557 557
 		//ok so we definitely have a data migration script
558
-		try{
558
+		try {
559 559
 			//how big of a bite do we want to take? Allow users to easily override via their wp-config
560
-			if( ! absint( $step_size ) > 0 ){
561
-				$step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size;
560
+			if ( ! absint($step_size) > 0) {
561
+				$step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size;
562 562
 			}
563 563
 			//do what we came to do!
564 564
 			$currently_executing_script->migration_step($step_size);
565 565
 			//can we wrap it up and verify default data?
566 566
 			$init_dbs = false;
567
-			switch($currently_executing_script->get_status()){
567
+			switch ($currently_executing_script->get_status()) {
568 568
 				case EE_Data_Migration_Manager::status_continue:
569 569
 					$response_array = array(
570 570
 						'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(),
@@ -576,16 +576,16 @@  discard block
 block discarded – undo
576 576
 				case EE_Data_Migration_Manager::status_completed:
577 577
 					//ok so THAT script has completed
578 578
 					$this->update_current_database_state_to($this->script_migrates_to_version($current_script_name));
579
-					$response_array =  array(
579
+					$response_array = array(
580 580
 							'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(),
581 581
 							'records_migrated'=>$currently_executing_script->count_records_migrated(),
582 582
 							'status'=> EE_Data_Migration_Manager::status_completed,
583 583
 							'message'=>$currently_executing_script->get_feedback_message(),
584
-							'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name())
584
+							'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name())
585 585
 						);
586 586
 					//check if there are any more after this one.
587 587
 					$scripts_remaining = $this->check_for_applicable_data_migration_scripts();
588
-					if( ! $scripts_remaining ){
588
+					if ( ! $scripts_remaining) {
589 589
 						//we should be good to allow them to exit maintenance mode now
590 590
 						EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance));
591 591
 						////huh, no more scripts to run... apparently we're done!
@@ -599,39 +599,39 @@  discard block
 block discarded – undo
599 599
 						'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(),
600 600
 						'records_migrated'=>$currently_executing_script->count_records_migrated(),
601 601
 						'status'=> $currently_executing_script->get_status(),
602
-						'message'=>  sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())),
602
+						'message'=>  sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())),
603 603
 						'script'=>$currently_executing_script->pretty_name()
604 604
 					);
605 605
 					break;
606 606
 			}
607
-		}catch(Exception $e){
607
+		} catch (Exception $e) {
608 608
 			//ok so some exception was thrown which killed the data migration script
609 609
 			//double-check we have a real script
610
-			if($currently_executing_script instanceof EE_Data_Migration_Script_Base){
610
+			if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) {
611 611
 				$script_name = $currently_executing_script->pretty_name();
612 612
 				$currently_executing_script->set_broken();
613 613
 				$currently_executing_script->add_error($e->getMessage());
614
-			}else{
614
+			} else {
615 615
 				$script_name = __("Error getting Migration Script", "event_espresso");
616 616
 			}
617 617
 			$response_array = array(
618 618
 				'records_to_migrate'=>1,
619 619
 				'records_migrated'=>0,
620 620
 				'status'=>self::status_fatal_error,
621
-				'message'=>  sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()),
621
+				'message'=>  sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()),
622 622
 				'script'=>$script_name
623 623
 			);
624 624
 		}
625 625
 		$successful_save = $this->_save_migrations_ran();
626
-		if($successful_save !== TRUE){
626
+		if ($successful_save !== TRUE) {
627 627
 			//ok so the current wp option didn't save. that's tricky, because we'd like to update it
628 628
 			//and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION!
629 629
 			//however, if we throw an exception, and return that, then the next request
630 630
 			//won't have as much info in it, and it may be able to save
631
-			throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save));
631
+			throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save));
632 632
 		}
633 633
 		//if we're all done, initialize EE plugins' default data etc.
634
-		if( $init_dbs ) {
634
+		if ($init_dbs) {
635 635
 			$this->initialize_db_for_enqueued_ee_plugins();
636 636
 		}
637 637
 		return $response_array;
@@ -649,23 +649,23 @@  discard block
 block discarded – undo
649 649
 	 * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes
650 650
 	 * 'script'=>a pretty name of the script currently running
651 651
 	 */
652
-	public function response_to_migration_ajax_request(){
652
+	public function response_to_migration_ajax_request() {
653 653
 //		//start output buffer just to make sure we don't mess up the json
654 654
 		ob_start();
655
-		try{
655
+		try {
656 656
 			$response = $this->migration_step();
657
-		}catch(Exception $e){
657
+		} catch (Exception $e) {
658 658
 			$response = array(
659 659
 				'records_to_migrate'=>0,
660 660
 				'records_migrated'=>0,
661 661
 				'status'=> EE_Data_Migration_Manager::status_fatal_error,
662
-				'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()),
662
+				'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()),
663 663
 				'script'=>'Unknown');
664 664
 			$this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString());
665 665
 		}
666 666
 		$warnings_etc = @ob_get_contents();
667 667
 		ob_end_clean();
668
-		$response['message'] .=$warnings_etc;
668
+		$response['message'] .= $warnings_etc;
669 669
 		return $response;
670 670
 	}
671 671
 
@@ -678,14 +678,14 @@  discard block
 block discarded – undo
678 678
 	 * }
679 679
 	 * @return void
680 680
 	 */
681
-	public function update_current_database_state_to($slug_and_version = null){
682
-		if( ! $slug_and_version ){
681
+	public function update_current_database_state_to($slug_and_version = null) {
682
+		if ( ! $slug_and_version) {
683 683
 			//no version was provided, assume it should be at the current code version
684 684
 			$slug_and_version = array('slug' => 'Core', 'version' => espresso_version());
685 685
 		}
686 686
 		$current_database_state = get_option(self::current_database_state);
687
-		$current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ];
688
-		update_option(self::current_database_state,$current_database_state);
687
+		$current_database_state[$slug_and_version['slug']] = $slug_and_version['version'];
688
+		update_option(self::current_database_state, $current_database_state);
689 689
 	}
690 690
 
691 691
 	/**
@@ -696,20 +696,20 @@  discard block
 block discarded – undo
696 696
 	 * }
697 697
 	 * @return boolean
698 698
 	 */
699
-	public function database_needs_updating_to( $slug_and_version ) {
699
+	public function database_needs_updating_to($slug_and_version) {
700 700
 
701
-		$slug = $slug_and_version[ 'slug' ];
702
-		$version = $slug_and_version[ 'version' ];
701
+		$slug = $slug_and_version['slug'];
702
+		$version = $slug_and_version['version'];
703 703
 		$current_database_state = get_option(self::current_database_state);
704
-		if( ! isset( $current_database_state[ $slug ] ) ) {
704
+		if ( ! isset($current_database_state[$slug])) {
705 705
 			return true;
706
-		}else{
706
+		} else {
707 707
 			//just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes
708
-			$version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3);
709
-			$version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 );
708
+			$version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3);
709
+			$version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3);
710 710
 			$needs_updating = false;
711
-			foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) {
712
-				if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) {
711
+			foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) {
712
+				if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) {
713 713
 					$needs_updating = true;
714 714
 					break;
715 715
 				}
@@ -727,33 +727,33 @@  discard block
 block discarded – undo
727 727
      * @return array keys are expected classnames, values are their filepaths
728 728
      * @throws \EE_Error
729 729
      */
730
-	public function get_all_data_migration_scripts_available(){
731
-		if( ! $this->_data_migration_class_to_filepath_map){
730
+	public function get_all_data_migration_scripts_available() {
731
+		if ( ! $this->_data_migration_class_to_filepath_map) {
732 732
 			$this->_data_migration_class_to_filepath_map = array();
733
-			foreach($this->get_data_migration_script_folders() as $folder_path){
733
+			foreach ($this->get_data_migration_script_folders() as $folder_path) {
734 734
                 $folder_path = EEH_File::end_with_directory_separator($folder_path);
735
-				$files = glob( $folder_path. '*.dms.php' );
735
+				$files = glob($folder_path.'*.dms.php');
736 736
 
737
-				if ( empty( $files ) ) {
737
+				if (empty($files)) {
738 738
 					continue;
739 739
 				}
740 740
 
741
-				foreach($files as $file){
742
-					$pos_of_last_slash = strrpos($file,DS);
741
+				foreach ($files as $file) {
742
+					$pos_of_last_slash = strrpos($file, DS);
743 743
 					$classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1));
744
-					$migrates_to = $this->script_migrates_to_version( $classname );
745
-					$slug = $migrates_to[ 'slug' ];
744
+					$migrates_to = $this->script_migrates_to_version($classname);
745
+					$slug = $migrates_to['slug'];
746 746
 					//check that the slug as contained in the DMS is associated with
747 747
 					//the slug of an addon or core
748
-					if( $slug !== 'Core' ){
749
-						if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) {
748
+					if ($slug !== 'Core') {
749
+						if ( ! EE_Registry::instance()->get_addon_by_name($slug)) {
750 750
 							EE_Error::doing_it_wrong(
751 751
 							    __FUNCTION__,
752 752
                                 sprintf(
753
-                                    __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ),
753
+                                    __('The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso'),
754 754
                                     $classname,
755 755
                                     $slug,
756
-                                    implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) )
756
+                                    implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name()))
757 757
                                 ),
758 758
                                 '4.3.0.alpha.019'
759 759
                             );
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 	 * from each addon, and check if they need updating,
777 777
 	 * @return boolean
778 778
 	 */
779
-	public function addons_need_updating(){
779
+	public function addons_need_updating() {
780 780
 		return false;
781 781
 	}
782 782
 	/**
@@ -785,25 +785,25 @@  discard block
 block discarded – undo
785 785
 	 * @param string $error_message
786 786
 	 * @throws EE_Error
787 787
 	 */
788
-	public function add_error_to_migrations_ran($error_message){
788
+	public function add_error_to_migrations_ran($error_message) {
789 789
 		//get last-ran migration script
790 790
 		global $wpdb;
791
-		$last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A);
791
+		$last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A);
792 792
 
793 793
 		$last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null;
794 794
 		//now, tread lightly because we're here because a FATAL non-catchable error
795 795
 		//was thrown last time when we were trying to run a data migration script
796 796
 		//so the fatal error could have happened while getting the migration script
797 797
 		//or doing running it...
798
-		$versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null;
798
+		$versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null;
799 799
 
800 800
 		//check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet
801 801
 		//because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done)
802
-		if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){
802
+		if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) {
803 803
 			//ok then just add this error to its list of errors
804 804
 			$last_ran_migration_script_properties['_errors'][] = $error_message;
805 805
 			$last_ran_migration_script_properties['_status'] = self::status_fatal_error;
806
-		}else{
806
+		} else {
807 807
 			//so we don't even know which script was last running
808 808
 			//use the data migration error stub, which is designed specifically for this type of thing
809 809
 			$general_migration_error = new EE_DMS_Unknown_1_0_0();
@@ -813,39 +813,39 @@  discard block
 block discarded – undo
813 813
 			$versions_migrated_to = 'Unknown.1.0.0';
814 814
 			//now just to make sure appears as last (in case the were previously a fatal error like this)
815 815
 			//delete the old one
816
-			delete_option( self::data_migration_script_option_prefix . $versions_migrated_to );
816
+			delete_option(self::data_migration_script_option_prefix.$versions_migrated_to);
817 817
 		}
818
-		update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties);
818
+		update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties);
819 819
 
820 820
 	}
821 821
 	/**
822 822
 	 * saves what data migrations have ran to the database
823 823
 	 * @return mixed TRUE if successfully saved migrations ran, string if an error occurred
824 824
 	 */
825
-	protected function _save_migrations_ran(){
826
-		if($this->_data_migrations_ran == null){
825
+	protected function _save_migrations_ran() {
826
+		if ($this->_data_migrations_ran == null) {
827 827
 			$this->get_data_migrations_ran();
828 828
 		}
829 829
 		//now, we don't want to save actual classes to the DB because that's messy
830 830
 		$successful_updates = true;
831
-		foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){
832
-			foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){
831
+		foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) {
832
+			foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) {
833 833
 	//			echo "saving migration script to $version_string<br>";
834 834
 				$plugin_slug_for_use_in_option_name = $plugin_slug.".";
835 835
 				$option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string;
836 836
 				$old_option_value = get_option($option_name);
837
-				if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){
837
+				if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) {
838 838
 					$script_array_for_saving = $array_or_migration_obj->properties_as_array();
839
-					if( $old_option_value != $script_array_for_saving){
840
-						$successful_updates = update_option($option_name,$script_array_for_saving);
839
+					if ($old_option_value != $script_array_for_saving) {
840
+						$successful_updates = update_option($option_name, $script_array_for_saving);
841 841
 					}
842
-				}else{//we don't know what this array-thing is. So just save it as-is
842
+				} else {//we don't know what this array-thing is. So just save it as-is
843 843
 	//				$array_of_migrations[$version_string] = $array_or_migration_obj;
844
-					if($old_option_value != $array_or_migration_obj){
845
-						$successful_updates = update_option($option_name,$array_or_migration_obj);
844
+					if ($old_option_value != $array_or_migration_obj) {
845
+						$successful_updates = update_option($option_name, $array_or_migration_obj);
846 846
 					}
847 847
 				}
848
-				if( ! $successful_updates ){
848
+				if ( ! $successful_updates) {
849 849
 					global $wpdb;
850 850
 					return $wpdb->last_error;
851 851
 				}
@@ -869,17 +869,17 @@  discard block
 block discarded – undo
869 869
 	 * @return EE_Data_Migration_Script_Base
870 870
 	 * @throws EE_Error
871 871
 	 */
872
-	function _instantiate_script_from_properties_array($properties_array){
873
-		if( ! isset($properties_array['class'])){
874
-			throw new EE_Error(sprintf(__("Properties array  has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array)));
872
+	function _instantiate_script_from_properties_array($properties_array) {
873
+		if ( ! isset($properties_array['class'])) {
874
+			throw new EE_Error(sprintf(__("Properties array  has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array)));
875 875
 		}
876 876
 		$class_name = $properties_array['class'];
877
-		if( ! class_exists($class_name)){
878
-			throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name));
877
+		if ( ! class_exists($class_name)) {
878
+			throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name));
879 879
 		}
880 880
 		$class = new $class_name;
881
-		if( ! $class instanceof EE_Data_Migration_Script_Base){
882
-			throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class)));
881
+		if ( ! $class instanceof EE_Data_Migration_Script_Base) {
882
+			throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class)));
883 883
 		}
884 884
 		$class->instantiate_from_array_of_properties($properties_array);
885 885
 		return $class;
@@ -891,25 +891,25 @@  discard block
 block discarded – undo
891 891
 	 * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core'
892 892
 	 * @return string
893 893
 	 */
894
-	public function get_most_up_to_date_dms($plugin_slug = 'Core'){
894
+	public function get_most_up_to_date_dms($plugin_slug = 'Core') {
895 895
 		$class_to_filepath_map = $this->get_all_data_migration_scripts_available();
896 896
 		$most_up_to_date_dms_classname = NULL;
897
-		foreach($class_to_filepath_map as $classname => $filepath){
898
-			if($most_up_to_date_dms_classname === NULL){
897
+		foreach ($class_to_filepath_map as $classname => $filepath) {
898
+			if ($most_up_to_date_dms_classname === NULL) {
899 899
 				$migrates_to = $this->script_migrates_to_version($classname);
900
-				$this_plugin_slug = $migrates_to[ 'slug' ];
900
+				$this_plugin_slug = $migrates_to['slug'];
901 901
 //				$version_string = $migrates_to[ 'version' ];
902 902
 //				$details = $this->parse_dms_classname($classname);
903
-				if($this_plugin_slug == $plugin_slug){
903
+				if ($this_plugin_slug == $plugin_slug) {
904 904
 					//if it's for core, it wins
905 905
 					$most_up_to_date_dms_classname = $classname;
906 906
 				}
907 907
 				//if it wasn't for core, we must keep searching for one that is!
908 908
 				continue;
909
-			}else{
910
-				$champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname);
909
+			} else {
910
+				$champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname);
911 911
 				$contender_migrates_to = $this->script_migrates_to_version($classname);
912
-				if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){
912
+				if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) {
913 913
 					//so the contenders version is higher and its for Core
914 914
 					$most_up_to_date_dms_classname = $classname;
915 915
 				}
@@ -929,11 +929,11 @@  discard block
 block discarded – undo
929 929
 	 * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc
930 930
 	 * @return EE_Data_Migration_Script_Base
931 931
 	 */
932
-	public function get_migration_ran( $version, $plugin_slug = 'Core' ) {
932
+	public function get_migration_ran($version, $plugin_slug = 'Core') {
933 933
 		$migrations_ran = $this->get_data_migrations_ran();
934
-		if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){
935
-			return $migrations_ran[ $plugin_slug ][ $version ];
936
-		}else{
934
+		if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) {
935
+			return $migrations_ran[$plugin_slug][$version];
936
+		} else {
937 937
 			return NULL;
938 938
 		}
939 939
 	}
@@ -945,20 +945,20 @@  discard block
 block discarded – undo
945 945
 	 * @return bool
946 946
 	 * @throws \EE_Error
947 947
 	 */
948
-	public function reattempt(){
948
+	public function reattempt() {
949 949
 		//find if the last-ran script was borked
950 950
 		//set it as being non-borked (we shouldn't ever get DMSs that we don't recognize)
951 951
 		//add an 'error' saying that we attempted to reset
952 952
 		//does it have a stage that was borked too? if so make it no longer borked
953 953
 		//add an 'error' saying we attempted to reset
954 954
 		$last_ran_script = $this->get_last_ran_script();
955
-		if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){
955
+		if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) {
956 956
 			//if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it)
957 957
 			$last_ran_script->set_completed();
958
-		}elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) {
958
+		}elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) {
959 959
 			$last_ran_script->reattempt();
960
-		}else{
961
-			throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) );
960
+		} else {
961
+			throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true)));
962 962
 		}
963 963
 		return $this->_save_migrations_ran();
964 964
 	}
@@ -968,19 +968,19 @@  discard block
 block discarded – undo
968 968
 	 * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc
969 969
 	 * @return boolean
970 970
 	 */
971
-	public function migration_has_ran( $version, $plugin_slug = 'Core' ) {
972
-		return $this->get_migration_ran( $version, $plugin_slug ) !== NULL;
971
+	public function migration_has_ran($version, $plugin_slug = 'Core') {
972
+		return $this->get_migration_ran($version, $plugin_slug) !== NULL;
973 973
 	}
974 974
 	/**
975 975
 	 * Enqueues this ee plugin to have its data initialized
976 976
 	 * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value
977 977
 	 */
978
-	public function enqueue_db_initialization_for( $plugin_slug ) {
978
+	public function enqueue_db_initialization_for($plugin_slug) {
979 979
 		$queue = $this->get_db_initialization_queue();
980
-		if( ! in_array( $plugin_slug, $queue ) ) {
980
+		if ( ! in_array($plugin_slug, $queue)) {
981 981
 			$queue[] = $plugin_slug;
982 982
 		}
983
-		update_option( self::db_init_queue_option_name, $queue );
983
+		update_option(self::db_init_queue_option_name, $queue);
984 984
 	}
985 985
 	/**
986 986
 	 * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon
@@ -990,26 +990,26 @@  discard block
 block discarded – undo
990 990
 	public function initialize_db_for_enqueued_ee_plugins() {
991 991
 //		EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' );
992 992
 		$queue = $this->get_db_initialization_queue();
993
-		foreach( $queue as $plugin_slug ) {
994
-			$most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug );
995
-			if( ! $most_up_to_date_dms ) {
993
+		foreach ($queue as $plugin_slug) {
994
+			$most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug);
995
+			if ( ! $most_up_to_date_dms) {
996 996
 				//if there is NO DMS for this plugin, obviously there's no schema to verify anyways
997 997
 				$verify_db = false;
998
-			}else{
999
-				$most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms );
1000
-				$verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to );
998
+			} else {
999
+				$most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms);
1000
+				$verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to);
1001 1001
 			}
1002
-			if( $plugin_slug == 'Core' ){
1002
+			if ($plugin_slug == 'Core') {
1003 1003
 				EE_System::instance()->initialize_db_if_no_migrations_required(
1004 1004
 						false,
1005 1005
 						$verify_db
1006 1006
 					);
1007
-			}else{
1007
+			} else {
1008 1008
 				//just loop through the addons to make sure their database is setup
1009
-				foreach( EE_Registry::instance()->addons as $addon ) {
1010
-					if( $addon->name() == $plugin_slug ) {
1009
+				foreach (EE_Registry::instance()->addons as $addon) {
1010
+					if ($addon->name() == $plugin_slug) {
1011 1011
 
1012
-						$addon->initialize_db_if_no_migrations_required( $verify_db );
1012
+						$addon->initialize_db_if_no_migrations_required($verify_db);
1013 1013
 						break;
1014 1014
 					}
1015 1015
 				}
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 //		EEH_Debug_Tools::instance()->show_times();
1020 1020
 		//because we just initialized the DBs for the enqueued ee plugins
1021 1021
 		//we don't need to keep remembering which ones needed to be initialized
1022
-		delete_option( self::db_init_queue_option_name );
1022
+		delete_option(self::db_init_queue_option_name);
1023 1023
 	}
1024 1024
 
1025 1025
 	/**
@@ -1028,8 +1028,8 @@  discard block
 block discarded – undo
1028 1028
 	 * 'Core', or the return value of EE_Addon::name() for an addon
1029 1029
 	 * @return array
1030 1030
 	 */
1031
-	public function get_db_initialization_queue(){
1032
-		return get_option ( self::db_init_queue_option_name, array() );
1031
+	public function get_db_initialization_queue() {
1032
+		return get_option(self::db_init_queue_option_name, array());
1033 1033
 	}
1034 1034
 
1035 1035
 	/**
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
 	 * @throws \EE_Error
1039 1039
 	 */
1040 1040
 	protected function _get_table_analysis() {
1041
-		if( $this->_table_analysis instanceof TableAnalysis ) {
1041
+		if ($this->_table_analysis instanceof TableAnalysis) {
1042 1042
 			return $this->_table_analysis;
1043 1043
 		} else {
1044 1044
 			throw new \EE_Error(
1045 1045
 				sprintf(
1046
-					__( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'),
1047
-					get_class( $this )
1046
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
1047
+					get_class($this)
1048 1048
 				)
1049 1049
 			);
1050 1050
 		}
@@ -1056,13 +1056,13 @@  discard block
 block discarded – undo
1056 1056
 	 * @throws \EE_Error
1057 1057
 	 */
1058 1058
 	protected function _get_table_manager() {
1059
-		if( $this->_table_manager instanceof TableManager ) {
1059
+		if ($this->_table_manager instanceof TableManager) {
1060 1060
 			return $this->_table_manager;
1061 1061
 		} else {
1062 1062
 			throw new \EE_Error(
1063 1063
 				sprintf(
1064
-					__( 'Table manager class on class %1$s is not set properly.', 'event_espresso'),
1065
-					get_class( $this )
1064
+					__('Table manager class on class %1$s is not set properly.', 'event_espresso'),
1065
+					get_class($this)
1066 1066
 				)
1067 1067
 			);
1068 1068
 		}
Please login to merge, or discard this patch.
Braces   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 			//it's 4.2-style.eg Core.4.1.0
209 209
 			$plugin_slug = $parts[0];//eg Core
210 210
 			$version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0
211
-		}else{
211
+		} else{
212 212
 			//it's 4.1-style: eg 4.1.0
213 213
 			$plugin_slug = 'Core';
214 214
 			$version_string = $plugin_slug_and_version_string;//eg 4.1.0
@@ -231,12 +231,12 @@  discard block
 block discarded – undo
231 231
 			if($class instanceof EE_Data_Migration_Script_Base){
232 232
 				$class->instantiate_from_array_of_properties($data_migration_data);
233 233
 				return $class;
234
-			}else{
234
+			} else{
235 235
 				//huh, so its an object but not a data migration script?? that shouldn't happen
236 236
 				//just leave it as an array (which will probably just get ignored)
237 237
 				throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class']));
238 238
 			}
239
-		}else{
239
+		} else{
240 240
 			//so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists
241 241
 			throw new EE_Error(sprintf(__("The wp option  with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name));
242 242
 		}
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 						//sometimes we also like to know which was the last incomplete script (or if there are any at all)
267 267
 						$this->_last_ran_incomplete_script = $class;
268 268
 					}
269
-				}catch(EE_Error $e){
269
+				} catch(EE_Error $e){
270 270
 					//ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs
271 271
 					$data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']);
272 272
 				}
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 				//so we want the data migrations to happen. SO, we're going to say the DB is at that state
368 368
 //				echo "4.1.0 is greater than $previous_version_installed! update the option";
369 369
 				$db_state = array('Core'=>$previous_version_installed);
370
-			}else{
370
+			} else{
371 371
 //					echo "4.1.0 is SMALLER than $previous_version_installed";
372 372
 					$db_state = array('Core'=>EVENT_ESPRESSO_VERSION);
373 373
 			}
@@ -435,10 +435,10 @@  discard block
 block discarded – undo
435 435
 						$migrates_to_version = $script->migrates_to_version();
436 436
 						$next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ];
437 437
 						unset($script_class_and_filepaths_available[$classname]);
438
-					}else{
438
+					} else{
439 439
 						//it must have a status that indicates it has finished, so we don't want to try and run it again
440 440
 					}
441
-				}else{
441
+				} else{
442 442
 					//it exists but it's not  a proper data migration script
443 443
 					//maybe the script got renamed? or was simply removed from EE?
444 444
 					//either way, its certainly not runnable!
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 		}
479 479
 		if($include_completed_scripts){
480 480
 			return $this->_last_ran_script;
481
-		}else{
481
+		} else{
482 482
 			return $this->_last_ran_incomplete_script;
483 483
 		}
484 484
 	}
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 				$this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script;
540 540
 			}
541 541
 			$current_script_name = get_class($currently_executing_script);
542
-		}catch(Exception $e){
542
+		} catch(Exception $e){
543 543
 			//an exception occurred while trying to get migration scripts
544 544
 
545 545
 			$message =  sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() );
@@ -604,14 +604,14 @@  discard block
 block discarded – undo
604 604
 					);
605 605
 					break;
606 606
 			}
607
-		}catch(Exception $e){
607
+		} catch(Exception $e){
608 608
 			//ok so some exception was thrown which killed the data migration script
609 609
 			//double-check we have a real script
610 610
 			if($currently_executing_script instanceof EE_Data_Migration_Script_Base){
611 611
 				$script_name = $currently_executing_script->pretty_name();
612 612
 				$currently_executing_script->set_broken();
613 613
 				$currently_executing_script->add_error($e->getMessage());
614
-			}else{
614
+			} else{
615 615
 				$script_name = __("Error getting Migration Script", "event_espresso");
616 616
 			}
617 617
 			$response_array = array(
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 		ob_start();
655 655
 		try{
656 656
 			$response = $this->migration_step();
657
-		}catch(Exception $e){
657
+		} catch(Exception $e){
658 658
 			$response = array(
659 659
 				'records_to_migrate'=>0,
660 660
 				'records_migrated'=>0,
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 		$current_database_state = get_option(self::current_database_state);
704 704
 		if( ! isset( $current_database_state[ $slug ] ) ) {
705 705
 			return true;
706
-		}else{
706
+		} else{
707 707
 			//just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes
708 708
 			$version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3);
709 709
 			$version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 );
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 			//ok then just add this error to its list of errors
804 804
 			$last_ran_migration_script_properties['_errors'][] = $error_message;
805 805
 			$last_ran_migration_script_properties['_status'] = self::status_fatal_error;
806
-		}else{
806
+		} else{
807 807
 			//so we don't even know which script was last running
808 808
 			//use the data migration error stub, which is designed specifically for this type of thing
809 809
 			$general_migration_error = new EE_DMS_Unknown_1_0_0();
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 					if( $old_option_value != $script_array_for_saving){
840 840
 						$successful_updates = update_option($option_name,$script_array_for_saving);
841 841
 					}
842
-				}else{//we don't know what this array-thing is. So just save it as-is
842
+				} else{//we don't know what this array-thing is. So just save it as-is
843 843
 	//				$array_of_migrations[$version_string] = $array_or_migration_obj;
844 844
 					if($old_option_value != $array_or_migration_obj){
845 845
 						$successful_updates = update_option($option_name,$array_or_migration_obj);
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 				}
907 907
 				//if it wasn't for core, we must keep searching for one that is!
908 908
 				continue;
909
-			}else{
909
+			} else{
910 910
 				$champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname);
911 911
 				$contender_migrates_to = $this->script_migrates_to_version($classname);
912 912
 				if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
 		$migrations_ran = $this->get_data_migrations_ran();
934 934
 		if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){
935 935
 			return $migrations_ran[ $plugin_slug ][ $version ];
936
-		}else{
936
+		} else{
937 937
 			return NULL;
938 938
 		}
939 939
 	}
@@ -955,9 +955,9 @@  discard block
 block discarded – undo
955 955
 		if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){
956 956
 			//if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it)
957 957
 			$last_ran_script->set_completed();
958
-		}elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) {
958
+		} elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) {
959 959
 			$last_ran_script->reattempt();
960
-		}else{
960
+		} else{
961 961
 			throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) );
962 962
 		}
963 963
 		return $this->_save_migrations_ran();
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 			if( ! $most_up_to_date_dms ) {
996 996
 				//if there is NO DMS for this plugin, obviously there's no schema to verify anyways
997 997
 				$verify_db = false;
998
-			}else{
998
+			} else{
999 999
 				$most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms );
1000 1000
 				$verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to );
1001 1001
 			}
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
 						false,
1005 1005
 						$verify_db
1006 1006
 					);
1007
-			}else{
1007
+			} else{
1008 1008
 				//just loop through the addons to make sure their database is setup
1009 1009
 				foreach( EE_Registry::instance()->addons as $addon ) {
1010 1010
 					if( $addon->name() == $plugin_slug ) {
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * allowed)
568 568
      *
569 569
      * @param string $datetime_string mysql timestamp in UTC
570
-     * @return  mixed null | DateTime
570
+     * @return  null|DbSafeDateTime null | DateTime
571 571
      * @throws \EE_Error
572 572
      */
573 573
     public function prepare_for_set_from_db($datetime_string)
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
      *
725 725
      * @param \DateTimeZone $DateTimeZone
726 726
      * @param int           $time
727
-     * @return mixed
727
+     * @return integer
728 728
      * @throws \DomainException
729 729
      */
730 730
     public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 
211 211
             default :
212 212
                 return $pretty
213
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
214
-                    : $this->_date_format . ' ' . $this->_time_format;
213
+                    ? $this->_pretty_date_format.' '.$this->_pretty_time_format
214
+                    : $this->_date_format.' '.$this->_time_format;
215 215
         }
216 216
     }
217 217
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     protected function _prepare_for_display($DateTime, $schema = false)
469 469
     {
470
-        if (! $DateTime instanceof DateTime) {
470
+        if ( ! $DateTime instanceof DateTime) {
471 471
             if ($this->_nullable) {
472 472
                 return '';
473 473
             } else {
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
             if ($this->_display_timezone()) {
503 503
                 //must be explicit because schema could equal true.
504 504
                 if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
505
+                    $timezone_string = ' ('.$DateTime->format('T').')';
506 506
                 } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
507
+                    $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>';
508 508
                 }
509 509
             } else {
510 510
                 $timezone_string = '';
511 511
             }
512 512
 
513
-            return $DateTime->format($format_string) . $timezone_string;
513
+            return $DateTime->format($format_string).$timezone_string;
514 514
         } else {
515 515
             return $DateTime->format($format_string);
516 516
         }
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     public function prepare_for_use_in_db($datetime_value)
529 529
     {
530 530
         //we allow an empty value or DateTime object, but nothing else.
531
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531
+        if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532 532
             throw new EE_Error(
533 533
                 __(
534 534
                     'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
             }
584 584
         }
585 585
 
586
-        if (! $DateTime instanceof DbSafeDateTime) {
586
+        if ( ! $DateTime instanceof DbSafeDateTime) {
587 587
             // if still no datetime object, then let's just use now
588 588
             $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
589 589
         }
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
         }
663 663
         //not a unix timestamp.  So we will use the set format on this object and set timezone to
664 664
         //create the DateTime object.
665
-        $format = $this->_date_format . ' ' . $this->_time_format;
665
+        $format = $this->_date_format.' '.$this->_time_format;
666 666
         try {
667 667
             $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
668 668
             if ($DateTime instanceof DateTime) {
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
                     $this->_DateTimeZone
672 672
                 );
673 673
             }
674
-            if (! $DateTime instanceof DbSafeDateTime) {
674
+            if ( ! $DateTime instanceof DbSafeDateTime) {
675 675
                 throw new EE_Error(
676 676
                     sprintf(
677 677
                         __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
Please login to merge, or discard this patch.
Indentation   +749 added lines, -749 removed lines patch added patch discarded remove patch
@@ -15,753 +15,753 @@
 block discarded – undo
15 15
 class EE_Datetime_Field extends EE_Model_Field_Base
16 16
 {
17 17
 
18
-    /**
19
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
-     *
22
-     * @type string unix_timestamp_regex
23
-     */
24
-    const unix_timestamp_regex = '/[0-9]{10,}/';
25
-
26
-    /**
27
-     * @type string mysql_timestamp_format
28
-     */
29
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
30
-
31
-    /**
32
-     * @type string mysql_date_format
33
-     */
34
-    const mysql_date_format = 'Y-m-d';
35
-
36
-    /**
37
-     * @type string mysql_time_format
38
-     */
39
-    const mysql_time_format = 'H:i:s';
40
-
41
-    /**
42
-     * Const for using in the default value. If the field's default is set to this,
43
-     * then we will return the time of calling `get_default_value()`, not
44
-     * just the current time at construction
45
-     */
46
-    const now = 'now';
47
-
48
-    /**
49
-     * The following properties hold the default formats for date and time.
50
-     * Defaults are set via the constructor and can be overridden on class instantiation.
51
-     * However they can also be overridden later by the set_format() method
52
-     * (and corresponding set_date_format, set_time_format methods);
53
-     */
54
-    /**
55
-     * @type string $_date_format
56
-     */
57
-    protected $_date_format = '';
58
-
59
-    /**
60
-     * @type string $_time_format
61
-     */
62
-    protected $_time_format = '';
63
-
64
-    /**
65
-     * @type string $_pretty_date_format
66
-     */
67
-    protected $_pretty_date_format = '';
68
-
69
-    /**
70
-     * @type string $_pretty_time_format
71
-     */
72
-    protected $_pretty_time_format = '';
73
-
74
-    /**
75
-     * @type DateTimeZone $_DateTimeZone
76
-     */
77
-    protected $_DateTimeZone;
78
-
79
-    /**
80
-     * @type DateTimeZone $_UTC_DateTimeZone
81
-     */
82
-    protected $_UTC_DateTimeZone;
83
-
84
-    /**
85
-     * @type DateTimeZone $_blog_DateTimeZone
86
-     */
87
-    protected $_blog_DateTimeZone;
88
-
89
-
90
-    /**
91
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
-     * and time returned via getters.
94
-     *
95
-     * @var mixed (null|string)
96
-     */
97
-    protected $_date_time_output;
98
-
99
-
100
-    /**
101
-     * timezone string
102
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
-     *
106
-     * @var string
107
-     */
108
-    protected $_timezone_string;
109
-
110
-
111
-    /**
112
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
-     * offsets for comparison purposes).
114
-     *
115
-     * @var int
116
-     */
117
-    protected $_blog_offset;
118
-
119
-
120
-    /**
121
-     * @param string $table_column
122
-     * @param string $nice_name
123
-     * @param bool   $nullable
124
-     * @param string $default_value
125
-     * @param string $timezone_string
126
-     * @param string $date_format
127
-     * @param string $time_format
128
-     * @param string $pretty_date_format
129
-     * @param string $pretty_time_format
130
-     * @throws \EE_Error
131
-     */
132
-    public function __construct(
133
-        $table_column,
134
-        $nice_name,
135
-        $nullable,
136
-        $default_value,
137
-        $timezone_string = '',
138
-        $date_format = '',
139
-        $time_format = '',
140
-        $pretty_date_format = '',
141
-        $pretty_time_format = ''
142
-    ) {
143
-
144
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
145
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
146
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
147
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
148
-
149
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
150
-        $this->set_timezone($timezone_string);
151
-        $this->setSchemaFormat('date-time');
152
-    }
153
-
154
-
155
-    /**
156
-     * @return DateTimeZone
157
-     * @throws \EE_Error
158
-     */
159
-    public function get_UTC_DateTimeZone()
160
-    {
161
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
162
-            ? $this->_UTC_DateTimeZone
163
-            : $this->_create_timezone_object_from_timezone_string('UTC');
164
-    }
165
-
166
-
167
-    /**
168
-     * @return DateTimeZone
169
-     * @throws \EE_Error
170
-     */
171
-    public function get_blog_DateTimeZone()
172
-    {
173
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
174
-            ? $this->_blog_DateTimeZone
175
-            : $this->_create_timezone_object_from_timezone_string('');
176
-    }
177
-
178
-
179
-    /**
180
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
181
-     *
182
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
183
-     *                                                              timestamp
184
-     * @return DateTime
185
-     */
186
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
187
-    {
188
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
189
-    }
190
-
191
-
192
-    /**
193
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
194
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
195
-     *
196
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
197
-     * @return string    The final assembled format string.
198
-     */
199
-    protected function _get_date_time_output($pretty = false)
200
-    {
201
-
202
-        switch ($this->_date_time_output) {
203
-            case 'time' :
204
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
205
-                break;
206
-
207
-            case 'date' :
208
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
209
-                break;
210
-
211
-            default :
212
-                return $pretty
213
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
214
-                    : $this->_date_format . ' ' . $this->_time_format;
215
-        }
216
-    }
217
-
218
-
219
-    /**
220
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
221
-     * returned (using the format properties)
222
-     *
223
-     * @param string $what acceptable values are 'time' or 'date'.
224
-     *                     Any other value will be set but will always result
225
-     *                     in both 'date' and 'time' being returned.
226
-     * @return void
227
-     */
228
-    public function set_date_time_output($what = null)
229
-    {
230
-        $this->_date_time_output = $what;
231
-    }
232
-
233
-
234
-    /**
235
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
236
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
237
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
238
-     * We also set some other properties in this method.
239
-     *
240
-     * @param string $timezone_string A valid timezone string as described by @link
241
-     *                                http://www.php.net/manual/en/timezones.php
242
-     * @return void
243
-     * @throws \EE_Error
244
-     */
245
-    public function set_timezone($timezone_string)
246
-    {
247
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
248
-            // leave the timezone AS-IS if we already have one and
249
-            // the function arg didn't provide one
250
-            return;
251
-        }
252
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
253
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
254
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
255
-    }
256
-
257
-
258
-    /**
259
-     * _create_timezone_object_from_timezone_name
260
-     *
261
-     * @access protected
262
-     * @param string $timezone_string
263
-     * @return \DateTimeZone
264
-     * @throws \EE_Error
265
-     */
266
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
267
-    {
268
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
269
-    }
270
-
271
-
272
-    /**
273
-     * This just returns whatever is set for the current timezone.
274
-     *
275
-     * @access public
276
-     * @return string timezone string
277
-     */
278
-    public function get_timezone()
279
-    {
280
-        return $this->_timezone_string;
281
-    }
282
-
283
-
284
-    /**
285
-     * set the $_date_format property
286
-     *
287
-     * @access public
288
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
289
-     * @param bool   $pretty Whether to set pretty format or not.
290
-     * @return void
291
-     */
292
-    public function set_date_format($format, $pretty = false)
293
-    {
294
-        if ($pretty) {
295
-            $this->_pretty_date_format = $format;
296
-        } else {
297
-            $this->_date_format = $format;
298
-        }
299
-    }
300
-
301
-
302
-    /**
303
-     * return the $_date_format property value.
304
-     *
305
-     * @param bool $pretty Whether to get pretty format or not.
306
-     * @return string
307
-     */
308
-    public function get_date_format($pretty = false)
309
-    {
310
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
311
-    }
312
-
313
-
314
-    /**
315
-     * set the $_time_format property
316
-     *
317
-     * @access public
318
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
319
-     * @param bool   $pretty Whether to set pretty format or not.
320
-     * @return void
321
-     */
322
-    public function set_time_format($format, $pretty = false)
323
-    {
324
-        if ($pretty) {
325
-            $this->_pretty_time_format = $format;
326
-        } else {
327
-            $this->_time_format = $format;
328
-        }
329
-    }
330
-
331
-
332
-    /**
333
-     * return the $_time_format property value.
334
-     *
335
-     * @param bool $pretty Whether to get pretty format or not.
336
-     * @return string
337
-     */
338
-    public function get_time_format($pretty = false)
339
-    {
340
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
341
-    }
342
-
343
-
344
-    /**
345
-     * set the $_pretty_date_format property
346
-     *
347
-     * @access public
348
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
349
-     * @return void
350
-     */
351
-    public function set_pretty_date_format($format)
352
-    {
353
-        $this->_pretty_date_format = $format;
354
-    }
355
-
356
-
357
-    /**
358
-     * set the $_pretty_time_format property
359
-     *
360
-     * @access public
361
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
362
-     * @return void
363
-     */
364
-    public function set_pretty_time_format($format)
365
-    {
366
-        $this->_pretty_time_format = $format;
367
-    }
368
-
369
-
370
-    /**
371
-     * Only sets the time portion of the datetime.
372
-     *
373
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
374
-     * @param DateTime        $current            current DateTime object for the datetime field
375
-     * @return DateTime
376
-     */
377
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
378
-    {
379
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
380
-        // Otherwise parse the string.
381
-        if ($time_to_set_string instanceof DateTime) {
382
-            $parsed = array(
383
-                'hour'   => $time_to_set_string->format('H'),
384
-                'minute' => $time_to_set_string->format('i'),
385
-                'second' => $time_to_set_string->format('s'),
386
-            );
387
-        } else {
388
-            //parse incoming string
389
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
390
-        }
391
-
392
-        //make sure $current is in the correct timezone.
393
-        $current->setTimezone($this->_DateTimeZone);
394
-
395
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
396
-    }
397
-
398
-
399
-    /**
400
-     * Only sets the date portion of the datetime.
401
-     *
402
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
403
-     * @param DateTime        $current            current DateTime object for the datetime field
404
-     * @return DateTime
405
-     */
406
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
407
-    {
408
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
409
-        // Otherwise parse the string.
410
-        if ($date_to_set_string instanceof DateTime) {
411
-            $parsed = array(
412
-                'year'  => $date_to_set_string->format('Y'),
413
-                'month' => $date_to_set_string->format('m'),
414
-                'day'   => $date_to_set_string->format('d'),
415
-            );
416
-        } else {
417
-            //parse incoming string
418
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
419
-        }
420
-
421
-        //make sure $current is in the correct timezone
422
-        $current->setTimezone($this->_DateTimeZone);
423
-
424
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
425
-    }
426
-
427
-
428
-    /**
429
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
430
-     * datetime gets to this stage it should ALREADY be in UTC time
431
-     *
432
-     * @param  DateTime $DateTime
433
-     * @return string formatted date time for given timezone
434
-     * @throws \EE_Error
435
-     */
436
-    public function prepare_for_get($DateTime)
437
-    {
438
-        return $this->_prepare_for_display($DateTime);
439
-    }
440
-
441
-
442
-    /**
443
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
444
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
445
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
446
-     * abbreviation to the date_string.
447
-     *
448
-     * @param mixed $DateTime
449
-     * @param null  $schema
450
-     * @return string
451
-     * @throws \EE_Error
452
-     */
453
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
454
-    {
455
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
456
-    }
457
-
458
-
459
-    /**
460
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
461
-     * timezone).
462
-     *
463
-     * @param DateTime    $DateTime
464
-     * @param bool|string $schema
465
-     * @return string
466
-     * @throws \EE_Error
467
-     */
468
-    protected function _prepare_for_display($DateTime, $schema = false)
469
-    {
470
-        if (! $DateTime instanceof DateTime) {
471
-            if ($this->_nullable) {
472
-                return '';
473
-            } else {
474
-                if (WP_DEBUG) {
475
-                    throw new EE_Error(
476
-                        sprintf(
477
-                            __(
478
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
479
-                                'event_espresso'
480
-                            ),
481
-                            $this->_nicename
482
-                        )
483
-                    );
484
-                } else {
485
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
486
-                    EE_Error::add_error(
487
-                        sprintf(
488
-                            __(
489
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
490
-                                'event_espresso'
491
-                            ),
492
-                            $this->_nicename
493
-                        )
494
-                    );
495
-                }
496
-            }
497
-        }
498
-        $format_string = $this->_get_date_time_output($schema);
499
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
500
-        $DateTime->setTimezone($this->_DateTimeZone);
501
-        if ($schema) {
502
-            if ($this->_display_timezone()) {
503
-                //must be explicit because schema could equal true.
504
-                if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
506
-                } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
-                }
509
-            } else {
510
-                $timezone_string = '';
511
-            }
512
-
513
-            return $DateTime->format($format_string) . $timezone_string;
514
-        } else {
515
-            return $DateTime->format($format_string);
516
-        }
517
-    }
518
-
519
-
520
-    /**
521
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
522
-     * timezone).
523
-     *
524
-     * @param  mixed $datetime_value u
525
-     * @return string mysql timestamp in UTC
526
-     * @throws \EE_Error
527
-     */
528
-    public function prepare_for_use_in_db($datetime_value)
529
-    {
530
-        //we allow an empty value or DateTime object, but nothing else.
531
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532
-            throw new EE_Error(
533
-                __(
534
-                    'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
535
-                    'event_espresso'
536
-                )
537
-            );
538
-        }
539
-
540
-        if ($datetime_value instanceof DateTime) {
541
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
542
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
543
-            }
544
-
545
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
546
-                EE_Datetime_Field::mysql_timestamp_format
547
-            );
548
-        }
549
-
550
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
551
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
552
-    }
553
-
554
-
555
-    /**
556
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
557
-     * allowed)
558
-     *
559
-     * @param string $datetime_string mysql timestamp in UTC
560
-     * @return  mixed null | DateTime
561
-     * @throws \EE_Error
562
-     */
563
-    public function prepare_for_set_from_db($datetime_string)
564
-    {
565
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
566
-        if (empty($datetime_string) && $this->_nullable) {
567
-            return null;
568
-        }
569
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
570
-        if (empty($datetime_string)) {
571
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
572
-        } else {
573
-            $DateTime = DateTime::createFromFormat(
574
-                EE_Datetime_Field::mysql_timestamp_format,
575
-                $datetime_string,
576
-                $this->get_UTC_DateTimeZone()
577
-            );
578
-            if ($DateTime instanceof \DateTime) {
579
-                $DateTime = new DbSafeDateTime(
580
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
581
-                    $this->get_UTC_DateTimeZone()
582
-                );
583
-            }
584
-        }
585
-
586
-        if (! $DateTime instanceof DbSafeDateTime) {
587
-            // if still no datetime object, then let's just use now
588
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
589
-        }
590
-        // THEN apply the field's set DateTimeZone
591
-        $DateTime->setTimezone($this->_DateTimeZone);
592
-
593
-        return $DateTime;
594
-    }
595
-
596
-
597
-    /**
598
-     * All this method does is determine if we're going to display the timezone string or not on any output.
599
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
600
-     * If so, then true.
601
-     *
602
-     * @return bool true for yes false for no
603
-     * @throws \EE_Error
604
-     */
605
-    protected function _display_timezone()
606
-    {
607
-
608
-        // first let's do a comparison of timezone strings.
609
-        // If they match then we can get out without any further calculations
610
-        $blog_string = get_option('timezone_string');
611
-        if ($blog_string === $this->_timezone_string) {
612
-            return false;
613
-        }
614
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
615
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
616
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
617
-        // now compare
618
-        return $blog_offset !== $this_offset;
619
-    }
620
-
621
-
622
-    /**
623
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
624
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
625
-     * with.
626
-     *
627
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
628
-     *                                                    in the format that is set on the date_field (or DateTime
629
-     *                                                    object)!
630
-     * @return DateTime
631
-     */
632
-    protected function _get_date_object($date_string)
633
-    {
634
-        //first if this is an empty date_string and nullable is allowed, just return null.
635
-        if ($this->_nullable && empty($date_string)) {
636
-            return null;
637
-        }
638
-
639
-        // if incoming date
640
-        if ($date_string instanceof DateTime) {
641
-            $date_string->setTimezone($this->_DateTimeZone);
642
-
643
-            return $date_string;
644
-        }
645
-        // if empty date_string and made it here.
646
-        // Return a datetime object for now in the given timezone.
647
-        if (empty($date_string)) {
648
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
649
-        }
650
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
651
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
652
-            try {
653
-                // This is operating under the assumption that the incoming Unix timestamp
654
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
655
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
-                $DateTime->setTimestamp($date_string);
657
-
658
-                return $DateTime;
659
-            } catch (Exception $e) {
660
-                // should be rare, but if things got fooled then let's just continue
661
-            }
662
-        }
663
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
664
-        //create the DateTime object.
665
-        $format = $this->_date_format . ' ' . $this->_time_format;
666
-        try {
667
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
668
-            if ($DateTime instanceof DateTime) {
669
-                $DateTime = new DbSafeDateTime(
670
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
671
-                    $this->_DateTimeZone
672
-                );
673
-            }
674
-            if (! $DateTime instanceof DbSafeDateTime) {
675
-                throw new EE_Error(
676
-                    sprintf(
677
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
678
-                        $date_string,
679
-                        $format
680
-                    )
681
-                );
682
-            }
683
-        } catch (Exception $e) {
684
-            // if we made it here then likely then something went really wrong.
685
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
686
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
687
-        }
688
-
689
-        return $DateTime;
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * get_timezone_transitions
696
-     *
697
-     * @param \DateTimeZone $DateTimeZone
698
-     * @param int           $time
699
-     * @param bool          $first_only
700
-     * @return mixed
701
-     */
702
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
703
-    {
704
-        $time = is_int($time) || $time === null ? $time : strtotime($time);
705
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
706
-        $transitions = $DateTimeZone->getTransitions($time);
707
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * get_timezone_offset
714
-     *
715
-     * @param \DateTimeZone $DateTimeZone
716
-     * @param int           $time
717
-     * @return mixed
718
-     * @throws \DomainException
719
-     */
720
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
721
-    {
722
-        $transitions = $this->get_timezone_transitions($DateTimeZone, $time);
723
-        if ( ! isset($transitions['offset'])) {
724
-            throw new DomainException();
725
-        }
726
-        return $transitions['offset'];
727
-    }
728
-
729
-
730
-    /**
731
-     * This will take an incoming timezone string and return the abbreviation for that timezone
732
-     *
733
-     * @param  string $timezone_string
734
-     * @return string           abbreviation
735
-     * @throws \EE_Error
736
-     */
737
-    public function get_timezone_abbrev($timezone_string)
738
-    {
739
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
740
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
741
-
742
-        return $dateTime->format('T');
743
-    }
744
-
745
-    /**
746
-     * Overrides the parent to allow for having a dynamic "now" value
747
-     *
748
-     * @return mixed
749
-     */
750
-    public function get_default_value()
751
-    {
752
-        if ($this->_default_value === EE_Datetime_Field::now) {
753
-            return time();
754
-        } else {
755
-            return parent::get_default_value();
756
-        }
757
-    }
758
-
759
-
760
-    public function getSchemaDescription()
761
-    {
762
-        return sprintf(
763
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
764
-            $this->get_nicename()
765
-        );
766
-    }
18
+	/**
19
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
+	 *
22
+	 * @type string unix_timestamp_regex
23
+	 */
24
+	const unix_timestamp_regex = '/[0-9]{10,}/';
25
+
26
+	/**
27
+	 * @type string mysql_timestamp_format
28
+	 */
29
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
30
+
31
+	/**
32
+	 * @type string mysql_date_format
33
+	 */
34
+	const mysql_date_format = 'Y-m-d';
35
+
36
+	/**
37
+	 * @type string mysql_time_format
38
+	 */
39
+	const mysql_time_format = 'H:i:s';
40
+
41
+	/**
42
+	 * Const for using in the default value. If the field's default is set to this,
43
+	 * then we will return the time of calling `get_default_value()`, not
44
+	 * just the current time at construction
45
+	 */
46
+	const now = 'now';
47
+
48
+	/**
49
+	 * The following properties hold the default formats for date and time.
50
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
51
+	 * However they can also be overridden later by the set_format() method
52
+	 * (and corresponding set_date_format, set_time_format methods);
53
+	 */
54
+	/**
55
+	 * @type string $_date_format
56
+	 */
57
+	protected $_date_format = '';
58
+
59
+	/**
60
+	 * @type string $_time_format
61
+	 */
62
+	protected $_time_format = '';
63
+
64
+	/**
65
+	 * @type string $_pretty_date_format
66
+	 */
67
+	protected $_pretty_date_format = '';
68
+
69
+	/**
70
+	 * @type string $_pretty_time_format
71
+	 */
72
+	protected $_pretty_time_format = '';
73
+
74
+	/**
75
+	 * @type DateTimeZone $_DateTimeZone
76
+	 */
77
+	protected $_DateTimeZone;
78
+
79
+	/**
80
+	 * @type DateTimeZone $_UTC_DateTimeZone
81
+	 */
82
+	protected $_UTC_DateTimeZone;
83
+
84
+	/**
85
+	 * @type DateTimeZone $_blog_DateTimeZone
86
+	 */
87
+	protected $_blog_DateTimeZone;
88
+
89
+
90
+	/**
91
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
+	 * and time returned via getters.
94
+	 *
95
+	 * @var mixed (null|string)
96
+	 */
97
+	protected $_date_time_output;
98
+
99
+
100
+	/**
101
+	 * timezone string
102
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $_timezone_string;
109
+
110
+
111
+	/**
112
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
+	 * offsets for comparison purposes).
114
+	 *
115
+	 * @var int
116
+	 */
117
+	protected $_blog_offset;
118
+
119
+
120
+	/**
121
+	 * @param string $table_column
122
+	 * @param string $nice_name
123
+	 * @param bool   $nullable
124
+	 * @param string $default_value
125
+	 * @param string $timezone_string
126
+	 * @param string $date_format
127
+	 * @param string $time_format
128
+	 * @param string $pretty_date_format
129
+	 * @param string $pretty_time_format
130
+	 * @throws \EE_Error
131
+	 */
132
+	public function __construct(
133
+		$table_column,
134
+		$nice_name,
135
+		$nullable,
136
+		$default_value,
137
+		$timezone_string = '',
138
+		$date_format = '',
139
+		$time_format = '',
140
+		$pretty_date_format = '',
141
+		$pretty_time_format = ''
142
+	) {
143
+
144
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
145
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
146
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
147
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
148
+
149
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
150
+		$this->set_timezone($timezone_string);
151
+		$this->setSchemaFormat('date-time');
152
+	}
153
+
154
+
155
+	/**
156
+	 * @return DateTimeZone
157
+	 * @throws \EE_Error
158
+	 */
159
+	public function get_UTC_DateTimeZone()
160
+	{
161
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
162
+			? $this->_UTC_DateTimeZone
163
+			: $this->_create_timezone_object_from_timezone_string('UTC');
164
+	}
165
+
166
+
167
+	/**
168
+	 * @return DateTimeZone
169
+	 * @throws \EE_Error
170
+	 */
171
+	public function get_blog_DateTimeZone()
172
+	{
173
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
174
+			? $this->_blog_DateTimeZone
175
+			: $this->_create_timezone_object_from_timezone_string('');
176
+	}
177
+
178
+
179
+	/**
180
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
181
+	 *
182
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
183
+	 *                                                              timestamp
184
+	 * @return DateTime
185
+	 */
186
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
187
+	{
188
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
189
+	}
190
+
191
+
192
+	/**
193
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
194
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
195
+	 *
196
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
197
+	 * @return string    The final assembled format string.
198
+	 */
199
+	protected function _get_date_time_output($pretty = false)
200
+	{
201
+
202
+		switch ($this->_date_time_output) {
203
+			case 'time' :
204
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
205
+				break;
206
+
207
+			case 'date' :
208
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
209
+				break;
210
+
211
+			default :
212
+				return $pretty
213
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
214
+					: $this->_date_format . ' ' . $this->_time_format;
215
+		}
216
+	}
217
+
218
+
219
+	/**
220
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
221
+	 * returned (using the format properties)
222
+	 *
223
+	 * @param string $what acceptable values are 'time' or 'date'.
224
+	 *                     Any other value will be set but will always result
225
+	 *                     in both 'date' and 'time' being returned.
226
+	 * @return void
227
+	 */
228
+	public function set_date_time_output($what = null)
229
+	{
230
+		$this->_date_time_output = $what;
231
+	}
232
+
233
+
234
+	/**
235
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
236
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
237
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
238
+	 * We also set some other properties in this method.
239
+	 *
240
+	 * @param string $timezone_string A valid timezone string as described by @link
241
+	 *                                http://www.php.net/manual/en/timezones.php
242
+	 * @return void
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function set_timezone($timezone_string)
246
+	{
247
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
248
+			// leave the timezone AS-IS if we already have one and
249
+			// the function arg didn't provide one
250
+			return;
251
+		}
252
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
253
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
254
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
255
+	}
256
+
257
+
258
+	/**
259
+	 * _create_timezone_object_from_timezone_name
260
+	 *
261
+	 * @access protected
262
+	 * @param string $timezone_string
263
+	 * @return \DateTimeZone
264
+	 * @throws \EE_Error
265
+	 */
266
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
267
+	{
268
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
269
+	}
270
+
271
+
272
+	/**
273
+	 * This just returns whatever is set for the current timezone.
274
+	 *
275
+	 * @access public
276
+	 * @return string timezone string
277
+	 */
278
+	public function get_timezone()
279
+	{
280
+		return $this->_timezone_string;
281
+	}
282
+
283
+
284
+	/**
285
+	 * set the $_date_format property
286
+	 *
287
+	 * @access public
288
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
289
+	 * @param bool   $pretty Whether to set pretty format or not.
290
+	 * @return void
291
+	 */
292
+	public function set_date_format($format, $pretty = false)
293
+	{
294
+		if ($pretty) {
295
+			$this->_pretty_date_format = $format;
296
+		} else {
297
+			$this->_date_format = $format;
298
+		}
299
+	}
300
+
301
+
302
+	/**
303
+	 * return the $_date_format property value.
304
+	 *
305
+	 * @param bool $pretty Whether to get pretty format or not.
306
+	 * @return string
307
+	 */
308
+	public function get_date_format($pretty = false)
309
+	{
310
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
311
+	}
312
+
313
+
314
+	/**
315
+	 * set the $_time_format property
316
+	 *
317
+	 * @access public
318
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
319
+	 * @param bool   $pretty Whether to set pretty format or not.
320
+	 * @return void
321
+	 */
322
+	public function set_time_format($format, $pretty = false)
323
+	{
324
+		if ($pretty) {
325
+			$this->_pretty_time_format = $format;
326
+		} else {
327
+			$this->_time_format = $format;
328
+		}
329
+	}
330
+
331
+
332
+	/**
333
+	 * return the $_time_format property value.
334
+	 *
335
+	 * @param bool $pretty Whether to get pretty format or not.
336
+	 * @return string
337
+	 */
338
+	public function get_time_format($pretty = false)
339
+	{
340
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
341
+	}
342
+
343
+
344
+	/**
345
+	 * set the $_pretty_date_format property
346
+	 *
347
+	 * @access public
348
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
349
+	 * @return void
350
+	 */
351
+	public function set_pretty_date_format($format)
352
+	{
353
+		$this->_pretty_date_format = $format;
354
+	}
355
+
356
+
357
+	/**
358
+	 * set the $_pretty_time_format property
359
+	 *
360
+	 * @access public
361
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
362
+	 * @return void
363
+	 */
364
+	public function set_pretty_time_format($format)
365
+	{
366
+		$this->_pretty_time_format = $format;
367
+	}
368
+
369
+
370
+	/**
371
+	 * Only sets the time portion of the datetime.
372
+	 *
373
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
374
+	 * @param DateTime        $current            current DateTime object for the datetime field
375
+	 * @return DateTime
376
+	 */
377
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
378
+	{
379
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
380
+		// Otherwise parse the string.
381
+		if ($time_to_set_string instanceof DateTime) {
382
+			$parsed = array(
383
+				'hour'   => $time_to_set_string->format('H'),
384
+				'minute' => $time_to_set_string->format('i'),
385
+				'second' => $time_to_set_string->format('s'),
386
+			);
387
+		} else {
388
+			//parse incoming string
389
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
390
+		}
391
+
392
+		//make sure $current is in the correct timezone.
393
+		$current->setTimezone($this->_DateTimeZone);
394
+
395
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
396
+	}
397
+
398
+
399
+	/**
400
+	 * Only sets the date portion of the datetime.
401
+	 *
402
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
403
+	 * @param DateTime        $current            current DateTime object for the datetime field
404
+	 * @return DateTime
405
+	 */
406
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
407
+	{
408
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
409
+		// Otherwise parse the string.
410
+		if ($date_to_set_string instanceof DateTime) {
411
+			$parsed = array(
412
+				'year'  => $date_to_set_string->format('Y'),
413
+				'month' => $date_to_set_string->format('m'),
414
+				'day'   => $date_to_set_string->format('d'),
415
+			);
416
+		} else {
417
+			//parse incoming string
418
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
419
+		}
420
+
421
+		//make sure $current is in the correct timezone
422
+		$current->setTimezone($this->_DateTimeZone);
423
+
424
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
425
+	}
426
+
427
+
428
+	/**
429
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
430
+	 * datetime gets to this stage it should ALREADY be in UTC time
431
+	 *
432
+	 * @param  DateTime $DateTime
433
+	 * @return string formatted date time for given timezone
434
+	 * @throws \EE_Error
435
+	 */
436
+	public function prepare_for_get($DateTime)
437
+	{
438
+		return $this->_prepare_for_display($DateTime);
439
+	}
440
+
441
+
442
+	/**
443
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
444
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
445
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
446
+	 * abbreviation to the date_string.
447
+	 *
448
+	 * @param mixed $DateTime
449
+	 * @param null  $schema
450
+	 * @return string
451
+	 * @throws \EE_Error
452
+	 */
453
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
454
+	{
455
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
456
+	}
457
+
458
+
459
+	/**
460
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
461
+	 * timezone).
462
+	 *
463
+	 * @param DateTime    $DateTime
464
+	 * @param bool|string $schema
465
+	 * @return string
466
+	 * @throws \EE_Error
467
+	 */
468
+	protected function _prepare_for_display($DateTime, $schema = false)
469
+	{
470
+		if (! $DateTime instanceof DateTime) {
471
+			if ($this->_nullable) {
472
+				return '';
473
+			} else {
474
+				if (WP_DEBUG) {
475
+					throw new EE_Error(
476
+						sprintf(
477
+							__(
478
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
479
+								'event_espresso'
480
+							),
481
+							$this->_nicename
482
+						)
483
+					);
484
+				} else {
485
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
486
+					EE_Error::add_error(
487
+						sprintf(
488
+							__(
489
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
490
+								'event_espresso'
491
+							),
492
+							$this->_nicename
493
+						)
494
+					);
495
+				}
496
+			}
497
+		}
498
+		$format_string = $this->_get_date_time_output($schema);
499
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
500
+		$DateTime->setTimezone($this->_DateTimeZone);
501
+		if ($schema) {
502
+			if ($this->_display_timezone()) {
503
+				//must be explicit because schema could equal true.
504
+				if ($schema === 'no_html') {
505
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
506
+				} else {
507
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
+				}
509
+			} else {
510
+				$timezone_string = '';
511
+			}
512
+
513
+			return $DateTime->format($format_string) . $timezone_string;
514
+		} else {
515
+			return $DateTime->format($format_string);
516
+		}
517
+	}
518
+
519
+
520
+	/**
521
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
522
+	 * timezone).
523
+	 *
524
+	 * @param  mixed $datetime_value u
525
+	 * @return string mysql timestamp in UTC
526
+	 * @throws \EE_Error
527
+	 */
528
+	public function prepare_for_use_in_db($datetime_value)
529
+	{
530
+		//we allow an empty value or DateTime object, but nothing else.
531
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532
+			throw new EE_Error(
533
+				__(
534
+					'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
535
+					'event_espresso'
536
+				)
537
+			);
538
+		}
539
+
540
+		if ($datetime_value instanceof DateTime) {
541
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
542
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
543
+			}
544
+
545
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
546
+				EE_Datetime_Field::mysql_timestamp_format
547
+			);
548
+		}
549
+
550
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
551
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
552
+	}
553
+
554
+
555
+	/**
556
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
557
+	 * allowed)
558
+	 *
559
+	 * @param string $datetime_string mysql timestamp in UTC
560
+	 * @return  mixed null | DateTime
561
+	 * @throws \EE_Error
562
+	 */
563
+	public function prepare_for_set_from_db($datetime_string)
564
+	{
565
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
566
+		if (empty($datetime_string) && $this->_nullable) {
567
+			return null;
568
+		}
569
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
570
+		if (empty($datetime_string)) {
571
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
572
+		} else {
573
+			$DateTime = DateTime::createFromFormat(
574
+				EE_Datetime_Field::mysql_timestamp_format,
575
+				$datetime_string,
576
+				$this->get_UTC_DateTimeZone()
577
+			);
578
+			if ($DateTime instanceof \DateTime) {
579
+				$DateTime = new DbSafeDateTime(
580
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
581
+					$this->get_UTC_DateTimeZone()
582
+				);
583
+			}
584
+		}
585
+
586
+		if (! $DateTime instanceof DbSafeDateTime) {
587
+			// if still no datetime object, then let's just use now
588
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
589
+		}
590
+		// THEN apply the field's set DateTimeZone
591
+		$DateTime->setTimezone($this->_DateTimeZone);
592
+
593
+		return $DateTime;
594
+	}
595
+
596
+
597
+	/**
598
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
599
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
600
+	 * If so, then true.
601
+	 *
602
+	 * @return bool true for yes false for no
603
+	 * @throws \EE_Error
604
+	 */
605
+	protected function _display_timezone()
606
+	{
607
+
608
+		// first let's do a comparison of timezone strings.
609
+		// If they match then we can get out without any further calculations
610
+		$blog_string = get_option('timezone_string');
611
+		if ($blog_string === $this->_timezone_string) {
612
+			return false;
613
+		}
614
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
615
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
616
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
617
+		// now compare
618
+		return $blog_offset !== $this_offset;
619
+	}
620
+
621
+
622
+	/**
623
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
624
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
625
+	 * with.
626
+	 *
627
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
628
+	 *                                                    in the format that is set on the date_field (or DateTime
629
+	 *                                                    object)!
630
+	 * @return DateTime
631
+	 */
632
+	protected function _get_date_object($date_string)
633
+	{
634
+		//first if this is an empty date_string and nullable is allowed, just return null.
635
+		if ($this->_nullable && empty($date_string)) {
636
+			return null;
637
+		}
638
+
639
+		// if incoming date
640
+		if ($date_string instanceof DateTime) {
641
+			$date_string->setTimezone($this->_DateTimeZone);
642
+
643
+			return $date_string;
644
+		}
645
+		// if empty date_string and made it here.
646
+		// Return a datetime object for now in the given timezone.
647
+		if (empty($date_string)) {
648
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
649
+		}
650
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
651
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
652
+			try {
653
+				// This is operating under the assumption that the incoming Unix timestamp
654
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
655
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
+				$DateTime->setTimestamp($date_string);
657
+
658
+				return $DateTime;
659
+			} catch (Exception $e) {
660
+				// should be rare, but if things got fooled then let's just continue
661
+			}
662
+		}
663
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
664
+		//create the DateTime object.
665
+		$format = $this->_date_format . ' ' . $this->_time_format;
666
+		try {
667
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
668
+			if ($DateTime instanceof DateTime) {
669
+				$DateTime = new DbSafeDateTime(
670
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
671
+					$this->_DateTimeZone
672
+				);
673
+			}
674
+			if (! $DateTime instanceof DbSafeDateTime) {
675
+				throw new EE_Error(
676
+					sprintf(
677
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
678
+						$date_string,
679
+						$format
680
+					)
681
+				);
682
+			}
683
+		} catch (Exception $e) {
684
+			// if we made it here then likely then something went really wrong.
685
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
686
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
687
+		}
688
+
689
+		return $DateTime;
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * get_timezone_transitions
696
+	 *
697
+	 * @param \DateTimeZone $DateTimeZone
698
+	 * @param int           $time
699
+	 * @param bool          $first_only
700
+	 * @return mixed
701
+	 */
702
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
703
+	{
704
+		$time = is_int($time) || $time === null ? $time : strtotime($time);
705
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
706
+		$transitions = $DateTimeZone->getTransitions($time);
707
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * get_timezone_offset
714
+	 *
715
+	 * @param \DateTimeZone $DateTimeZone
716
+	 * @param int           $time
717
+	 * @return mixed
718
+	 * @throws \DomainException
719
+	 */
720
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
721
+	{
722
+		$transitions = $this->get_timezone_transitions($DateTimeZone, $time);
723
+		if ( ! isset($transitions['offset'])) {
724
+			throw new DomainException();
725
+		}
726
+		return $transitions['offset'];
727
+	}
728
+
729
+
730
+	/**
731
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
732
+	 *
733
+	 * @param  string $timezone_string
734
+	 * @return string           abbreviation
735
+	 * @throws \EE_Error
736
+	 */
737
+	public function get_timezone_abbrev($timezone_string)
738
+	{
739
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
740
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
741
+
742
+		return $dateTime->format('T');
743
+	}
744
+
745
+	/**
746
+	 * Overrides the parent to allow for having a dynamic "now" value
747
+	 *
748
+	 * @return mixed
749
+	 */
750
+	public function get_default_value()
751
+	{
752
+		if ($this->_default_value === EE_Datetime_Field::now) {
753
+			return time();
754
+		} else {
755
+			return parent::get_default_value();
756
+		}
757
+	}
758
+
759
+
760
+	public function getSchemaDescription()
761
+	{
762
+		return sprintf(
763
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
764
+			$this->get_nicename()
765
+		);
766
+	}
767 767
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EEI_Payment_Method_Interfaces.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  * allows gateways to be used by different systems other than Event Espresso
7 7
  */
8
-interface EEI_Payment extends EEI_Base{
8
+interface EEI_Payment extends EEI_Base {
9 9
 
10 10
 	/**
11 11
 	 * @return string indicating which the payment is approved, pending, cancelled or failed
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 /**
154 154
  * Interface EEI_Payment_Method
155 155
  */
156
-interface EEI_Payment_Method{
156
+interface EEI_Payment_Method {
157 157
 
158 158
 }
159 159
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @param string $model_name
173 173
 	 * @return EE_Log
174 174
 	 */
175
-	public function gateway_log($message,$id,$model_name);
175
+	public function gateway_log($message, $id, $model_name);
176 176
 }
177 177
 
178 178
 
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 2 patches
Indentation   +98 added lines, -100 removed lines patch added patch discarded remove patch
@@ -44,77 +44,76 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	protected $_image_url;
46 46
 
47
-    /**
48
-     * gateway URL variable
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_base_gateway_url = '';
53
-
54
-
55
-
56
-    /**
57
-     * EEG_Paypal_Express constructor.
58
-     */
59
-    public function __construct()
60
-    {
61
-        $this->_currencies_supported = array(
62
-            'USD',
63
-            'AUD',
64
-            'BRL',
65
-            'CAD',
66
-            'CZK',
67
-            'DKK',
68
-            'EUR',
69
-            'HKD',
70
-            'HUF',
71
-            'ILS',
72
-            'JPY',
73
-            'MYR',
74
-            'MXN',
75
-            'NOK',
76
-            'NZD',
77
-            'PHP',
78
-            'PLN',
79
-            'GBP',
80
-            'RUB',
81
-            'SGD',
82
-            'SEK',
83
-            'CHF',
84
-            'TWD',
85
-            'THB',
86
-            'TRY'
87
-        );
88
-        parent::__construct();
89
-    }
90
-
91
-
92
-
93
-    /**
94
-	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
47
+	/**
48
+	 * gateway URL variable
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_base_gateway_url = '';
53
+
54
+
55
+
56
+	/**
57
+	 * EEG_Paypal_Express constructor.
58
+	 */
59
+	public function __construct()
60
+	{
61
+		$this->_currencies_supported = array(
62
+			'USD',
63
+			'AUD',
64
+			'BRL',
65
+			'CAD',
66
+			'CZK',
67
+			'DKK',
68
+			'EUR',
69
+			'HKD',
70
+			'HUF',
71
+			'ILS',
72
+			'JPY',
73
+			'MYR',
74
+			'MXN',
75
+			'NOK',
76
+			'NZD',
77
+			'PHP',
78
+			'PLN',
79
+			'GBP',
80
+			'RUB',
81
+			'SGD',
82
+			'SEK',
83
+			'CHF',
84
+			'TWD',
85
+			'THB',
86
+			'TRY'
87
+		);
88
+		parent::__construct();
89
+	}
90
+
95 91
 
92
+
93
+	/**
94
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
96 95
 	 *
97 96
 *@param array $settings_array
98 97
 	 */
99 98
 	public function set_settings( $settings_array ) {
100 99
 		parent::set_settings($settings_array);
101 100
 		// Redirect URL.
102
-        $this->_base_gateway_url = $this->_debug_mode
103
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
104
-            : 'https://api-3t.paypal.com/nvp';
101
+		$this->_base_gateway_url = $this->_debug_mode
102
+			? 'https://api-3t.sandbox.paypal.com/nvp'
103
+			: 'https://api-3t.paypal.com/nvp';
105 104
 	}
106 105
 
107 106
 
108 107
 
109
-    /**
110
-     * @param EEI_Payment $payment
111
-     * @param array       $billing_info
112
-     * @param string      $return_url
113
-     * @param string      $notify_url
114
-     * @param string      $cancel_url
115
-     * @return \EE_Payment|\EEI_Payment
116
-     * @throws \EE_Error
117
-     */
108
+	/**
109
+	 * @param EEI_Payment $payment
110
+	 * @param array       $billing_info
111
+	 * @param string      $return_url
112
+	 * @param string      $notify_url
113
+	 * @param string      $cancel_url
114
+	 * @return \EE_Payment|\EEI_Payment
115
+	 * @throws \EE_Error
116
+	 */
118 117
 	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
119 118
 		if ( ! $payment instanceof EEI_Payment ) {
120 119
 			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
@@ -202,9 +201,9 @@  discard block
 block discarded – undo
202 201
 				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
203 202
 				// Item quantity.
204 203
 				$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1;
205
-                // Digital item is sold.
206
-                $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
207
-                $item_num++;
204
+				// Digital item is sold.
205
+				$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical';
206
+				$item_num++;
208 207
 			}
209 208
 		} else {
210 209
 			// Just one Item.
@@ -272,7 +271,6 @@  discard block
 block discarded – undo
272 271
 
273 272
 
274 273
 	/**
275
-
276 274
 	 *  @param array $update_info {
277 275
 	 *	  @type string $gateway_txn_id
278 276
 	 *	  @type string status an EEMI_Payment status
@@ -292,8 +290,8 @@  discard block
 block discarded – undo
292 290
 				return $payment;
293 291
 			}
294 292
 			$primary_registrant = $transaction->primary_registration();
295
-            $payment_details = $payment->details();
296
-            // Check if we still have the token.
293
+			$payment_details = $payment->details();
294
+			// Check if we still have the token.
297 295
 			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
298 296
 				$payment->set_status( $this->_pay_model->failed_status() );
299 297
 				return $payment;
@@ -402,36 +400,36 @@  discard block
 block discarded – undo
402 400
 	 */
403 401
 	public function _ppExpress_check_response( $request_response ) {
404 402
 		if (empty($request_response['body']) || is_wp_error( $request_response ) ) {
405
-            // If we got here then there was an error in this request.
406
-            return array('status' => false, 'args' => $request_response);
407
-        }
408
-        $response_args = array();
409
-        parse_str( urldecode($request_response['body']), $response_args );
410
-        if ( ! isset($response_args['ACK'])) {
411
-            return array('status' => false, 'args' => $request_response);
412
-        }
413
-        if (
414
-            $response_args['ACK'] === 'Success'
415
-            && (
416
-                isset($response_args['PAYERID'])
417
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
418
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
419
-                || isset($response_args['TOKEN'])
420
-            )
421
-        ) {
422
-            // Response status OK, return response parameters for further processing.
423
-            return array('status' => true, 'args' => $response_args);
424
-        } else {
425
-            $errors = $this->_get_errors($response_args);
426
-            return array('status' => false, 'args' => $errors);
427
-        }
403
+			// If we got here then there was an error in this request.
404
+			return array('status' => false, 'args' => $request_response);
405
+		}
406
+		$response_args = array();
407
+		parse_str( urldecode($request_response['body']), $response_args );
408
+		if ( ! isset($response_args['ACK'])) {
409
+			return array('status' => false, 'args' => $request_response);
410
+		}
411
+		if (
412
+			$response_args['ACK'] === 'Success'
413
+			&& (
414
+				isset($response_args['PAYERID'])
415
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
416
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
417
+				|| isset($response_args['TOKEN'])
418
+			)
419
+		) {
420
+			// Response status OK, return response parameters for further processing.
421
+			return array('status' => true, 'args' => $response_args);
422
+		} else {
423
+			$errors = $this->_get_errors($response_args);
424
+			return array('status' => false, 'args' => $errors);
425
+		}
428 426
 	}
429 427
 
430 428
 
431 429
 	/**
432
-     *  Log a "Cleared" request.
433
-     *
434
-     * @param array $request
430
+	 *  Log a "Cleared" request.
431
+	 *
432
+	 * @param array $request
435 433
 	 * @param EEI_Payment  $payment
436 434
 	 * @param string  		$info
437 435
 	 * @return void
@@ -454,17 +452,17 @@  discard block
 block discarded – undo
454 452
 		$n = 0;
455 453
 		while ( isset($data_array["L_ERRORCODE{$n}"]) ) {
456 454
 			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
457
-                ? $data_array["L_ERRORCODE{$n}"]
458
-                : '';
455
+				? $data_array["L_ERRORCODE{$n}"]
456
+				: '';
459 457
 			$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"])
460
-                ? $data_array["L_SEVERITYCODE{$n}"]
461
-                : '';
458
+				? $data_array["L_SEVERITYCODE{$n}"]
459
+				: '';
462 460
 			$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"])
463
-                ? $data_array["L_SHORTMESSAGE{$n}"]
464
-                : '';
461
+				? $data_array["L_SHORTMESSAGE{$n}"]
462
+				: '';
465 463
 			$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"])
466
-                ? $data_array["L_LONGMESSAGE{$n}"]
467
-                : '';
464
+				? $data_array["L_LONGMESSAGE{$n}"]
465
+				: '';
468 466
 
469 467
 			if ( $n === 0 ) {
470 468
 				$errors = array(
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); }
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); }
2 2
 
3 3
 /**
4 4
  * ----------------------------------------------
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 *@param array $settings_array
98 98
 	 */
99
-	public function set_settings( $settings_array ) {
99
+	public function set_settings($settings_array) {
100 100
 		parent::set_settings($settings_array);
101 101
 		// Redirect URL.
102 102
         $this->_base_gateway_url = $this->_debug_mode
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
      * @return \EE_Payment|\EEI_Payment
116 116
      * @throws \EE_Error
117 117
      */
118
-	public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) {
119
-		if ( ! $payment instanceof EEI_Payment ) {
120
-			$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) );
121
-			$payment->set_status( $this->_pay_model->failed_status() );
118
+	public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) {
119
+		if ( ! $payment instanceof EEI_Payment) {
120
+			$payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso'));
121
+			$payment->set_status($this->_pay_model->failed_status());
122 122
 			return $payment;
123 123
 		}
124 124
 		$transaction = $payment->transaction();
125
-		if ( ! $transaction instanceof EEI_Transaction ) {
126
-			$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
127
-			$payment->set_status( $this->_pay_model->failed_status() );
125
+		if ( ! $transaction instanceof EEI_Transaction) {
126
+			$payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso'));
127
+			$payment->set_status($this->_pay_model->failed_status());
128 128
 			return $payment;
129 129
 		}
130
-		$order_description = substr( $this->_format_order_description($payment), 0, 127 );
130
+		$order_description = substr($this->_format_order_description($payment), 0, 127);
131 131
 		$primary_registration = $transaction->primary_registration();
132 132
 		$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false;
133 133
 		$locale = explode('-', get_bloginfo('language'));
@@ -141,37 +141,37 @@  discard block
 block discarded – undo
141 141
 			'RETURNURL' => $return_url,
142 142
 			'CANCELURL' => $cancel_url,
143 143
 			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
144
-			'SOLUTIONTYPE' => 'Sole',	// Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional.
145
-			'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this
144
+			'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional.
145
+			'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this
146 146
 			'LOCALECODE' => $locale[1]	// Locale of the pages displayed by PayPal during Express Checkout.
147 147
 		);
148 148
 
149 149
 		// Show itemized list.
150
-		if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) {
150
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
151 151
 			$item_num = 0;
152 152
 			$itemized_sum = 0;
153 153
 			$total_line_items = $transaction->total_line_item();
154 154
 			// Go through each item in the list.
155
-			foreach ( $total_line_items->get_items() as $line_item ) {
156
-				if ( $line_item instanceof EE_Line_Item ) {
155
+			foreach ($total_line_items->get_items() as $line_item) {
156
+				if ($line_item instanceof EE_Line_Item) {
157 157
 					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
158
-					if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) {
158
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
159 159
 						continue;
160 160
 					}
161 161
 
162 162
 					$unit_price = $line_item->unit_price();
163 163
 					$line_item_quantity = $line_item->quantity();
164 164
 					// This is a discount.
165
-					if ( $line_item->is_percent() ) {
165
+					if ($line_item->is_percent()) {
166 166
 						$unit_price = $line_item->total();
167 167
 						$line_item_quantity = 1;
168 168
 					}
169 169
 					// Item Name.
170
-					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127);
170
+					$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127);
171 171
 					// Item description.
172
-					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127);
172
+					$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127);
173 173
 					// Cost of individual item.
174
-					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price );
174
+					$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price);
175 175
 					// Item Number.
176 176
 					$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
177 177
 					// Item quantity.
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
189 189
 			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
190 190
 
191
-			$itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 );
191
+			$itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2);
192 192
 			// If we were not able to recognize some item like promotion, surcharge or cancellation,
193 193
 			// add the difference as an extra line item.
194
-			if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) {
194
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
195 195
 				// Item Name.
196
-				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 );
196
+				$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127);
197 197
 				// Item description.
198 198
 				$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = '';
199 199
 				// Cost of individual item.
200
-				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total );
200
+				$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total);
201 201
 				// Item Number.
202 202
 				$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1;
203 203
 				// Item quantity.
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 		} else {
210 210
 			// Just one Item.
211 211
 			// Item Name.
212
-			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 );
212
+			$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127);
213 213
 			// Item description.
214
-			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 );
214
+			$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127);
215 215
 			// Cost of individual item.
216
-			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() );
216
+			$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount());
217 217
 			// Item Number.
218 218
 			$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
219 219
 			// Item quantity.
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 			// Digital item is sold.
222 222
 			$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
223 223
 			// Item's sales S/H and tax amount.
224
-			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() );
224
+			$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount());
225 225
 			$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0';
226 226
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
227 227
 			$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
228 228
 		}
229 229
 		// Automatically filling out shipping and contact information.
230
-		if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) {
231
-			$token_request_dtls['NOSHIPPING'] = '2';	//  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
230
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
231
+			$token_request_dtls['NOSHIPPING'] = '2'; //  If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
232 232
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
233 233
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
234 234
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
238 238
 			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
239 239
 			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
240
-		} elseif ( ! $this->_request_shipping_addr ) {
240
+		} elseif ( ! $this->_request_shipping_addr) {
241 241
 			// Do not request shipping details on the PP Checkout page.
242 242
 			$token_request_dtls['NOSHIPPING'] = '1';
243 243
 			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
244 244
 
245 245
 		}
246 246
 		// Used a business/personal logo on the PayPal page.
247
-		if ( ! empty($this->_image_url) ) {
247
+		if ( ! empty($this->_image_url)) {
248 248
 			$token_request_dtls['LOGOIMG'] = $this->_image_url;
249 249
 		}
250 250
 		$token_request_dtls = apply_filters( 
@@ -253,23 +253,23 @@  discard block
 block discarded – undo
253 253
 			$this 
254 254
 		);
255 255
 		// Request PayPal token.
256
-		$token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment );
257
-		$token_rstatus = $this->_ppExpress_check_response( $token_request_response );
258
-		$response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array();
259
-		if ( $token_rstatus['status'] ) {
256
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
257
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
258
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array();
259
+		if ($token_rstatus['status']) {
260 260
 			// We got the Token so we may continue with the payment and redirect the client.
261
-			$payment->set_details( $response_args );
261
+			$payment->set_details($response_args);
262 262
 
263 263
 			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
264
-			$payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] );
264
+			$payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']);
265 265
 		} else {
266
-			if ( isset($response_args['L_ERRORCODE']) ) {
267
-				$payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] );
266
+			if (isset($response_args['L_ERRORCODE'])) {
267
+				$payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']);
268 268
 			} else {
269
-				$payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) );
269
+				$payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso'));
270 270
 			}
271
-			$payment->set_details( $response_args );
272
-			$payment->set_status( $this->_pay_model->failed_status() );
271
+			$payment->set_details($response_args);
272
+			$payment->set_status($this->_pay_model->failed_status());
273 273
 		}
274 274
 
275 275
 		return $payment;
@@ -285,22 +285,22 @@  discard block
 block discarded – undo
285 285
 	 *  @param EEI_Transaction $transaction
286 286
 	 *  @return EEI_Payment
287 287
 	 */
288
-	public function handle_payment_update( $update_info, $transaction ) {
288
+	public function handle_payment_update($update_info, $transaction) {
289 289
 		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
290 290
 
291
-		if ( $payment instanceof EEI_Payment ) {
292
-			$this->log( array( 'Return from Authorization' => $update_info ), $payment );
291
+		if ($payment instanceof EEI_Payment) {
292
+			$this->log(array('Return from Authorization' => $update_info), $payment);
293 293
 			$transaction = $payment->transaction();
294
-			if ( ! $transaction instanceof EEI_Transaction ) {
295
-				$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) );
296
-				$payment->set_status( $this->_pay_model->failed_status() );
294
+			if ( ! $transaction instanceof EEI_Transaction) {
295
+				$payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso'));
296
+				$payment->set_status($this->_pay_model->failed_status());
297 297
 				return $payment;
298 298
 			}
299 299
 			$primary_registrant = $transaction->primary_registration();
300 300
             $payment_details = $payment->details();
301 301
             // Check if we still have the token.
302
-			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) {
303
-				$payment->set_status( $this->_pay_model->failed_status() );
302
+			if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
303
+				$payment->set_status($this->_pay_model->failed_status());
304 304
 				return $payment;
305 305
 			}
306 306
 
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
 				'TOKEN' => $payment_details['TOKEN']
310 310
 			);
311 311
 			// Request Customer Details.
312
-			$cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment );
313
-			$cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response );
314
-			$cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array();
315
-			if ( $cdetails_rstatus['status'] ) {
312
+			$cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment);
313
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
314
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array();
315
+			if ($cdetails_rstatus['status']) {
316 316
 				// We got the PayerID so now we can Complete the transaction.
317 317
 				$docheckout_request_dtls = array(
318 318
 					'METHOD' => 'DoExpressCheckoutPayment',
@@ -323,39 +323,39 @@  discard block
 block discarded – undo
323 323
 					'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code()
324 324
 				);
325 325
 				// Payment Checkout/Capture.
326
-				$docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment );
327
-				$docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response );
328
-				$docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array();
329
-				if ( $docheckout_rstatus['status'] ) {
326
+				$docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment);
327
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
328
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array();
329
+				if ($docheckout_rstatus['status']) {
330 330
 					// All is well, payment approved.
331 331
 					$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : '';
332
-					$payment->set_extra_accntng( $primary_registration_code );
333
-					$payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 );
334
-					$payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null );
335
-					$payment->set_details( $cdata_response_args );
336
-					$payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' );
337
-					$payment->set_status( $this->_pay_model->approved_status() );
332
+					$payment->set_extra_accntng($primary_registration_code);
333
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0);
334
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null);
335
+					$payment->set_details($cdata_response_args);
336
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '');
337
+					$payment->set_status($this->_pay_model->approved_status());
338 338
 				} else {
339
-					if ( isset($docheckout_response_args['L_ERRORCODE']) ) {
340
-						$payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] );
339
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
340
+						$payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']);
341 341
 					} else {
342
-						$payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) );
342
+						$payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso'));
343 343
 					}
344
-					$payment->set_details( $docheckout_response_args );
345
-					$payment->set_status( $this->_pay_model->declined_status() );
344
+					$payment->set_details($docheckout_response_args);
345
+					$payment->set_status($this->_pay_model->declined_status());
346 346
 				}
347 347
 			} else {
348
-				if ( isset($cdata_response_args['L_ERRORCODE']) ) {
349
-					$payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] );
348
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
349
+					$payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']);
350 350
 				} else {
351
-					$payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) );
351
+					$payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso'));
352 352
 				}
353
-				$payment->set_details( $cdata_response_args );
354
-				$payment->set_status( $this->_pay_model->failed_status() );
353
+				$payment->set_details($cdata_response_args);
354
+				$payment->set_status($this->_pay_model->failed_status());
355 355
 			}
356 356
 		} else {
357
-			$payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) );
358
-			$payment->set_status( $this->_pay_model->failed_status() );
357
+			$payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso'));
358
+			$payment->set_status($this->_pay_model->failed_status());
359 359
 		}
360 360
 
361 361
 		return $payment;
@@ -370,16 +370,16 @@  discard block
 block discarded – undo
370 370
 	 *  @param EEI_Payment  $payment
371 371
 	 *	@return mixed
372 372
 	 */
373
-	public function _ppExpress_request( $request_params, $request_text, $payment ) {
373
+	public function _ppExpress_request($request_params, $request_text, $payment) {
374 374
 		$request_dtls = array(
375 375
 			'VERSION' => '204.0',
376
-			'USER' => urlencode( $this->_api_username ),
377
-			'PWD' => urlencode( $this->_api_password ),
378
-			'SIGNATURE' => urlencode( $this->_api_signature )
376
+			'USER' => urlencode($this->_api_username),
377
+			'PWD' => urlencode($this->_api_password),
378
+			'SIGNATURE' => urlencode($this->_api_signature)
379 379
 		);
380
-		$dtls = array_merge( $request_dtls, $request_params );
380
+		$dtls = array_merge($request_dtls, $request_params);
381 381
 
382
-		$this->_log_clean_request( $dtls, $payment, $request_text . ' Request' );
382
+		$this->_log_clean_request($dtls, $payment, $request_text.' Request');
383 383
 		// Request Customer Details.
384 384
 		$request_response = wp_remote_post(
385 385
 			$this->_base_gateway_url,
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 				'httpversion' => '1.1',
390 390
 				'cookies' => array(),
391 391
 				'headers' => array(),
392
-				'body' => http_build_query( $dtls )
392
+				'body' => http_build_query($dtls)
393 393
 			)
394 394
 		);
395 395
 		// Log the response.
396
-		$this->log( array( $request_text . ' Response' => $request_response), $payment );
396
+		$this->log(array($request_text.' Response' => $request_response), $payment);
397 397
 
398 398
 		return $request_response;
399 399
 	}
@@ -405,13 +405,13 @@  discard block
 block discarded – undo
405 405
 	 *	@param mixed        $request_response
406 406
 	 *	@return array
407 407
 	 */
408
-	public function _ppExpress_check_response( $request_response ) {
409
-		if (empty($request_response['body']) || is_wp_error( $request_response ) ) {
408
+	public function _ppExpress_check_response($request_response) {
409
+		if (empty($request_response['body']) || is_wp_error($request_response)) {
410 410
             // If we got here then there was an error in this request.
411 411
             return array('status' => false, 'args' => $request_response);
412 412
         }
413 413
         $response_args = array();
414
-        parse_str( urldecode($request_response['body']), $response_args );
414
+        parse_str(urldecode($request_response['body']), $response_args);
415 415
         if ( ! isset($response_args['ACK'])) {
416 416
             return array('status' => false, 'args' => $request_response);
417 417
         }
@@ -441,10 +441,10 @@  discard block
 block discarded – undo
441 441
 	 * @param string  		$info
442 442
 	 * @return void
443 443
 	 */
444
-	private function _log_clean_request($request, $payment, $info ) {
444
+	private function _log_clean_request($request, $payment, $info) {
445 445
 		$cleaned_request_data = $request;
446 446
 		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
447
-		$this->log( array($info => $cleaned_request_data), $payment );
447
+		$this->log(array($info => $cleaned_request_data), $payment);
448 448
 	}
449 449
 
450 450
 
@@ -454,10 +454,10 @@  discard block
 block discarded – undo
454 454
 	 *  @param array	$data_array
455 455
 	 *  @return array
456 456
 	 */
457
-	private function _get_errors( $data_array ) {
457
+	private function _get_errors($data_array) {
458 458
 		$errors = array();
459 459
 		$n = 0;
460
-		while ( isset($data_array["L_ERRORCODE{$n}"]) ) {
460
+		while (isset($data_array["L_ERRORCODE{$n}"])) {
461 461
 			$l_error_code = isset($data_array["L_ERRORCODE{$n}"])
462 462
                 ? $data_array["L_ERRORCODE{$n}"]
463 463
                 : '';
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
                 ? $data_array["L_LONGMESSAGE{$n}"]
472 472
                 : '';
473 473
 
474
-			if ( $n === 0 ) {
474
+			if ($n === 0) {
475 475
 				$errors = array(
476 476
 					'L_ERRORCODE' => $l_error_code,
477 477
 					'L_SHORTMESSAGE' => $l_short_message,
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
 					'L_SEVERITYCODE' => $l_severity_code
480 480
 				);
481 481
 			} else {
482
-				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
483
-				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
484
-				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
485
-				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
482
+				$errors['L_ERRORCODE'] .= ', '.$l_error_code;
483
+				$errors['L_SHORTMESSAGE'] .= ', '.$l_short_message;
484
+				$errors['L_LONGMESSAGE'] .= ', '.$l_long_message;
485
+				$errors['L_SEVERITYCODE'] .= ', '.$l_severity_code;
486 486
 			}
487 487
 
488 488
 			$n++;
Please login to merge, or discard this patch.
core/helpers/EEH_Schema.helper.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             $VNU_ID
70 70
         );
71 71
         extract($template_args, EXTR_OVERWRITE);
72
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
72
+        include EE_TEMPLATES.'json_linked_data_for_event.template.php';
73 73
     }
74 74
 
75 75
 
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @param string $location
83 83
 	 * @return string
84 84
 	 */
85
-	public static function location( $location = null ) {
86
-		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
85
+	public static function location($location = null) {
86
+		return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
87 87
 		                              . $location
88 88
 		                              . '</div>' : '';
89 89
 	}
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 * @param string $name
99 99
 	 * @return string
100 100
 	 */
101
-	public static function name( $name = null ) {
102
-		return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : '';
101
+	public static function name($name = null) {
102
+		return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : '';
103 103
 	}
104 104
 
105 105
 
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 * @param EEI_Address $obj_with_address
113 113
 	 * @return string
114 114
 	 */
115
-	public static function streetAddress( EEI_Address $obj_with_address = null ) {
115
+	public static function streetAddress(EEI_Address $obj_with_address = null) {
116 116
 		return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
117
-			? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
117
+			? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : '';
118 118
 	}
119 119
 
120 120
 
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
 	 * @param EEI_Address $obj_with_address
128 128
 	 * @return string
129 129
 	 */
130
-	public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) {
130
+	public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) {
131 131
 		// regex check for some form of PO Box or P.O. Box, etc, etc, etc
132
-		if ( preg_match(
132
+		if (preg_match(
133 133
 			"/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
134 134
 			$obj_with_address->address2()
135
-		) ) {
135
+		)) {
136 136
 			return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
137
-				? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
137
+				? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : '';
138 138
 		} else {
139 139
 			return $obj_with_address->address2();
140 140
 		}
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
 	 * @param EEI_Address $obj_with_address
151 151
 	 * @return string
152 152
 	 */
153
-	public static function addressLocality( EEI_Address $obj_with_address = null ) {
153
+	public static function addressLocality(EEI_Address $obj_with_address = null) {
154 154
 		return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
155
-			? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
155
+			? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : '';
156 156
 	}
157 157
 
158 158
 
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 	 * @param EEI_Address $obj_with_address
166 166
 	 * @return string
167 167
 	 */
168
-	public static function addressRegion( EEI_Address $obj_with_address = null ) {
168
+	public static function addressRegion(EEI_Address $obj_with_address = null) {
169 169
 		$state = $obj_with_address->state_name();
170
-		if ( ! empty( $state ) ) {
171
-			return '<span itemprop="addressRegion">' . $state . '</span>';
170
+		if ( ! empty($state)) {
171
+			return '<span itemprop="addressRegion">'.$state.'</span>';
172 172
 		} else {
173 173
 			return '';
174 174
 		}
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
 	 * @param EEI_Address $obj_with_address
185 185
 	 * @return string
186 186
 	 */
187
-	public static function addressCountry( EEI_Address $obj_with_address = null ) {
187
+	public static function addressCountry(EEI_Address $obj_with_address = null) {
188 188
 		$country = $obj_with_address->country_name();
189
-		if ( ! empty( $country ) ) {
190
-			return '<span itemprop="addressCountry">' . $country . '</span>';
189
+		if ( ! empty($country)) {
190
+			return '<span itemprop="addressCountry">'.$country.'</span>';
191 191
 		} else {
192 192
 			return '';
193 193
 		}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * @param EEI_Address $obj_with_address
204 204
 	 * @return string
205 205
 	 */
206
-	public static function postalCode( EEI_Address $obj_with_address = null ) {
206
+	public static function postalCode(EEI_Address $obj_with_address = null) {
207 207
 		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
208 208
 		                                                                              . $obj_with_address->zip()
209 209
 		                                                                              . '</span>' : '';
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 * @param string $phone_nmbr
220 220
 	 * @return string
221 221
 	 */
222
-	public static function telephone( $phone_nmbr = null ) {
223
-		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
222
+	public static function telephone($phone_nmbr = null) {
223
+		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>'
224 224
 			: '';
225 225
 	}
226 226
 
@@ -236,13 +236,13 @@  discard block
 block discarded – undo
236 236
 	 * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
237 237
 	 * @return string (link)
238 238
 	 */
239
-	public static function url( $url = null, $text = null, $attributes = array() ) {
239
+	public static function url($url = null, $text = null, $attributes = array()) {
240 240
 		$atts = '';
241
-		foreach ( $attributes as $attribute => $value ) {
242
-			$atts .= ' ' . $attribute . '="' . $value . '"';
241
+		foreach ($attributes as $attribute => $value) {
242
+			$atts .= ' '.$attribute.'="'.$value.'"';
243 243
 		}
244 244
 		$text = $text !== null && $text !== '' ? $text : $url;
245
-		return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>'
245
+		return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>'
246 246
 			: '';
247 247
 	}
248 248
 
Please login to merge, or discard this patch.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -17,62 +17,62 @@  discard block
 block discarded – undo
17 17
 class EEH_Schema {
18 18
 
19 19
 
20
-    /**
21
-     * generates JSON-based linked data for an event
22
-     *
23
-     * @param \EE_Event $event
24
-     */
25
-    public static function add_json_linked_data_for_event(\EE_Event $event)
26
-    {
27
-        $template_args = array(
28
-            'event_permalink' => '',
29
-            'event_name' => '',
30
-            'event_description' => '',
31
-            'event_start' => '',
32
-            'event_end' => '',
33
-            'currency' => '',
34
-            'event_tickets' => array(),
35
-            'venue_name' => '',
36
-            'venue_url' => '',
37
-            'venue_locality' => '',
38
-            'venue_region' => '',
39
-            'event_image' => '',
40
-        );
41
-        $template_args['event_permalink'] = $event->get_permalink();
42
-        $template_args['event_name'] = $event->name();
43
-        $template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
44
-        $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM);
45
-        $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM);
46
-        $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
47
-        foreach ($event->tickets() as $ticket) {
48
-            $ID = $ticket->ID();
49
-            $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
50
-            $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
51
-            $template_args['event_tickets'][$ID]['price'] = number_format(
52
-                $ticket->price(),
53
-                EE_Registry::instance()->CFG->currency->dec_plc,
54
-                EE_Registry::instance()->CFG->currency->dec_mrk,
55
-                EE_Registry::instance()->CFG->currency->thsnds
56
-            );
57
-        }
58
-        $VNU_ID = espresso_venue_id();
59
-        if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
60
-            $venue = EEH_Venue_View::get_venue($VNU_ID);
61
-            $template_args['venue_name'] = get_the_title($VNU_ID);
62
-            $template_args['venue_url'] = get_permalink($VNU_ID);
63
-            $template_args['venue_locality'] = $venue->city();
64
-            $template_args['venue_region'] = $venue->state_name();
65
-        }
66
-        $template_args['event_image'] = $event->feature_image_url();
67
-        $template_args = apply_filters(
68
-            'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
69
-            $template_args,
70
-            $event,
71
-            $VNU_ID
72
-        );
73
-        extract($template_args, EXTR_OVERWRITE);
74
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
75
-    }
20
+	/**
21
+	 * generates JSON-based linked data for an event
22
+	 *
23
+	 * @param \EE_Event $event
24
+	 */
25
+	public static function add_json_linked_data_for_event(\EE_Event $event)
26
+	{
27
+		$template_args = array(
28
+			'event_permalink' => '',
29
+			'event_name' => '',
30
+			'event_description' => '',
31
+			'event_start' => '',
32
+			'event_end' => '',
33
+			'currency' => '',
34
+			'event_tickets' => array(),
35
+			'venue_name' => '',
36
+			'venue_url' => '',
37
+			'venue_locality' => '',
38
+			'venue_region' => '',
39
+			'event_image' => '',
40
+		);
41
+		$template_args['event_permalink'] = $event->get_permalink();
42
+		$template_args['event_name'] = $event->name();
43
+		$template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
44
+		$template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM);
45
+		$template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM);
46
+		$template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
47
+		foreach ($event->tickets() as $ticket) {
48
+			$ID = $ticket->ID();
49
+			$template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
50
+			$template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
51
+			$template_args['event_tickets'][$ID]['price'] = number_format(
52
+				$ticket->price(),
53
+				EE_Registry::instance()->CFG->currency->dec_plc,
54
+				EE_Registry::instance()->CFG->currency->dec_mrk,
55
+				EE_Registry::instance()->CFG->currency->thsnds
56
+			);
57
+		}
58
+		$VNU_ID = espresso_venue_id();
59
+		if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
60
+			$venue = EEH_Venue_View::get_venue($VNU_ID);
61
+			$template_args['venue_name'] = get_the_title($VNU_ID);
62
+			$template_args['venue_url'] = get_permalink($VNU_ID);
63
+			$template_args['venue_locality'] = $venue->city();
64
+			$template_args['venue_region'] = $venue->state_name();
65
+		}
66
+		$template_args['event_image'] = $event->feature_image_url();
67
+		$template_args = apply_filters(
68
+			'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
69
+			$template_args,
70
+			$event,
71
+			$VNU_ID
72
+		);
73
+		extract($template_args, EXTR_OVERWRITE);
74
+		include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
75
+	}
76 76
 
77 77
 
78 78
 	/**
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public static function location( $location = null ) {
88 88
 		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
89
-		                              . $location
90
-		                              . '</div>' : '';
89
+									  . $location
90
+									  . '</div>' : '';
91 91
 	}
92 92
 
93 93
 
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public static function postalCode( EEI_Address $obj_with_address = null ) {
209 209
 		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
210
-		                                                                              . $obj_with_address->zip()
211
-		                                                                              . '</span>' : '';
210
+																					  . $obj_with_address->zip()
211
+																					  . '</span>' : '';
212 212
 	}
213 213
 
214 214
 
Please login to merge, or discard this patch.
core/db_classes/EE_Base_Class.class.php 3 patches
Doc Comments   +9 added lines, -8 removed lines patch added patch discarded remove patch
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      *
575 575
      * @param \EE_Datetime_Field $datetime_field
576 576
      * @param bool               $pretty
577
-     * @param null $date_or_time
577
+     * @param string|null $date_or_time
578 578
      * @return void
579 579
      * @throws \EE_Error
580 580
      */
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
      *
893 893
      * @param null  $field_to_order_by  What field is being used as the reference point.
894 894
      * @param array $query_params       Any additional conditions on the query.
895
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
895
+     * @param string  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
896 896
      *                                  you can indicate just the columns you want returned
897 897
      * @return array|EE_Base_Class
898 898
      * @throws \EE_Error
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
      *
918 918
      * @param null  $field_to_order_by  What field is being used as the reference point.
919 919
      * @param array $query_params       Any additional conditions on the query.
920
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
920
+     * @param string  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
921 921
      *                                  you can indicate just the column you want returned
922 922
      * @return array|EE_Base_Class
923 923
      * @throws \EE_Error
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
      * This method simply returns the RAW unprocessed value for the given property in this class
991 991
      *
992 992
      * @param  string $field_name A valid fieldname
993
-     * @return mixed              Whatever the raw value stored on the property is.
993
+     * @return integer|null              Whatever the raw value stored on the property is.
994 994
      * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
995 995
      */
996 996
     public function get_raw($field_name)
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
      * sets the time on a datetime property
1257 1257
      *
1258 1258
      * @access protected
1259
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1259
+     * @param string $time      a valid time string for php datetime functions (or DateTime object)
1260 1260
      * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1261 1261
      * @throws \EE_Error
1262 1262
      */
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
      * sets the date on a datetime property
1272 1272
      *
1273 1273
      * @access protected
1274
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1274
+     * @param string $date      a valid date string for php datetime functions ( or DateTime object)
1275 1275
      * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1276 1276
      * @throws \EE_Error
1277 1277
      */
@@ -1329,6 +1329,7 @@  discard block
 block discarded – undo
1329 1329
      * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1330 1330
      * @param string               $prepend    You can include something to prepend on the timestamp
1331 1331
      * @param string               $append     You can include something to append on the timestamp
1332
+     * @param string $args
1332 1333
      * @throws EE_Error
1333 1334
      * @return string timestamp
1334 1335
      */
@@ -1699,7 +1700,7 @@  discard block
 block discarded – undo
1699 1700
      *
1700 1701
      * @param  array  $props_n_values   incoming array of properties and their values
1701 1702
      * @param  string $classname        the classname of the child class
1702
-     * @param null    $timezone
1703
+     * @param string|null    $timezone
1703 1704
      * @param array   $date_formats     incoming date_formats in an array where the first value is the
1704 1705
      *                                  date_format and the second value is the time format
1705 1706
      * @return mixed (EE_Base_Class|bool)
@@ -1777,7 +1778,7 @@  discard block
 block discarded – undo
1777 1778
      * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1778 1779
      *
1779 1780
      * @param string $model_classname
1780
-     * @param null   $timezone
1781
+     * @param string|null   $timezone
1781 1782
      * @return EEM_Base
1782 1783
      */
1783 1784
     protected static function _get_model_instance_with_name($model_classname, $timezone = null)
Please login to merge, or discard this patch.
Indentation   +2647 added lines, -2647 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
 do_action('AHEE_log', __FILE__, ' FILE LOADED', '');
5 5
 
@@ -25,2652 +25,2652 @@  discard block
 block discarded – undo
25 25
 abstract class EE_Base_Class
26 26
 {
27 27
 
28
-    /**
29
-     * This is an array of the original properties and values provided during construction
30
-     * of this model object. (keys are model field names, values are their values).
31
-     * This list is important to remember so that when we are merging data from the db, we know
32
-     * which values to override and which to not override.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_props_n_values_provided_in_constructor;
37
-
38
-    /**
39
-     * Timezone
40
-     * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.
41
-     * This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT
42
-     * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have
43
-     * access to it.
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_timezone;
48
-
49
-
50
-
51
-    /**
52
-     * date format
53
-     * pattern or format for displaying dates
54
-     *
55
-     * @var string $_dt_frmt
56
-     */
57
-    protected $_dt_frmt;
58
-
59
-
60
-
61
-    /**
62
-     * time format
63
-     * pattern or format for displaying time
64
-     *
65
-     * @var string $_tm_frmt
66
-     */
67
-    protected $_tm_frmt;
68
-
69
-
70
-
71
-    /**
72
-     * This property is for holding a cached array of object properties indexed by property name as the key.
73
-     * The purpose of this is for setting a cache on properties that may have calculated values after a
74
-     * prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having
75
-     * to recalculate. Used by _set_cached_property() and _get_cached_property() methods.
76
-     *
77
-     * @var array
78
-     */
79
-    protected $_cached_properties = array();
80
-
81
-    /**
82
-     * An array containing keys of the related model, and values are either an array of related mode objects or a
83
-     * single
84
-     * related model object. see the model's _model_relations. The keys should match those specified. And if the
85
-     * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object,
86
-     * all others have an array)
87
-     *
88
-     * @var array
89
-     */
90
-    protected $_model_relations = array();
91
-
92
-    /**
93
-     * Array where keys are field names (see the model's _fields property) and values are their values. To see what
94
-     * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
95
-     *
96
-     * @var array
97
-     */
98
-    protected $_fields = array();
99
-
100
-    /**
101
-     * @var boolean indicating whether or not this model object is intended to ever be saved
102
-     * For example, we might create model objects intended to only be used for the duration
103
-     * of this request and to be thrown away, and if they were accidentally saved
104
-     * it would be a bug.
105
-     */
106
-    protected $_allow_persist = true;
107
-
108
-
109
-
110
-    /**
111
-     * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children
112
-     * play nice
113
-     *
114
-     * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd
115
-     *                                                         layer of the model's _fields array, (eg, EVT_ID,
116
-     *                                                         TXN_amount, QST_name, etc) and values are their values
117
-     * @param boolean $bydb                                    a flag for setting if the class is instantiated by the
118
-     *                                                         corresponding db model or not.
119
-     * @param string  $timezone                                indicate what timezone you want any datetime fields to
120
-     *                                                         be in when instantiating a EE_Base_Class object.
121
-     * @param array   $date_formats                            An array of date formats to set on construct where first
122
-     *                                                         value is the date_format and second value is the time
123
-     *                                                         format.
124
-     * @throws EE_Error
125
-     */
126
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
127
-    {
128
-        $className = get_class($this);
129
-        do_action("AHEE__{$className}__construct", $this, $fieldValues);
130
-        $model = $this->get_model();
131
-        $model_fields = $model->field_settings(false);
132
-        // ensure $fieldValues is an array
133
-        $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
134
-        // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
135
-        // verify client code has not passed any invalid field names
136
-        foreach ($fieldValues as $field_name => $field_value) {
137
-            if ( ! isset($model_fields[$field_name])) {
138
-                throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s",
139
-                    "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
140
-            }
141
-        }
142
-        // EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
143
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
144
-        if ( ! empty($date_formats) && is_array($date_formats)) {
145
-            list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
146
-        } else {
147
-            //set default formats for date and time
148
-            $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
149
-            $this->_tm_frmt = (string)get_option('time_format', 'g:i a');
150
-        }
151
-        //if db model is instantiating
152
-        if ($bydb) {
153
-            //client code has indicated these field values are from the database
154
-            foreach ($model_fields as $fieldName => $field) {
155
-                $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
156
-            }
157
-        } else {
158
-            //we're constructing a brand
159
-            //new instance of the model object. Generally, this means we'll need to do more field validation
160
-            foreach ($model_fields as $fieldName => $field) {
161
-                $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
162
-            }
163
-        }
164
-        //remember what values were passed to this constructor
165
-        $this->_props_n_values_provided_in_constructor = $fieldValues;
166
-        //remember in entity mapper
167
-        if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
168
-            $model->add_to_entity_map($this);
169
-        }
170
-        //setup all the relations
171
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
172
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
173
-                $this->_model_relations[$relation_name] = null;
174
-            } else {
175
-                $this->_model_relations[$relation_name] = array();
176
-            }
177
-        }
178
-        /**
179
-         * Action done at the end of each model object construction
180
-         *
181
-         * @param EE_Base_Class $this the model object just created
182
-         */
183
-        do_action('AHEE__EE_Base_Class__construct__finished', $this);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets whether or not this model object is allowed to persist/be saved to the database.
190
-     *
191
-     * @return boolean
192
-     */
193
-    public function allow_persist()
194
-    {
195
-        return $this->_allow_persist;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Sets whether or not this model object should be allowed to be saved to the DB.
202
-     * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
203
-     * you got new information that somehow made you change your mind.
204
-     *
205
-     * @param boolean $allow_persist
206
-     * @return boolean
207
-     */
208
-    public function set_allow_persist($allow_persist)
209
-    {
210
-        return $this->_allow_persist = $allow_persist;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * Gets the field's original value when this object was constructed during this request.
217
-     * This can be helpful when determining if a model object has changed or not
218
-     *
219
-     * @param string $field_name
220
-     * @return mixed|null
221
-     * @throws \EE_Error
222
-     */
223
-    public function get_original($field_name)
224
-    {
225
-        if (isset($this->_props_n_values_provided_in_constructor[$field_name])
226
-            && $field_settings = $this->get_model()->field_settings_for($field_name)
227
-        ) {
228
-            return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
229
-        } else {
230
-            return null;
231
-        }
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * @param EE_Base_Class $obj
238
-     * @return string
239
-     */
240
-    public function get_class($obj)
241
-    {
242
-        return get_class($obj);
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Overrides parent because parent expects old models.
249
-     * This also doesn't do any validation, and won't work for serialized arrays
250
-     *
251
-     * @param    string $field_name
252
-     * @param    mixed  $field_value
253
-     * @param bool      $use_default
254
-     * @throws \EE_Error
255
-     */
256
-    public function set($field_name, $field_value, $use_default = false)
257
-    {
258
-        $field_obj = $this->get_model()->field_settings_for($field_name);
259
-        if ($field_obj instanceof EE_Model_Field_Base) {
260
-            //			if ( method_exists( $field_obj, 'set_timezone' )) {
261
-            if ($field_obj instanceof EE_Datetime_Field) {
262
-                $field_obj->set_timezone($this->_timezone);
263
-                $field_obj->set_date_format($this->_dt_frmt);
264
-                $field_obj->set_time_format($this->_tm_frmt);
265
-            }
266
-            $holder_of_value = $field_obj->prepare_for_set($field_value);
267
-            //should the value be null?
268
-            if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
269
-                $this->_fields[$field_name] = $field_obj->get_default_value();
270
-                /**
271
-                 * To save having to refactor all the models, if a default value is used for a
272
-                 * EE_Datetime_Field, and that value is not null nor is it a DateTime
273
-                 * object.  Then let's do a set again to ensure that it becomes a DateTime
274
-                 * object.
275
-                 *
276
-                 * @since 4.6.10+
277
-                 */
278
-                if (
279
-                    $field_obj instanceof EE_Datetime_Field
280
-                    && $this->_fields[$field_name] !== null
281
-                    && ! $this->_fields[$field_name] instanceof DateTime
282
-                ) {
283
-                    empty($this->_fields[$field_name])
284
-                        ? $this->set($field_name, time())
285
-                        : $this->set($field_name, $this->_fields[$field_name]);
286
-                }
287
-            } else {
288
-                $this->_fields[$field_name] = $holder_of_value;
289
-            }
290
-            //if we're not in the constructor...
291
-            //now check if what we set was a primary key
292
-            if (
293
-                //note: props_n_values_provided_in_constructor is only set at the END of the constructor
294
-                $this->_props_n_values_provided_in_constructor
295
-                && $field_value
296
-                && $field_name === self::_get_primary_key_name(get_class($this))
297
-            ) {
298
-                //if so, we want all this object's fields to be filled either with
299
-                //what we've explicitly set on this model
300
-                //or what we have in the db
301
-                // echo "setting primary key!";
302
-                $fields_on_model = self::_get_model(get_class($this))->field_settings();
303
-                $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
304
-                foreach ($fields_on_model as $field_obj) {
305
-                    if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
306
-                         && $field_obj->get_name() !== $field_name
307
-                    ) {
308
-                        $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
309
-                    }
310
-                }
311
-                //oh this model object has an ID? well make sure its in the entity mapper
312
-                $this->get_model()->add_to_entity_map($this);
313
-            }
314
-            //let's unset any cache for this field_name from the $_cached_properties property.
315
-            $this->_clear_cached_property($field_name);
316
-        } else {
317
-            throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s",
318
-                "event_espresso"), $field_name));
319
-        }
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * This sets the field value on the db column if it exists for the given $column_name or
326
-     * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
327
-     *
328
-     * @see EE_message::get_column_value for related documentation on the necessity of this method.
329
-     * @param string $field_name  Must be the exact column name.
330
-     * @param mixed  $field_value The value to set.
331
-     * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
332
-     * @throws \EE_Error
333
-     */
334
-    public function set_field_or_extra_meta($field_name, $field_value)
335
-    {
336
-        if ($this->get_model()->has_field($field_name)) {
337
-            $this->set($field_name, $field_value);
338
-            return true;
339
-        } else {
340
-            //ensure this object is saved first so that extra meta can be properly related.
341
-            $this->save();
342
-            return $this->update_extra_meta($field_name, $field_value);
343
-        }
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * This retrieves the value of the db column set on this class or if that's not present
350
-     * it will attempt to retrieve from extra_meta if found.
351
-     * Example Usage:
352
-     * Via EE_Message child class:
353
-     * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
354
-     * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
355
-     * also have additional main fields specific to the messenger.  The system accommodates those extra
356
-     * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
357
-     * value for those extra fields dynamically via the EE_message object.
358
-     *
359
-     * @param  string $field_name expecting the fully qualified field name.
360
-     * @return mixed|null  value for the field if found.  null if not found.
361
-     * @throws \EE_Error
362
-     */
363
-    public function get_field_or_extra_meta($field_name)
364
-    {
365
-        if ($this->get_model()->has_field($field_name)) {
366
-            $column_value = $this->get($field_name);
367
-        } else {
368
-            //This isn't a column in the main table, let's see if it is in the extra meta.
369
-            $column_value = $this->get_extra_meta($field_name, true, null);
370
-        }
371
-        return $column_value;
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
378
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
379
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is
380
-     * available to all child classes that may be using the EE_Datetime_Field for a field data type.
381
-     *
382
-     * @access public
383
-     * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
384
-     * @return void
385
-     * @throws \EE_Error
386
-     */
387
-    public function set_timezone($timezone = '')
388
-    {
389
-        $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
390
-        //make sure we clear all cached properties because they won't be relevant now
391
-        $this->_clear_cached_properties();
392
-        //make sure we update field settings and the date for all EE_Datetime_Fields
393
-        $model_fields = $this->get_model()->field_settings(false);
394
-        foreach ($model_fields as $field_name => $field_obj) {
395
-            if ($field_obj instanceof EE_Datetime_Field) {
396
-                $field_obj->set_timezone($this->_timezone);
397
-                if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
398
-                    $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
399
-                }
400
-            }
401
-        }
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * This just returns whatever is set for the current timezone.
408
-     *
409
-     * @access public
410
-     * @return string timezone string
411
-     */
412
-    public function get_timezone()
413
-    {
414
-        return $this->_timezone;
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * This sets the internal date format to what is sent in to be used as the new default for the class
421
-     * internally instead of wp set date format options
422
-     *
423
-     * @since 4.6
424
-     * @param string $format should be a format recognizable by PHP date() functions.
425
-     */
426
-    public function set_date_format($format)
427
-    {
428
-        $this->_dt_frmt = $format;
429
-        //clear cached_properties because they won't be relevant now.
430
-        $this->_clear_cached_properties();
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * This sets the internal time format string to what is sent in to be used as the new default for the
437
-     * class internally instead of wp set time format options.
438
-     *
439
-     * @since 4.6
440
-     * @param string $format should be a format recognizable by PHP date() functions.
441
-     */
442
-    public function set_time_format($format)
443
-    {
444
-        $this->_tm_frmt = $format;
445
-        //clear cached_properties because they won't be relevant now.
446
-        $this->_clear_cached_properties();
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     * This returns the current internal set format for the date and time formats.
453
-     *
454
-     * @param bool $full           if true (default), then return the full format.  Otherwise will return an array
455
-     *                             where the first value is the date format and the second value is the time format.
456
-     * @return mixed string|array
457
-     */
458
-    public function get_format($full = true)
459
-    {
460
-        return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
461
-    }
462
-
463
-
464
-
465
-    /**
466
-     * cache
467
-     * stores the passed model object on the current model object.
468
-     * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
469
-     *
470
-     * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg
471
-     *                                       'Registration' associated with this model object
472
-     * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction,
473
-     *                                       that could be a payment or a registration)
474
-     * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many
475
-     *                                       items which will be stored in an array on this object
476
-     * @throws EE_Error
477
-     * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one
478
-     *                  related thing, no array)
479
-     */
480
-    public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
481
-    {
482
-        // its entirely possible that there IS no related object yet in which case there is nothing to cache.
483
-        if ( ! $object_to_cache instanceof EE_Base_Class) {
484
-            return false;
485
-        }
486
-        // also get "how" the object is related, or throw an error
487
-        if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
488
-            throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'),
489
-                $relationName, get_class($this)));
490
-        }
491
-        // how many things are related ?
492
-        if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
493
-            // if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
494
-            // so for these model objects just set it to be cached
495
-            $this->_model_relations[$relationName] = $object_to_cache;
496
-            $return = true;
497
-        } else {
498
-            // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
499
-            // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
500
-            if ( ! is_array($this->_model_relations[$relationName])) {
501
-                // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
502
-                $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class
503
-                    ? array($this->_model_relations[$relationName]) : array();
504
-            }
505
-            // first check for a cache_id which is normally empty
506
-            if ( ! empty($cache_id)) {
507
-                // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
508
-                $this->_model_relations[$relationName][$cache_id] = $object_to_cache;
509
-                $return = $cache_id;
510
-            } elseif ($object_to_cache->ID()) {
511
-                // OR the cached object originally came from the db, so let's just use it's PK for an ID
512
-                $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
513
-                $return = $object_to_cache->ID();
514
-            } else {
515
-                // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
516
-                $this->_model_relations[$relationName][] = $object_to_cache;
517
-                // move the internal pointer to the end of the array
518
-                end($this->_model_relations[$relationName]);
519
-                // and grab the key so that we can return it
520
-                $return = key($this->_model_relations[$relationName]);
521
-            }
522
-        }
523
-        return $return;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * For adding an item to the cached_properties property.
530
-     *
531
-     * @access protected
532
-     * @param string      $fieldname the property item the corresponding value is for.
533
-     * @param mixed       $value     The value we are caching.
534
-     * @param string|null $cache_type
535
-     * @return void
536
-     * @throws \EE_Error
537
-     */
538
-    protected function _set_cached_property($fieldname, $value, $cache_type = null)
539
-    {
540
-        //first make sure this property exists
541
-        $this->get_model()->field_settings_for($fieldname);
542
-        $cache_type = empty($cache_type) ? 'standard' : $cache_type;
543
-        $this->_cached_properties[$fieldname][$cache_type] = $value;
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
550
-     * This also SETS the cache if we return the actual property!
551
-     *
552
-     * @param string $fieldname        the name of the property we're trying to retrieve
553
-     * @param bool   $pretty
554
-     * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
555
-     *                                 (in cases where the same property may be used for different outputs
556
-     *                                 - i.e. datetime, money etc.)
557
-     *                                 It can also accept certain pre-defined "schema" strings
558
-     *                                 to define how to output the property.
559
-     *                                 see the field's prepare_for_pretty_echoing for what strings can be used
560
-     * @return mixed                   whatever the value for the property is we're retrieving
561
-     * @throws \EE_Error
562
-     */
563
-    protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
564
-    {
565
-        //verify the field exists
566
-        $this->get_model()->field_settings_for($fieldname);
567
-        $cache_type = $pretty ? 'pretty' : 'standard';
568
-        $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
569
-        if (isset($this->_cached_properties[$fieldname][$cache_type])) {
570
-            return $this->_cached_properties[$fieldname][$cache_type];
571
-        }
572
-        $field_obj = $this->get_model()->field_settings_for($fieldname);
573
-        if ($field_obj instanceof EE_Model_Field_Base) {
574
-            // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
575
-            if ($field_obj instanceof EE_Datetime_Field) {
576
-                $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
577
-            }
578
-            if ( ! isset($this->_fields[$fieldname])) {
579
-                $this->_fields[$fieldname] = null;
580
-            }
581
-            $value = $pretty
582
-                ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
583
-                : $field_obj->prepare_for_get($this->_fields[$fieldname]);
584
-            $this->_set_cached_property($fieldname, $value, $cache_type);
585
-            return $value;
586
-        }
587
-        return null;
588
-    }
589
-
590
-
591
-
592
-    /**
593
-     * set timezone, formats, and output for EE_Datetime_Field objects
594
-     *
595
-     * @param \EE_Datetime_Field $datetime_field
596
-     * @param bool               $pretty
597
-     * @param null $date_or_time
598
-     * @return void
599
-     * @throws \EE_Error
600
-     */
601
-    protected function _prepare_datetime_field(
602
-        EE_Datetime_Field $datetime_field,
603
-        $pretty = false,
604
-        $date_or_time = null
605
-    ) {
606
-        $datetime_field->set_timezone($this->_timezone);
607
-        $datetime_field->set_date_format($this->_dt_frmt, $pretty);
608
-        $datetime_field->set_time_format($this->_tm_frmt, $pretty);
609
-        //set the output returned
610
-        switch ($date_or_time) {
611
-            case 'D' :
612
-                $datetime_field->set_date_time_output('date');
613
-                break;
614
-            case 'T' :
615
-                $datetime_field->set_date_time_output('time');
616
-                break;
617
-            default :
618
-                $datetime_field->set_date_time_output();
619
-        }
620
-    }
621
-
622
-
623
-
624
-    /**
625
-     * This just takes care of clearing out the cached_properties
626
-     *
627
-     * @return void
628
-     */
629
-    protected function _clear_cached_properties()
630
-    {
631
-        $this->_cached_properties = array();
632
-    }
633
-
634
-
635
-
636
-    /**
637
-     * This just clears out ONE property if it exists in the cache
638
-     *
639
-     * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
640
-     * @return void
641
-     */
642
-    protected function _clear_cached_property($property_name)
643
-    {
644
-        if (isset($this->_cached_properties[$property_name])) {
645
-            unset($this->_cached_properties[$property_name]);
646
-        }
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * Ensures that this related thing is a model object.
653
-     *
654
-     * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
655
-     * @param string $model_name   name of the related thing, eg 'Attendee',
656
-     * @return EE_Base_Class
657
-     * @throws \EE_Error
658
-     */
659
-    protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
660
-    {
661
-        $other_model_instance = self::_get_model_instance_with_name(
662
-            self::_get_model_classname($model_name),
663
-            $this->_timezone
664
-        );
665
-        return $other_model_instance->ensure_is_obj($object_or_id);
666
-    }
667
-
668
-
669
-
670
-    /**
671
-     * Forgets the cached model of the given relation Name. So the next time we request it,
672
-     * we will fetch it again from the database. (Handy if you know it's changed somehow).
673
-     * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
674
-     * then only remove that one object from our cached array. Otherwise, clear the entire list
675
-     *
676
-     * @param string $relationName                         one of the keys in the _model_relations array on the model.
677
-     *                                                     Eg 'Registration'
678
-     * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
679
-     *                                                     if you intend to use $clear_all = TRUE, or the relation only
680
-     *                                                     has 1 object anyways (ie, it's a BelongsToRelation)
681
-     * @param bool   $clear_all                            This flags clearing the entire cache relation property if
682
-     *                                                     this is HasMany or HABTM.
683
-     * @throws EE_Error
684
-     * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a
685
-     *                       relation from all
686
-     */
687
-    public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
688
-    {
689
-        $relationship_to_model = $this->get_model()->related_settings_for($relationName);
690
-        $index_in_cache = '';
691
-        if ( ! $relationship_to_model) {
692
-            throw new EE_Error(
693
-                sprintf(
694
-                    __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
695
-                    $relationName,
696
-                    get_class($this)
697
-                )
698
-            );
699
-        }
700
-        if ($clear_all) {
701
-            $obj_removed = true;
702
-            $this->_model_relations[$relationName] = null;
703
-        } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
704
-            $obj_removed = $this->_model_relations[$relationName];
705
-            $this->_model_relations[$relationName] = null;
706
-        } else {
707
-            if ($object_to_remove_or_index_into_array instanceof EE_Base_Class
708
-                && $object_to_remove_or_index_into_array->ID()
709
-            ) {
710
-                $index_in_cache = $object_to_remove_or_index_into_array->ID();
711
-                if (is_array($this->_model_relations[$relationName])
712
-                    && ! isset($this->_model_relations[$relationName][$index_in_cache])
713
-                ) {
714
-                    $index_found_at = null;
715
-                    //find this object in the array even though it has a different key
716
-                    foreach ($this->_model_relations[$relationName] as $index => $obj) {
717
-                        if (
718
-                            $obj instanceof EE_Base_Class
719
-                            && (
720
-                                $obj == $object_to_remove_or_index_into_array
721
-                                || $obj->ID() === $object_to_remove_or_index_into_array->ID()
722
-                            )
723
-                        ) {
724
-                            $index_found_at = $index;
725
-                            break;
726
-                        }
727
-                    }
728
-                    if ($index_found_at) {
729
-                        $index_in_cache = $index_found_at;
730
-                    } else {
731
-                        //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
732
-                        //if it wasn't in it to begin with. So we're done
733
-                        return $object_to_remove_or_index_into_array;
734
-                    }
735
-                }
736
-            } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
737
-                //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
738
-                foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
739
-                    if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
740
-                        $index_in_cache = $index;
741
-                    }
742
-                }
743
-            } else {
744
-                $index_in_cache = $object_to_remove_or_index_into_array;
745
-            }
746
-            //supposedly we've found it. But it could just be that the client code
747
-            //provided a bad index/object
748
-            if (
749
-            isset(
750
-                $this->_model_relations[$relationName],
751
-                $this->_model_relations[$relationName][$index_in_cache]
752
-            )
753
-            ) {
754
-                $obj_removed = $this->_model_relations[$relationName][$index_in_cache];
755
-                unset($this->_model_relations[$relationName][$index_in_cache]);
756
-            } else {
757
-                //that thing was never cached anyways.
758
-                $obj_removed = null;
759
-            }
760
-        }
761
-        return $obj_removed;
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * update_cache_after_object_save
768
-     * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has
769
-     * obtained after being saved to the db
770
-     *
771
-     * @param string         $relationName       - the type of object that is cached
772
-     * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
773
-     * @param string         $current_cache_id   - the ID that was used when originally caching the object
774
-     * @return boolean TRUE on success, FALSE on fail
775
-     * @throws \EE_Error
776
-     */
777
-    public function update_cache_after_object_save(
778
-        $relationName,
779
-        EE_Base_Class $newly_saved_object,
780
-        $current_cache_id = ''
781
-    ) {
782
-        // verify that incoming object is of the correct type
783
-        $obj_class = 'EE_' . $relationName;
784
-        if ($newly_saved_object instanceof $obj_class) {
785
-            /* @type EE_Base_Class $newly_saved_object */
786
-            // now get the type of relation
787
-            $relationship_to_model = $this->get_model()->related_settings_for($relationName);
788
-            // if this is a 1:1 relationship
789
-            if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
790
-                // then just replace the cached object with the newly saved object
791
-                $this->_model_relations[$relationName] = $newly_saved_object;
792
-                return true;
793
-                // or if it's some kind of sordid feral polyamorous relationship...
794
-            } elseif (is_array($this->_model_relations[$relationName])
795
-                      && isset($this->_model_relations[$relationName][$current_cache_id])
796
-            ) {
797
-                // then remove the current cached item
798
-                unset($this->_model_relations[$relationName][$current_cache_id]);
799
-                // and cache the newly saved object using it's new ID
800
-                $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
801
-                return true;
802
-            }
803
-        }
804
-        return false;
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
811
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
812
-     *
813
-     * @param string $relationName
814
-     * @return EE_Base_Class
815
-     */
816
-    public function get_one_from_cache($relationName)
817
-    {
818
-        $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName]
819
-            : null;
820
-        if (is_array($cached_array_or_object)) {
821
-            return array_shift($cached_array_or_object);
822
-        } else {
823
-            return $cached_array_or_object;
824
-        }
825
-    }
826
-
827
-
828
-
829
-    /**
830
-     * Fetches a single EE_Base_Class on that relation. (If the relation is of type
831
-     * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
832
-     *
833
-     * @param string $relationName
834
-     * @throws \EE_Error
835
-     * @return EE_Base_Class[] NOT necessarily indexed by primary keys
836
-     */
837
-    public function get_all_from_cache($relationName)
838
-    {
839
-        $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
840
-        // if the result is not an array, but exists, make it an array
841
-        $objects = is_array($objects) ? $objects : array($objects);
842
-        //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
843
-        //basically, if this model object was stored in the session, and these cached model objects
844
-        //already have IDs, let's make sure they're in their model's entity mapper
845
-        //otherwise we will have duplicates next time we call
846
-        // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
847
-        $model = EE_Registry::instance()->load_model($relationName);
848
-        foreach ($objects as $model_object) {
849
-            if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
850
-                //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
851
-                if ($model_object->ID()) {
852
-                    $model->add_to_entity_map($model_object);
853
-                }
854
-            } else {
855
-                throw new EE_Error(
856
-                    sprintf(
857
-                        __(
858
-                            'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
859
-                            'event_espresso'
860
-                        ),
861
-                        $relationName,
862
-                        gettype($model_object)
863
-                    )
864
-                );
865
-            }
866
-        }
867
-        return $objects;
868
-    }
869
-
870
-
871
-
872
-    /**
873
-     * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
874
-     * matching the given query conditions.
875
-     *
876
-     * @param null  $field_to_order_by  What field is being used as the reference point.
877
-     * @param int   $limit              How many objects to return.
878
-     * @param array $query_params       Any additional conditions on the query.
879
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
880
-     *                                  you can indicate just the columns you want returned
881
-     * @return array|EE_Base_Class[]
882
-     * @throws \EE_Error
883
-     */
884
-    public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
885
-    {
886
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
887
-            ? $this->get_model()->get_primary_key_field()->get_name()
888
-            : $field_to_order_by;
889
-        $current_value = ! empty($field) ? $this->get($field) : null;
890
-        if (empty($field) || empty($current_value)) {
891
-            return array();
892
-        }
893
-        return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
900
-     * matching the given query conditions.
901
-     *
902
-     * @param null  $field_to_order_by  What field is being used as the reference point.
903
-     * @param int   $limit              How many objects to return.
904
-     * @param array $query_params       Any additional conditions on the query.
905
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
906
-     *                                  you can indicate just the columns you want returned
907
-     * @return array|EE_Base_Class[]
908
-     * @throws \EE_Error
909
-     */
910
-    public function previous_x(
911
-        $field_to_order_by = null,
912
-        $limit = 1,
913
-        $query_params = array(),
914
-        $columns_to_select = null
915
-    ) {
916
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
917
-            ? $this->get_model()->get_primary_key_field()->get_name()
918
-            : $field_to_order_by;
919
-        $current_value = ! empty($field) ? $this->get($field) : null;
920
-        if (empty($field) || empty($current_value)) {
921
-            return array();
922
-        }
923
-        return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * Returns the next EE_Base_Class object in sequence from this object as found in the database
930
-     * matching the given query conditions.
931
-     *
932
-     * @param null  $field_to_order_by  What field is being used as the reference point.
933
-     * @param array $query_params       Any additional conditions on the query.
934
-     * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
935
-     *                                  you can indicate just the columns you want returned
936
-     * @return array|EE_Base_Class
937
-     * @throws \EE_Error
938
-     */
939
-    public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
940
-    {
941
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
942
-            ? $this->get_model()->get_primary_key_field()->get_name()
943
-            : $field_to_order_by;
944
-        $current_value = ! empty($field) ? $this->get($field) : null;
945
-        if (empty($field) || empty($current_value)) {
946
-            return array();
947
-        }
948
-        return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * Returns the previous EE_Base_Class object in sequence from this object as found in the database
955
-     * matching the given query conditions.
956
-     *
957
-     * @param null  $field_to_order_by  What field is being used as the reference point.
958
-     * @param array $query_params       Any additional conditions on the query.
959
-     * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
960
-     *                                  you can indicate just the column you want returned
961
-     * @return array|EE_Base_Class
962
-     * @throws \EE_Error
963
-     */
964
-    public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
965
-    {
966
-        $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
967
-            ? $this->get_model()->get_primary_key_field()->get_name()
968
-            : $field_to_order_by;
969
-        $current_value = ! empty($field) ? $this->get($field) : null;
970
-        if (empty($field) || empty($current_value)) {
971
-            return array();
972
-        }
973
-        return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * Overrides parent because parent expects old models.
980
-     * This also doesn't do any validation, and won't work for serialized arrays
981
-     *
982
-     * @param string $field_name
983
-     * @param mixed  $field_value_from_db
984
-     * @throws \EE_Error
985
-     */
986
-    public function set_from_db($field_name, $field_value_from_db)
987
-    {
988
-        $field_obj = $this->get_model()->field_settings_for($field_name);
989
-        if ($field_obj instanceof EE_Model_Field_Base) {
990
-            //you would think the DB has no NULLs for non-null label fields right? wrong!
991
-            //eg, a CPT model object could have an entry in the posts table, but no
992
-            //entry in the meta table. Meaning that all its columns in the meta table
993
-            //are null! yikes! so when we find one like that, use defaults for its meta columns
994
-            if ($field_value_from_db === null) {
995
-                if ($field_obj->is_nullable()) {
996
-                    //if the field allows nulls, then let it be null
997
-                    $field_value = null;
998
-                } else {
999
-                    $field_value = $field_obj->get_default_value();
1000
-                }
1001
-            } else {
1002
-                $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
1003
-            }
1004
-            $this->_fields[$field_name] = $field_value;
1005
-            $this->_clear_cached_property($field_name);
1006
-        }
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     * verifies that the specified field is of the correct type
1013
-     *
1014
-     * @param string $field_name
1015
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1016
-     *                                (in cases where the same property may be used for different outputs
1017
-     *                                - i.e. datetime, money etc.)
1018
-     * @return mixed
1019
-     * @throws \EE_Error
1020
-     */
1021
-    public function get($field_name, $extra_cache_ref = null)
1022
-    {
1023
-        return $this->_get_cached_property($field_name, false, $extra_cache_ref);
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     * This method simply returns the RAW unprocessed value for the given property in this class
1030
-     *
1031
-     * @param  string $field_name A valid fieldname
1032
-     * @return mixed              Whatever the raw value stored on the property is.
1033
-     * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1034
-     */
1035
-    public function get_raw($field_name)
1036
-    {
1037
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1038
-        return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1039
-            ? $this->_fields[$field_name]->format('U')
1040
-            : $this->_fields[$field_name];
1041
-    }
1042
-
1043
-
1044
-
1045
-    /**
1046
-     * This is used to return the internal DateTime object used for a field that is a
1047
-     * EE_Datetime_Field.
1048
-     *
1049
-     * @param string $field_name               The field name retrieving the DateTime object.
1050
-     * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1051
-     * @throws \EE_Error
1052
-     *                                         an error is set and false returned.  If the field IS an
1053
-     *                                         EE_Datetime_Field and but the field value is null, then
1054
-     *                                         just null is returned (because that indicates that likely
1055
-     *                                         this field is nullable).
1056
-     */
1057
-    public function get_DateTime_object($field_name)
1058
-    {
1059
-        $field_settings = $this->get_model()->field_settings_for($field_name);
1060
-        if ( ! $field_settings instanceof EE_Datetime_Field) {
1061
-            EE_Error::add_error(
1062
-                sprintf(
1063
-                    __(
1064
-                        'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1065
-                        'event_espresso'
1066
-                    ),
1067
-                    $field_name
1068
-                ),
1069
-                __FILE__,
1070
-                __FUNCTION__,
1071
-                __LINE__
1072
-            );
1073
-            return false;
1074
-        }
1075
-        return $this->_fields[$field_name];
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * To be used in template to immediately echo out the value, and format it for output.
1082
-     * Eg, should call stripslashes and whatnot before echoing
1083
-     *
1084
-     * @param string $field_name      the name of the field as it appears in the DB
1085
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1086
-     *                                (in cases where the same property may be used for different outputs
1087
-     *                                - i.e. datetime, money etc.)
1088
-     * @return void
1089
-     * @throws \EE_Error
1090
-     */
1091
-    public function e($field_name, $extra_cache_ref = null)
1092
-    {
1093
-        echo $this->get_pretty($field_name, $extra_cache_ref);
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1100
-     * can be easily used as the value of form input.
1101
-     *
1102
-     * @param string $field_name
1103
-     * @return void
1104
-     * @throws \EE_Error
1105
-     */
1106
-    public function f($field_name)
1107
-    {
1108
-        $this->e($field_name, 'form_input');
1109
-    }
1110
-
1111
-
1112
-
1113
-    /**
1114
-     * @param string $field_name
1115
-     * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1116
-     *                                (in cases where the same property may be used for different outputs
1117
-     *                                - i.e. datetime, money etc.)
1118
-     * @return mixed
1119
-     * @throws \EE_Error
1120
-     */
1121
-    public function get_pretty($field_name, $extra_cache_ref = null)
1122
-    {
1123
-        return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1124
-    }
1125
-
1126
-
1127
-
1128
-    /**
1129
-     * This simply returns the datetime for the given field name
1130
-     * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1131
-     * (and the equivalent e_date, e_time, e_datetime).
1132
-     *
1133
-     * @access   protected
1134
-     * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1135
-     * @param string   $dt_frmt      valid datetime format used for date
1136
-     *                               (if '' then we just use the default on the field,
1137
-     *                               if NULL we use the last-used format)
1138
-     * @param string   $tm_frmt      Same as above except this is for time format
1139
-     * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1140
-     * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1141
-     * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1142
-     *                               if field is not a valid dtt field, or void if echoing
1143
-     * @throws \EE_Error
1144
-     */
1145
-    protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1146
-    {
1147
-        // clear cached property
1148
-        $this->_clear_cached_property($field_name);
1149
-        //reset format properties because they are used in get()
1150
-        $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1151
-        $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1152
-        if ($echo) {
1153
-            $this->e($field_name, $date_or_time);
1154
-            return '';
1155
-        }
1156
-        return $this->get($field_name, $date_or_time);
1157
-    }
1158
-
1159
-
1160
-
1161
-    /**
1162
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date
1163
-     * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1164
-     * other echoes the pretty value for dtt)
1165
-     *
1166
-     * @param  string $field_name name of model object datetime field holding the value
1167
-     * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1168
-     * @return string            datetime value formatted
1169
-     * @throws \EE_Error
1170
-     */
1171
-    public function get_date($field_name, $format = '')
1172
-    {
1173
-        return $this->_get_datetime($field_name, $format, null, 'D');
1174
-    }
1175
-
1176
-
1177
-
1178
-    /**
1179
-     * @param      $field_name
1180
-     * @param string $format
1181
-     * @throws \EE_Error
1182
-     */
1183
-    public function e_date($field_name, $format = '')
1184
-    {
1185
-        $this->_get_datetime($field_name, $format, null, 'D', true);
1186
-    }
1187
-
1188
-
1189
-
1190
-    /**
1191
-     * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time
1192
-     * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1193
-     * other echoes the pretty value for dtt)
1194
-     *
1195
-     * @param  string $field_name name of model object datetime field holding the value
1196
-     * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1197
-     * @return string             datetime value formatted
1198
-     * @throws \EE_Error
1199
-     */
1200
-    public function get_time($field_name, $format = '')
1201
-    {
1202
-        return $this->_get_datetime($field_name, null, $format, 'T');
1203
-    }
1204
-
1205
-
1206
-
1207
-    /**
1208
-     * @param      $field_name
1209
-     * @param string $format
1210
-     * @throws \EE_Error
1211
-     */
1212
-    public function e_time($field_name, $format = '')
1213
-    {
1214
-        $this->_get_datetime($field_name, null, $format, 'T', true);
1215
-    }
1216
-
1217
-
1218
-
1219
-    /**
1220
-     * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND
1221
-     * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1222
-     * other echoes the pretty value for dtt)
1223
-     *
1224
-     * @param  string $field_name name of model object datetime field holding the value
1225
-     * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1226
-     * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1227
-     * @return string             datetime value formatted
1228
-     * @throws \EE_Error
1229
-     */
1230
-    public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1231
-    {
1232
-        return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1233
-    }
1234
-
1235
-
1236
-
1237
-    /**
1238
-     * @param string $field_name
1239
-     * @param string $dt_frmt
1240
-     * @param string $tm_frmt
1241
-     * @throws \EE_Error
1242
-     */
1243
-    public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1244
-    {
1245
-        $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1246
-    }
1247
-
1248
-
1249
-
1250
-    /**
1251
-     * Get the i8ln value for a date using the WordPress @see date_i18n function.
1252
-     *
1253
-     * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1254
-     * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format
1255
-     *                           on the object will be used.
1256
-     * @return string Date and time string in set locale or false if no field exists for the given
1257
-     * @throws \EE_Error
1258
-     *                           field name.
1259
-     */
1260
-    public function get_i18n_datetime($field_name, $format = '')
1261
-    {
1262
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1263
-        return date_i18n(
1264
-            $format,
1265
-            EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1266
-        );
1267
-    }
1268
-
1269
-
1270
-
1271
-    /**
1272
-     * This method validates whether the given field name is a valid field on the model object as well as it is of a
1273
-     * type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is
1274
-     * thrown.
1275
-     *
1276
-     * @param  string $field_name The field name being checked
1277
-     * @throws EE_Error
1278
-     * @return EE_Datetime_Field
1279
-     */
1280
-    protected function _get_dtt_field_settings($field_name)
1281
-    {
1282
-        $field = $this->get_model()->field_settings_for($field_name);
1283
-        //check if field is dtt
1284
-        if ($field instanceof EE_Datetime_Field) {
1285
-            return $field;
1286
-        } else {
1287
-            throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1288
-                'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1289
-        }
1290
-    }
1291
-
1292
-
1293
-
1294
-
1295
-    /**
1296
-     * NOTE ABOUT BELOW:
1297
-     * These convenience date and time setters are for setting date and time independently.  In other words you might
1298
-     * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand
1299
-     * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value)
1300
-     * method and make sure you send the entire datetime value for setting.
1301
-     */
1302
-    /**
1303
-     * sets the time on a datetime property
1304
-     *
1305
-     * @access protected
1306
-     * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1307
-     * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1308
-     * @throws \EE_Error
1309
-     */
1310
-    protected function _set_time_for($time, $fieldname)
1311
-    {
1312
-        $this->_set_date_time('T', $time, $fieldname);
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     * sets the date on a datetime property
1319
-     *
1320
-     * @access protected
1321
-     * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1322
-     * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1323
-     * @throws \EE_Error
1324
-     */
1325
-    protected function _set_date_for($date, $fieldname)
1326
-    {
1327
-        $this->_set_date_time('D', $date, $fieldname);
1328
-    }
1329
-
1330
-
1331
-
1332
-    /**
1333
-     * This takes care of setting a date or time independently on a given model object property. This method also
1334
-     * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1335
-     *
1336
-     * @access protected
1337
-     * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1338
-     * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1339
-     * @param string          $fieldname      the name of the field the date OR time is being set on (must match a
1340
-     *                                        EE_Datetime_Field property)
1341
-     * @throws \EE_Error
1342
-     */
1343
-    protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1344
-    {
1345
-        $field = $this->_get_dtt_field_settings($fieldname);
1346
-        $field->set_timezone($this->_timezone);
1347
-        $field->set_date_format($this->_dt_frmt);
1348
-        $field->set_time_format($this->_tm_frmt);
1349
-        switch ($what) {
1350
-            case 'T' :
1351
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1352
-                    $datetime_value,
1353
-                    $this->_fields[$fieldname]
1354
-                );
1355
-                break;
1356
-            case 'D' :
1357
-                $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1358
-                    $datetime_value,
1359
-                    $this->_fields[$fieldname]
1360
-                );
1361
-                break;
1362
-            case 'B' :
1363
-                $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1364
-                break;
1365
-        }
1366
-        $this->_clear_cached_property($fieldname);
1367
-    }
1368
-
1369
-
1370
-
1371
-    /**
1372
-     * This will return a timestamp for the website timezone but ONLY when the current website timezone is different
1373
-     * than the timezone set for the website. NOTE, this currently only works well with methods that return values.  If
1374
-     * you use it with methods that echo values the $_timestamp property may not get reset to its original value and
1375
-     * that could lead to some unexpected results!
1376
-     *
1377
-     * @access public
1378
-     * @param string               $field_name This is the name of the field on the object that contains the date/time
1379
-     *                                         value being returned.
1380
-     * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1381
-     * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1382
-     * @param string               $prepend    You can include something to prepend on the timestamp
1383
-     * @param string               $append     You can include something to append on the timestamp
1384
-     * @throws EE_Error
1385
-     * @return string timestamp
1386
-     */
1387
-    public function display_in_my_timezone(
1388
-        $field_name,
1389
-        $callback = 'get_datetime',
1390
-        $args = null,
1391
-        $prepend = '',
1392
-        $append = ''
1393
-    ) {
1394
-        $timezone = EEH_DTT_Helper::get_timezone();
1395
-        if ($timezone === $this->_timezone) {
1396
-            return '';
1397
-        }
1398
-        $original_timezone = $this->_timezone;
1399
-        $this->set_timezone($timezone);
1400
-        $fn = (array)$field_name;
1401
-        $args = array_merge($fn, (array)$args);
1402
-        if ( ! method_exists($this, $callback)) {
1403
-            throw new EE_Error(
1404
-                sprintf(
1405
-                    __(
1406
-                        'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1407
-                        'event_espresso'
1408
-                    ),
1409
-                    $callback
1410
-                )
1411
-            );
1412
-        }
1413
-        $args = (array)$args;
1414
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1415
-        $this->set_timezone($original_timezone);
1416
-        return $return;
1417
-    }
1418
-
1419
-
1420
-
1421
-    /**
1422
-     * Deletes this model object.
1423
-     * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should
1424
-     * override
1425
-     * `EE_Base_Class::_delete` NOT this class.
1426
-     *
1427
-     * @return boolean | int
1428
-     * @throws \EE_Error
1429
-     */
1430
-    public function delete()
1431
-    {
1432
-        /**
1433
-         * Called just before the `EE_Base_Class::_delete` method call.
1434
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1435
-         * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1436
-         * soft deletes (trash) the object and does not permanently delete it.
1437
-         *
1438
-         * @param EE_Base_Class $model_object about to be 'deleted'
1439
-         */
1440
-        do_action('AHEE__EE_Base_Class__delete__before', $this);
1441
-        $result = $this->_delete();
1442
-        /**
1443
-         * Called just after the `EE_Base_Class::_delete` method call.
1444
-         * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1445
-         * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1446
-         * soft deletes (trash) the object and does not permanently delete it.
1447
-         *
1448
-         * @param EE_Base_Class $model_object that was just 'deleted'
1449
-         * @param boolean       $result
1450
-         */
1451
-        do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1452
-        return $result;
1453
-    }
1454
-
1455
-
1456
-
1457
-    /**
1458
-     * Calls the specific delete method for the instantiated class.
1459
-     * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override
1460
-     * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT
1461
-     * `EE_Base_Class::delete`
1462
-     *
1463
-     * @return bool|int
1464
-     * @throws \EE_Error
1465
-     */
1466
-    protected function _delete()
1467
-    {
1468
-        return $this->delete_permanently();
1469
-    }
1470
-
1471
-
1472
-
1473
-    /**
1474
-     * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an
1475
-     * error)
1476
-     *
1477
-     * @return bool | int
1478
-     * @throws \EE_Error
1479
-     */
1480
-    public function delete_permanently()
1481
-    {
1482
-        /**
1483
-         * Called just before HARD deleting a model object
1484
-         *
1485
-         * @param EE_Base_Class $model_object about to be 'deleted'
1486
-         */
1487
-        do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1488
-        $model = $this->get_model();
1489
-        $result = $model->delete_permanently_by_ID($this->ID());
1490
-        $this->refresh_cache_of_related_objects();
1491
-        /**
1492
-         * Called just after HARD deleting a model object
1493
-         *
1494
-         * @param EE_Base_Class $model_object that was just 'deleted'
1495
-         * @param boolean       $result
1496
-         */
1497
-        do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1498
-        return $result;
1499
-    }
1500
-
1501
-
1502
-
1503
-    /**
1504
-     * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1505
-     * related model objects
1506
-     *
1507
-     * @throws \EE_Error
1508
-     */
1509
-    public function refresh_cache_of_related_objects()
1510
-    {
1511
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1512
-            if ( ! empty($this->_model_relations[$relation_name])) {
1513
-                $related_objects = $this->_model_relations[$relation_name];
1514
-                if ($relation_obj instanceof EE_Belongs_To_Relation) {
1515
-                    //this relation only stores a single model object, not an array
1516
-                    //but let's make it consistent
1517
-                    $related_objects = array($related_objects);
1518
-                }
1519
-                foreach ($related_objects as $related_object) {
1520
-                    //only refresh their cache if they're in memory
1521
-                    if ($related_object instanceof EE_Base_Class) {
1522
-                        $related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1523
-                    }
1524
-                }
1525
-            }
1526
-        }
1527
-    }
1528
-
1529
-
1530
-
1531
-    /**
1532
-     *        Saves this object to the database. An array may be supplied to set some values on this
1533
-     * object just before saving.
1534
-     *
1535
-     * @access public
1536
-     * @param array $set_cols_n_values keys are field names, values are their new values,
1537
-     *                                 if provided during the save() method (often client code will change the fields'
1538
-     *                                 values before calling save)
1539
-     * @throws \EE_Error
1540
-     * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1541
-     *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1542
-     */
1543
-    public function save($set_cols_n_values = array())
1544
-    {
1545
-        /**
1546
-         * Filters the fields we're about to save on the model object
1547
-         *
1548
-         * @param array         $set_cols_n_values
1549
-         * @param EE_Base_Class $model_object
1550
-         */
1551
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1552
-            $this);
1553
-        //set attributes as provided in $set_cols_n_values
1554
-        foreach ($set_cols_n_values as $column => $value) {
1555
-            $this->set($column, $value);
1556
-        }
1557
-        /**
1558
-         * Saving a model object.
1559
-         * Before we perform a save, this action is fired.
1560
-         *
1561
-         * @param EE_Base_Class $model_object the model object about to be saved.
1562
-         */
1563
-        do_action('AHEE__EE_Base_Class__save__begin', $this);
1564
-        if ( ! $this->allow_persist()) {
1565
-            return 0;
1566
-        }
1567
-        //now get current attribute values
1568
-        $save_cols_n_values = $this->_fields;
1569
-        //if the object already has an ID, update it. Otherwise, insert it
1570
-        //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1571
-        $old_assumption_concerning_value_preparation = $this->get_model()
1572
-                                                            ->get_assumption_concerning_values_already_prepared_by_model_object();
1573
-        $this->get_model()->assume_values_already_prepared_by_model_object(true);
1574
-        //does this model have an autoincrement PK?
1575
-        if ($this->get_model()->has_primary_key_field()) {
1576
-            if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1577
-                //ok check if it's set, if so: update; if not, insert
1578
-                if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1579
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1580
-                } else {
1581
-                    unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1582
-                    $results = $this->get_model()->insert($save_cols_n_values);
1583
-                    if ($results) {
1584
-                        //if successful, set the primary key
1585
-                        //but don't use the normal SET method, because it will check if
1586
-                        //an item with the same ID exists in the mapper & db, then
1587
-                        //will find it in the db (because we just added it) and THAT object
1588
-                        //will get added to the mapper before we can add this one!
1589
-                        //but if we just avoid using the SET method, all that headache can be avoided
1590
-                        $pk_field_name = self::_get_primary_key_name(get_class($this));
1591
-                        $this->_fields[$pk_field_name] = $results;
1592
-                        $this->_clear_cached_property($pk_field_name);
1593
-                        $this->get_model()->add_to_entity_map($this);
1594
-                        $this->_update_cached_related_model_objs_fks();
1595
-                    }
1596
-                }
1597
-            } else {//PK is NOT auto-increment
1598
-                //so check if one like it already exists in the db
1599
-                if ($this->get_model()->exists_by_ID($this->ID())) {
1600
-                    if (WP_DEBUG && ! $this->in_entity_map()) {
1601
-                        throw new EE_Error(
1602
-                            sprintf(
1603
-                                __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1604
-                                    'event_espresso'),
1605
-                                get_class($this),
1606
-                                get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1607
-                                get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1608
-                                '<br />'
1609
-                            )
1610
-                        );
1611
-                    }
1612
-                    $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1613
-                } else {
1614
-                    $results = $this->get_model()->insert($save_cols_n_values);
1615
-                    $this->_update_cached_related_model_objs_fks();
1616
-                }
1617
-            }
1618
-        } else {//there is NO primary key
1619
-            $already_in_db = false;
1620
-            foreach ($this->get_model()->unique_indexes() as $index) {
1621
-                $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1622
-                if ($this->get_model()->exists(array($uniqueness_where_params))) {
1623
-                    $already_in_db = true;
1624
-                }
1625
-            }
1626
-            if ($already_in_db) {
1627
-                $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values,
1628
-                    $this->get_model()->get_combined_primary_key_fields());
1629
-                $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1630
-            } else {
1631
-                $results = $this->get_model()->insert($save_cols_n_values);
1632
-            }
1633
-        }
1634
-        //restore the old assumption about values being prepared by the model object
1635
-        $this->get_model()
1636
-             ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1637
-        /**
1638
-         * After saving the model object this action is called
1639
-         *
1640
-         * @param EE_Base_Class $model_object which was just saved
1641
-         * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1642
-         *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1643
-         */
1644
-        do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1645
-        return $results;
1646
-    }
1647
-
1648
-
1649
-
1650
-    /**
1651
-     * Updates the foreign key on related models objects pointing to this to have this model object's ID
1652
-     * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB
1653
-     * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its
1654
-     * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't
1655
-     * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the
1656
-     * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether
1657
-     * or not they exist in the DB (if they do, their DB records will be automatically updated)
1658
-     *
1659
-     * @return void
1660
-     * @throws \EE_Error
1661
-     */
1662
-    protected function _update_cached_related_model_objs_fks()
1663
-    {
1664
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1665
-            if ($relation_obj instanceof EE_Has_Many_Relation) {
1666
-                foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1667
-                    $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1668
-                        $this->get_model()->get_this_model_name()
1669
-                    );
1670
-                    $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1671
-                    if ($related_model_obj_in_cache->ID()) {
1672
-                        $related_model_obj_in_cache->save();
1673
-                    }
1674
-                }
1675
-            }
1676
-        }
1677
-    }
1678
-
1679
-
1680
-
1681
-    /**
1682
-     * Saves this model object and its NEW cached relations to the database.
1683
-     * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1684
-     * In order for that to work, we would need to mark model objects as dirty/clean...
1685
-     * because otherwise, there's a potential for infinite looping of saving
1686
-     * Saves the cached related model objects, and ensures the relation between them
1687
-     * and this object and properly setup
1688
-     *
1689
-     * @return int ID of new model object on save; 0 on failure+
1690
-     * @throws \EE_Error
1691
-     */
1692
-    public function save_new_cached_related_model_objs()
1693
-    {
1694
-        //make sure this has been saved
1695
-        if ( ! $this->ID()) {
1696
-            $id = $this->save();
1697
-        } else {
1698
-            $id = $this->ID();
1699
-        }
1700
-        //now save all the NEW cached model objects  (ie they don't exist in the DB)
1701
-        foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1702
-            if ($this->_model_relations[$relationName]) {
1703
-                //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1704
-                //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1705
-                if ($relationObj instanceof EE_Belongs_To_Relation) {
1706
-                    //add a relation to that relation type (which saves the appropriate thing in the process)
1707
-                    //but ONLY if it DOES NOT exist in the DB
1708
-                    /* @var $related_model_obj EE_Base_Class */
1709
-                    $related_model_obj = $this->_model_relations[$relationName];
1710
-                    //					if( ! $related_model_obj->ID()){
1711
-                    $this->_add_relation_to($related_model_obj, $relationName);
1712
-                    $related_model_obj->save_new_cached_related_model_objs();
1713
-                    //					}
1714
-                } else {
1715
-                    foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1716
-                        //add a relation to that relation type (which saves the appropriate thing in the process)
1717
-                        //but ONLY if it DOES NOT exist in the DB
1718
-                        //						if( ! $related_model_obj->ID()){
1719
-                        $this->_add_relation_to($related_model_obj, $relationName);
1720
-                        $related_model_obj->save_new_cached_related_model_objs();
1721
-                        //						}
1722
-                    }
1723
-                }
1724
-            }
1725
-        }
1726
-        return $id;
1727
-    }
1728
-
1729
-
1730
-
1731
-    /**
1732
-     * for getting a model while instantiated.
1733
-     *
1734
-     * @return \EEM_Base | \EEM_CPT_Base
1735
-     */
1736
-    public function get_model()
1737
-    {
1738
-        $modelName = self::_get_model_classname(get_class($this));
1739
-        return self::_get_model_instance_with_name($modelName, $this->_timezone);
1740
-    }
1741
-
1742
-
1743
-
1744
-    /**
1745
-     * @param $props_n_values
1746
-     * @param $classname
1747
-     * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1748
-     * @throws \EE_Error
1749
-     */
1750
-    protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1751
-    {
1752
-        //TODO: will not work for Term_Relationships because they have no PK!
1753
-        $primary_id_ref = self::_get_primary_key_name($classname);
1754
-        if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1755
-            $id = $props_n_values[$primary_id_ref];
1756
-            return self::_get_model($classname)->get_from_entity_map($id);
1757
-        }
1758
-        return false;
1759
-    }
1760
-
1761
-
1762
-
1763
-    /**
1764
-     * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for
1765
-     * the primary key (if present in incoming values). If there is a key in the incoming array that matches the
1766
-     * primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not
1767
-     * we return false.
1768
-     *
1769
-     * @param  array  $props_n_values   incoming array of properties and their values
1770
-     * @param  string $classname        the classname of the child class
1771
-     * @param null    $timezone
1772
-     * @param array   $date_formats     incoming date_formats in an array where the first value is the
1773
-     *                                  date_format and the second value is the time format
1774
-     * @return mixed (EE_Base_Class|bool)
1775
-     * @throws \EE_Error
1776
-     */
1777
-    protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1778
-    {
1779
-        $existing = null;
1780
-        if (self::_get_model($classname)->has_primary_key_field()) {
1781
-            $primary_id_ref = self::_get_primary_key_name($classname);
1782
-            if (array_key_exists($primary_id_ref, $props_n_values)
1783
-                && ! empty($props_n_values[$primary_id_ref])
1784
-            ) {
1785
-                $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1786
-                    $props_n_values[$primary_id_ref]
1787
-                );
1788
-            }
1789
-        } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1790
-            //no primary key on this model, but there's still a matching item in the DB
1791
-            $existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1792
-                self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1793
-            );
1794
-        }
1795
-        if ($existing) {
1796
-            //set date formats if present before setting values
1797
-            if ( ! empty($date_formats) && is_array($date_formats)) {
1798
-                $existing->set_date_format($date_formats[0]);
1799
-                $existing->set_time_format($date_formats[1]);
1800
-            } else {
1801
-                //set default formats for date and time
1802
-                $existing->set_date_format(get_option('date_format'));
1803
-                $existing->set_time_format(get_option('time_format'));
1804
-            }
1805
-            foreach ($props_n_values as $property => $field_value) {
1806
-                $existing->set($property, $field_value);
1807
-            }
1808
-            return $existing;
1809
-        } else {
1810
-            return false;
1811
-        }
1812
-    }
1813
-
1814
-
1815
-
1816
-    /**
1817
-     * Gets the EEM_*_Model for this class
1818
-     *
1819
-     * @access public now, as this is more convenient
1820
-     * @param      $classname
1821
-     * @param null $timezone
1822
-     * @throws EE_Error
1823
-     * @return EEM_Base
1824
-     */
1825
-    protected static function _get_model($classname, $timezone = null)
1826
-    {
1827
-        //find model for this class
1828
-        if ( ! $classname) {
1829
-            throw new EE_Error(
1830
-                sprintf(
1831
-                    __(
1832
-                        "What were you thinking calling _get_model(%s)?? You need to specify the class name",
1833
-                        "event_espresso"
1834
-                    ),
1835
-                    $classname
1836
-                )
1837
-            );
1838
-        }
1839
-        $modelName = self::_get_model_classname($classname);
1840
-        return self::_get_model_instance_with_name($modelName, $timezone);
1841
-    }
1842
-
1843
-
1844
-
1845
-    /**
1846
-     * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1847
-     *
1848
-     * @param string $model_classname
1849
-     * @param null   $timezone
1850
-     * @return EEM_Base
1851
-     */
1852
-    protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1853
-    {
1854
-        $model_classname = str_replace('EEM_', '', $model_classname);
1855
-        $model = EE_Registry::instance()->load_model($model_classname);
1856
-        $model->set_timezone($timezone);
1857
-        return $model;
1858
-    }
1859
-
1860
-
1861
-
1862
-    /**
1863
-     * If a model name is provided (eg Registration), gets the model classname for that model.
1864
-     * Also works if a model class's classname is provided (eg EE_Registration).
1865
-     *
1866
-     * @param null $model_name
1867
-     * @return string like EEM_Attendee
1868
-     */
1869
-    private static function _get_model_classname($model_name = null)
1870
-    {
1871
-        if (strpos($model_name, "EE_") === 0) {
1872
-            $model_classname = str_replace("EE_", "EEM_", $model_name);
1873
-        } else {
1874
-            $model_classname = "EEM_" . $model_name;
1875
-        }
1876
-        return $model_classname;
1877
-    }
1878
-
1879
-
1880
-
1881
-    /**
1882
-     * returns the name of the primary key attribute
1883
-     *
1884
-     * @param null $classname
1885
-     * @throws EE_Error
1886
-     * @return string
1887
-     */
1888
-    protected static function _get_primary_key_name($classname = null)
1889
-    {
1890
-        if ( ! $classname) {
1891
-            throw new EE_Error(
1892
-                sprintf(
1893
-                    __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1894
-                    $classname
1895
-                )
1896
-            );
1897
-        }
1898
-        return self::_get_model($classname)->get_primary_key_field()->get_name();
1899
-    }
1900
-
1901
-
1902
-
1903
-    /**
1904
-     * Gets the value of the primary key.
1905
-     * If the object hasn't yet been saved, it should be whatever the model field's default was
1906
-     * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value
1907
-     * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1908
-     *
1909
-     * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1910
-     * @throws \EE_Error
1911
-     */
1912
-    public function ID()
1913
-    {
1914
-        //now that we know the name of the variable, use a variable variable to get its value and return its
1915
-        if ($this->get_model()->has_primary_key_field()) {
1916
-            return $this->_fields[self::_get_primary_key_name(get_class($this))];
1917
-        } else {
1918
-            return $this->get_model()->get_index_primary_key_string($this->_fields);
1919
-        }
1920
-    }
1921
-
1922
-
1923
-
1924
-    /**
1925
-     * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current
1926
-     * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE
1927
-     * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing
1928
-     *
1929
-     * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1930
-     * @param string $relationName                     eg 'Events','Question',etc.
1931
-     *                                                 an attendee to a group, you also want to specify which role they
1932
-     *                                                 will have in that group. So you would use this parameter to
1933
-     *                                                 specify array('role-column-name'=>'role-id')
1934
-     * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that
1935
-     *                                                 allow you to further constrict the relation to being added.
1936
-     *                                                 However, keep in mind that the columns (keys) given must match a
1937
-     *                                                 column on the JOIN table and currently only the HABTM models
1938
-     *                                                 accept these additional conditions.  Also remember that if an
1939
-     *                                                 exact match isn't found for these extra cols/val pairs, then a
1940
-     *                                                 NEW row is created in the join table.
1941
-     * @param null   $cache_id
1942
-     * @throws EE_Error
1943
-     * @return EE_Base_Class the object the relation was added to
1944
-     */
1945
-    public function _add_relation_to(
1946
-        $otherObjectModelObjectOrID,
1947
-        $relationName,
1948
-        $extra_join_model_fields_n_values = array(),
1949
-        $cache_id = null
1950
-    ) {
1951
-        //if this thing exists in the DB, save the relation to the DB
1952
-        if ($this->ID()) {
1953
-            $otherObject = $this->get_model()
1954
-                                ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
1955
-                                    $extra_join_model_fields_n_values);
1956
-            //clear cache so future get_many_related and get_first_related() return new results.
1957
-            $this->clear_cache($relationName, $otherObject, true);
1958
-            if ($otherObject instanceof EE_Base_Class) {
1959
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1960
-            }
1961
-        } else {
1962
-            //this thing doesn't exist in the DB,  so just cache it
1963
-            if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1964
-                throw new EE_Error(sprintf(
1965
-                    __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s',
1966
-                        'event_espresso'),
1967
-                    $otherObjectModelObjectOrID,
1968
-                    get_class($this)
1969
-                ));
1970
-            } else {
1971
-                $otherObject = $otherObjectModelObjectOrID;
1972
-            }
1973
-            $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1974
-        }
1975
-        if ($otherObject instanceof EE_Base_Class) {
1976
-            //fix the reciprocal relation too
1977
-            if ($otherObject->ID()) {
1978
-                //its saved so assumed relations exist in the DB, so we can just
1979
-                //clear the cache so future queries use the updated info in the DB
1980
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1981
-            } else {
1982
-                //it's not saved, so it caches relations like this
1983
-                $otherObject->cache($this->get_model()->get_this_model_name(), $this);
1984
-            }
1985
-        }
1986
-        return $otherObject;
1987
-    }
1988
-
1989
-
1990
-
1991
-    /**
1992
-     * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current
1993
-     * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE
1994
-     * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing
1995
-     * from the cache
1996
-     *
1997
-     * @param mixed  $otherObjectModelObjectOrID
1998
-     *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved
1999
-     *                to the DB yet
2000
-     * @param string $relationName
2001
-     * @param array  $where_query
2002
-     *                You can optionally include an array of key=>value pairs that allow you to further constrict the
2003
-     *                relation to being added. However, keep in mind that the columns (keys) given must match a column
2004
-     *                on the JOIN table and currently only the HABTM models accept these additional conditions. Also
2005
-     *                remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is
2006
-     *                created in the join table.
2007
-     * @return EE_Base_Class the relation was removed from
2008
-     * @throws \EE_Error
2009
-     */
2010
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
2011
-    {
2012
-        if ($this->ID()) {
2013
-            //if this exists in the DB, save the relation change to the DB too
2014
-            $otherObject = $this->get_model()
2015
-                                ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2016
-                                    $where_query);
2017
-            $this->clear_cache($relationName, $otherObject);
2018
-        } else {
2019
-            //this doesn't exist in the DB, just remove it from the cache
2020
-            $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
2021
-        }
2022
-        if ($otherObject instanceof EE_Base_Class) {
2023
-            $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2024
-        }
2025
-        return $otherObject;
2026
-    }
2027
-
2028
-
2029
-
2030
-    /**
2031
-     * Removes ALL the related things for the $relationName.
2032
-     *
2033
-     * @param string $relationName
2034
-     * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
2035
-     * @return EE_Base_Class
2036
-     * @throws \EE_Error
2037
-     */
2038
-    public function _remove_relations($relationName, $where_query_params = array())
2039
-    {
2040
-        if ($this->ID()) {
2041
-            //if this exists in the DB, save the relation change to the DB too
2042
-            $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
2043
-            $this->clear_cache($relationName, null, true);
2044
-        } else {
2045
-            //this doesn't exist in the DB, just remove it from the cache
2046
-            $otherObjects = $this->clear_cache($relationName, null, true);
2047
-        }
2048
-        if (is_array($otherObjects)) {
2049
-            foreach ($otherObjects as $otherObject) {
2050
-                $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2051
-            }
2052
-        }
2053
-        return $otherObjects;
2054
-    }
2055
-
2056
-
2057
-
2058
-    /**
2059
-     * Gets all the related model objects of the specified type. Eg, if the current class if
2060
-     * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
2061
-     * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
2062
-     * because we want to get even deleted items etc.
2063
-     *
2064
-     * @param string $relationName key in the model's _model_relations array
2065
-     * @param array  $query_params like EEM_Base::get_all
2066
-     * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
2067
-     * @throws \EE_Error
2068
-     *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if
2069
-     *                             you want IDs
2070
-     */
2071
-    public function get_many_related($relationName, $query_params = array())
2072
-    {
2073
-        if ($this->ID()) {
2074
-            //this exists in the DB, so get the related things from either the cache or the DB
2075
-            //if there are query parameters, forget about caching the related model objects.
2076
-            if ($query_params) {
2077
-                $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2078
-            } else {
2079
-                //did we already cache the result of this query?
2080
-                $cached_results = $this->get_all_from_cache($relationName);
2081
-                if ( ! $cached_results) {
2082
-                    $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2083
-                    //if no query parameters were passed, then we got all the related model objects
2084
-                    //for that relation. We can cache them then.
2085
-                    foreach ($related_model_objects as $related_model_object) {
2086
-                        $this->cache($relationName, $related_model_object);
2087
-                    }
2088
-                } else {
2089
-                    $related_model_objects = $cached_results;
2090
-                }
2091
-            }
2092
-        } else {
2093
-            //this doesn't exist in the DB, so just get the related things from the cache
2094
-            $related_model_objects = $this->get_all_from_cache($relationName);
2095
-        }
2096
-        return $related_model_objects;
2097
-    }
2098
-
2099
-
2100
-
2101
-    /**
2102
-     * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2103
-     * unless otherwise specified in the $query_params
2104
-     *
2105
-     * @param string $relation_name  model_name like 'Event', or 'Registration'
2106
-     * @param array  $query_params   like EEM_Base::get_all's
2107
-     * @param string $field_to_count name of field to count by. By default, uses primary key
2108
-     * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger
2109
-     *                               that by the setting $distinct to TRUE;
2110
-     * @return int
2111
-     */
2112
-    public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2113
-    {
2114
-        return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2115
-    }
2116
-
2117
-
2118
-
2119
-    /**
2120
-     * Instead of getting the related model objects, simply sums up the values of the specified field.
2121
-     * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2122
-     *
2123
-     * @param string $relation_name model_name like 'Event', or 'Registration'
2124
-     * @param array  $query_params  like EEM_Base::get_all's
2125
-     * @param string $field_to_sum  name of field to count by.
2126
-     *                              By default, uses primary key (which doesn't make much sense, so you should probably
2127
-     *                              change it)
2128
-     * @return int
2129
-     */
2130
-    public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2131
-    {
2132
-        return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2133
-    }
2134
-
2135
-
2136
-
2137
-    /**
2138
-     * Gets the first (ie, one) related model object of the specified type.
2139
-     *
2140
-     * @param string $relationName key in the model's _model_relations array
2141
-     * @param array  $query_params like EEM_Base::get_all
2142
-     * @return EE_Base_Class (not an array, a single object)
2143
-     * @throws \EE_Error
2144
-     */
2145
-    public function get_first_related($relationName, $query_params = array())
2146
-    {
2147
-        if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2148
-            //if they've provided some query parameters, don't bother trying to cache the result
2149
-            //also make sure we're not caching the result of get_first_related
2150
-            //on a relation which should have an array of objects (because the cache might have an array of objects)
2151
-            if ($query_params
2152
-                || ! $this->get_model()->related_settings_for($relationName)
2153
-                     instanceof
2154
-                     EE_Belongs_To_Relation
2155
-            ) {
2156
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2157
-            } else {
2158
-                //first, check if we've already cached the result of this query
2159
-                $cached_result = $this->get_one_from_cache($relationName);
2160
-                if ( ! $cached_result) {
2161
-                    $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2162
-                    $this->cache($relationName, $related_model_object);
2163
-                } else {
2164
-                    $related_model_object = $cached_result;
2165
-                }
2166
-            }
2167
-        } else {
2168
-            $related_model_object = null;
2169
-            //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2170
-            if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2171
-                $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2172
-            }
2173
-            //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2174
-            if ( ! $related_model_object) {
2175
-                $related_model_object = $this->get_one_from_cache($relationName);
2176
-            }
2177
-        }
2178
-        return $related_model_object;
2179
-    }
2180
-
2181
-
2182
-
2183
-    /**
2184
-     * Does a delete on all related objects of type $relationName and removes
2185
-     * the current model object's relation to them. If they can't be deleted (because
2186
-     * of blocking related model objects) does nothing. If the related model objects are
2187
-     * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2188
-     * If this model object doesn't exist yet in the DB, just removes its related things
2189
-     *
2190
-     * @param string $relationName
2191
-     * @param array  $query_params like EEM_Base::get_all's
2192
-     * @return int how many deleted
2193
-     * @throws \EE_Error
2194
-     */
2195
-    public function delete_related($relationName, $query_params = array())
2196
-    {
2197
-        if ($this->ID()) {
2198
-            $count = $this->get_model()->delete_related($this, $relationName, $query_params);
2199
-        } else {
2200
-            $count = count($this->get_all_from_cache($relationName));
2201
-            $this->clear_cache($relationName, null, true);
2202
-        }
2203
-        return $count;
2204
-    }
2205
-
2206
-
2207
-
2208
-    /**
2209
-     * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2210
-     * the current model object's relation to them. If they can't be deleted (because
2211
-     * of blocking related model objects) just does a soft delete on it instead, if possible.
2212
-     * If the related thing isn't a soft-deletable model object, this function is identical
2213
-     * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2214
-     *
2215
-     * @param string $relationName
2216
-     * @param array  $query_params like EEM_Base::get_all's
2217
-     * @return int how many deleted (including those soft deleted)
2218
-     * @throws \EE_Error
2219
-     */
2220
-    public function delete_related_permanently($relationName, $query_params = array())
2221
-    {
2222
-        if ($this->ID()) {
2223
-            $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2224
-        } else {
2225
-            $count = count($this->get_all_from_cache($relationName));
2226
-        }
2227
-        $this->clear_cache($relationName, null, true);
2228
-        return $count;
2229
-    }
2230
-
2231
-
2232
-
2233
-    /**
2234
-     * is_set
2235
-     * Just a simple utility function children can use for checking if property exists
2236
-     *
2237
-     * @access  public
2238
-     * @param  string $field_name property to check
2239
-     * @return bool                              TRUE if existing,FALSE if not.
2240
-     */
2241
-    public function is_set($field_name)
2242
-    {
2243
-        return isset($this->_fields[$field_name]);
2244
-    }
2245
-
2246
-
2247
-
2248
-    /**
2249
-     * Just a simple utility function children can use for checking if property (or properties) exists and throwing an
2250
-     * EE_Error exception if they don't
2251
-     *
2252
-     * @param  mixed (string|array) $properties properties to check
2253
-     * @throws EE_Error
2254
-     * @return bool                              TRUE if existing, throw EE_Error if not.
2255
-     */
2256
-    protected function _property_exists($properties)
2257
-    {
2258
-        foreach ((array)$properties as $property_name) {
2259
-            //first make sure this property exists
2260
-            if ( ! $this->_fields[$property_name]) {
2261
-                throw new EE_Error(
2262
-                    sprintf(
2263
-                        __(
2264
-                            'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2265
-                            'event_espresso'
2266
-                        ),
2267
-                        $property_name
2268
-                    )
2269
-                );
2270
-            }
2271
-        }
2272
-        return true;
2273
-    }
2274
-
2275
-
2276
-
2277
-    /**
2278
-     * This simply returns an array of model fields for this object
2279
-     *
2280
-     * @return array
2281
-     * @throws \EE_Error
2282
-     */
2283
-    public function model_field_array()
2284
-    {
2285
-        $fields = $this->get_model()->field_settings(false);
2286
-        $properties = array();
2287
-        //remove prepended underscore
2288
-        foreach ($fields as $field_name => $settings) {
2289
-            $properties[$field_name] = $this->get($field_name);
2290
-        }
2291
-        return $properties;
2292
-    }
2293
-
2294
-
2295
-
2296
-    /**
2297
-     * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2298
-     * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called
2299
-     * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of
2300
-     * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that
2301
-     * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg,
2302
-     * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function
2303
-     * was called, and an array of the original arguments passed to the function. Whatever their callback function
2304
-     * returns will be returned by this function. Example: in functions.php (or in a plugin):
2305
-     * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function
2306
-     * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2307
-     * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2308
-     *        return $previousReturnValue.$returnString;
2309
-     * }
2310
-     * require('EE_Answer.class.php');
2311
-     * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2312
-     * echo $answer->my_callback('monkeys',100);
2313
-     * //will output "you called my_callback! and passed args:monkeys,100"
2314
-     *
2315
-     * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2316
-     * @param array  $args       array of original arguments passed to the function
2317
-     * @throws EE_Error
2318
-     * @return mixed whatever the plugin which calls add_filter decides
2319
-     */
2320
-    public function __call($methodName, $args)
2321
-    {
2322
-        $className = get_class($this);
2323
-        $tagName = "FHEE__{$className}__{$methodName}";
2324
-        if ( ! has_filter($tagName)) {
2325
-            throw new EE_Error(
2326
-                sprintf(
2327
-                    __(
2328
-                        "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2329
-                        "event_espresso"
2330
-                    ),
2331
-                    $methodName,
2332
-                    $className,
2333
-                    $tagName
2334
-                )
2335
-            );
2336
-        }
2337
-        return apply_filters($tagName, null, $this, $args);
2338
-    }
2339
-
2340
-
2341
-
2342
-    /**
2343
-     * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2344
-     * A $previous_value can be specified in case there are many meta rows with the same key
2345
-     *
2346
-     * @param string $meta_key
2347
-     * @param string $meta_value
2348
-     * @param string $previous_value
2349
-     * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2350
-     * @throws \EE_Error
2351
-     * NOTE: if the values haven't changed, returns 0
2352
-     */
2353
-    public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2354
-    {
2355
-        $query_params = array(
2356
-            array(
2357
-                'EXM_key'  => $meta_key,
2358
-                'OBJ_ID'   => $this->ID(),
2359
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2360
-            ),
2361
-        );
2362
-        if ($previous_value !== null) {
2363
-            $query_params[0]['EXM_value'] = $meta_value;
2364
-        }
2365
-        $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2366
-        if ( ! $existing_rows_like_that) {
2367
-            return $this->add_extra_meta($meta_key, $meta_value);
2368
-        } else {
2369
-            foreach ($existing_rows_like_that as $existing_row) {
2370
-                $existing_row->save(array('EXM_value' => $meta_value));
2371
-            }
2372
-            return count($existing_rows_like_that);
2373
-        }
2374
-    }
2375
-
2376
-
2377
-
2378
-    /**
2379
-     * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2380
-     * no other extra meta for this model object have the same key. Returns TRUE if the
2381
-     * extra meta row was entered, false if not
2382
-     *
2383
-     * @param string  $meta_key
2384
-     * @param string  $meta_value
2385
-     * @param boolean $unique
2386
-     * @return boolean
2387
-     * @throws \EE_Error
2388
-     */
2389
-    public function add_extra_meta($meta_key, $meta_value, $unique = false)
2390
-    {
2391
-        if ($unique) {
2392
-            $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2393
-                array(
2394
-                    array(
2395
-                        'EXM_key'  => $meta_key,
2396
-                        'OBJ_ID'   => $this->ID(),
2397
-                        'EXM_type' => $this->get_model()->get_this_model_name(),
2398
-                    ),
2399
-                )
2400
-            );
2401
-            if ($existing_extra_meta) {
2402
-                return false;
2403
-            }
2404
-        }
2405
-        $new_extra_meta = EE_Extra_Meta::new_instance(
2406
-            array(
2407
-                'EXM_key'   => $meta_key,
2408
-                'EXM_value' => $meta_value,
2409
-                'OBJ_ID'    => $this->ID(),
2410
-                'EXM_type'  => $this->get_model()->get_this_model_name(),
2411
-            )
2412
-        );
2413
-        $new_extra_meta->save();
2414
-        return true;
2415
-    }
2416
-
2417
-
2418
-
2419
-    /**
2420
-     * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2421
-     * is specified, only deletes extra meta records with that value.
2422
-     *
2423
-     * @param string $meta_key
2424
-     * @param string $meta_value
2425
-     * @return int number of extra meta rows deleted
2426
-     * @throws \EE_Error
2427
-     */
2428
-    public function delete_extra_meta($meta_key, $meta_value = null)
2429
-    {
2430
-        $query_params = array(
2431
-            array(
2432
-                'EXM_key'  => $meta_key,
2433
-                'OBJ_ID'   => $this->ID(),
2434
-                'EXM_type' => $this->get_model()->get_this_model_name(),
2435
-            ),
2436
-        );
2437
-        if ($meta_value !== null) {
2438
-            $query_params[0]['EXM_value'] = $meta_value;
2439
-        }
2440
-        return EEM_Extra_Meta::instance()->delete($query_params);
2441
-    }
2442
-
2443
-
2444
-
2445
-    /**
2446
-     * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2447
-     * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2448
-     * You can specify $default is case you haven't found the extra meta
2449
-     *
2450
-     * @param string  $meta_key
2451
-     * @param boolean $single
2452
-     * @param mixed   $default if we don't find anything, what should we return?
2453
-     * @return mixed single value if $single; array if ! $single
2454
-     * @throws \EE_Error
2455
-     */
2456
-    public function get_extra_meta($meta_key, $single = false, $default = null)
2457
-    {
2458
-        if ($single) {
2459
-            $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2460
-            if ($result instanceof EE_Extra_Meta) {
2461
-                return $result->value();
2462
-            } else {
2463
-                return $default;
2464
-            }
2465
-        } else {
2466
-            $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2467
-            if ($results) {
2468
-                $values = array();
2469
-                foreach ($results as $result) {
2470
-                    if ($result instanceof EE_Extra_Meta) {
2471
-                        $values[$result->ID()] = $result->value();
2472
-                    }
2473
-                }
2474
-                return $values;
2475
-            } else {
2476
-                return $default;
2477
-            }
2478
-        }
2479
-    }
2480
-
2481
-
2482
-
2483
-    /**
2484
-     * Returns a simple array of all the extra meta associated with this model object.
2485
-     * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2486
-     * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2487
-     * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2488
-     * If $one_of_each_key is false, it will return an array with the top-level keys being
2489
-     * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2490
-     * finally the extra meta's value as each sub-value. (eg
2491
-     * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2492
-     *
2493
-     * @param boolean $one_of_each_key
2494
-     * @return array
2495
-     * @throws \EE_Error
2496
-     */
2497
-    public function all_extra_meta_array($one_of_each_key = true)
2498
-    {
2499
-        $return_array = array();
2500
-        if ($one_of_each_key) {
2501
-            $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2502
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2503
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2504
-                    $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2505
-                }
2506
-            }
2507
-        } else {
2508
-            $extra_meta_objs = $this->get_many_related('Extra_Meta');
2509
-            foreach ($extra_meta_objs as $extra_meta_obj) {
2510
-                if ($extra_meta_obj instanceof EE_Extra_Meta) {
2511
-                    if ( ! isset($return_array[$extra_meta_obj->key()])) {
2512
-                        $return_array[$extra_meta_obj->key()] = array();
2513
-                    }
2514
-                    $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2515
-                }
2516
-            }
2517
-        }
2518
-        return $return_array;
2519
-    }
2520
-
2521
-
2522
-
2523
-    /**
2524
-     * Gets a pretty nice displayable nice for this model object. Often overridden
2525
-     *
2526
-     * @return string
2527
-     * @throws \EE_Error
2528
-     */
2529
-    public function name()
2530
-    {
2531
-        //find a field that's not a text field
2532
-        $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2533
-        if ($field_we_can_use) {
2534
-            return $this->get($field_we_can_use->get_name());
2535
-        } else {
2536
-            $first_few_properties = $this->model_field_array();
2537
-            $first_few_properties = array_slice($first_few_properties, 0, 3);
2538
-            $name_parts = array();
2539
-            foreach ($first_few_properties as $name => $value) {
2540
-                $name_parts[] = "$name:$value";
2541
-            }
2542
-            return implode(",", $name_parts);
2543
-        }
2544
-    }
2545
-
2546
-
2547
-
2548
-    /**
2549
-     * in_entity_map
2550
-     * Checks if this model object has been proven to already be in the entity map
2551
-     *
2552
-     * @return boolean
2553
-     * @throws \EE_Error
2554
-     */
2555
-    public function in_entity_map()
2556
-    {
2557
-        if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2558
-            //well, if we looked, did we find it in the entity map?
2559
-            return true;
2560
-        } else {
2561
-            return false;
2562
-        }
2563
-    }
2564
-
2565
-
2566
-
2567
-    /**
2568
-     * refresh_from_db
2569
-     * Makes sure the fields and values on this model object are in-sync with what's in the database.
2570
-     *
2571
-     * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2572
-     * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2573
-     */
2574
-    public function refresh_from_db()
2575
-    {
2576
-        if ($this->ID() && $this->in_entity_map()) {
2577
-            $this->get_model()->refresh_entity_map_from_db($this->ID());
2578
-        } else {
2579
-            //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2580
-            //if it has an ID but it's not in the map, and you're asking me to refresh it
2581
-            //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2582
-            //absolutely nothing in it for this ID
2583
-            if (WP_DEBUG) {
2584
-                throw new EE_Error(
2585
-                    sprintf(
2586
-                        __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2587
-                            'event_espresso'),
2588
-                        $this->ID(),
2589
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2590
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2591
-                    )
2592
-                );
2593
-            }
2594
-        }
2595
-    }
2596
-
2597
-
2598
-
2599
-    /**
2600
-     * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2601
-     * (probably a bad assumption they have made, oh well)
2602
-     *
2603
-     * @return string
2604
-     */
2605
-    public function __toString()
2606
-    {
2607
-        try {
2608
-            return sprintf('%s (%s)', $this->name(), $this->ID());
2609
-        } catch (Exception $e) {
2610
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2611
-            return '';
2612
-        }
2613
-    }
2614
-
2615
-
2616
-
2617
-    /**
2618
-     * Clear related model objects if they're already in the DB, because otherwise when we
2619
-     * UN-serialize this model object we'll need to be careful to add them to the entity map.
2620
-     * This means if we have made changes to those related model objects, and want to unserialize
2621
-     * the this model object on a subsequent request, changes to those related model objects will be lost.
2622
-     * Instead, those related model objects should be directly serialized and stored.
2623
-     * Eg, the following won't work:
2624
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2625
-     * $att = $reg->attendee();
2626
-     * $att->set( 'ATT_fname', 'Dirk' );
2627
-     * update_option( 'my_option', serialize( $reg ) );
2628
-     * //END REQUEST
2629
-     * //START NEXT REQUEST
2630
-     * $reg = get_option( 'my_option' );
2631
-     * $reg->attendee()->save();
2632
-     * And would need to be replace with:
2633
-     * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2634
-     * $att = $reg->attendee();
2635
-     * $att->set( 'ATT_fname', 'Dirk' );
2636
-     * update_option( 'my_option', serialize( $reg ) );
2637
-     * //END REQUEST
2638
-     * //START NEXT REQUEST
2639
-     * $att = get_option( 'my_option' );
2640
-     * $att->save();
2641
-     *
2642
-     * @return array
2643
-     * @throws \EE_Error
2644
-     */
2645
-    public function __sleep()
2646
-    {
2647
-        foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2648
-            if ($relation_obj instanceof EE_Belongs_To_Relation) {
2649
-                $classname = 'EE_' . $this->get_model()->get_this_model_name();
2650
-                if (
2651
-                    $this->get_one_from_cache($relation_name) instanceof $classname
2652
-                    && $this->get_one_from_cache($relation_name)->ID()
2653
-                ) {
2654
-                    $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2655
-                }
2656
-            }
2657
-        }
2658
-        $this->_props_n_values_provided_in_constructor = array();
2659
-        return array_keys(get_object_vars($this));
2660
-    }
2661
-
2662
-
2663
-
2664
-    /**
2665
-     * restore _props_n_values_provided_in_constructor
2666
-     * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2667
-     * and therefore should NOT be used to determine if state change has occurred since initial construction.
2668
-     * At best, you would only be able to detect if state change has occurred during THIS request.
2669
-     */
2670
-    public function __wakeup()
2671
-    {
2672
-        $this->_props_n_values_provided_in_constructor = $this->_fields;
2673
-    }
28
+	/**
29
+	 * This is an array of the original properties and values provided during construction
30
+	 * of this model object. (keys are model field names, values are their values).
31
+	 * This list is important to remember so that when we are merging data from the db, we know
32
+	 * which values to override and which to not override.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_props_n_values_provided_in_constructor;
37
+
38
+	/**
39
+	 * Timezone
40
+	 * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in.
41
+	 * This can also be used before a get to set what timezone you want strings coming out of the object to be in.  NOT
42
+	 * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have
43
+	 * access to it.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_timezone;
48
+
49
+
50
+
51
+	/**
52
+	 * date format
53
+	 * pattern or format for displaying dates
54
+	 *
55
+	 * @var string $_dt_frmt
56
+	 */
57
+	protected $_dt_frmt;
58
+
59
+
60
+
61
+	/**
62
+	 * time format
63
+	 * pattern or format for displaying time
64
+	 *
65
+	 * @var string $_tm_frmt
66
+	 */
67
+	protected $_tm_frmt;
68
+
69
+
70
+
71
+	/**
72
+	 * This property is for holding a cached array of object properties indexed by property name as the key.
73
+	 * The purpose of this is for setting a cache on properties that may have calculated values after a
74
+	 * prepare_for_get.  That way the cache can be checked first and the calculated property returned instead of having
75
+	 * to recalculate. Used by _set_cached_property() and _get_cached_property() methods.
76
+	 *
77
+	 * @var array
78
+	 */
79
+	protected $_cached_properties = array();
80
+
81
+	/**
82
+	 * An array containing keys of the related model, and values are either an array of related mode objects or a
83
+	 * single
84
+	 * related model object. see the model's _model_relations. The keys should match those specified. And if the
85
+	 * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object,
86
+	 * all others have an array)
87
+	 *
88
+	 * @var array
89
+	 */
90
+	protected $_model_relations = array();
91
+
92
+	/**
93
+	 * Array where keys are field names (see the model's _fields property) and values are their values. To see what
94
+	 * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods)
95
+	 *
96
+	 * @var array
97
+	 */
98
+	protected $_fields = array();
99
+
100
+	/**
101
+	 * @var boolean indicating whether or not this model object is intended to ever be saved
102
+	 * For example, we might create model objects intended to only be used for the duration
103
+	 * of this request and to be thrown away, and if they were accidentally saved
104
+	 * it would be a bug.
105
+	 */
106
+	protected $_allow_persist = true;
107
+
108
+
109
+
110
+	/**
111
+	 * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children
112
+	 * play nice
113
+	 *
114
+	 * @param array   $fieldValues                             where each key is a field (ie, array key in the 2nd
115
+	 *                                                         layer of the model's _fields array, (eg, EVT_ID,
116
+	 *                                                         TXN_amount, QST_name, etc) and values are their values
117
+	 * @param boolean $bydb                                    a flag for setting if the class is instantiated by the
118
+	 *                                                         corresponding db model or not.
119
+	 * @param string  $timezone                                indicate what timezone you want any datetime fields to
120
+	 *                                                         be in when instantiating a EE_Base_Class object.
121
+	 * @param array   $date_formats                            An array of date formats to set on construct where first
122
+	 *                                                         value is the date_format and second value is the time
123
+	 *                                                         format.
124
+	 * @throws EE_Error
125
+	 */
126
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array())
127
+	{
128
+		$className = get_class($this);
129
+		do_action("AHEE__{$className}__construct", $this, $fieldValues);
130
+		$model = $this->get_model();
131
+		$model_fields = $model->field_settings(false);
132
+		// ensure $fieldValues is an array
133
+		$fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues);
134
+		// EEH_Debug_Tools::printr( $fieldValues, '$fieldValues  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
135
+		// verify client code has not passed any invalid field names
136
+		foreach ($fieldValues as $field_name => $field_value) {
137
+			if ( ! isset($model_fields[$field_name])) {
138
+				throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s",
139
+					"event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields))));
140
+			}
141
+		}
142
+		// EEH_Debug_Tools::printr( $model_fields, '$model_fields  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
143
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
144
+		if ( ! empty($date_formats) && is_array($date_formats)) {
145
+			list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
146
+		} else {
147
+			//set default formats for date and time
148
+			$this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
149
+			$this->_tm_frmt = (string)get_option('time_format', 'g:i a');
150
+		}
151
+		//if db model is instantiating
152
+		if ($bydb) {
153
+			//client code has indicated these field values are from the database
154
+			foreach ($model_fields as $fieldName => $field) {
155
+				$this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null);
156
+			}
157
+		} else {
158
+			//we're constructing a brand
159
+			//new instance of the model object. Generally, this means we'll need to do more field validation
160
+			foreach ($model_fields as $fieldName => $field) {
161
+				$this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true);
162
+			}
163
+		}
164
+		//remember what values were passed to this constructor
165
+		$this->_props_n_values_provided_in_constructor = $fieldValues;
166
+		//remember in entity mapper
167
+		if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) {
168
+			$model->add_to_entity_map($this);
169
+		}
170
+		//setup all the relations
171
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
172
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
173
+				$this->_model_relations[$relation_name] = null;
174
+			} else {
175
+				$this->_model_relations[$relation_name] = array();
176
+			}
177
+		}
178
+		/**
179
+		 * Action done at the end of each model object construction
180
+		 *
181
+		 * @param EE_Base_Class $this the model object just created
182
+		 */
183
+		do_action('AHEE__EE_Base_Class__construct__finished', $this);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets whether or not this model object is allowed to persist/be saved to the database.
190
+	 *
191
+	 * @return boolean
192
+	 */
193
+	public function allow_persist()
194
+	{
195
+		return $this->_allow_persist;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Sets whether or not this model object should be allowed to be saved to the DB.
202
+	 * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless
203
+	 * you got new information that somehow made you change your mind.
204
+	 *
205
+	 * @param boolean $allow_persist
206
+	 * @return boolean
207
+	 */
208
+	public function set_allow_persist($allow_persist)
209
+	{
210
+		return $this->_allow_persist = $allow_persist;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * Gets the field's original value when this object was constructed during this request.
217
+	 * This can be helpful when determining if a model object has changed or not
218
+	 *
219
+	 * @param string $field_name
220
+	 * @return mixed|null
221
+	 * @throws \EE_Error
222
+	 */
223
+	public function get_original($field_name)
224
+	{
225
+		if (isset($this->_props_n_values_provided_in_constructor[$field_name])
226
+			&& $field_settings = $this->get_model()->field_settings_for($field_name)
227
+		) {
228
+			return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]);
229
+		} else {
230
+			return null;
231
+		}
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * @param EE_Base_Class $obj
238
+	 * @return string
239
+	 */
240
+	public function get_class($obj)
241
+	{
242
+		return get_class($obj);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Overrides parent because parent expects old models.
249
+	 * This also doesn't do any validation, and won't work for serialized arrays
250
+	 *
251
+	 * @param    string $field_name
252
+	 * @param    mixed  $field_value
253
+	 * @param bool      $use_default
254
+	 * @throws \EE_Error
255
+	 */
256
+	public function set($field_name, $field_value, $use_default = false)
257
+	{
258
+		$field_obj = $this->get_model()->field_settings_for($field_name);
259
+		if ($field_obj instanceof EE_Model_Field_Base) {
260
+			//			if ( method_exists( $field_obj, 'set_timezone' )) {
261
+			if ($field_obj instanceof EE_Datetime_Field) {
262
+				$field_obj->set_timezone($this->_timezone);
263
+				$field_obj->set_date_format($this->_dt_frmt);
264
+				$field_obj->set_time_format($this->_tm_frmt);
265
+			}
266
+			$holder_of_value = $field_obj->prepare_for_set($field_value);
267
+			//should the value be null?
268
+			if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) {
269
+				$this->_fields[$field_name] = $field_obj->get_default_value();
270
+				/**
271
+				 * To save having to refactor all the models, if a default value is used for a
272
+				 * EE_Datetime_Field, and that value is not null nor is it a DateTime
273
+				 * object.  Then let's do a set again to ensure that it becomes a DateTime
274
+				 * object.
275
+				 *
276
+				 * @since 4.6.10+
277
+				 */
278
+				if (
279
+					$field_obj instanceof EE_Datetime_Field
280
+					&& $this->_fields[$field_name] !== null
281
+					&& ! $this->_fields[$field_name] instanceof DateTime
282
+				) {
283
+					empty($this->_fields[$field_name])
284
+						? $this->set($field_name, time())
285
+						: $this->set($field_name, $this->_fields[$field_name]);
286
+				}
287
+			} else {
288
+				$this->_fields[$field_name] = $holder_of_value;
289
+			}
290
+			//if we're not in the constructor...
291
+			//now check if what we set was a primary key
292
+			if (
293
+				//note: props_n_values_provided_in_constructor is only set at the END of the constructor
294
+				$this->_props_n_values_provided_in_constructor
295
+				&& $field_value
296
+				&& $field_name === self::_get_primary_key_name(get_class($this))
297
+			) {
298
+				//if so, we want all this object's fields to be filled either with
299
+				//what we've explicitly set on this model
300
+				//or what we have in the db
301
+				// echo "setting primary key!";
302
+				$fields_on_model = self::_get_model(get_class($this))->field_settings();
303
+				$obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value);
304
+				foreach ($fields_on_model as $field_obj) {
305
+					if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor)
306
+						 && $field_obj->get_name() !== $field_name
307
+					) {
308
+						$this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name()));
309
+					}
310
+				}
311
+				//oh this model object has an ID? well make sure its in the entity mapper
312
+				$this->get_model()->add_to_entity_map($this);
313
+			}
314
+			//let's unset any cache for this field_name from the $_cached_properties property.
315
+			$this->_clear_cached_property($field_name);
316
+		} else {
317
+			throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s",
318
+				"event_espresso"), $field_name));
319
+		}
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * This sets the field value on the db column if it exists for the given $column_name or
326
+	 * saves it to EE_Extra_Meta if the given $column_name does not match a db column.
327
+	 *
328
+	 * @see EE_message::get_column_value for related documentation on the necessity of this method.
329
+	 * @param string $field_name  Must be the exact column name.
330
+	 * @param mixed  $field_value The value to set.
331
+	 * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs.
332
+	 * @throws \EE_Error
333
+	 */
334
+	public function set_field_or_extra_meta($field_name, $field_value)
335
+	{
336
+		if ($this->get_model()->has_field($field_name)) {
337
+			$this->set($field_name, $field_value);
338
+			return true;
339
+		} else {
340
+			//ensure this object is saved first so that extra meta can be properly related.
341
+			$this->save();
342
+			return $this->update_extra_meta($field_name, $field_value);
343
+		}
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * This retrieves the value of the db column set on this class or if that's not present
350
+	 * it will attempt to retrieve from extra_meta if found.
351
+	 * Example Usage:
352
+	 * Via EE_Message child class:
353
+	 * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to",
354
+	 * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may
355
+	 * also have additional main fields specific to the messenger.  The system accommodates those extra
356
+	 * fields through the EE_Extra_Meta table.  This method allows for EE_messengers to retrieve the
357
+	 * value for those extra fields dynamically via the EE_message object.
358
+	 *
359
+	 * @param  string $field_name expecting the fully qualified field name.
360
+	 * @return mixed|null  value for the field if found.  null if not found.
361
+	 * @throws \EE_Error
362
+	 */
363
+	public function get_field_or_extra_meta($field_name)
364
+	{
365
+		if ($this->get_model()->has_field($field_name)) {
366
+			$column_value = $this->get($field_name);
367
+		} else {
368
+			//This isn't a column in the main table, let's see if it is in the extra meta.
369
+			$column_value = $this->get_extra_meta($field_name, true, null);
370
+		}
371
+		return $column_value;
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
378
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
379
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is
380
+	 * available to all child classes that may be using the EE_Datetime_Field for a field data type.
381
+	 *
382
+	 * @access public
383
+	 * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php
384
+	 * @return void
385
+	 * @throws \EE_Error
386
+	 */
387
+	public function set_timezone($timezone = '')
388
+	{
389
+		$this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone);
390
+		//make sure we clear all cached properties because they won't be relevant now
391
+		$this->_clear_cached_properties();
392
+		//make sure we update field settings and the date for all EE_Datetime_Fields
393
+		$model_fields = $this->get_model()->field_settings(false);
394
+		foreach ($model_fields as $field_name => $field_obj) {
395
+			if ($field_obj instanceof EE_Datetime_Field) {
396
+				$field_obj->set_timezone($this->_timezone);
397
+				if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) {
398
+					$this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone));
399
+				}
400
+			}
401
+		}
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * This just returns whatever is set for the current timezone.
408
+	 *
409
+	 * @access public
410
+	 * @return string timezone string
411
+	 */
412
+	public function get_timezone()
413
+	{
414
+		return $this->_timezone;
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * This sets the internal date format to what is sent in to be used as the new default for the class
421
+	 * internally instead of wp set date format options
422
+	 *
423
+	 * @since 4.6
424
+	 * @param string $format should be a format recognizable by PHP date() functions.
425
+	 */
426
+	public function set_date_format($format)
427
+	{
428
+		$this->_dt_frmt = $format;
429
+		//clear cached_properties because they won't be relevant now.
430
+		$this->_clear_cached_properties();
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * This sets the internal time format string to what is sent in to be used as the new default for the
437
+	 * class internally instead of wp set time format options.
438
+	 *
439
+	 * @since 4.6
440
+	 * @param string $format should be a format recognizable by PHP date() functions.
441
+	 */
442
+	public function set_time_format($format)
443
+	{
444
+		$this->_tm_frmt = $format;
445
+		//clear cached_properties because they won't be relevant now.
446
+		$this->_clear_cached_properties();
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 * This returns the current internal set format for the date and time formats.
453
+	 *
454
+	 * @param bool $full           if true (default), then return the full format.  Otherwise will return an array
455
+	 *                             where the first value is the date format and the second value is the time format.
456
+	 * @return mixed string|array
457
+	 */
458
+	public function get_format($full = true)
459
+	{
460
+		return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
461
+	}
462
+
463
+
464
+
465
+	/**
466
+	 * cache
467
+	 * stores the passed model object on the current model object.
468
+	 * In certain circumstances, we can use this cached model object instead of querying for another one entirely.
469
+	 *
470
+	 * @param string        $relationName    one of the keys in the _model_relations array on the model. Eg
471
+	 *                                       'Registration' associated with this model object
472
+	 * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction,
473
+	 *                                       that could be a payment or a registration)
474
+	 * @param null          $cache_id        a string or number that will be used as the key for any Belongs_To_Many
475
+	 *                                       items which will be stored in an array on this object
476
+	 * @throws EE_Error
477
+	 * @return mixed    index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one
478
+	 *                  related thing, no array)
479
+	 */
480
+	public function cache($relationName = '', $object_to_cache = null, $cache_id = null)
481
+	{
482
+		// its entirely possible that there IS no related object yet in which case there is nothing to cache.
483
+		if ( ! $object_to_cache instanceof EE_Base_Class) {
484
+			return false;
485
+		}
486
+		// also get "how" the object is related, or throw an error
487
+		if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) {
488
+			throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'),
489
+				$relationName, get_class($this)));
490
+		}
491
+		// how many things are related ?
492
+		if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
493
+			// if it's a "belongs to" relationship, then there's only one related model object  eg, if this is a registration, there's only 1 attendee for it
494
+			// so for these model objects just set it to be cached
495
+			$this->_model_relations[$relationName] = $object_to_cache;
496
+			$return = true;
497
+		} else {
498
+			// otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type.
499
+			// eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array
500
+			if ( ! is_array($this->_model_relations[$relationName])) {
501
+				// if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array
502
+				$this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class
503
+					? array($this->_model_relations[$relationName]) : array();
504
+			}
505
+			// first check for a cache_id which is normally empty
506
+			if ( ! empty($cache_id)) {
507
+				// if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on
508
+				$this->_model_relations[$relationName][$cache_id] = $object_to_cache;
509
+				$return = $cache_id;
510
+			} elseif ($object_to_cache->ID()) {
511
+				// OR the cached object originally came from the db, so let's just use it's PK for an ID
512
+				$this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache;
513
+				$return = $object_to_cache->ID();
514
+			} else {
515
+				// OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID
516
+				$this->_model_relations[$relationName][] = $object_to_cache;
517
+				// move the internal pointer to the end of the array
518
+				end($this->_model_relations[$relationName]);
519
+				// and grab the key so that we can return it
520
+				$return = key($this->_model_relations[$relationName]);
521
+			}
522
+		}
523
+		return $return;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * For adding an item to the cached_properties property.
530
+	 *
531
+	 * @access protected
532
+	 * @param string      $fieldname the property item the corresponding value is for.
533
+	 * @param mixed       $value     The value we are caching.
534
+	 * @param string|null $cache_type
535
+	 * @return void
536
+	 * @throws \EE_Error
537
+	 */
538
+	protected function _set_cached_property($fieldname, $value, $cache_type = null)
539
+	{
540
+		//first make sure this property exists
541
+		$this->get_model()->field_settings_for($fieldname);
542
+		$cache_type = empty($cache_type) ? 'standard' : $cache_type;
543
+		$this->_cached_properties[$fieldname][$cache_type] = $value;
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist.
550
+	 * This also SETS the cache if we return the actual property!
551
+	 *
552
+	 * @param string $fieldname        the name of the property we're trying to retrieve
553
+	 * @param bool   $pretty
554
+	 * @param string $extra_cache_ref  This allows the user to specify an extra cache ref for the given property
555
+	 *                                 (in cases where the same property may be used for different outputs
556
+	 *                                 - i.e. datetime, money etc.)
557
+	 *                                 It can also accept certain pre-defined "schema" strings
558
+	 *                                 to define how to output the property.
559
+	 *                                 see the field's prepare_for_pretty_echoing for what strings can be used
560
+	 * @return mixed                   whatever the value for the property is we're retrieving
561
+	 * @throws \EE_Error
562
+	 */
563
+	protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null)
564
+	{
565
+		//verify the field exists
566
+		$this->get_model()->field_settings_for($fieldname);
567
+		$cache_type = $pretty ? 'pretty' : 'standard';
568
+		$cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
569
+		if (isset($this->_cached_properties[$fieldname][$cache_type])) {
570
+			return $this->_cached_properties[$fieldname][$cache_type];
571
+		}
572
+		$field_obj = $this->get_model()->field_settings_for($fieldname);
573
+		if ($field_obj instanceof EE_Model_Field_Base) {
574
+			// If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct
575
+			if ($field_obj instanceof EE_Datetime_Field) {
576
+				$this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref);
577
+			}
578
+			if ( ! isset($this->_fields[$fieldname])) {
579
+				$this->_fields[$fieldname] = null;
580
+			}
581
+			$value = $pretty
582
+				? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref)
583
+				: $field_obj->prepare_for_get($this->_fields[$fieldname]);
584
+			$this->_set_cached_property($fieldname, $value, $cache_type);
585
+			return $value;
586
+		}
587
+		return null;
588
+	}
589
+
590
+
591
+
592
+	/**
593
+	 * set timezone, formats, and output for EE_Datetime_Field objects
594
+	 *
595
+	 * @param \EE_Datetime_Field $datetime_field
596
+	 * @param bool               $pretty
597
+	 * @param null $date_or_time
598
+	 * @return void
599
+	 * @throws \EE_Error
600
+	 */
601
+	protected function _prepare_datetime_field(
602
+		EE_Datetime_Field $datetime_field,
603
+		$pretty = false,
604
+		$date_or_time = null
605
+	) {
606
+		$datetime_field->set_timezone($this->_timezone);
607
+		$datetime_field->set_date_format($this->_dt_frmt, $pretty);
608
+		$datetime_field->set_time_format($this->_tm_frmt, $pretty);
609
+		//set the output returned
610
+		switch ($date_or_time) {
611
+			case 'D' :
612
+				$datetime_field->set_date_time_output('date');
613
+				break;
614
+			case 'T' :
615
+				$datetime_field->set_date_time_output('time');
616
+				break;
617
+			default :
618
+				$datetime_field->set_date_time_output();
619
+		}
620
+	}
621
+
622
+
623
+
624
+	/**
625
+	 * This just takes care of clearing out the cached_properties
626
+	 *
627
+	 * @return void
628
+	 */
629
+	protected function _clear_cached_properties()
630
+	{
631
+		$this->_cached_properties = array();
632
+	}
633
+
634
+
635
+
636
+	/**
637
+	 * This just clears out ONE property if it exists in the cache
638
+	 *
639
+	 * @param  string $property_name the property to remove if it exists (from the _cached_properties array)
640
+	 * @return void
641
+	 */
642
+	protected function _clear_cached_property($property_name)
643
+	{
644
+		if (isset($this->_cached_properties[$property_name])) {
645
+			unset($this->_cached_properties[$property_name]);
646
+		}
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * Ensures that this related thing is a model object.
653
+	 *
654
+	 * @param mixed  $object_or_id EE_base_Class/int/string either a related model object, or its ID
655
+	 * @param string $model_name   name of the related thing, eg 'Attendee',
656
+	 * @return EE_Base_Class
657
+	 * @throws \EE_Error
658
+	 */
659
+	protected function ensure_related_thing_is_model_obj($object_or_id, $model_name)
660
+	{
661
+		$other_model_instance = self::_get_model_instance_with_name(
662
+			self::_get_model_classname($model_name),
663
+			$this->_timezone
664
+		);
665
+		return $other_model_instance->ensure_is_obj($object_or_id);
666
+	}
667
+
668
+
669
+
670
+	/**
671
+	 * Forgets the cached model of the given relation Name. So the next time we request it,
672
+	 * we will fetch it again from the database. (Handy if you know it's changed somehow).
673
+	 * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM,
674
+	 * then only remove that one object from our cached array. Otherwise, clear the entire list
675
+	 *
676
+	 * @param string $relationName                         one of the keys in the _model_relations array on the model.
677
+	 *                                                     Eg 'Registration'
678
+	 * @param mixed  $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL
679
+	 *                                                     if you intend to use $clear_all = TRUE, or the relation only
680
+	 *                                                     has 1 object anyways (ie, it's a BelongsToRelation)
681
+	 * @param bool   $clear_all                            This flags clearing the entire cache relation property if
682
+	 *                                                     this is HasMany or HABTM.
683
+	 * @throws EE_Error
684
+	 * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a
685
+	 *                       relation from all
686
+	 */
687
+	public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false)
688
+	{
689
+		$relationship_to_model = $this->get_model()->related_settings_for($relationName);
690
+		$index_in_cache = '';
691
+		if ( ! $relationship_to_model) {
692
+			throw new EE_Error(
693
+				sprintf(
694
+					__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'),
695
+					$relationName,
696
+					get_class($this)
697
+				)
698
+			);
699
+		}
700
+		if ($clear_all) {
701
+			$obj_removed = true;
702
+			$this->_model_relations[$relationName] = null;
703
+		} elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) {
704
+			$obj_removed = $this->_model_relations[$relationName];
705
+			$this->_model_relations[$relationName] = null;
706
+		} else {
707
+			if ($object_to_remove_or_index_into_array instanceof EE_Base_Class
708
+				&& $object_to_remove_or_index_into_array->ID()
709
+			) {
710
+				$index_in_cache = $object_to_remove_or_index_into_array->ID();
711
+				if (is_array($this->_model_relations[$relationName])
712
+					&& ! isset($this->_model_relations[$relationName][$index_in_cache])
713
+				) {
714
+					$index_found_at = null;
715
+					//find this object in the array even though it has a different key
716
+					foreach ($this->_model_relations[$relationName] as $index => $obj) {
717
+						if (
718
+							$obj instanceof EE_Base_Class
719
+							&& (
720
+								$obj == $object_to_remove_or_index_into_array
721
+								|| $obj->ID() === $object_to_remove_or_index_into_array->ID()
722
+							)
723
+						) {
724
+							$index_found_at = $index;
725
+							break;
726
+						}
727
+					}
728
+					if ($index_found_at) {
729
+						$index_in_cache = $index_found_at;
730
+					} else {
731
+						//it wasn't found. huh. well obviously it doesn't need to be removed from teh cache
732
+						//if it wasn't in it to begin with. So we're done
733
+						return $object_to_remove_or_index_into_array;
734
+					}
735
+				}
736
+			} elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) {
737
+				//so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it!
738
+				foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) {
739
+					if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) {
740
+						$index_in_cache = $index;
741
+					}
742
+				}
743
+			} else {
744
+				$index_in_cache = $object_to_remove_or_index_into_array;
745
+			}
746
+			//supposedly we've found it. But it could just be that the client code
747
+			//provided a bad index/object
748
+			if (
749
+			isset(
750
+				$this->_model_relations[$relationName],
751
+				$this->_model_relations[$relationName][$index_in_cache]
752
+			)
753
+			) {
754
+				$obj_removed = $this->_model_relations[$relationName][$index_in_cache];
755
+				unset($this->_model_relations[$relationName][$index_in_cache]);
756
+			} else {
757
+				//that thing was never cached anyways.
758
+				$obj_removed = null;
759
+			}
760
+		}
761
+		return $obj_removed;
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * update_cache_after_object_save
768
+	 * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has
769
+	 * obtained after being saved to the db
770
+	 *
771
+	 * @param string         $relationName       - the type of object that is cached
772
+	 * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached
773
+	 * @param string         $current_cache_id   - the ID that was used when originally caching the object
774
+	 * @return boolean TRUE on success, FALSE on fail
775
+	 * @throws \EE_Error
776
+	 */
777
+	public function update_cache_after_object_save(
778
+		$relationName,
779
+		EE_Base_Class $newly_saved_object,
780
+		$current_cache_id = ''
781
+	) {
782
+		// verify that incoming object is of the correct type
783
+		$obj_class = 'EE_' . $relationName;
784
+		if ($newly_saved_object instanceof $obj_class) {
785
+			/* @type EE_Base_Class $newly_saved_object */
786
+			// now get the type of relation
787
+			$relationship_to_model = $this->get_model()->related_settings_for($relationName);
788
+			// if this is a 1:1 relationship
789
+			if ($relationship_to_model instanceof EE_Belongs_To_Relation) {
790
+				// then just replace the cached object with the newly saved object
791
+				$this->_model_relations[$relationName] = $newly_saved_object;
792
+				return true;
793
+				// or if it's some kind of sordid feral polyamorous relationship...
794
+			} elseif (is_array($this->_model_relations[$relationName])
795
+					  && isset($this->_model_relations[$relationName][$current_cache_id])
796
+			) {
797
+				// then remove the current cached item
798
+				unset($this->_model_relations[$relationName][$current_cache_id]);
799
+				// and cache the newly saved object using it's new ID
800
+				$this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object;
801
+				return true;
802
+			}
803
+		}
804
+		return false;
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
811
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
812
+	 *
813
+	 * @param string $relationName
814
+	 * @return EE_Base_Class
815
+	 */
816
+	public function get_one_from_cache($relationName)
817
+	{
818
+		$cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName]
819
+			: null;
820
+		if (is_array($cached_array_or_object)) {
821
+			return array_shift($cached_array_or_object);
822
+		} else {
823
+			return $cached_array_or_object;
824
+		}
825
+	}
826
+
827
+
828
+
829
+	/**
830
+	 * Fetches a single EE_Base_Class on that relation. (If the relation is of type
831
+	 * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects)
832
+	 *
833
+	 * @param string $relationName
834
+	 * @throws \EE_Error
835
+	 * @return EE_Base_Class[] NOT necessarily indexed by primary keys
836
+	 */
837
+	public function get_all_from_cache($relationName)
838
+	{
839
+		$objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array();
840
+		// if the result is not an array, but exists, make it an array
841
+		$objects = is_array($objects) ? $objects : array($objects);
842
+		//bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143
843
+		//basically, if this model object was stored in the session, and these cached model objects
844
+		//already have IDs, let's make sure they're in their model's entity mapper
845
+		//otherwise we will have duplicates next time we call
846
+		// EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() );
847
+		$model = EE_Registry::instance()->load_model($relationName);
848
+		foreach ($objects as $model_object) {
849
+			if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) {
850
+				//ensure its in the map if it has an ID; otherwise it will be added to the map when its saved
851
+				if ($model_object->ID()) {
852
+					$model->add_to_entity_map($model_object);
853
+				}
854
+			} else {
855
+				throw new EE_Error(
856
+					sprintf(
857
+						__(
858
+							'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object',
859
+							'event_espresso'
860
+						),
861
+						$relationName,
862
+						gettype($model_object)
863
+					)
864
+				);
865
+			}
866
+		}
867
+		return $objects;
868
+	}
869
+
870
+
871
+
872
+	/**
873
+	 * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database
874
+	 * matching the given query conditions.
875
+	 *
876
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
877
+	 * @param int   $limit              How many objects to return.
878
+	 * @param array $query_params       Any additional conditions on the query.
879
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
880
+	 *                                  you can indicate just the columns you want returned
881
+	 * @return array|EE_Base_Class[]
882
+	 * @throws \EE_Error
883
+	 */
884
+	public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null)
885
+	{
886
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
887
+			? $this->get_model()->get_primary_key_field()->get_name()
888
+			: $field_to_order_by;
889
+		$current_value = ! empty($field) ? $this->get($field) : null;
890
+		if (empty($field) || empty($current_value)) {
891
+			return array();
892
+		}
893
+		return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select);
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database
900
+	 * matching the given query conditions.
901
+	 *
902
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
903
+	 * @param int   $limit              How many objects to return.
904
+	 * @param array $query_params       Any additional conditions on the query.
905
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
906
+	 *                                  you can indicate just the columns you want returned
907
+	 * @return array|EE_Base_Class[]
908
+	 * @throws \EE_Error
909
+	 */
910
+	public function previous_x(
911
+		$field_to_order_by = null,
912
+		$limit = 1,
913
+		$query_params = array(),
914
+		$columns_to_select = null
915
+	) {
916
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
917
+			? $this->get_model()->get_primary_key_field()->get_name()
918
+			: $field_to_order_by;
919
+		$current_value = ! empty($field) ? $this->get($field) : null;
920
+		if (empty($field) || empty($current_value)) {
921
+			return array();
922
+		}
923
+		return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select);
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * Returns the next EE_Base_Class object in sequence from this object as found in the database
930
+	 * matching the given query conditions.
931
+	 *
932
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
933
+	 * @param array $query_params       Any additional conditions on the query.
934
+	 * @param null  $columns_to_select  If left null, then an array of EE_Base_Class objects is returned, otherwise
935
+	 *                                  you can indicate just the columns you want returned
936
+	 * @return array|EE_Base_Class
937
+	 * @throws \EE_Error
938
+	 */
939
+	public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
940
+	{
941
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
942
+			? $this->get_model()->get_primary_key_field()->get_name()
943
+			: $field_to_order_by;
944
+		$current_value = ! empty($field) ? $this->get($field) : null;
945
+		if (empty($field) || empty($current_value)) {
946
+			return array();
947
+		}
948
+		return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select);
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * Returns the previous EE_Base_Class object in sequence from this object as found in the database
955
+	 * matching the given query conditions.
956
+	 *
957
+	 * @param null  $field_to_order_by  What field is being used as the reference point.
958
+	 * @param array $query_params       Any additional conditions on the query.
959
+	 * @param null  $columns_to_select  If left null, then an EE_Base_Class object is returned, otherwise
960
+	 *                                  you can indicate just the column you want returned
961
+	 * @return array|EE_Base_Class
962
+	 * @throws \EE_Error
963
+	 */
964
+	public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null)
965
+	{
966
+		$field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field()
967
+			? $this->get_model()->get_primary_key_field()->get_name()
968
+			: $field_to_order_by;
969
+		$current_value = ! empty($field) ? $this->get($field) : null;
970
+		if (empty($field) || empty($current_value)) {
971
+			return array();
972
+		}
973
+		return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * Overrides parent because parent expects old models.
980
+	 * This also doesn't do any validation, and won't work for serialized arrays
981
+	 *
982
+	 * @param string $field_name
983
+	 * @param mixed  $field_value_from_db
984
+	 * @throws \EE_Error
985
+	 */
986
+	public function set_from_db($field_name, $field_value_from_db)
987
+	{
988
+		$field_obj = $this->get_model()->field_settings_for($field_name);
989
+		if ($field_obj instanceof EE_Model_Field_Base) {
990
+			//you would think the DB has no NULLs for non-null label fields right? wrong!
991
+			//eg, a CPT model object could have an entry in the posts table, but no
992
+			//entry in the meta table. Meaning that all its columns in the meta table
993
+			//are null! yikes! so when we find one like that, use defaults for its meta columns
994
+			if ($field_value_from_db === null) {
995
+				if ($field_obj->is_nullable()) {
996
+					//if the field allows nulls, then let it be null
997
+					$field_value = null;
998
+				} else {
999
+					$field_value = $field_obj->get_default_value();
1000
+				}
1001
+			} else {
1002
+				$field_value = $field_obj->prepare_for_set_from_db($field_value_from_db);
1003
+			}
1004
+			$this->_fields[$field_name] = $field_value;
1005
+			$this->_clear_cached_property($field_name);
1006
+		}
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 * verifies that the specified field is of the correct type
1013
+	 *
1014
+	 * @param string $field_name
1015
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1016
+	 *                                (in cases where the same property may be used for different outputs
1017
+	 *                                - i.e. datetime, money etc.)
1018
+	 * @return mixed
1019
+	 * @throws \EE_Error
1020
+	 */
1021
+	public function get($field_name, $extra_cache_ref = null)
1022
+	{
1023
+		return $this->_get_cached_property($field_name, false, $extra_cache_ref);
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 * This method simply returns the RAW unprocessed value for the given property in this class
1030
+	 *
1031
+	 * @param  string $field_name A valid fieldname
1032
+	 * @return mixed              Whatever the raw value stored on the property is.
1033
+	 * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist.
1034
+	 */
1035
+	public function get_raw($field_name)
1036
+	{
1037
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1038
+		return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime
1039
+			? $this->_fields[$field_name]->format('U')
1040
+			: $this->_fields[$field_name];
1041
+	}
1042
+
1043
+
1044
+
1045
+	/**
1046
+	 * This is used to return the internal DateTime object used for a field that is a
1047
+	 * EE_Datetime_Field.
1048
+	 *
1049
+	 * @param string $field_name               The field name retrieving the DateTime object.
1050
+	 * @return mixed null | false | DateTime  If the requested field is NOT a EE_Datetime_Field then
1051
+	 * @throws \EE_Error
1052
+	 *                                         an error is set and false returned.  If the field IS an
1053
+	 *                                         EE_Datetime_Field and but the field value is null, then
1054
+	 *                                         just null is returned (because that indicates that likely
1055
+	 *                                         this field is nullable).
1056
+	 */
1057
+	public function get_DateTime_object($field_name)
1058
+	{
1059
+		$field_settings = $this->get_model()->field_settings_for($field_name);
1060
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1061
+			EE_Error::add_error(
1062
+				sprintf(
1063
+					__(
1064
+						'The field %s is not an EE_Datetime_Field field.  There is no DateTime object stored on this field type.',
1065
+						'event_espresso'
1066
+					),
1067
+					$field_name
1068
+				),
1069
+				__FILE__,
1070
+				__FUNCTION__,
1071
+				__LINE__
1072
+			);
1073
+			return false;
1074
+		}
1075
+		return $this->_fields[$field_name];
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * To be used in template to immediately echo out the value, and format it for output.
1082
+	 * Eg, should call stripslashes and whatnot before echoing
1083
+	 *
1084
+	 * @param string $field_name      the name of the field as it appears in the DB
1085
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1086
+	 *                                (in cases where the same property may be used for different outputs
1087
+	 *                                - i.e. datetime, money etc.)
1088
+	 * @return void
1089
+	 * @throws \EE_Error
1090
+	 */
1091
+	public function e($field_name, $extra_cache_ref = null)
1092
+	{
1093
+		echo $this->get_pretty($field_name, $extra_cache_ref);
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it
1100
+	 * can be easily used as the value of form input.
1101
+	 *
1102
+	 * @param string $field_name
1103
+	 * @return void
1104
+	 * @throws \EE_Error
1105
+	 */
1106
+	public function f($field_name)
1107
+	{
1108
+		$this->e($field_name, 'form_input');
1109
+	}
1110
+
1111
+
1112
+
1113
+	/**
1114
+	 * @param string $field_name
1115
+	 * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property
1116
+	 *                                (in cases where the same property may be used for different outputs
1117
+	 *                                - i.e. datetime, money etc.)
1118
+	 * @return mixed
1119
+	 * @throws \EE_Error
1120
+	 */
1121
+	public function get_pretty($field_name, $extra_cache_ref = null)
1122
+	{
1123
+		return $this->_get_cached_property($field_name, true, $extra_cache_ref);
1124
+	}
1125
+
1126
+
1127
+
1128
+	/**
1129
+	 * This simply returns the datetime for the given field name
1130
+	 * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions
1131
+	 * (and the equivalent e_date, e_time, e_datetime).
1132
+	 *
1133
+	 * @access   protected
1134
+	 * @param string   $field_name   Field on the instantiated EE_Base_Class child object
1135
+	 * @param string   $dt_frmt      valid datetime format used for date
1136
+	 *                               (if '' then we just use the default on the field,
1137
+	 *                               if NULL we use the last-used format)
1138
+	 * @param string   $tm_frmt      Same as above except this is for time format
1139
+	 * @param string   $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time.
1140
+	 * @param  boolean $echo         Whether the dtt is echoing using pretty echoing or just returned using vanilla get
1141
+	 * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown
1142
+	 *                               if field is not a valid dtt field, or void if echoing
1143
+	 * @throws \EE_Error
1144
+	 */
1145
+	protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false)
1146
+	{
1147
+		// clear cached property
1148
+		$this->_clear_cached_property($field_name);
1149
+		//reset format properties because they are used in get()
1150
+		$this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt;
1151
+		$this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt;
1152
+		if ($echo) {
1153
+			$this->e($field_name, $date_or_time);
1154
+			return '';
1155
+		}
1156
+		return $this->get($field_name, $date_or_time);
1157
+	}
1158
+
1159
+
1160
+
1161
+	/**
1162
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date
1163
+	 * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1164
+	 * other echoes the pretty value for dtt)
1165
+	 *
1166
+	 * @param  string $field_name name of model object datetime field holding the value
1167
+	 * @param  string $format     format for the date returned (if NULL we use default in dt_frmt property)
1168
+	 * @return string            datetime value formatted
1169
+	 * @throws \EE_Error
1170
+	 */
1171
+	public function get_date($field_name, $format = '')
1172
+	{
1173
+		return $this->_get_datetime($field_name, $format, null, 'D');
1174
+	}
1175
+
1176
+
1177
+
1178
+	/**
1179
+	 * @param      $field_name
1180
+	 * @param string $format
1181
+	 * @throws \EE_Error
1182
+	 */
1183
+	public function e_date($field_name, $format = '')
1184
+	{
1185
+		$this->_get_datetime($field_name, $format, null, 'D', true);
1186
+	}
1187
+
1188
+
1189
+
1190
+	/**
1191
+	 * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time
1192
+	 * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1193
+	 * other echoes the pretty value for dtt)
1194
+	 *
1195
+	 * @param  string $field_name name of model object datetime field holding the value
1196
+	 * @param  string $format     format for the time returned ( if NULL we use default in tm_frmt property)
1197
+	 * @return string             datetime value formatted
1198
+	 * @throws \EE_Error
1199
+	 */
1200
+	public function get_time($field_name, $format = '')
1201
+	{
1202
+		return $this->_get_datetime($field_name, null, $format, 'T');
1203
+	}
1204
+
1205
+
1206
+
1207
+	/**
1208
+	 * @param      $field_name
1209
+	 * @param string $format
1210
+	 * @throws \EE_Error
1211
+	 */
1212
+	public function e_time($field_name, $format = '')
1213
+	{
1214
+		$this->_get_datetime($field_name, null, $format, 'T', true);
1215
+	}
1216
+
1217
+
1218
+
1219
+	/**
1220
+	 * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND
1221
+	 * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the
1222
+	 * other echoes the pretty value for dtt)
1223
+	 *
1224
+	 * @param  string $field_name name of model object datetime field holding the value
1225
+	 * @param  string $dt_frmt    format for the date returned (if NULL we use default in dt_frmt property)
1226
+	 * @param  string $tm_frmt    format for the time returned (if NULL we use default in tm_frmt property)
1227
+	 * @return string             datetime value formatted
1228
+	 * @throws \EE_Error
1229
+	 */
1230
+	public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1231
+	{
1232
+		return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt);
1233
+	}
1234
+
1235
+
1236
+
1237
+	/**
1238
+	 * @param string $field_name
1239
+	 * @param string $dt_frmt
1240
+	 * @param string $tm_frmt
1241
+	 * @throws \EE_Error
1242
+	 */
1243
+	public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '')
1244
+	{
1245
+		$this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true);
1246
+	}
1247
+
1248
+
1249
+
1250
+	/**
1251
+	 * Get the i8ln value for a date using the WordPress @see date_i18n function.
1252
+	 *
1253
+	 * @param string $field_name The EE_Datetime_Field reference for the date being retrieved.
1254
+	 * @param string $format     PHP valid date/time string format.  If none is provided then the internal set format
1255
+	 *                           on the object will be used.
1256
+	 * @return string Date and time string in set locale or false if no field exists for the given
1257
+	 * @throws \EE_Error
1258
+	 *                           field name.
1259
+	 */
1260
+	public function get_i18n_datetime($field_name, $format = '')
1261
+	{
1262
+		$format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1263
+		return date_i18n(
1264
+			$format,
1265
+			EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
1266
+		);
1267
+	}
1268
+
1269
+
1270
+
1271
+	/**
1272
+	 * This method validates whether the given field name is a valid field on the model object as well as it is of a
1273
+	 * type EE_Datetime_Field.  On success there will be returned the field settings.  On fail an EE_Error exception is
1274
+	 * thrown.
1275
+	 *
1276
+	 * @param  string $field_name The field name being checked
1277
+	 * @throws EE_Error
1278
+	 * @return EE_Datetime_Field
1279
+	 */
1280
+	protected function _get_dtt_field_settings($field_name)
1281
+	{
1282
+		$field = $this->get_model()->field_settings_for($field_name);
1283
+		//check if field is dtt
1284
+		if ($field instanceof EE_Datetime_Field) {
1285
+			return $field;
1286
+		} else {
1287
+			throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field.  Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor',
1288
+				'event_espresso'), $field_name, self::_get_model_classname(get_class($this))));
1289
+		}
1290
+	}
1291
+
1292
+
1293
+
1294
+
1295
+	/**
1296
+	 * NOTE ABOUT BELOW:
1297
+	 * These convenience date and time setters are for setting date and time independently.  In other words you might
1298
+	 * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand
1299
+	 * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value)
1300
+	 * method and make sure you send the entire datetime value for setting.
1301
+	 */
1302
+	/**
1303
+	 * sets the time on a datetime property
1304
+	 *
1305
+	 * @access protected
1306
+	 * @param string|Datetime $time      a valid time string for php datetime functions (or DateTime object)
1307
+	 * @param string          $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field)
1308
+	 * @throws \EE_Error
1309
+	 */
1310
+	protected function _set_time_for($time, $fieldname)
1311
+	{
1312
+		$this->_set_date_time('T', $time, $fieldname);
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 * sets the date on a datetime property
1319
+	 *
1320
+	 * @access protected
1321
+	 * @param string|DateTime $date      a valid date string for php datetime functions ( or DateTime object)
1322
+	 * @param string          $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field)
1323
+	 * @throws \EE_Error
1324
+	 */
1325
+	protected function _set_date_for($date, $fieldname)
1326
+	{
1327
+		$this->_set_date_time('D', $date, $fieldname);
1328
+	}
1329
+
1330
+
1331
+
1332
+	/**
1333
+	 * This takes care of setting a date or time independently on a given model object property. This method also
1334
+	 * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field
1335
+	 *
1336
+	 * @access protected
1337
+	 * @param string          $what           "T" for time, 'B' for both, 'D' for Date.
1338
+	 * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object)
1339
+	 * @param string          $fieldname      the name of the field the date OR time is being set on (must match a
1340
+	 *                                        EE_Datetime_Field property)
1341
+	 * @throws \EE_Error
1342
+	 */
1343
+	protected function _set_date_time($what = 'T', $datetime_value, $fieldname)
1344
+	{
1345
+		$field = $this->_get_dtt_field_settings($fieldname);
1346
+		$field->set_timezone($this->_timezone);
1347
+		$field->set_date_format($this->_dt_frmt);
1348
+		$field->set_time_format($this->_tm_frmt);
1349
+		switch ($what) {
1350
+			case 'T' :
1351
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_time(
1352
+					$datetime_value,
1353
+					$this->_fields[$fieldname]
1354
+				);
1355
+				break;
1356
+			case 'D' :
1357
+				$this->_fields[$fieldname] = $field->prepare_for_set_with_new_date(
1358
+					$datetime_value,
1359
+					$this->_fields[$fieldname]
1360
+				);
1361
+				break;
1362
+			case 'B' :
1363
+				$this->_fields[$fieldname] = $field->prepare_for_set($datetime_value);
1364
+				break;
1365
+		}
1366
+		$this->_clear_cached_property($fieldname);
1367
+	}
1368
+
1369
+
1370
+
1371
+	/**
1372
+	 * This will return a timestamp for the website timezone but ONLY when the current website timezone is different
1373
+	 * than the timezone set for the website. NOTE, this currently only works well with methods that return values.  If
1374
+	 * you use it with methods that echo values the $_timestamp property may not get reset to its original value and
1375
+	 * that could lead to some unexpected results!
1376
+	 *
1377
+	 * @access public
1378
+	 * @param string               $field_name This is the name of the field on the object that contains the date/time
1379
+	 *                                         value being returned.
1380
+	 * @param string               $callback   must match a valid method in this class (defaults to get_datetime)
1381
+	 * @param mixed (array|string) $args       This is the arguments that will be passed to the callback.
1382
+	 * @param string               $prepend    You can include something to prepend on the timestamp
1383
+	 * @param string               $append     You can include something to append on the timestamp
1384
+	 * @throws EE_Error
1385
+	 * @return string timestamp
1386
+	 */
1387
+	public function display_in_my_timezone(
1388
+		$field_name,
1389
+		$callback = 'get_datetime',
1390
+		$args = null,
1391
+		$prepend = '',
1392
+		$append = ''
1393
+	) {
1394
+		$timezone = EEH_DTT_Helper::get_timezone();
1395
+		if ($timezone === $this->_timezone) {
1396
+			return '';
1397
+		}
1398
+		$original_timezone = $this->_timezone;
1399
+		$this->set_timezone($timezone);
1400
+		$fn = (array)$field_name;
1401
+		$args = array_merge($fn, (array)$args);
1402
+		if ( ! method_exists($this, $callback)) {
1403
+			throw new EE_Error(
1404
+				sprintf(
1405
+					__(
1406
+						'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist.  Please check your spelling',
1407
+						'event_espresso'
1408
+					),
1409
+					$callback
1410
+				)
1411
+			);
1412
+		}
1413
+		$args = (array)$args;
1414
+		$return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1415
+		$this->set_timezone($original_timezone);
1416
+		return $return;
1417
+	}
1418
+
1419
+
1420
+
1421
+	/**
1422
+	 * Deletes this model object.
1423
+	 * This calls the `EE_Base_Class::_delete` method.  Child classes wishing to change default behaviour should
1424
+	 * override
1425
+	 * `EE_Base_Class::_delete` NOT this class.
1426
+	 *
1427
+	 * @return boolean | int
1428
+	 * @throws \EE_Error
1429
+	 */
1430
+	public function delete()
1431
+	{
1432
+		/**
1433
+		 * Called just before the `EE_Base_Class::_delete` method call.
1434
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1435
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example, `EE_Soft_Delete_Base_Class::_delete`
1436
+		 * soft deletes (trash) the object and does not permanently delete it.
1437
+		 *
1438
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1439
+		 */
1440
+		do_action('AHEE__EE_Base_Class__delete__before', $this);
1441
+		$result = $this->_delete();
1442
+		/**
1443
+		 * Called just after the `EE_Base_Class::_delete` method call.
1444
+		 * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions
1445
+		 * should be aware that `_delete` may not always result in a permanent delete.  For example `EE_Soft_Base_Class::_delete`
1446
+		 * soft deletes (trash) the object and does not permanently delete it.
1447
+		 *
1448
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1449
+		 * @param boolean       $result
1450
+		 */
1451
+		do_action('AHEE__EE_Base_Class__delete__end', $this, $result);
1452
+		return $result;
1453
+	}
1454
+
1455
+
1456
+
1457
+	/**
1458
+	 * Calls the specific delete method for the instantiated class.
1459
+	 * This method is called by the public `EE_Base_Class::delete` method.  Any child classes desiring to override
1460
+	 * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT
1461
+	 * `EE_Base_Class::delete`
1462
+	 *
1463
+	 * @return bool|int
1464
+	 * @throws \EE_Error
1465
+	 */
1466
+	protected function _delete()
1467
+	{
1468
+		return $this->delete_permanently();
1469
+	}
1470
+
1471
+
1472
+
1473
+	/**
1474
+	 * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an
1475
+	 * error)
1476
+	 *
1477
+	 * @return bool | int
1478
+	 * @throws \EE_Error
1479
+	 */
1480
+	public function delete_permanently()
1481
+	{
1482
+		/**
1483
+		 * Called just before HARD deleting a model object
1484
+		 *
1485
+		 * @param EE_Base_Class $model_object about to be 'deleted'
1486
+		 */
1487
+		do_action('AHEE__EE_Base_Class__delete_permanently__before', $this);
1488
+		$model = $this->get_model();
1489
+		$result = $model->delete_permanently_by_ID($this->ID());
1490
+		$this->refresh_cache_of_related_objects();
1491
+		/**
1492
+		 * Called just after HARD deleting a model object
1493
+		 *
1494
+		 * @param EE_Base_Class $model_object that was just 'deleted'
1495
+		 * @param boolean       $result
1496
+		 */
1497
+		do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result);
1498
+		return $result;
1499
+	}
1500
+
1501
+
1502
+
1503
+	/**
1504
+	 * When this model object is deleted, it may still be cached on related model objects. This clears the cache of
1505
+	 * related model objects
1506
+	 *
1507
+	 * @throws \EE_Error
1508
+	 */
1509
+	public function refresh_cache_of_related_objects()
1510
+	{
1511
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1512
+			if ( ! empty($this->_model_relations[$relation_name])) {
1513
+				$related_objects = $this->_model_relations[$relation_name];
1514
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
1515
+					//this relation only stores a single model object, not an array
1516
+					//but let's make it consistent
1517
+					$related_objects = array($related_objects);
1518
+				}
1519
+				foreach ($related_objects as $related_object) {
1520
+					//only refresh their cache if they're in memory
1521
+					if ($related_object instanceof EE_Base_Class) {
1522
+						$related_object->clear_cache($this->get_model()->get_this_model_name(), $this);
1523
+					}
1524
+				}
1525
+			}
1526
+		}
1527
+	}
1528
+
1529
+
1530
+
1531
+	/**
1532
+	 *        Saves this object to the database. An array may be supplied to set some values on this
1533
+	 * object just before saving.
1534
+	 *
1535
+	 * @access public
1536
+	 * @param array $set_cols_n_values keys are field names, values are their new values,
1537
+	 *                                 if provided during the save() method (often client code will change the fields'
1538
+	 *                                 values before calling save)
1539
+	 * @throws \EE_Error
1540
+	 * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object
1541
+	 *                                 isn't allowed to persist (as determined by EE_Base_Class::allow_persist())
1542
+	 */
1543
+	public function save($set_cols_n_values = array())
1544
+	{
1545
+		/**
1546
+		 * Filters the fields we're about to save on the model object
1547
+		 *
1548
+		 * @param array         $set_cols_n_values
1549
+		 * @param EE_Base_Class $model_object
1550
+		 */
1551
+		$set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1552
+			$this);
1553
+		//set attributes as provided in $set_cols_n_values
1554
+		foreach ($set_cols_n_values as $column => $value) {
1555
+			$this->set($column, $value);
1556
+		}
1557
+		/**
1558
+		 * Saving a model object.
1559
+		 * Before we perform a save, this action is fired.
1560
+		 *
1561
+		 * @param EE_Base_Class $model_object the model object about to be saved.
1562
+		 */
1563
+		do_action('AHEE__EE_Base_Class__save__begin', $this);
1564
+		if ( ! $this->allow_persist()) {
1565
+			return 0;
1566
+		}
1567
+		//now get current attribute values
1568
+		$save_cols_n_values = $this->_fields;
1569
+		//if the object already has an ID, update it. Otherwise, insert it
1570
+		//also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been
1571
+		$old_assumption_concerning_value_preparation = $this->get_model()
1572
+															->get_assumption_concerning_values_already_prepared_by_model_object();
1573
+		$this->get_model()->assume_values_already_prepared_by_model_object(true);
1574
+		//does this model have an autoincrement PK?
1575
+		if ($this->get_model()->has_primary_key_field()) {
1576
+			if ($this->get_model()->get_primary_key_field()->is_auto_increment()) {
1577
+				//ok check if it's set, if so: update; if not, insert
1578
+				if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) {
1579
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1580
+				} else {
1581
+					unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]);
1582
+					$results = $this->get_model()->insert($save_cols_n_values);
1583
+					if ($results) {
1584
+						//if successful, set the primary key
1585
+						//but don't use the normal SET method, because it will check if
1586
+						//an item with the same ID exists in the mapper & db, then
1587
+						//will find it in the db (because we just added it) and THAT object
1588
+						//will get added to the mapper before we can add this one!
1589
+						//but if we just avoid using the SET method, all that headache can be avoided
1590
+						$pk_field_name = self::_get_primary_key_name(get_class($this));
1591
+						$this->_fields[$pk_field_name] = $results;
1592
+						$this->_clear_cached_property($pk_field_name);
1593
+						$this->get_model()->add_to_entity_map($this);
1594
+						$this->_update_cached_related_model_objs_fks();
1595
+					}
1596
+				}
1597
+			} else {//PK is NOT auto-increment
1598
+				//so check if one like it already exists in the db
1599
+				if ($this->get_model()->exists_by_ID($this->ID())) {
1600
+					if (WP_DEBUG && ! $this->in_entity_map()) {
1601
+						throw new EE_Error(
1602
+							sprintf(
1603
+								__('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1604
+									'event_espresso'),
1605
+								get_class($this),
1606
+								get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1607
+								get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1608
+								'<br />'
1609
+							)
1610
+						);
1611
+					}
1612
+					$results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID());
1613
+				} else {
1614
+					$results = $this->get_model()->insert($save_cols_n_values);
1615
+					$this->_update_cached_related_model_objs_fks();
1616
+				}
1617
+			}
1618
+		} else {//there is NO primary key
1619
+			$already_in_db = false;
1620
+			foreach ($this->get_model()->unique_indexes() as $index) {
1621
+				$uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields());
1622
+				if ($this->get_model()->exists(array($uniqueness_where_params))) {
1623
+					$already_in_db = true;
1624
+				}
1625
+			}
1626
+			if ($already_in_db) {
1627
+				$combined_pk_fields_n_values = array_intersect_key($save_cols_n_values,
1628
+					$this->get_model()->get_combined_primary_key_fields());
1629
+				$results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values);
1630
+			} else {
1631
+				$results = $this->get_model()->insert($save_cols_n_values);
1632
+			}
1633
+		}
1634
+		//restore the old assumption about values being prepared by the model object
1635
+		$this->get_model()
1636
+			 ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation);
1637
+		/**
1638
+		 * After saving the model object this action is called
1639
+		 *
1640
+		 * @param EE_Base_Class $model_object which was just saved
1641
+		 * @param boolean|int   $results      if it were updated, TRUE or FALSE; if it were newly inserted
1642
+		 *                                    the new ID (or 0 if an error occurred and it wasn't updated)
1643
+		 */
1644
+		do_action('AHEE__EE_Base_Class__save__end', $this, $results);
1645
+		return $results;
1646
+	}
1647
+
1648
+
1649
+
1650
+	/**
1651
+	 * Updates the foreign key on related models objects pointing to this to have this model object's ID
1652
+	 * as their foreign key.  If the cached related model objects already exist in the db, saves them (so that the DB
1653
+	 * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its
1654
+	 * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't
1655
+	 * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the
1656
+	 * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether
1657
+	 * or not they exist in the DB (if they do, their DB records will be automatically updated)
1658
+	 *
1659
+	 * @return void
1660
+	 * @throws \EE_Error
1661
+	 */
1662
+	protected function _update_cached_related_model_objs_fks()
1663
+	{
1664
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
1665
+			if ($relation_obj instanceof EE_Has_Many_Relation) {
1666
+				foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) {
1667
+					$fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to(
1668
+						$this->get_model()->get_this_model_name()
1669
+					);
1670
+					$related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID());
1671
+					if ($related_model_obj_in_cache->ID()) {
1672
+						$related_model_obj_in_cache->save();
1673
+					}
1674
+				}
1675
+			}
1676
+		}
1677
+	}
1678
+
1679
+
1680
+
1681
+	/**
1682
+	 * Saves this model object and its NEW cached relations to the database.
1683
+	 * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB.
1684
+	 * In order for that to work, we would need to mark model objects as dirty/clean...
1685
+	 * because otherwise, there's a potential for infinite looping of saving
1686
+	 * Saves the cached related model objects, and ensures the relation between them
1687
+	 * and this object and properly setup
1688
+	 *
1689
+	 * @return int ID of new model object on save; 0 on failure+
1690
+	 * @throws \EE_Error
1691
+	 */
1692
+	public function save_new_cached_related_model_objs()
1693
+	{
1694
+		//make sure this has been saved
1695
+		if ( ! $this->ID()) {
1696
+			$id = $this->save();
1697
+		} else {
1698
+			$id = $this->ID();
1699
+		}
1700
+		//now save all the NEW cached model objects  (ie they don't exist in the DB)
1701
+		foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) {
1702
+			if ($this->_model_relations[$relationName]) {
1703
+				//is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation)
1704
+				//or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)?
1705
+				if ($relationObj instanceof EE_Belongs_To_Relation) {
1706
+					//add a relation to that relation type (which saves the appropriate thing in the process)
1707
+					//but ONLY if it DOES NOT exist in the DB
1708
+					/* @var $related_model_obj EE_Base_Class */
1709
+					$related_model_obj = $this->_model_relations[$relationName];
1710
+					//					if( ! $related_model_obj->ID()){
1711
+					$this->_add_relation_to($related_model_obj, $relationName);
1712
+					$related_model_obj->save_new_cached_related_model_objs();
1713
+					//					}
1714
+				} else {
1715
+					foreach ($this->_model_relations[$relationName] as $related_model_obj) {
1716
+						//add a relation to that relation type (which saves the appropriate thing in the process)
1717
+						//but ONLY if it DOES NOT exist in the DB
1718
+						//						if( ! $related_model_obj->ID()){
1719
+						$this->_add_relation_to($related_model_obj, $relationName);
1720
+						$related_model_obj->save_new_cached_related_model_objs();
1721
+						//						}
1722
+					}
1723
+				}
1724
+			}
1725
+		}
1726
+		return $id;
1727
+	}
1728
+
1729
+
1730
+
1731
+	/**
1732
+	 * for getting a model while instantiated.
1733
+	 *
1734
+	 * @return \EEM_Base | \EEM_CPT_Base
1735
+	 */
1736
+	public function get_model()
1737
+	{
1738
+		$modelName = self::_get_model_classname(get_class($this));
1739
+		return self::_get_model_instance_with_name($modelName, $this->_timezone);
1740
+	}
1741
+
1742
+
1743
+
1744
+	/**
1745
+	 * @param $props_n_values
1746
+	 * @param $classname
1747
+	 * @return mixed bool|EE_Base_Class|EEM_CPT_Base
1748
+	 * @throws \EE_Error
1749
+	 */
1750
+	protected static function _get_object_from_entity_mapper($props_n_values, $classname)
1751
+	{
1752
+		//TODO: will not work for Term_Relationships because they have no PK!
1753
+		$primary_id_ref = self::_get_primary_key_name($classname);
1754
+		if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) {
1755
+			$id = $props_n_values[$primary_id_ref];
1756
+			return self::_get_model($classname)->get_from_entity_map($id);
1757
+		}
1758
+		return false;
1759
+	}
1760
+
1761
+
1762
+
1763
+	/**
1764
+	 * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for
1765
+	 * the primary key (if present in incoming values). If there is a key in the incoming array that matches the
1766
+	 * primary key for the model AND it is not null, then we check the db. If there's a an object we return it.  If not
1767
+	 * we return false.
1768
+	 *
1769
+	 * @param  array  $props_n_values   incoming array of properties and their values
1770
+	 * @param  string $classname        the classname of the child class
1771
+	 * @param null    $timezone
1772
+	 * @param array   $date_formats     incoming date_formats in an array where the first value is the
1773
+	 *                                  date_format and the second value is the time format
1774
+	 * @return mixed (EE_Base_Class|bool)
1775
+	 * @throws \EE_Error
1776
+	 */
1777
+	protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array())
1778
+	{
1779
+		$existing = null;
1780
+		if (self::_get_model($classname)->has_primary_key_field()) {
1781
+			$primary_id_ref = self::_get_primary_key_name($classname);
1782
+			if (array_key_exists($primary_id_ref, $props_n_values)
1783
+				&& ! empty($props_n_values[$primary_id_ref])
1784
+			) {
1785
+				$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1786
+					$props_n_values[$primary_id_ref]
1787
+				);
1788
+			}
1789
+		} elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) {
1790
+			//no primary key on this model, but there's still a matching item in the DB
1791
+			$existing = self::_get_model($classname, $timezone)->get_one_by_ID(
1792
+				self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)
1793
+			);
1794
+		}
1795
+		if ($existing) {
1796
+			//set date formats if present before setting values
1797
+			if ( ! empty($date_formats) && is_array($date_formats)) {
1798
+				$existing->set_date_format($date_formats[0]);
1799
+				$existing->set_time_format($date_formats[1]);
1800
+			} else {
1801
+				//set default formats for date and time
1802
+				$existing->set_date_format(get_option('date_format'));
1803
+				$existing->set_time_format(get_option('time_format'));
1804
+			}
1805
+			foreach ($props_n_values as $property => $field_value) {
1806
+				$existing->set($property, $field_value);
1807
+			}
1808
+			return $existing;
1809
+		} else {
1810
+			return false;
1811
+		}
1812
+	}
1813
+
1814
+
1815
+
1816
+	/**
1817
+	 * Gets the EEM_*_Model for this class
1818
+	 *
1819
+	 * @access public now, as this is more convenient
1820
+	 * @param      $classname
1821
+	 * @param null $timezone
1822
+	 * @throws EE_Error
1823
+	 * @return EEM_Base
1824
+	 */
1825
+	protected static function _get_model($classname, $timezone = null)
1826
+	{
1827
+		//find model for this class
1828
+		if ( ! $classname) {
1829
+			throw new EE_Error(
1830
+				sprintf(
1831
+					__(
1832
+						"What were you thinking calling _get_model(%s)?? You need to specify the class name",
1833
+						"event_espresso"
1834
+					),
1835
+					$classname
1836
+				)
1837
+			);
1838
+		}
1839
+		$modelName = self::_get_model_classname($classname);
1840
+		return self::_get_model_instance_with_name($modelName, $timezone);
1841
+	}
1842
+
1843
+
1844
+
1845
+	/**
1846
+	 * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee)
1847
+	 *
1848
+	 * @param string $model_classname
1849
+	 * @param null   $timezone
1850
+	 * @return EEM_Base
1851
+	 */
1852
+	protected static function _get_model_instance_with_name($model_classname, $timezone = null)
1853
+	{
1854
+		$model_classname = str_replace('EEM_', '', $model_classname);
1855
+		$model = EE_Registry::instance()->load_model($model_classname);
1856
+		$model->set_timezone($timezone);
1857
+		return $model;
1858
+	}
1859
+
1860
+
1861
+
1862
+	/**
1863
+	 * If a model name is provided (eg Registration), gets the model classname for that model.
1864
+	 * Also works if a model class's classname is provided (eg EE_Registration).
1865
+	 *
1866
+	 * @param null $model_name
1867
+	 * @return string like EEM_Attendee
1868
+	 */
1869
+	private static function _get_model_classname($model_name = null)
1870
+	{
1871
+		if (strpos($model_name, "EE_") === 0) {
1872
+			$model_classname = str_replace("EE_", "EEM_", $model_name);
1873
+		} else {
1874
+			$model_classname = "EEM_" . $model_name;
1875
+		}
1876
+		return $model_classname;
1877
+	}
1878
+
1879
+
1880
+
1881
+	/**
1882
+	 * returns the name of the primary key attribute
1883
+	 *
1884
+	 * @param null $classname
1885
+	 * @throws EE_Error
1886
+	 * @return string
1887
+	 */
1888
+	protected static function _get_primary_key_name($classname = null)
1889
+	{
1890
+		if ( ! $classname) {
1891
+			throw new EE_Error(
1892
+				sprintf(
1893
+					__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),
1894
+					$classname
1895
+				)
1896
+			);
1897
+		}
1898
+		return self::_get_model($classname)->get_primary_key_field()->get_name();
1899
+	}
1900
+
1901
+
1902
+
1903
+	/**
1904
+	 * Gets the value of the primary key.
1905
+	 * If the object hasn't yet been saved, it should be whatever the model field's default was
1906
+	 * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value
1907
+	 * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL).
1908
+	 *
1909
+	 * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string
1910
+	 * @throws \EE_Error
1911
+	 */
1912
+	public function ID()
1913
+	{
1914
+		//now that we know the name of the variable, use a variable variable to get its value and return its
1915
+		if ($this->get_model()->has_primary_key_field()) {
1916
+			return $this->_fields[self::_get_primary_key_name(get_class($this))];
1917
+		} else {
1918
+			return $this->get_model()->get_index_primary_key_string($this->_fields);
1919
+		}
1920
+	}
1921
+
1922
+
1923
+
1924
+	/**
1925
+	 * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current
1926
+	 * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE
1927
+	 * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing
1928
+	 *
1929
+	 * @param mixed  $otherObjectModelObjectOrID       EE_Base_Class or the ID of the other object
1930
+	 * @param string $relationName                     eg 'Events','Question',etc.
1931
+	 *                                                 an attendee to a group, you also want to specify which role they
1932
+	 *                                                 will have in that group. So you would use this parameter to
1933
+	 *                                                 specify array('role-column-name'=>'role-id')
1934
+	 * @param array  $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that
1935
+	 *                                                 allow you to further constrict the relation to being added.
1936
+	 *                                                 However, keep in mind that the columns (keys) given must match a
1937
+	 *                                                 column on the JOIN table and currently only the HABTM models
1938
+	 *                                                 accept these additional conditions.  Also remember that if an
1939
+	 *                                                 exact match isn't found for these extra cols/val pairs, then a
1940
+	 *                                                 NEW row is created in the join table.
1941
+	 * @param null   $cache_id
1942
+	 * @throws EE_Error
1943
+	 * @return EE_Base_Class the object the relation was added to
1944
+	 */
1945
+	public function _add_relation_to(
1946
+		$otherObjectModelObjectOrID,
1947
+		$relationName,
1948
+		$extra_join_model_fields_n_values = array(),
1949
+		$cache_id = null
1950
+	) {
1951
+		//if this thing exists in the DB, save the relation to the DB
1952
+		if ($this->ID()) {
1953
+			$otherObject = $this->get_model()
1954
+								->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
1955
+									$extra_join_model_fields_n_values);
1956
+			//clear cache so future get_many_related and get_first_related() return new results.
1957
+			$this->clear_cache($relationName, $otherObject, true);
1958
+			if ($otherObject instanceof EE_Base_Class) {
1959
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
1960
+			}
1961
+		} else {
1962
+			//this thing doesn't exist in the DB,  so just cache it
1963
+			if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) {
1964
+				throw new EE_Error(sprintf(
1965
+					__('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s',
1966
+						'event_espresso'),
1967
+					$otherObjectModelObjectOrID,
1968
+					get_class($this)
1969
+				));
1970
+			} else {
1971
+				$otherObject = $otherObjectModelObjectOrID;
1972
+			}
1973
+			$this->cache($relationName, $otherObjectModelObjectOrID, $cache_id);
1974
+		}
1975
+		if ($otherObject instanceof EE_Base_Class) {
1976
+			//fix the reciprocal relation too
1977
+			if ($otherObject->ID()) {
1978
+				//its saved so assumed relations exist in the DB, so we can just
1979
+				//clear the cache so future queries use the updated info in the DB
1980
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true);
1981
+			} else {
1982
+				//it's not saved, so it caches relations like this
1983
+				$otherObject->cache($this->get_model()->get_this_model_name(), $this);
1984
+			}
1985
+		}
1986
+		return $otherObject;
1987
+	}
1988
+
1989
+
1990
+
1991
+	/**
1992
+	 * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current
1993
+	 * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE
1994
+	 * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing
1995
+	 * from the cache
1996
+	 *
1997
+	 * @param mixed  $otherObjectModelObjectOrID
1998
+	 *                EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved
1999
+	 *                to the DB yet
2000
+	 * @param string $relationName
2001
+	 * @param array  $where_query
2002
+	 *                You can optionally include an array of key=>value pairs that allow you to further constrict the
2003
+	 *                relation to being added. However, keep in mind that the columns (keys) given must match a column
2004
+	 *                on the JOIN table and currently only the HABTM models accept these additional conditions. Also
2005
+	 *                remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is
2006
+	 *                created in the join table.
2007
+	 * @return EE_Base_Class the relation was removed from
2008
+	 * @throws \EE_Error
2009
+	 */
2010
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array())
2011
+	{
2012
+		if ($this->ID()) {
2013
+			//if this exists in the DB, save the relation change to the DB too
2014
+			$otherObject = $this->get_model()
2015
+								->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName,
2016
+									$where_query);
2017
+			$this->clear_cache($relationName, $otherObject);
2018
+		} else {
2019
+			//this doesn't exist in the DB, just remove it from the cache
2020
+			$otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID);
2021
+		}
2022
+		if ($otherObject instanceof EE_Base_Class) {
2023
+			$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2024
+		}
2025
+		return $otherObject;
2026
+	}
2027
+
2028
+
2029
+
2030
+	/**
2031
+	 * Removes ALL the related things for the $relationName.
2032
+	 *
2033
+	 * @param string $relationName
2034
+	 * @param array  $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions)
2035
+	 * @return EE_Base_Class
2036
+	 * @throws \EE_Error
2037
+	 */
2038
+	public function _remove_relations($relationName, $where_query_params = array())
2039
+	{
2040
+		if ($this->ID()) {
2041
+			//if this exists in the DB, save the relation change to the DB too
2042
+			$otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params);
2043
+			$this->clear_cache($relationName, null, true);
2044
+		} else {
2045
+			//this doesn't exist in the DB, just remove it from the cache
2046
+			$otherObjects = $this->clear_cache($relationName, null, true);
2047
+		}
2048
+		if (is_array($otherObjects)) {
2049
+			foreach ($otherObjects as $otherObject) {
2050
+				$otherObject->clear_cache($this->get_model()->get_this_model_name(), $this);
2051
+			}
2052
+		}
2053
+		return $otherObjects;
2054
+	}
2055
+
2056
+
2057
+
2058
+	/**
2059
+	 * Gets all the related model objects of the specified type. Eg, if the current class if
2060
+	 * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the
2061
+	 * EE_Registration objects which related to this event. Note: by default, we remove the "default query params"
2062
+	 * because we want to get even deleted items etc.
2063
+	 *
2064
+	 * @param string $relationName key in the model's _model_relations array
2065
+	 * @param array  $query_params like EEM_Base::get_all
2066
+	 * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys
2067
+	 * @throws \EE_Error
2068
+	 *                             or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if
2069
+	 *                             you want IDs
2070
+	 */
2071
+	public function get_many_related($relationName, $query_params = array())
2072
+	{
2073
+		if ($this->ID()) {
2074
+			//this exists in the DB, so get the related things from either the cache or the DB
2075
+			//if there are query parameters, forget about caching the related model objects.
2076
+			if ($query_params) {
2077
+				$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2078
+			} else {
2079
+				//did we already cache the result of this query?
2080
+				$cached_results = $this->get_all_from_cache($relationName);
2081
+				if ( ! $cached_results) {
2082
+					$related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params);
2083
+					//if no query parameters were passed, then we got all the related model objects
2084
+					//for that relation. We can cache them then.
2085
+					foreach ($related_model_objects as $related_model_object) {
2086
+						$this->cache($relationName, $related_model_object);
2087
+					}
2088
+				} else {
2089
+					$related_model_objects = $cached_results;
2090
+				}
2091
+			}
2092
+		} else {
2093
+			//this doesn't exist in the DB, so just get the related things from the cache
2094
+			$related_model_objects = $this->get_all_from_cache($relationName);
2095
+		}
2096
+		return $related_model_objects;
2097
+	}
2098
+
2099
+
2100
+
2101
+	/**
2102
+	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2103
+	 * unless otherwise specified in the $query_params
2104
+	 *
2105
+	 * @param string $relation_name  model_name like 'Event', or 'Registration'
2106
+	 * @param array  $query_params   like EEM_Base::get_all's
2107
+	 * @param string $field_to_count name of field to count by. By default, uses primary key
2108
+	 * @param bool   $distinct       if we want to only count the distinct values for the column then you can trigger
2109
+	 *                               that by the setting $distinct to TRUE;
2110
+	 * @return int
2111
+	 */
2112
+	public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false)
2113
+	{
2114
+		return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct);
2115
+	}
2116
+
2117
+
2118
+
2119
+	/**
2120
+	 * Instead of getting the related model objects, simply sums up the values of the specified field.
2121
+	 * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params
2122
+	 *
2123
+	 * @param string $relation_name model_name like 'Event', or 'Registration'
2124
+	 * @param array  $query_params  like EEM_Base::get_all's
2125
+	 * @param string $field_to_sum  name of field to count by.
2126
+	 *                              By default, uses primary key (which doesn't make much sense, so you should probably
2127
+	 *                              change it)
2128
+	 * @return int
2129
+	 */
2130
+	public function sum_related($relation_name, $query_params = array(), $field_to_sum = null)
2131
+	{
2132
+		return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum);
2133
+	}
2134
+
2135
+
2136
+
2137
+	/**
2138
+	 * Gets the first (ie, one) related model object of the specified type.
2139
+	 *
2140
+	 * @param string $relationName key in the model's _model_relations array
2141
+	 * @param array  $query_params like EEM_Base::get_all
2142
+	 * @return EE_Base_Class (not an array, a single object)
2143
+	 * @throws \EE_Error
2144
+	 */
2145
+	public function get_first_related($relationName, $query_params = array())
2146
+	{
2147
+		if ($this->ID()) {//this exists in the DB, get from the cache OR the DB
2148
+			//if they've provided some query parameters, don't bother trying to cache the result
2149
+			//also make sure we're not caching the result of get_first_related
2150
+			//on a relation which should have an array of objects (because the cache might have an array of objects)
2151
+			if ($query_params
2152
+				|| ! $this->get_model()->related_settings_for($relationName)
2153
+					 instanceof
2154
+					 EE_Belongs_To_Relation
2155
+			) {
2156
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2157
+			} else {
2158
+				//first, check if we've already cached the result of this query
2159
+				$cached_result = $this->get_one_from_cache($relationName);
2160
+				if ( ! $cached_result) {
2161
+					$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2162
+					$this->cache($relationName, $related_model_object);
2163
+				} else {
2164
+					$related_model_object = $cached_result;
2165
+				}
2166
+			}
2167
+		} else {
2168
+			$related_model_object = null;
2169
+			//this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might
2170
+			if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) {
2171
+				$related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params);
2172
+			}
2173
+			//this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object
2174
+			if ( ! $related_model_object) {
2175
+				$related_model_object = $this->get_one_from_cache($relationName);
2176
+			}
2177
+		}
2178
+		return $related_model_object;
2179
+	}
2180
+
2181
+
2182
+
2183
+	/**
2184
+	 * Does a delete on all related objects of type $relationName and removes
2185
+	 * the current model object's relation to them. If they can't be deleted (because
2186
+	 * of blocking related model objects) does nothing. If the related model objects are
2187
+	 * soft-deletable, they will be soft-deleted regardless of related blocking model objects.
2188
+	 * If this model object doesn't exist yet in the DB, just removes its related things
2189
+	 *
2190
+	 * @param string $relationName
2191
+	 * @param array  $query_params like EEM_Base::get_all's
2192
+	 * @return int how many deleted
2193
+	 * @throws \EE_Error
2194
+	 */
2195
+	public function delete_related($relationName, $query_params = array())
2196
+	{
2197
+		if ($this->ID()) {
2198
+			$count = $this->get_model()->delete_related($this, $relationName, $query_params);
2199
+		} else {
2200
+			$count = count($this->get_all_from_cache($relationName));
2201
+			$this->clear_cache($relationName, null, true);
2202
+		}
2203
+		return $count;
2204
+	}
2205
+
2206
+
2207
+
2208
+	/**
2209
+	 * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes
2210
+	 * the current model object's relation to them. If they can't be deleted (because
2211
+	 * of blocking related model objects) just does a soft delete on it instead, if possible.
2212
+	 * If the related thing isn't a soft-deletable model object, this function is identical
2213
+	 * to delete_related(). If this model object doesn't exist in the DB, just remove its related things
2214
+	 *
2215
+	 * @param string $relationName
2216
+	 * @param array  $query_params like EEM_Base::get_all's
2217
+	 * @return int how many deleted (including those soft deleted)
2218
+	 * @throws \EE_Error
2219
+	 */
2220
+	public function delete_related_permanently($relationName, $query_params = array())
2221
+	{
2222
+		if ($this->ID()) {
2223
+			$count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params);
2224
+		} else {
2225
+			$count = count($this->get_all_from_cache($relationName));
2226
+		}
2227
+		$this->clear_cache($relationName, null, true);
2228
+		return $count;
2229
+	}
2230
+
2231
+
2232
+
2233
+	/**
2234
+	 * is_set
2235
+	 * Just a simple utility function children can use for checking if property exists
2236
+	 *
2237
+	 * @access  public
2238
+	 * @param  string $field_name property to check
2239
+	 * @return bool                              TRUE if existing,FALSE if not.
2240
+	 */
2241
+	public function is_set($field_name)
2242
+	{
2243
+		return isset($this->_fields[$field_name]);
2244
+	}
2245
+
2246
+
2247
+
2248
+	/**
2249
+	 * Just a simple utility function children can use for checking if property (or properties) exists and throwing an
2250
+	 * EE_Error exception if they don't
2251
+	 *
2252
+	 * @param  mixed (string|array) $properties properties to check
2253
+	 * @throws EE_Error
2254
+	 * @return bool                              TRUE if existing, throw EE_Error if not.
2255
+	 */
2256
+	protected function _property_exists($properties)
2257
+	{
2258
+		foreach ((array)$properties as $property_name) {
2259
+			//first make sure this property exists
2260
+			if ( ! $this->_fields[$property_name]) {
2261
+				throw new EE_Error(
2262
+					sprintf(
2263
+						__(
2264
+							'Trying to retrieve a non-existent property (%s).  Double check the spelling please',
2265
+							'event_espresso'
2266
+						),
2267
+						$property_name
2268
+					)
2269
+				);
2270
+			}
2271
+		}
2272
+		return true;
2273
+	}
2274
+
2275
+
2276
+
2277
+	/**
2278
+	 * This simply returns an array of model fields for this object
2279
+	 *
2280
+	 * @return array
2281
+	 * @throws \EE_Error
2282
+	 */
2283
+	public function model_field_array()
2284
+	{
2285
+		$fields = $this->get_model()->field_settings(false);
2286
+		$properties = array();
2287
+		//remove prepended underscore
2288
+		foreach ($fields as $field_name => $settings) {
2289
+			$properties[$field_name] = $this->get($field_name);
2290
+		}
2291
+		return $properties;
2292
+	}
2293
+
2294
+
2295
+
2296
+	/**
2297
+	 * Very handy general function to allow for plugins to extend any child of EE_Base_Class.
2298
+	 * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called
2299
+	 * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of
2300
+	 * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that
2301
+	 * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg,
2302
+	 * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function
2303
+	 * was called, and an array of the original arguments passed to the function. Whatever their callback function
2304
+	 * returns will be returned by this function. Example: in functions.php (or in a plugin):
2305
+	 * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function
2306
+	 * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){
2307
+	 * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray);
2308
+	 *        return $previousReturnValue.$returnString;
2309
+	 * }
2310
+	 * require('EE_Answer.class.php');
2311
+	 * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42'));
2312
+	 * echo $answer->my_callback('monkeys',100);
2313
+	 * //will output "you called my_callback! and passed args:monkeys,100"
2314
+	 *
2315
+	 * @param string $methodName name of method which was called on a child of EE_Base_Class, but which
2316
+	 * @param array  $args       array of original arguments passed to the function
2317
+	 * @throws EE_Error
2318
+	 * @return mixed whatever the plugin which calls add_filter decides
2319
+	 */
2320
+	public function __call($methodName, $args)
2321
+	{
2322
+		$className = get_class($this);
2323
+		$tagName = "FHEE__{$className}__{$methodName}";
2324
+		if ( ! has_filter($tagName)) {
2325
+			throw new EE_Error(
2326
+				sprintf(
2327
+					__(
2328
+						"Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}",
2329
+						"event_espresso"
2330
+					),
2331
+					$methodName,
2332
+					$className,
2333
+					$tagName
2334
+				)
2335
+			);
2336
+		}
2337
+		return apply_filters($tagName, null, $this, $args);
2338
+	}
2339
+
2340
+
2341
+
2342
+	/**
2343
+	 * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value.
2344
+	 * A $previous_value can be specified in case there are many meta rows with the same key
2345
+	 *
2346
+	 * @param string $meta_key
2347
+	 * @param string $meta_value
2348
+	 * @param string $previous_value
2349
+	 * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row)
2350
+	 * @throws \EE_Error
2351
+	 * NOTE: if the values haven't changed, returns 0
2352
+	 */
2353
+	public function update_extra_meta($meta_key, $meta_value, $previous_value = null)
2354
+	{
2355
+		$query_params = array(
2356
+			array(
2357
+				'EXM_key'  => $meta_key,
2358
+				'OBJ_ID'   => $this->ID(),
2359
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2360
+			),
2361
+		);
2362
+		if ($previous_value !== null) {
2363
+			$query_params[0]['EXM_value'] = $meta_value;
2364
+		}
2365
+		$existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params);
2366
+		if ( ! $existing_rows_like_that) {
2367
+			return $this->add_extra_meta($meta_key, $meta_value);
2368
+		} else {
2369
+			foreach ($existing_rows_like_that as $existing_row) {
2370
+				$existing_row->save(array('EXM_value' => $meta_value));
2371
+			}
2372
+			return count($existing_rows_like_that);
2373
+		}
2374
+	}
2375
+
2376
+
2377
+
2378
+	/**
2379
+	 * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check
2380
+	 * no other extra meta for this model object have the same key. Returns TRUE if the
2381
+	 * extra meta row was entered, false if not
2382
+	 *
2383
+	 * @param string  $meta_key
2384
+	 * @param string  $meta_value
2385
+	 * @param boolean $unique
2386
+	 * @return boolean
2387
+	 * @throws \EE_Error
2388
+	 */
2389
+	public function add_extra_meta($meta_key, $meta_value, $unique = false)
2390
+	{
2391
+		if ($unique) {
2392
+			$existing_extra_meta = EEM_Extra_Meta::instance()->get_one(
2393
+				array(
2394
+					array(
2395
+						'EXM_key'  => $meta_key,
2396
+						'OBJ_ID'   => $this->ID(),
2397
+						'EXM_type' => $this->get_model()->get_this_model_name(),
2398
+					),
2399
+				)
2400
+			);
2401
+			if ($existing_extra_meta) {
2402
+				return false;
2403
+			}
2404
+		}
2405
+		$new_extra_meta = EE_Extra_Meta::new_instance(
2406
+			array(
2407
+				'EXM_key'   => $meta_key,
2408
+				'EXM_value' => $meta_value,
2409
+				'OBJ_ID'    => $this->ID(),
2410
+				'EXM_type'  => $this->get_model()->get_this_model_name(),
2411
+			)
2412
+		);
2413
+		$new_extra_meta->save();
2414
+		return true;
2415
+	}
2416
+
2417
+
2418
+
2419
+	/**
2420
+	 * Deletes all the extra meta rows for this record as specified by key. If $meta_value
2421
+	 * is specified, only deletes extra meta records with that value.
2422
+	 *
2423
+	 * @param string $meta_key
2424
+	 * @param string $meta_value
2425
+	 * @return int number of extra meta rows deleted
2426
+	 * @throws \EE_Error
2427
+	 */
2428
+	public function delete_extra_meta($meta_key, $meta_value = null)
2429
+	{
2430
+		$query_params = array(
2431
+			array(
2432
+				'EXM_key'  => $meta_key,
2433
+				'OBJ_ID'   => $this->ID(),
2434
+				'EXM_type' => $this->get_model()->get_this_model_name(),
2435
+			),
2436
+		);
2437
+		if ($meta_value !== null) {
2438
+			$query_params[0]['EXM_value'] = $meta_value;
2439
+		}
2440
+		return EEM_Extra_Meta::instance()->delete($query_params);
2441
+	}
2442
+
2443
+
2444
+
2445
+	/**
2446
+	 * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise
2447
+	 * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation.
2448
+	 * You can specify $default is case you haven't found the extra meta
2449
+	 *
2450
+	 * @param string  $meta_key
2451
+	 * @param boolean $single
2452
+	 * @param mixed   $default if we don't find anything, what should we return?
2453
+	 * @return mixed single value if $single; array if ! $single
2454
+	 * @throws \EE_Error
2455
+	 */
2456
+	public function get_extra_meta($meta_key, $single = false, $default = null)
2457
+	{
2458
+		if ($single) {
2459
+			$result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2460
+			if ($result instanceof EE_Extra_Meta) {
2461
+				return $result->value();
2462
+			} else {
2463
+				return $default;
2464
+			}
2465
+		} else {
2466
+			$results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key)));
2467
+			if ($results) {
2468
+				$values = array();
2469
+				foreach ($results as $result) {
2470
+					if ($result instanceof EE_Extra_Meta) {
2471
+						$values[$result->ID()] = $result->value();
2472
+					}
2473
+				}
2474
+				return $values;
2475
+			} else {
2476
+				return $default;
2477
+			}
2478
+		}
2479
+	}
2480
+
2481
+
2482
+
2483
+	/**
2484
+	 * Returns a simple array of all the extra meta associated with this model object.
2485
+	 * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the
2486
+	 * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with
2487
+	 * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123))
2488
+	 * If $one_of_each_key is false, it will return an array with the top-level keys being
2489
+	 * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and
2490
+	 * finally the extra meta's value as each sub-value. (eg
2491
+	 * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123)))
2492
+	 *
2493
+	 * @param boolean $one_of_each_key
2494
+	 * @return array
2495
+	 * @throws \EE_Error
2496
+	 */
2497
+	public function all_extra_meta_array($one_of_each_key = true)
2498
+	{
2499
+		$return_array = array();
2500
+		if ($one_of_each_key) {
2501
+			$extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key'));
2502
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2503
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2504
+					$return_array[$extra_meta_obj->key()] = $extra_meta_obj->value();
2505
+				}
2506
+			}
2507
+		} else {
2508
+			$extra_meta_objs = $this->get_many_related('Extra_Meta');
2509
+			foreach ($extra_meta_objs as $extra_meta_obj) {
2510
+				if ($extra_meta_obj instanceof EE_Extra_Meta) {
2511
+					if ( ! isset($return_array[$extra_meta_obj->key()])) {
2512
+						$return_array[$extra_meta_obj->key()] = array();
2513
+					}
2514
+					$return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value();
2515
+				}
2516
+			}
2517
+		}
2518
+		return $return_array;
2519
+	}
2520
+
2521
+
2522
+
2523
+	/**
2524
+	 * Gets a pretty nice displayable nice for this model object. Often overridden
2525
+	 *
2526
+	 * @return string
2527
+	 * @throws \EE_Error
2528
+	 */
2529
+	public function name()
2530
+	{
2531
+		//find a field that's not a text field
2532
+		$field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base');
2533
+		if ($field_we_can_use) {
2534
+			return $this->get($field_we_can_use->get_name());
2535
+		} else {
2536
+			$first_few_properties = $this->model_field_array();
2537
+			$first_few_properties = array_slice($first_few_properties, 0, 3);
2538
+			$name_parts = array();
2539
+			foreach ($first_few_properties as $name => $value) {
2540
+				$name_parts[] = "$name:$value";
2541
+			}
2542
+			return implode(",", $name_parts);
2543
+		}
2544
+	}
2545
+
2546
+
2547
+
2548
+	/**
2549
+	 * in_entity_map
2550
+	 * Checks if this model object has been proven to already be in the entity map
2551
+	 *
2552
+	 * @return boolean
2553
+	 * @throws \EE_Error
2554
+	 */
2555
+	public function in_entity_map()
2556
+	{
2557
+		if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) {
2558
+			//well, if we looked, did we find it in the entity map?
2559
+			return true;
2560
+		} else {
2561
+			return false;
2562
+		}
2563
+	}
2564
+
2565
+
2566
+
2567
+	/**
2568
+	 * refresh_from_db
2569
+	 * Makes sure the fields and values on this model object are in-sync with what's in the database.
2570
+	 *
2571
+	 * @throws EE_Error if this model object isn't in the entity mapper (because then you should
2572
+	 * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE
2573
+	 */
2574
+	public function refresh_from_db()
2575
+	{
2576
+		if ($this->ID() && $this->in_entity_map()) {
2577
+			$this->get_model()->refresh_entity_map_from_db($this->ID());
2578
+		} else {
2579
+			//if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database)
2580
+			//if it has an ID but it's not in the map, and you're asking me to refresh it
2581
+			//that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's
2582
+			//absolutely nothing in it for this ID
2583
+			if (WP_DEBUG) {
2584
+				throw new EE_Error(
2585
+					sprintf(
2586
+						__('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2587
+							'event_espresso'),
2588
+						$this->ID(),
2589
+						get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2590
+						get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2591
+					)
2592
+				);
2593
+			}
2594
+		}
2595
+	}
2596
+
2597
+
2598
+
2599
+	/**
2600
+	 * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method
2601
+	 * (probably a bad assumption they have made, oh well)
2602
+	 *
2603
+	 * @return string
2604
+	 */
2605
+	public function __toString()
2606
+	{
2607
+		try {
2608
+			return sprintf('%s (%s)', $this->name(), $this->ID());
2609
+		} catch (Exception $e) {
2610
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
2611
+			return '';
2612
+		}
2613
+	}
2614
+
2615
+
2616
+
2617
+	/**
2618
+	 * Clear related model objects if they're already in the DB, because otherwise when we
2619
+	 * UN-serialize this model object we'll need to be careful to add them to the entity map.
2620
+	 * This means if we have made changes to those related model objects, and want to unserialize
2621
+	 * the this model object on a subsequent request, changes to those related model objects will be lost.
2622
+	 * Instead, those related model objects should be directly serialized and stored.
2623
+	 * Eg, the following won't work:
2624
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2625
+	 * $att = $reg->attendee();
2626
+	 * $att->set( 'ATT_fname', 'Dirk' );
2627
+	 * update_option( 'my_option', serialize( $reg ) );
2628
+	 * //END REQUEST
2629
+	 * //START NEXT REQUEST
2630
+	 * $reg = get_option( 'my_option' );
2631
+	 * $reg->attendee()->save();
2632
+	 * And would need to be replace with:
2633
+	 * $reg = EEM_Registration::instance()->get_one_by_ID( 123 );
2634
+	 * $att = $reg->attendee();
2635
+	 * $att->set( 'ATT_fname', 'Dirk' );
2636
+	 * update_option( 'my_option', serialize( $reg ) );
2637
+	 * //END REQUEST
2638
+	 * //START NEXT REQUEST
2639
+	 * $att = get_option( 'my_option' );
2640
+	 * $att->save();
2641
+	 *
2642
+	 * @return array
2643
+	 * @throws \EE_Error
2644
+	 */
2645
+	public function __sleep()
2646
+	{
2647
+		foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2648
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
2649
+				$classname = 'EE_' . $this->get_model()->get_this_model_name();
2650
+				if (
2651
+					$this->get_one_from_cache($relation_name) instanceof $classname
2652
+					&& $this->get_one_from_cache($relation_name)->ID()
2653
+				) {
2654
+					$this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID());
2655
+				}
2656
+			}
2657
+		}
2658
+		$this->_props_n_values_provided_in_constructor = array();
2659
+		return array_keys(get_object_vars($this));
2660
+	}
2661
+
2662
+
2663
+
2664
+	/**
2665
+	 * restore _props_n_values_provided_in_constructor
2666
+	 * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization,
2667
+	 * and therefore should NOT be used to determine if state change has occurred since initial construction.
2668
+	 * At best, you would only be able to detect if state change has occurred during THIS request.
2669
+	 */
2670
+	public function __wakeup()
2671
+	{
2672
+		$this->_props_n_values_provided_in_constructor = $this->_fields;
2673
+	}
2674 2674
 
2675 2675
 
2676 2676
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
             list($this->_dt_frmt, $this->_tm_frmt) = $date_formats;
146 146
         } else {
147 147
             //set default formats for date and time
148
-            $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d');
149
-            $this->_tm_frmt = (string)get_option('time_format', 'g:i a');
148
+            $this->_dt_frmt = (string) get_option('date_format', 'Y-m-d');
149
+            $this->_tm_frmt = (string) get_option('time_format', 'g:i a');
150 150
         }
151 151
         //if db model is instantiating
152 152
         if ($bydb) {
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      */
458 458
     public function get_format($full = true)
459 459
     {
460
-        return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
460
+        return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt);
461 461
     }
462 462
 
463 463
 
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         //verify the field exists
566 566
         $this->get_model()->field_settings_for($fieldname);
567 567
         $cache_type = $pretty ? 'pretty' : 'standard';
568
-        $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : '';
568
+        $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : '';
569 569
         if (isset($this->_cached_properties[$fieldname][$cache_type])) {
570 570
             return $this->_cached_properties[$fieldname][$cache_type];
571 571
         }
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
         $current_cache_id = ''
781 781
     ) {
782 782
         // verify that incoming object is of the correct type
783
-        $obj_class = 'EE_' . $relationName;
783
+        $obj_class = 'EE_'.$relationName;
784 784
         if ($newly_saved_object instanceof $obj_class) {
785 785
             /* @type EE_Base_Class $newly_saved_object */
786 786
             // now get the type of relation
@@ -1259,7 +1259,7 @@  discard block
 block discarded – undo
1259 1259
      */
1260 1260
     public function get_i18n_datetime($field_name, $format = '')
1261 1261
     {
1262
-        $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format;
1262
+        $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format;
1263 1263
         return date_i18n(
1264 1264
             $format,
1265 1265
             EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)
@@ -1397,8 +1397,8 @@  discard block
 block discarded – undo
1397 1397
         }
1398 1398
         $original_timezone = $this->_timezone;
1399 1399
         $this->set_timezone($timezone);
1400
-        $fn = (array)$field_name;
1401
-        $args = array_merge($fn, (array)$args);
1400
+        $fn = (array) $field_name;
1401
+        $args = array_merge($fn, (array) $args);
1402 1402
         if ( ! method_exists($this, $callback)) {
1403 1403
             throw new EE_Error(
1404 1404
                 sprintf(
@@ -1410,8 +1410,8 @@  discard block
 block discarded – undo
1410 1410
                 )
1411 1411
             );
1412 1412
         }
1413
-        $args = (array)$args;
1414
-        $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append;
1413
+        $args = (array) $args;
1414
+        $return = $prepend.call_user_func_array(array($this, $callback), $args).$append;
1415 1415
         $this->set_timezone($original_timezone);
1416 1416
         return $return;
1417 1417
     }
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
          * @param array         $set_cols_n_values
1549 1549
          * @param EE_Base_Class $model_object
1550 1550
          */
1551
-        $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1551
+        $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values,
1552 1552
             $this);
1553 1553
         //set attributes as provided in $set_cols_n_values
1554 1554
         foreach ($set_cols_n_values as $column => $value) {
@@ -1603,8 +1603,8 @@  discard block
 block discarded – undo
1603 1603
                                 __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s',
1604 1604
                                     'event_espresso'),
1605 1605
                                 get_class($this),
1606
-                                get_class($this->get_model()) . '::instance()->add_to_entity_map()',
1607
-                                get_class($this->get_model()) . '::instance()->get_one_by_ID()',
1606
+                                get_class($this->get_model()).'::instance()->add_to_entity_map()',
1607
+                                get_class($this->get_model()).'::instance()->get_one_by_ID()',
1608 1608
                                 '<br />'
1609 1609
                             )
1610 1610
                         );
@@ -1871,7 +1871,7 @@  discard block
 block discarded – undo
1871 1871
         if (strpos($model_name, "EE_") === 0) {
1872 1872
             $model_classname = str_replace("EE_", "EEM_", $model_name);
1873 1873
         } else {
1874
-            $model_classname = "EEM_" . $model_name;
1874
+            $model_classname = "EEM_".$model_name;
1875 1875
         }
1876 1876
         return $model_classname;
1877 1877
     }
@@ -2255,7 +2255,7 @@  discard block
 block discarded – undo
2255 2255
      */
2256 2256
     protected function _property_exists($properties)
2257 2257
     {
2258
-        foreach ((array)$properties as $property_name) {
2258
+        foreach ((array) $properties as $property_name) {
2259 2259
             //first make sure this property exists
2260 2260
             if ( ! $this->_fields[$property_name]) {
2261 2261
                 throw new EE_Error(
@@ -2586,8 +2586,8 @@  discard block
 block discarded – undo
2586 2586
                         __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.',
2587 2587
                             'event_espresso'),
2588 2588
                         $this->ID(),
2589
-                        get_class($this->get_model()) . '::instance()->add_to_entity_map()',
2590
-                        get_class($this->get_model()) . '::instance()->refresh_entity_map()'
2589
+                        get_class($this->get_model()).'::instance()->add_to_entity_map()',
2590
+                        get_class($this->get_model()).'::instance()->refresh_entity_map()'
2591 2591
                     )
2592 2592
                 );
2593 2593
             }
@@ -2646,7 +2646,7 @@  discard block
 block discarded – undo
2646 2646
     {
2647 2647
         foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) {
2648 2648
             if ($relation_obj instanceof EE_Belongs_To_Relation) {
2649
-                $classname = 'EE_' . $this->get_model()->get_this_model_name();
2649
+                $classname = 'EE_'.$this->get_model()->get_this_model_name();
2650 2650
                 if (
2651 2651
                     $this->get_one_from_cache($relation_name) instanceof $classname
2652 2652
                     && $this->get_one_from_cache($relation_name)->ID()
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
      * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704 704
      *
705 705
      * @access protected
706
-     * @return void
706
+     * @return false|null
707 707
      */
708 708
     protected function _verify_routes()
709 709
     {
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
      * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758 758
      *
759 759
      * @param  string $route the route name we're verifying
760
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
760
+     * @return boolean  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761 761
      */
762 762
     protected function _verify_route($route)
763 763
     {
@@ -3247,7 +3247,7 @@  discard block
 block discarded – undo
3247 3247
 
3248 3248
 
3249 3249
     /**
3250
-     * @return mixed
3250
+     * @return string[]
3251 3251
      */
3252 3252
     public function default_espresso_metaboxes()
3253 3253
     {
@@ -3267,7 +3267,7 @@  discard block
 block discarded – undo
3267 3267
 
3268 3268
 
3269 3269
     /**
3270
-     * @return mixed
3270
+     * @return string
3271 3271
      */
3272 3272
     public function wp_page_slug()
3273 3273
     {
Please login to merge, or discard this patch.
Indentation   +3305 added lines, -3305 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
@@ -28,2120 +28,2120 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    //set in _init_page_props()
32
-    public $page_slug;
31
+	//set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    //set in define_page_props()
39
-    protected $_admin_base_url;
38
+	//set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    //set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	//set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    //navtabs
52
-    protected $_nav_tabs;
51
+	//navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    //helptourstops
57
-    protected $_help_tour = array();
56
+	//helptourstops
57
+	protected $_help_tour = array();
58 58
 
59 59
 
60
-    //template variables (used by templates)
61
-    protected $_template_path;
60
+	//template variables (used by templates)
61
+	protected $_template_path;
62 62
 
63
-    protected $_column_template_path;
63
+	protected $_column_template_path;
64 64
 
65
-    /**
66
-     * @var array $_template_args
67
-     */
68
-    protected $_template_args = array();
65
+	/**
66
+	 * @var array $_template_args
67
+	 */
68
+	protected $_template_args = array();
69 69
 
70
-    /**
71
-     * this will hold the list table object for a given view.
72
-     *
73
-     * @var EE_Admin_List_Table $_list_table_object
74
-     */
75
-    protected $_list_table_object;
70
+	/**
71
+	 * this will hold the list table object for a given view.
72
+	 *
73
+	 * @var EE_Admin_List_Table $_list_table_object
74
+	 */
75
+	protected $_list_table_object;
76 76
 
77
-    //bools
78
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
77
+	//bools
78
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79 79
 
80
-    protected $_routing;
80
+	protected $_routing;
81 81
 
82
-    //list table args
83
-    protected $_view;
82
+	//list table args
83
+	protected $_view;
84 84
 
85
-    protected $_views;
85
+	protected $_views;
86 86
 
87 87
 
88
-    //action => method pairs used for routing incoming requests
89
-    protected $_page_routes;
88
+	//action => method pairs used for routing incoming requests
89
+	protected $_page_routes;
90 90
 
91
-    protected $_page_config;
91
+	protected $_page_config;
92 92
 
93
-    //the current page route and route config
94
-    protected $_route;
93
+	//the current page route and route config
94
+	protected $_route;
95 95
 
96
-    protected $_route_config;
96
+	protected $_route_config;
97 97
 
98
-    /**
99
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
-     * actions.
101
-     *
102
-     * @since 4.6.x
103
-     * @var array.
104
-     */
105
-    protected $_default_route_query_args;
98
+	/**
99
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
+	 * actions.
101
+	 *
102
+	 * @since 4.6.x
103
+	 * @var array.
104
+	 */
105
+	protected $_default_route_query_args;
106 106
 
107
-    //set via request page and action args.
108
-    protected $_current_page;
107
+	//set via request page and action args.
108
+	protected $_current_page;
109 109
 
110
-    protected $_current_view;
110
+	protected $_current_view;
111 111
 
112
-    protected $_current_page_view_url;
112
+	protected $_current_page_view_url;
113 113
 
114
-    //sanitized request action (and nonce)
115
-    /**
116
-     * @var string $_req_action
117
-     */
118
-    protected $_req_action;
114
+	//sanitized request action (and nonce)
115
+	/**
116
+	 * @var string $_req_action
117
+	 */
118
+	protected $_req_action;
119 119
 
120
-    /**
121
-     * @var string $_req_nonce
122
-     */
123
-    protected $_req_nonce;
120
+	/**
121
+	 * @var string $_req_nonce
122
+	 */
123
+	protected $_req_nonce;
124 124
 
125
-    //search related
126
-    protected $_search_btn_label;
125
+	//search related
126
+	protected $_search_btn_label;
127 127
 
128
-    protected $_search_box_callback;
128
+	protected $_search_box_callback;
129 129
 
130
-    /**
131
-     * WP Current Screen object
132
-     *
133
-     * @var WP_Screen
134
-     */
135
-    protected $_current_screen;
130
+	/**
131
+	 * WP Current Screen object
132
+	 *
133
+	 * @var WP_Screen
134
+	 */
135
+	protected $_current_screen;
136 136
 
137
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
-    protected $_hook_obj;
137
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
+	protected $_hook_obj;
139 139
 
140
-    //for holding incoming request data
141
-    protected $_req_data;
140
+	//for holding incoming request data
141
+	protected $_req_data;
142 142
 
143
-    // yes / no array for admin form fields
144
-    protected $_yes_no_values = array();
145
-
146
-    //some default things shared by all child classes
147
-    protected $_default_espresso_metaboxes;
148
-
149
-    /**
150
-     *    EE_Registry Object
151
-     *
152
-     * @var    EE_Registry
153
-     * @access    protected
154
-     */
155
-    protected $EE = null;
156
-
157
-
158
-
159
-    /**
160
-     * This is just a property that flags whether the given route is a caffeinated route or not.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $_is_caf = false;
165
-
166
-
167
-
168
-    /**
169
-     * @Constructor
170
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
-     * @access public
172
-     */
173
-    public function __construct($routing = true)
174
-    {
175
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
-            $this->_is_caf = true;
177
-        }
178
-        $this->_yes_no_values = array(
179
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
-                array('id' => false, 'text' => __('No', 'event_espresso')),
181
-        );
182
-        //set the _req_data property.
183
-        $this->_req_data = array_merge($_GET, $_POST);
184
-        //routing enabled?
185
-        $this->_routing = $routing;
186
-        //set initial page props (child method)
187
-        $this->_init_page_props();
188
-        //set global defaults
189
-        $this->_set_defaults();
190
-        //set early because incoming requests could be ajax related and we need to register those hooks.
191
-        $this->_global_ajax_hooks();
192
-        $this->_ajax_hooks();
193
-        //other_page_hooks have to be early too.
194
-        $this->_do_other_page_hooks();
195
-        //This just allows us to have extending classes do something specific
196
-        // before the parent constructor runs _page_setup().
197
-        if (method_exists($this, '_before_page_setup')) {
198
-            $this->_before_page_setup();
199
-        }
200
-        //set up page dependencies
201
-        $this->_page_setup();
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * _init_page_props
208
-     * Child classes use to set at least the following properties:
209
-     * $page_slug.
210
-     * $page_label.
211
-     *
212
-     * @abstract
213
-     * @access protected
214
-     * @return void
215
-     */
216
-    abstract protected function _init_page_props();
217
-
218
-
219
-
220
-    /**
221
-     * _ajax_hooks
222
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
-     * Note: within the ajax callback methods.
224
-     *
225
-     * @abstract
226
-     * @access protected
227
-     * @return void
228
-     */
229
-    abstract protected function _ajax_hooks();
230
-
231
-
232
-
233
-    /**
234
-     * _define_page_props
235
-     * child classes define page properties in here.  Must include at least:
236
-     * $_admin_base_url = base_url for all admin pages
237
-     * $_admin_page_title = default admin_page_title for admin pages
238
-     * $_labels = array of default labels for various automatically generated elements:
239
-     *    array(
240
-     *        'buttons' => array(
241
-     *            'add' => __('label for add new button'),
242
-     *            'edit' => __('label for edit button'),
243
-     *            'delete' => __('label for delete button')
244
-     *            )
245
-     *        )
246
-     *
247
-     * @abstract
248
-     * @access protected
249
-     * @return void
250
-     */
251
-    abstract protected function _define_page_props();
252
-
253
-
254
-
255
-    /**
256
-     * _set_page_routes
257
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
-     * route. Here's the format
259
-     * $this->_page_routes = array(
260
-     *        'default' => array(
261
-     *            'func' => '_default_method_handling_route',
262
-     *            'args' => array('array','of','args'),
263
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
-     *        ),
268
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
-     *        )
270
-     * )
271
-     *
272
-     * @abstract
273
-     * @access protected
274
-     * @return void
275
-     */
276
-    abstract protected function _set_page_routes();
277
-
278
-
279
-
280
-    /**
281
-     * _set_page_config
282
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
-     * Format:
284
-     * $this->_page_config = array(
285
-     *        'default' => array(
286
-     *            'labels' => array(
287
-     *                'buttons' => array(
288
-     *                    'add' => __('label for adding item'),
289
-     *                    'edit' => __('label for editing item'),
290
-     *                    'delete' => __('label for deleting item')
291
-     *                ),
292
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
-     *            'nav' => array(
295
-     *                'label' => __('Label for Tab', 'event_espresso').
296
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
-     *                'order' => 10, //required to indicate tab position.
299
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
-     *            this flag to make sure the necessary js gets enqueued on page load.
304
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
308
-     *                'tab_id' => array(
309
-     *                    'title' => 'tab_title',
310
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
-     *                    ),
314
-     *                'tab2_id' => array(
315
-     *                    'title' => 'tab2 title',
316
-     *                    'filename' => 'file_name_2'
317
-     *                    'callback' => 'callback_method_for_content',
318
-     *                 ),
319
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
-     *            'help_tour' => array(
321
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
-     *            ),
324
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
-     *            'require_nonce' to FALSE
326
-     *            )
327
-     * )
328
-     *
329
-     * @abstract
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    abstract protected function _set_page_config();
334
-
335
-
336
-
337
-
338
-
339
-    /** end sample help_tour methods **/
340
-    /**
341
-     * _add_screen_options
342
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
-     *
345
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
-     *         see also WP_Screen object documents...
347
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
-     * @abstract
349
-     * @access protected
350
-     * @return void
351
-     */
352
-    abstract protected function _add_screen_options();
353
-
354
-
355
-
356
-    /**
357
-     * _add_feature_pointers
358
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
-     * Note: this is just a placeholder for now.  Implementation will come down the road
361
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
-     *
363
-     * @link   http://eamann.com/tech/wordpress-portland/
364
-     * @abstract
365
-     * @access protected
366
-     * @return void
367
-     */
368
-    abstract protected function _add_feature_pointers();
369
-
370
-
371
-
372
-    /**
373
-     * load_scripts_styles
374
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
-     *
377
-     * @abstract
378
-     * @access public
379
-     * @return void
380
-     */
381
-    abstract public function load_scripts_styles();
382
-
383
-
384
-
385
-    /**
386
-     * admin_init
387
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
-     *
389
-     * @abstract
390
-     * @access public
391
-     * @return void
392
-     */
393
-    abstract public function admin_init();
394
-
395
-
396
-
397
-    /**
398
-     * admin_notices
399
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
-     *
401
-     * @abstract
402
-     * @access public
403
-     * @return void
404
-     */
405
-    abstract public function admin_notices();
406
-
407
-
408
-
409
-    /**
410
-     * admin_footer_scripts
411
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
-     *
413
-     * @access public
414
-     * @return void
415
-     */
416
-    abstract public function admin_footer_scripts();
417
-
418
-
419
-
420
-    /**
421
-     * admin_footer
422
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
-     *
424
-     * @access  public
425
-     * @return void
426
-     */
427
-    public function admin_footer()
428
-    {
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * _global_ajax_hooks
435
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
-     * Note: within the ajax callback methods.
437
-     *
438
-     * @abstract
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _global_ajax_hooks()
443
-    {
444
-        //for lazy loading of metabox content
445
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
-    }
447
-
448
-
449
-
450
-    public function ajax_metabox_content()
451
-    {
452
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
-        self::cached_rss_display($contentid, $url);
455
-        wp_die();
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * _page_setup
462
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
-     *
464
-     * @final
465
-     * @access protected
466
-     * @return void
467
-     */
468
-    final protected function _page_setup()
469
-    {
470
-        //requires?
471
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
472
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
473
-        //next verify if we need to load anything...
474
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
-        global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
478
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
-            return;
480
-        }
481
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
482
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
-        }
485
-        // then set blank or -1 action values to 'default'
486
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
493
-        $this->_define_page_props();
494
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
-        //default things
496
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
-        //set page configs
498
-        $this->_set_page_routes();
499
-        $this->_set_page_config();
500
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
501
-        if (isset($this->_req_data['wp_referer'])) {
502
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
-        }
504
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
-        if (method_exists($this, '_extend_page_config')) {
506
-            $this->_extend_page_config();
507
-        }
508
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
510
-            $this->_extend_page_config_for_cpt();
511
-        }
512
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
-        }
519
-        //next route only if routing enabled
520
-        if ($this->_routing && ! defined('DOING_AJAX')) {
521
-            $this->_verify_routes();
522
-            //next let's just check user_access and kill if no access
523
-            $this->check_user_access();
524
-            if ($this->_is_UI_request) {
525
-                //admin_init stuff - global, all views for this page class, specific view
526
-                add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
-                }
530
-            } else {
531
-                //hijack regular WP loading and route admin request immediately
532
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
-                $this->route_admin_request();
534
-            }
535
-        }
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
-     *
543
-     * @access private
544
-     * @return void
545
-     */
546
-    private function _do_other_page_hooks()
547
-    {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
-        foreach ($registered_pages as $page) {
550
-            //now let's setup the file name and class that should be present
551
-            $classname = str_replace('.class.php', '', $page);
552
-            //autoloaders should take care of loading file
553
-            if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
-                $error_msg[] = $error_msg[0]
556
-                               . "\r\n"
557
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
-                throw new EE_Error(implode('||', $error_msg));
560
-            }
561
-            $a = new ReflectionClass($classname);
562
-            //notice we are passing the instance of this class to the hook object.
563
-            $hookobj[] = $a->newInstance($this);
564
-        }
565
-    }
566
-
567
-
568
-
569
-    public function load_page_dependencies()
570
-    {
571
-        try {
572
-            $this->_load_page_dependencies();
573
-        } catch (EE_Error $e) {
574
-            $e->get_error();
575
-        }
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * load_page_dependencies
582
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
-     *
584
-     * @access public
585
-     * @return void
586
-     */
587
-    protected function _load_page_dependencies()
588
-    {
589
-        //let's set the current_screen and screen options to override what WP set
590
-        $this->_current_screen = get_current_screen();
591
-        //load admin_notices - global, page class, and view specific
592
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
-        }
597
-        //load network admin_notices - global, page class, and view specific
598
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
-        }
602
-        //this will save any per_page screen options if they are present
603
-        $this->_set_per_page_screen_options();
604
-        //setup list table properties
605
-        $this->_set_list_table();
606
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
-        $this->_add_registered_meta_boxes();
608
-        $this->_add_screen_columns();
609
-        //add screen options - global, page child class, and view specific
610
-        $this->_add_global_screen_options();
611
-        $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
-        }
615
-        //add help tab(s) and tours- set via page_config and qtips.
616
-        $this->_add_help_tour();
617
-        $this->_add_help_tabs();
618
-        $this->_add_qtips();
619
-        //add feature_pointers - global, page child class, and view specific
620
-        $this->_add_feature_pointers();
621
-        $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
-        }
625
-        //enqueue scripts/styles - global, page class, and view specific
626
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
-        }
631
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
-        }
638
-        //admin footer scripts
639
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
-        }
644
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
-        //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * _set_defaults
653
-     * This sets some global defaults for class properties.
654
-     */
655
-    private function _set_defaults()
656
-    {
657
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
-        $this->default_nav_tab_name = 'overview';
660
-        //init template args
661
-        $this->_template_args = array(
662
-                'admin_page_header'  => '',
663
-                'admin_page_content' => '',
664
-                'post_body_content'  => '',
665
-                'before_list_table'  => '',
666
-                'after_list_table'   => '',
667
-        );
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * route_admin_request
674
-     *
675
-     * @see    _route_admin_request()
676
-     * @access public
677
-     * @return void|exception error
678
-     */
679
-    public function route_admin_request()
680
-    {
681
-        try {
682
-            $this->_route_admin_request();
683
-        } catch (EE_Error $e) {
684
-            $e->get_error();
685
-        }
686
-    }
687
-
688
-
689
-
690
-    public function set_wp_page_slug($wp_page_slug)
691
-    {
692
-        $this->_wp_page_slug = $wp_page_slug;
693
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
-        if (is_network_admin()) {
695
-            $this->_wp_page_slug .= '-network';
696
-        }
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * _verify_routes
703
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
-     *
705
-     * @access protected
706
-     * @return void
707
-     */
708
-    protected function _verify_routes()
709
-    {
710
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
-            return false;
713
-        }
714
-        $this->_route = false;
715
-        $func = false;
716
-        $args = array();
717
-        // check that the page_routes array is not empty
718
-        if (empty($this->_page_routes)) {
719
-            // user error msg
720
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
-            // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
-            throw new EE_Error($error_msg);
724
-        }
725
-        // and that the requested page route exists
726
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
-            $this->_route = $this->_page_routes[$this->_req_action];
728
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
-        } else {
730
-            // user error msg
731
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
-            // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
-            throw new EE_Error($error_msg);
735
-        }
736
-        // and that a default route exists
737
-        if ( ! array_key_exists('default', $this->_page_routes)) {
738
-            // user error msg
739
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
-            // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
-            throw new EE_Error($error_msg);
743
-        }
744
-        //first lets' catch if the UI request has EVER been set.
745
-        if ($this->_is_UI_request === null) {
746
-            //lets set if this is a UI request or not.
747
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
-            //wait a minute... we might have a noheader in the route array
749
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
-        }
751
-        $this->_set_current_labels();
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
-     *
759
-     * @param  string $route the route name we're verifying
760
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
-     */
762
-    protected function _verify_route($route)
763
-    {
764
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
-            return true;
766
-        } else {
767
-            // user error msg
768
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
-            // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
-            throw new EE_Error($error_msg);
772
-        }
773
-    }
774
-
775
-
776
-
777
-    /**
778
-     * perform nonce verification
779
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
-     *
781
-     * @param  string $nonce     The nonce sent
782
-     * @param  string $nonce_ref The nonce reference string (name0)
783
-     * @return mixed (bool|die)
784
-     */
785
-    protected function _verify_nonce($nonce, $nonce_ref)
786
-    {
787
-        // verify nonce against expected value
788
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
-            // these are not the droids you are looking for !!!
790
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
-            if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
-            }
794
-            if ( ! defined('DOING_AJAX')) {
795
-                wp_die($msg);
796
-            } else {
797
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
-                $this->_return_json();
799
-            }
800
-        }
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * _route_admin_request()
807
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
-     * in the page routes and then will try to load the corresponding method.
810
-     *
811
-     * @access protected
812
-     * @return void
813
-     * @throws \EE_Error
814
-     */
815
-    protected function _route_admin_request()
816
-    {
817
-        if ( ! $this->_is_UI_request) {
818
-            $this->_verify_routes();
819
-        }
820
-        $nonce_check = isset($this->_route_config['require_nonce'])
821
-            ? $this->_route_config['require_nonce']
822
-            : true;
823
-        if ($this->_req_action !== 'default' && $nonce_check) {
824
-            // set nonce from post data
825
-            $nonce = isset($this->_req_data[$this->_req_nonce])
826
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
-                : '';
828
-            $this->_verify_nonce($nonce, $this->_req_nonce);
829
-        }
830
-        //set the nav_tabs array but ONLY if this is  UI_request
831
-        if ($this->_is_UI_request) {
832
-            $this->_set_nav_tabs();
833
-        }
834
-        // grab callback function
835
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
-        // check if callback has args
837
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
-        $error_msg = '';
839
-        // action right before calling route
840
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
-        }
844
-        // right before calling the route, let's remove _wp_http_referer from the
845
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
-        if ( ! empty($func)) {
848
-            if (is_array($func)) {
849
-                list($class, $method) = $func;
850
-            } else if (strpos($func, '::') !== false) {
851
-                list($class, $method) = explode('::', $func);
852
-            } else {
853
-                $class = $this;
854
-                $method = $func;
855
-            }
856
-            if ( ! (is_object($class) && $class === $this)) {
857
-                // send along this admin page object for access by addons.
858
-                $args['admin_page_object'] = $this;
859
-            }
860
-
861
-            if (
862
-                //is it a method on a class that doesn't work?
863
-                (
864
-                    (
865
-                        method_exists($class, $method)
866
-                        && call_user_func_array(array($class, $method), $args) === false
867
-                    )
868
-                    && (
869
-                        //is it a standalone function that doesn't work?
870
-                        function_exists($method)
871
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
-                    )
873
-                )
874
-                || (
875
-                    //is it neither a class method NOR a standalone function?
876
-                    ! method_exists($class, $method)
877
-                    && ! function_exists($method)
878
-                )
879
-            ) {
880
-                // user error msg
881
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
-                // developer error msg
883
-                $error_msg .= '||';
884
-                $error_msg .= sprintf(
885
-                    __(
886
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
-                        'event_espresso'
888
-                    ),
889
-                    $method
890
-                );
891
-            }
892
-            if ( ! empty($error_msg)) {
893
-                throw new EE_Error($error_msg);
894
-            }
895
-        }
896
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
898
-        if ($this->_is_UI_request === false
899
-            && is_array($this->_route)
900
-            && ! empty($this->_route['headers_sent_route'])
901
-        ) {
902
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
903
-        }
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * This method just allows the resetting of page properties in the case where a no headers
910
-     * route redirects to a headers route in its route config.
911
-     *
912
-     * @since   4.3.0
913
-     * @param  string $new_route New (non header) route to redirect to.
914
-     * @return   void
915
-     */
916
-    protected function _reset_routing_properties($new_route)
917
-    {
918
-        $this->_is_UI_request = true;
919
-        //now we set the current route to whatever the headers_sent_route is set at
920
-        $this->_req_data['action'] = $new_route;
921
-        //rerun page setup
922
-        $this->_page_setup();
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * _add_query_arg
929
-     * adds nonce to array of arguments then calls WP add_query_arg function
930
-     *(internally just uses EEH_URL's function with the same name)
931
-     *
932
-     * @access public
933
-     * @param array  $args
934
-     * @param string $url
935
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
-     *                                        url in an associative array indexed by the key 'wp_referer';
937
-     *                                        Example usage:
938
-     *                                        If the current page is:
939
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
-     *                                        &action=default&event_id=20&month_range=March%202015
941
-     *                                        &_wpnonce=5467821
942
-     *                                        and you call:
943
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
944
-     *                                        array(
945
-     *                                        'action' => 'resend_something',
946
-     *                                        'page=>espresso_registrations'
947
-     *                                        ),
948
-     *                                        $some_url,
949
-     *                                        true
950
-     *                                        );
951
-     *                                        It will produce a url in this structure:
952
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
-     *                                        month_range]=March%202015
955
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
-     * @return string
957
-     */
958
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
-    {
960
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
961
-        if ($sticky) {
962
-            $request = $_REQUEST;
963
-            unset($request['_wp_http_referer']);
964
-            unset($request['wp_referer']);
965
-            foreach ($request as $key => $value) {
966
-                //do not add nonces
967
-                if (strpos($key, 'nonce') !== false) {
968
-                    continue;
969
-                }
970
-                $args['wp_referer[' . $key . ']'] = $value;
971
-            }
972
-        }
973
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * This returns a generated link that will load the related help tab.
980
-     *
981
-     * @param  string $help_tab_id the id for the connected help tab
982
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
-     * @uses EEH_Template::get_help_tab_link()
985
-     * @return string              generated link
986
-     */
987
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
-    {
989
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
-    }
991
-
992
-
993
-
994
-    /**
995
-     * _add_help_tabs
996
-     * Note child classes define their help tabs within the page_config array.
997
-     *
998
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
-     * @access protected
1000
-     * @return void
1001
-     */
1002
-    protected function _add_help_tabs()
1003
-    {
1004
-        $tour_buttons = '';
1005
-        if (isset($this->_page_config[$this->_req_action])) {
1006
-            $config = $this->_page_config[$this->_req_action];
1007
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1008
-            if (isset($this->_help_tour[$this->_req_action])) {
1009
-                $tb = array();
1010
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
-                foreach ($this->_help_tour['tours'] as $tour) {
1012
-                    //if this is the end tour then we don't need to setup a button
1013
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1014
-                        continue;
1015
-                    }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
-                }
1018
-                $tour_buttons .= implode('<br />', $tb);
1019
-                $tour_buttons .= '</div></div>';
1020
-            }
1021
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
-            if (is_array($config) && isset($config['help_sidebar'])) {
1023
-                //check that the callback given is valid
1024
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1025
-                    throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
-                }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
-                $content .= $tour_buttons; //add help tour buttons.
1030
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1031
-                $this->_current_screen->set_help_sidebar($content);
1032
-            }
1033
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1036
-            }
1037
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
-                $_ht['id'] = $this->page_slug;
1040
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
-                $this->_current_screen->add_help_tab($_ht);
1043
-            }/**/
1044
-            if ( ! isset($config['help_tabs'])) {
1045
-                return;
1046
-            } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
-                //we're here so there ARE help tabs!
1049
-                //make sure we've got what we need
1050
-                if ( ! isset($cfg['title'])) {
1051
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
-                }
1053
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
-                    throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1055
-                            'event_espresso'));
1056
-                }
1057
-                //first priority goes to content.
1058
-                if ( ! empty($cfg['content'])) {
1059
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
-                    //second priority goes to filename
1061
-                } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
-                        EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1068
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
-                        return;
1070
-                    }
1071
-                    $template_args['admin_page_obj'] = $this;
1072
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1073
-                } else {
1074
-                    $content = '';
1075
-                }
1076
-                //check if callback is valid
1077
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
-                    EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1079
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
-                    return;
1081
-                }
1082
-                //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
-                $_ht = array(
1085
-                        'id'       => $id,
1086
-                        'title'    => $cfg['title'],
1087
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
-                        'content'  => $content,
1089
-                );
1090
-                $this->_current_screen->add_help_tab($_ht);
1091
-            }
1092
-        }
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
-     *
1100
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
-     * @access protected
1103
-     * @return void
1104
-     */
1105
-    protected function _add_help_tour()
1106
-    {
1107
-        $tours = array();
1108
-        $this->_help_tour = array();
1109
-        //exit early if help tours are turned off globally
1110
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
-            return;
1112
-        }
1113
-        //loop through _page_config to find any help_tour defined
1114
-        foreach ($this->_page_config as $route => $config) {
1115
-            //we're only going to set things up for this route
1116
-            if ($route !== $this->_req_action) {
1117
-                continue;
1118
-            }
1119
-            if (isset($config['help_tour'])) {
1120
-                foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
-                    if ( ! is_readable($file_path)) {
1126
-                        EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1127
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
-                        return;
1129
-                    }
1130
-                    require_once $file_path;
1131
-                    if ( ! class_exists($tour)) {
1132
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
-                        throw new EE_Error(implode('||', $error_msg));
1136
-                    }
1137
-                    $a = new ReflectionClass($tour);
1138
-                    $tour_obj = $a->newInstance($this->_is_caf);
1139
-                    $tours[] = $tour_obj;
1140
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
-                }
1142
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
-                $tours[] = $end_stop_tour;
1145
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
-            }
1147
-        }
1148
-        if ( ! empty($tours)) {
1149
-            $this->_help_tour['tours'] = $tours;
1150
-        }
1151
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * This simply sets up any qtips that have been defined in the page config
1158
-     *
1159
-     * @access protected
1160
-     * @return void
1161
-     */
1162
-    protected function _add_qtips()
1163
-    {
1164
-        if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1166
-            //load qtip loader
1167
-            $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
-            );
1171
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
-        }
1173
-    }
1174
-
1175
-
1176
-
1177
-    /**
1178
-     * _set_nav_tabs
1179
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
-     *
1181
-     * @access protected
1182
-     * @return void
1183
-     */
1184
-    protected function _set_nav_tabs()
1185
-    {
1186
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
-        $i = 0;
1188
-        foreach ($this->_page_config as $slug => $config) {
1189
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
-                continue;
1191
-            } //no nav tab for this config
1192
-            //check for persistent flag
1193
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
-                continue;
1195
-            } //nav tab is only to appear when route requested.
1196
-            if ( ! $this->check_user_access($slug, true)) {
1197
-                continue;
1198
-            } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
-            $this->_nav_tabs[$slug] = array(
1201
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
-            );
1206
-            $i++;
1207
-        }
1208
-        //if $this->_nav_tabs is empty then lets set the default
1209
-        if (empty($this->_nav_tabs)) {
1210
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
-                    'url'       => $this->admin_base_url,
1212
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
-                    'css_class' => 'nav-tab-active',
1214
-                    'order'     => 10,
1215
-            );
1216
-        }
1217
-        //now let's sort the tabs according to order
1218
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
-    }
1220
-
1221
-
1222
-
1223
-    /**
1224
-     * _set_current_labels
1225
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
-     *
1227
-     * @access private
1228
-     * @return void
1229
-     */
1230
-    private function _set_current_labels()
1231
-    {
1232
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
-            foreach ($this->_route_config['labels'] as $label => $text) {
1234
-                if (is_array($text)) {
1235
-                    foreach ($text as $sublabel => $subtext) {
1236
-                        $this->_labels[$label][$sublabel] = $subtext;
1237
-                    }
1238
-                } else {
1239
-                    $this->_labels[$label] = $text;
1240
-                }
1241
-            }
1242
-        }
1243
-    }
1244
-
1245
-
1246
-
1247
-    /**
1248
-     *        verifies user access for this admin page
1249
-     *
1250
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
-     * @return        BOOL|wp_die()
1253
-     */
1254
-    public function check_user_access($route_to_check = '', $verify_only = false)
1255
-    {
1256
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1260
-        if (empty($capability) && empty($route_to_check)) {
1261
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
-        } else {
1263
-            $capability = empty($capability) ? 'manage_options' : $capability;
1264
-        }
1265
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
-            if ($verify_only) {
1268
-                return false;
1269
-            } else {
1270
-                if ( is_user_logged_in() ) {
1271
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
-                } else {
1273
-                    return false;
1274
-                }
1275
-            }
1276
-        }
1277
-        return true;
1278
-    }
1279
-
1280
-
1281
-
1282
-    /**
1283
-     * admin_init_global
1284
-     * This runs all the code that we want executed within the WP admin_init hook.
1285
-     * This method executes for ALL EE Admin pages.
1286
-     *
1287
-     * @access public
1288
-     * @return void
1289
-     */
1290
-    public function admin_init_global()
1291
-    {
1292
-    }
1293
-
1294
-
1295
-
1296
-    /**
1297
-     * wp_loaded_global
1298
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
-     *
1300
-     * @access public
1301
-     * @return void
1302
-     */
1303
-    public function wp_loaded()
1304
-    {
1305
-    }
1306
-
1307
-
1308
-
1309
-    /**
1310
-     * admin_notices
1311
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
-     *
1313
-     * @access public
1314
-     * @return void
1315
-     */
1316
-    public function admin_notices_global()
1317
-    {
1318
-        $this->_display_no_javascript_warning();
1319
-        $this->_display_espresso_notices();
1320
-    }
1321
-
1322
-
1323
-
1324
-    public function network_admin_notices_global()
1325
-    {
1326
-        $this->_display_no_javascript_warning();
1327
-        $this->_display_espresso_notices();
1328
-    }
1329
-
1330
-
1331
-
1332
-    /**
1333
-     * admin_footer_scripts_global
1334
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
-     *
1336
-     * @access public
1337
-     * @return void
1338
-     */
1339
-    public function admin_footer_scripts_global()
1340
-    {
1341
-        $this->_add_admin_page_ajax_loading_img();
1342
-        $this->_add_admin_page_overlay();
1343
-        //if metaboxes are present we need to add the nonce field
1344
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
-        }
1348
-    }
1349
-
1350
-
1351
-
1352
-    /**
1353
-     * admin_footer_global
1354
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
-     *
1356
-     * @access  public
1357
-     * @return  void
1358
-     */
1359
-    public function admin_footer_global()
1360
-    {
1361
-        //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
-        $d_cont .= '<div class="ee-notices"></div>';
1364
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
-        $d_cont .= '</div>';
1366
-        echo $d_cont;
1367
-        //help tour stuff?
1368
-        if (isset($this->_help_tour[$this->_req_action])) {
1369
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
-        }
1371
-        //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
-     * For child classes:
1380
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
-     *    'help_trigger_id' => array(
1384
-     *        'title' => __('localized title for popup', 'event_espresso'),
1385
-     *        'content' => __('localized content for popup', 'event_espresso')
1386
-     *    )
1387
-     * );
1388
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
-     *
1390
-     * @access protected
1391
-     * @return string content
1392
-     */
1393
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1394
-    {
1395
-        $content = '';
1396
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
-        //loop through the array and setup content
1399
-        foreach ($help_array as $trigger => $help) {
1400
-            //make sure the array is setup properly
1401
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
-                throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1403
-                        'event_espresso'));
1404
-            }
1405
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
-            $template_args = array(
1407
-                    'help_popup_id'      => $trigger,
1408
-                    'help_popup_title'   => $help['title'],
1409
-                    'help_popup_content' => $help['content'],
1410
-            );
1411
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1412
-        }
1413
-        if ($display) {
1414
-            echo $content;
1415
-        } else {
1416
-            return $content;
1417
-        }
1418
-    }
1419
-
1420
-
1421
-
1422
-    /**
1423
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
-     *
1425
-     * @access private
1426
-     * @return array properly formatted array for help popup content
1427
-     */
1428
-    private function _get_help_content()
1429
-    {
1430
-        //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1432
-        //if method doesn't exist let's get out.
1433
-        if ( ! method_exists($this, $method_name)) {
1434
-            return array();
1435
-        }
1436
-        //k we're good to go let's retrieve the help array
1437
-        $help_array = call_user_func(array($this, $method_name));
1438
-        //make sure we've got an array!
1439
-        if ( ! is_array($help_array)) {
1440
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
-        }
1442
-        return $help_array;
1443
-    }
1444
-
1445
-
1446
-
1447
-    /**
1448
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
-     *
1452
-     * @access protected
1453
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
-     * @param boolean $display    if false then we return the trigger string
1455
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
-     * @return string
1457
-     */
1458
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
-    {
1460
-        if (defined('DOING_AJAX')) {
1461
-            return;
1462
-        }
1463
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1464
-        $help_array = $this->_get_help_content();
1465
-        $help_content = '';
1466
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
-            $help_array[$trigger_id] = array(
1468
-                    'title'   => __('Missing Content', 'event_espresso'),
1469
-                    'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1470
-                            'event_espresso'),
1471
-            );
1472
-            $help_content = $this->_set_help_popup_content($help_array, false);
1473
-        }
1474
-        //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1477
-        if ($display) {
1478
-            echo $content;
1479
-        } else {
1480
-            return $content;
1481
-        }
1482
-    }
1483
-
1484
-
1485
-
1486
-    /**
1487
-     * _add_global_screen_options
1488
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1490
-     *
1491
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
-     *         see also WP_Screen object documents...
1493
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
-     * @abstract
1495
-     * @access private
1496
-     * @return void
1497
-     */
1498
-    private function _add_global_screen_options()
1499
-    {
1500
-    }
1501
-
1502
-
1503
-
1504
-    /**
1505
-     * _add_global_feature_pointers
1506
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1509
-     *
1510
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
-     * @link   http://eamann.com/tech/wordpress-portland/
1512
-     * @abstract
1513
-     * @access protected
1514
-     * @return void
1515
-     */
1516
-    private function _add_global_feature_pointers()
1517
-    {
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * load_global_scripts_styles
1524
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
-     *
1526
-     * @return void
1527
-     */
1528
-    public function load_global_scripts_styles()
1529
-    {
1530
-        /** STYLES **/
1531
-        // add debugging styles
1532
-        if (WP_DEBUG) {
1533
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1534
-        }
1535
-        //register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
-        //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        //enqueue global styles
1541
-        wp_enqueue_style('ee-admin-css');
1542
-        /** SCRIPTS **/
1543
-        //register all scripts
1544
-        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1545
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1546
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1547
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1548
-        // register jQuery Validate - see /includes/functions/wp_hooks.php
1549
-        add_filter('FHEE_load_jquery_validate', '__return_true');
1550
-        add_filter('FHEE_load_joyride', '__return_true');
1551
-        //script for sorting tables
1552
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1553
-        //script for parsing uri's
1554
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
-        //and parsing associative serialized form elements
1556
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1557
-        //helpers scripts
1558
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1559
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1560
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1561
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1562
-        //google charts
1563
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1564
-        //enqueue global scripts
1565
-        //taking care of metaboxes
1566
-        if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) {
1567
-            wp_enqueue_script('dashboard');
1568
-        }
1569
-        //enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1570
-        if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) {
1571
-            wp_enqueue_script('ee_admin_js');
1572
-            wp_enqueue_style('ee-admin-css');
1573
-        }
1574
-        //localize script for ajax lazy loading
1575
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
-        /**
1578
-         * help tour stuff
1579
-         */
1580
-        if ( ! empty($this->_help_tour)) {
1581
-            //register the js for kicking things off
1582
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
-            //setup tours for the js tour object
1584
-            foreach ($this->_help_tour['tours'] as $tour) {
1585
-                $tours[] = array(
1586
-                        'id'      => $tour->get_slug(),
1587
-                        'options' => $tour->get_options(),
1588
-                );
1589
-            }
1590
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
-        }
1593
-    }
1594
-
1595
-
1596
-
1597
-    /**
1598
-     *        admin_footer_scripts_eei18n_js_strings
1599
-     *
1600
-     * @access        public
1601
-     * @return        void
1602
-     */
1603
-    public function admin_footer_scripts_eei18n_js_strings()
1604
-    {
1605
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
-        //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1646
-        //admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1647
-        //espresso_core is listed as a dependency of ee_admin_js.
1648
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
1649
-    }
1650
-
1651
-
1652
-
1653
-    /**
1654
-     *        load enhanced xdebug styles for ppl with failing eyesight
1655
-     *
1656
-     * @access        public
1657
-     * @return        void
1658
-     */
1659
-    public function add_xdebug_style()
1660
-    {
1661
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1662
-    }
1663
-
1664
-
1665
-    /************************/
1666
-    /** LIST TABLE METHODS **/
1667
-    /************************/
1668
-    /**
1669
-     * this sets up the list table if the current view requires it.
1670
-     *
1671
-     * @access protected
1672
-     * @return void
1673
-     */
1674
-    protected function _set_list_table()
1675
-    {
1676
-        //first is this a list_table view?
1677
-        if ( ! isset($this->_route_config['list_table'])) {
1678
-            return;
1679
-        } //not a list_table view so get out.
1680
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1681
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1682
-            //user error msg
1683
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1684
-            //developer error msg
1685
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1686
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1687
-            throw new EE_Error($error_msg);
1688
-        }
1689
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1690
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1691
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1692
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1693
-        $this->_set_list_table_view();
1694
-        $this->_set_list_table_object();
1695
-    }
1696
-
1697
-
1698
-
1699
-    /**
1700
-     *        set current view for List Table
1701
-     *
1702
-     * @access public
1703
-     * @return array
1704
-     */
1705
-    protected function _set_list_table_view()
1706
-    {
1707
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1708
-        // looking at active items or dumpster diving ?
1709
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1710
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1711
-        } else {
1712
-            $this->_view = sanitize_key($this->_req_data['status']);
1713
-        }
1714
-    }
1715
-
1716
-
1717
-
1718
-    /**
1719
-     * _set_list_table_object
1720
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1721
-     *
1722
-     * @throws \EE_Error
1723
-     */
1724
-    protected function _set_list_table_object()
1725
-    {
1726
-        if (isset($this->_route_config['list_table'])) {
1727
-            if ( ! class_exists($this->_route_config['list_table'])) {
1728
-                throw new EE_Error(
1729
-                        sprintf(
1730
-                                __(
1731
-                                        'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1732
-                                        'event_espresso'
1733
-                                ),
1734
-                                $this->_route_config['list_table'],
1735
-                                get_class($this)
1736
-                        )
1737
-                );
1738
-            }
1739
-            $list_table = $this->_route_config['list_table'];
1740
-            $this->_list_table_object = new $list_table($this);
1741
-        }
1742
-    }
1743
-
1744
-
1745
-
1746
-    /**
1747
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1748
-     *
1749
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1750
-     *                                                    urls.  The array should be indexed by the view it is being
1751
-     *                                                    added to.
1752
-     * @return array
1753
-     */
1754
-    public function get_list_table_view_RLs($extra_query_args = array())
1755
-    {
1756
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1757
-        if (empty($this->_views)) {
1758
-            $this->_views = array();
1759
-        }
1760
-        // cycle thru views
1761
-        foreach ($this->_views as $key => $view) {
1762
-            $query_args = array();
1763
-            // check for current view
1764
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1765
-            $query_args['action'] = $this->_req_action;
1766
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1767
-            $query_args['status'] = $view['slug'];
1768
-            //merge any other arguments sent in.
1769
-            if (isset($extra_query_args[$view['slug']])) {
1770
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1771
-            }
1772
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1773
-        }
1774
-        return $this->_views;
1775
-    }
1776
-
1777
-
1778
-
1779
-    /**
1780
-     * _entries_per_page_dropdown
1781
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1782
-     *
1783
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1784
-     * @access protected
1785
-     * @param int $max_entries total number of rows in the table
1786
-     * @return string
1787
-     */
1788
-    protected function _entries_per_page_dropdown($max_entries = false)
1789
-    {
1790
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1791
-        $values = array(10, 25, 50, 100);
1792
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1793
-        if ($max_entries) {
1794
-            $values[] = $max_entries;
1795
-            sort($values);
1796
-        }
1797
-        $entries_per_page_dropdown = '
143
+	// yes / no array for admin form fields
144
+	protected $_yes_no_values = array();
145
+
146
+	//some default things shared by all child classes
147
+	protected $_default_espresso_metaboxes;
148
+
149
+	/**
150
+	 *    EE_Registry Object
151
+	 *
152
+	 * @var    EE_Registry
153
+	 * @access    protected
154
+	 */
155
+	protected $EE = null;
156
+
157
+
158
+
159
+	/**
160
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $_is_caf = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @Constructor
170
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
+	 * @access public
172
+	 */
173
+	public function __construct($routing = true)
174
+	{
175
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
+			$this->_is_caf = true;
177
+		}
178
+		$this->_yes_no_values = array(
179
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
+				array('id' => false, 'text' => __('No', 'event_espresso')),
181
+		);
182
+		//set the _req_data property.
183
+		$this->_req_data = array_merge($_GET, $_POST);
184
+		//routing enabled?
185
+		$this->_routing = $routing;
186
+		//set initial page props (child method)
187
+		$this->_init_page_props();
188
+		//set global defaults
189
+		$this->_set_defaults();
190
+		//set early because incoming requests could be ajax related and we need to register those hooks.
191
+		$this->_global_ajax_hooks();
192
+		$this->_ajax_hooks();
193
+		//other_page_hooks have to be early too.
194
+		$this->_do_other_page_hooks();
195
+		//This just allows us to have extending classes do something specific
196
+		// before the parent constructor runs _page_setup().
197
+		if (method_exists($this, '_before_page_setup')) {
198
+			$this->_before_page_setup();
199
+		}
200
+		//set up page dependencies
201
+		$this->_page_setup();
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * _init_page_props
208
+	 * Child classes use to set at least the following properties:
209
+	 * $page_slug.
210
+	 * $page_label.
211
+	 *
212
+	 * @abstract
213
+	 * @access protected
214
+	 * @return void
215
+	 */
216
+	abstract protected function _init_page_props();
217
+
218
+
219
+
220
+	/**
221
+	 * _ajax_hooks
222
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
+	 * Note: within the ajax callback methods.
224
+	 *
225
+	 * @abstract
226
+	 * @access protected
227
+	 * @return void
228
+	 */
229
+	abstract protected function _ajax_hooks();
230
+
231
+
232
+
233
+	/**
234
+	 * _define_page_props
235
+	 * child classes define page properties in here.  Must include at least:
236
+	 * $_admin_base_url = base_url for all admin pages
237
+	 * $_admin_page_title = default admin_page_title for admin pages
238
+	 * $_labels = array of default labels for various automatically generated elements:
239
+	 *    array(
240
+	 *        'buttons' => array(
241
+	 *            'add' => __('label for add new button'),
242
+	 *            'edit' => __('label for edit button'),
243
+	 *            'delete' => __('label for delete button')
244
+	 *            )
245
+	 *        )
246
+	 *
247
+	 * @abstract
248
+	 * @access protected
249
+	 * @return void
250
+	 */
251
+	abstract protected function _define_page_props();
252
+
253
+
254
+
255
+	/**
256
+	 * _set_page_routes
257
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
+	 * route. Here's the format
259
+	 * $this->_page_routes = array(
260
+	 *        'default' => array(
261
+	 *            'func' => '_default_method_handling_route',
262
+	 *            'args' => array('array','of','args'),
263
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
+	 *        ),
268
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
+	 *        )
270
+	 * )
271
+	 *
272
+	 * @abstract
273
+	 * @access protected
274
+	 * @return void
275
+	 */
276
+	abstract protected function _set_page_routes();
277
+
278
+
279
+
280
+	/**
281
+	 * _set_page_config
282
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
+	 * Format:
284
+	 * $this->_page_config = array(
285
+	 *        'default' => array(
286
+	 *            'labels' => array(
287
+	 *                'buttons' => array(
288
+	 *                    'add' => __('label for adding item'),
289
+	 *                    'edit' => __('label for editing item'),
290
+	 *                    'delete' => __('label for deleting item')
291
+	 *                ),
292
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
+	 *            'nav' => array(
295
+	 *                'label' => __('Label for Tab', 'event_espresso').
296
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
+	 *                'order' => 10, //required to indicate tab position.
299
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
+	 *            this flag to make sure the necessary js gets enqueued on page load.
304
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
308
+	 *                'tab_id' => array(
309
+	 *                    'title' => 'tab_title',
310
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
+	 *                    ),
314
+	 *                'tab2_id' => array(
315
+	 *                    'title' => 'tab2 title',
316
+	 *                    'filename' => 'file_name_2'
317
+	 *                    'callback' => 'callback_method_for_content',
318
+	 *                 ),
319
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
+	 *            'help_tour' => array(
321
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
+	 *            ),
324
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
+	 *            'require_nonce' to FALSE
326
+	 *            )
327
+	 * )
328
+	 *
329
+	 * @abstract
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	abstract protected function _set_page_config();
334
+
335
+
336
+
337
+
338
+
339
+	/** end sample help_tour methods **/
340
+	/**
341
+	 * _add_screen_options
342
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
+	 *
345
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
+	 *         see also WP_Screen object documents...
347
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
+	 * @abstract
349
+	 * @access protected
350
+	 * @return void
351
+	 */
352
+	abstract protected function _add_screen_options();
353
+
354
+
355
+
356
+	/**
357
+	 * _add_feature_pointers
358
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
361
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
+	 *
363
+	 * @link   http://eamann.com/tech/wordpress-portland/
364
+	 * @abstract
365
+	 * @access protected
366
+	 * @return void
367
+	 */
368
+	abstract protected function _add_feature_pointers();
369
+
370
+
371
+
372
+	/**
373
+	 * load_scripts_styles
374
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
+	 *
377
+	 * @abstract
378
+	 * @access public
379
+	 * @return void
380
+	 */
381
+	abstract public function load_scripts_styles();
382
+
383
+
384
+
385
+	/**
386
+	 * admin_init
387
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
+	 *
389
+	 * @abstract
390
+	 * @access public
391
+	 * @return void
392
+	 */
393
+	abstract public function admin_init();
394
+
395
+
396
+
397
+	/**
398
+	 * admin_notices
399
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
+	 *
401
+	 * @abstract
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	abstract public function admin_notices();
406
+
407
+
408
+
409
+	/**
410
+	 * admin_footer_scripts
411
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
+	 *
413
+	 * @access public
414
+	 * @return void
415
+	 */
416
+	abstract public function admin_footer_scripts();
417
+
418
+
419
+
420
+	/**
421
+	 * admin_footer
422
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
+	 *
424
+	 * @access  public
425
+	 * @return void
426
+	 */
427
+	public function admin_footer()
428
+	{
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * _global_ajax_hooks
435
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
+	 * Note: within the ajax callback methods.
437
+	 *
438
+	 * @abstract
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _global_ajax_hooks()
443
+	{
444
+		//for lazy loading of metabox content
445
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
+	}
447
+
448
+
449
+
450
+	public function ajax_metabox_content()
451
+	{
452
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
+		self::cached_rss_display($contentid, $url);
455
+		wp_die();
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * _page_setup
462
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
+	 *
464
+	 * @final
465
+	 * @access protected
466
+	 * @return void
467
+	 */
468
+	final protected function _page_setup()
469
+	{
470
+		//requires?
471
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
472
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
473
+		//next verify if we need to load anything...
474
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
+		global $ee_menu_slugs;
477
+		$ee_menu_slugs = (array)$ee_menu_slugs;
478
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
+			return;
480
+		}
481
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
482
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
+		}
485
+		// then set blank or -1 action values to 'default'
486
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		$this->_current_view = $this->_req_action;
492
+		$this->_req_nonce = $this->_req_action . '_nonce';
493
+		$this->_define_page_props();
494
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
+		//default things
496
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
+		//set page configs
498
+		$this->_set_page_routes();
499
+		$this->_set_page_config();
500
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
501
+		if (isset($this->_req_data['wp_referer'])) {
502
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
+		}
504
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
+		if (method_exists($this, '_extend_page_config')) {
506
+			$this->_extend_page_config();
507
+		}
508
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
510
+			$this->_extend_page_config_for_cpt();
511
+		}
512
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
513
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
+		}
519
+		//next route only if routing enabled
520
+		if ($this->_routing && ! defined('DOING_AJAX')) {
521
+			$this->_verify_routes();
522
+			//next let's just check user_access and kill if no access
523
+			$this->check_user_access();
524
+			if ($this->_is_UI_request) {
525
+				//admin_init stuff - global, all views for this page class, specific view
526
+				add_action('admin_init', array($this, 'admin_init'), 10);
527
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
+				}
530
+			} else {
531
+				//hijack regular WP loading and route admin request immediately
532
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
+				$this->route_admin_request();
534
+			}
535
+		}
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
+	 *
543
+	 * @access private
544
+	 * @return void
545
+	 */
546
+	private function _do_other_page_hooks()
547
+	{
548
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
+		foreach ($registered_pages as $page) {
550
+			//now let's setup the file name and class that should be present
551
+			$classname = str_replace('.class.php', '', $page);
552
+			//autoloaders should take care of loading file
553
+			if ( ! class_exists($classname)) {
554
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
+				$error_msg[] = $error_msg[0]
556
+							   . "\r\n"
557
+							   . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
+				throw new EE_Error(implode('||', $error_msg));
560
+			}
561
+			$a = new ReflectionClass($classname);
562
+			//notice we are passing the instance of this class to the hook object.
563
+			$hookobj[] = $a->newInstance($this);
564
+		}
565
+	}
566
+
567
+
568
+
569
+	public function load_page_dependencies()
570
+	{
571
+		try {
572
+			$this->_load_page_dependencies();
573
+		} catch (EE_Error $e) {
574
+			$e->get_error();
575
+		}
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * load_page_dependencies
582
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
+	 *
584
+	 * @access public
585
+	 * @return void
586
+	 */
587
+	protected function _load_page_dependencies()
588
+	{
589
+		//let's set the current_screen and screen options to override what WP set
590
+		$this->_current_screen = get_current_screen();
591
+		//load admin_notices - global, page class, and view specific
592
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
594
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
+		}
597
+		//load network admin_notices - global, page class, and view specific
598
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
+		}
602
+		//this will save any per_page screen options if they are present
603
+		$this->_set_per_page_screen_options();
604
+		//setup list table properties
605
+		$this->_set_list_table();
606
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
+		$this->_add_registered_meta_boxes();
608
+		$this->_add_screen_columns();
609
+		//add screen options - global, page child class, and view specific
610
+		$this->_add_global_screen_options();
611
+		$this->_add_screen_options();
612
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
+		}
615
+		//add help tab(s) and tours- set via page_config and qtips.
616
+		$this->_add_help_tour();
617
+		$this->_add_help_tabs();
618
+		$this->_add_qtips();
619
+		//add feature_pointers - global, page child class, and view specific
620
+		$this->_add_feature_pointers();
621
+		$this->_add_global_feature_pointers();
622
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
+		}
625
+		//enqueue scripts/styles - global, page class, and view specific
626
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
+		}
631
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
+		}
638
+		//admin footer scripts
639
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
641
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
+		}
644
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
+		//targeted hook
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * _set_defaults
653
+	 * This sets some global defaults for class properties.
654
+	 */
655
+	private function _set_defaults()
656
+	{
657
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
+		$this->default_nav_tab_name = 'overview';
660
+		//init template args
661
+		$this->_template_args = array(
662
+				'admin_page_header'  => '',
663
+				'admin_page_content' => '',
664
+				'post_body_content'  => '',
665
+				'before_list_table'  => '',
666
+				'after_list_table'   => '',
667
+		);
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * route_admin_request
674
+	 *
675
+	 * @see    _route_admin_request()
676
+	 * @access public
677
+	 * @return void|exception error
678
+	 */
679
+	public function route_admin_request()
680
+	{
681
+		try {
682
+			$this->_route_admin_request();
683
+		} catch (EE_Error $e) {
684
+			$e->get_error();
685
+		}
686
+	}
687
+
688
+
689
+
690
+	public function set_wp_page_slug($wp_page_slug)
691
+	{
692
+		$this->_wp_page_slug = $wp_page_slug;
693
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
+		if (is_network_admin()) {
695
+			$this->_wp_page_slug .= '-network';
696
+		}
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * _verify_routes
703
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
+	 *
705
+	 * @access protected
706
+	 * @return void
707
+	 */
708
+	protected function _verify_routes()
709
+	{
710
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
+			return false;
713
+		}
714
+		$this->_route = false;
715
+		$func = false;
716
+		$args = array();
717
+		// check that the page_routes array is not empty
718
+		if (empty($this->_page_routes)) {
719
+			// user error msg
720
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
+			// developer error msg
722
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
+			throw new EE_Error($error_msg);
724
+		}
725
+		// and that the requested page route exists
726
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
+			$this->_route = $this->_page_routes[$this->_req_action];
728
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
+		} else {
730
+			// user error msg
731
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
+			// developer error msg
733
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
+			throw new EE_Error($error_msg);
735
+		}
736
+		// and that a default route exists
737
+		if ( ! array_key_exists('default', $this->_page_routes)) {
738
+			// user error msg
739
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
+			// developer error msg
741
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
+			throw new EE_Error($error_msg);
743
+		}
744
+		//first lets' catch if the UI request has EVER been set.
745
+		if ($this->_is_UI_request === null) {
746
+			//lets set if this is a UI request or not.
747
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
+			//wait a minute... we might have a noheader in the route array
749
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
+		}
751
+		$this->_set_current_labels();
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
+	 *
759
+	 * @param  string $route the route name we're verifying
760
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
+	 */
762
+	protected function _verify_route($route)
763
+	{
764
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
+			return true;
766
+		} else {
767
+			// user error msg
768
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
+			// developer error msg
770
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
+			throw new EE_Error($error_msg);
772
+		}
773
+	}
774
+
775
+
776
+
777
+	/**
778
+	 * perform nonce verification
779
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
+	 *
781
+	 * @param  string $nonce     The nonce sent
782
+	 * @param  string $nonce_ref The nonce reference string (name0)
783
+	 * @return mixed (bool|die)
784
+	 */
785
+	protected function _verify_nonce($nonce, $nonce_ref)
786
+	{
787
+		// verify nonce against expected value
788
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
+			// these are not the droids you are looking for !!!
790
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
+			if (WP_DEBUG) {
792
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
+			}
794
+			if ( ! defined('DOING_AJAX')) {
795
+				wp_die($msg);
796
+			} else {
797
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
+				$this->_return_json();
799
+			}
800
+		}
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * _route_admin_request()
807
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
+	 * in the page routes and then will try to load the corresponding method.
810
+	 *
811
+	 * @access protected
812
+	 * @return void
813
+	 * @throws \EE_Error
814
+	 */
815
+	protected function _route_admin_request()
816
+	{
817
+		if ( ! $this->_is_UI_request) {
818
+			$this->_verify_routes();
819
+		}
820
+		$nonce_check = isset($this->_route_config['require_nonce'])
821
+			? $this->_route_config['require_nonce']
822
+			: true;
823
+		if ($this->_req_action !== 'default' && $nonce_check) {
824
+			// set nonce from post data
825
+			$nonce = isset($this->_req_data[$this->_req_nonce])
826
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
+				: '';
828
+			$this->_verify_nonce($nonce, $this->_req_nonce);
829
+		}
830
+		//set the nav_tabs array but ONLY if this is  UI_request
831
+		if ($this->_is_UI_request) {
832
+			$this->_set_nav_tabs();
833
+		}
834
+		// grab callback function
835
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
+		// check if callback has args
837
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
+		$error_msg = '';
839
+		// action right before calling route
840
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
+		}
844
+		// right before calling the route, let's remove _wp_http_referer from the
845
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
+		if ( ! empty($func)) {
848
+			if (is_array($func)) {
849
+				list($class, $method) = $func;
850
+			} else if (strpos($func, '::') !== false) {
851
+				list($class, $method) = explode('::', $func);
852
+			} else {
853
+				$class = $this;
854
+				$method = $func;
855
+			}
856
+			if ( ! (is_object($class) && $class === $this)) {
857
+				// send along this admin page object for access by addons.
858
+				$args['admin_page_object'] = $this;
859
+			}
860
+
861
+			if (
862
+				//is it a method on a class that doesn't work?
863
+				(
864
+					(
865
+						method_exists($class, $method)
866
+						&& call_user_func_array(array($class, $method), $args) === false
867
+					)
868
+					&& (
869
+						//is it a standalone function that doesn't work?
870
+						function_exists($method)
871
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
+					)
873
+				)
874
+				|| (
875
+					//is it neither a class method NOR a standalone function?
876
+					! method_exists($class, $method)
877
+					&& ! function_exists($method)
878
+				)
879
+			) {
880
+				// user error msg
881
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
+				// developer error msg
883
+				$error_msg .= '||';
884
+				$error_msg .= sprintf(
885
+					__(
886
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
+						'event_espresso'
888
+					),
889
+					$method
890
+				);
891
+			}
892
+			if ( ! empty($error_msg)) {
893
+				throw new EE_Error($error_msg);
894
+			}
895
+		}
896
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
898
+		if ($this->_is_UI_request === false
899
+			&& is_array($this->_route)
900
+			&& ! empty($this->_route['headers_sent_route'])
901
+		) {
902
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
903
+		}
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * This method just allows the resetting of page properties in the case where a no headers
910
+	 * route redirects to a headers route in its route config.
911
+	 *
912
+	 * @since   4.3.0
913
+	 * @param  string $new_route New (non header) route to redirect to.
914
+	 * @return   void
915
+	 */
916
+	protected function _reset_routing_properties($new_route)
917
+	{
918
+		$this->_is_UI_request = true;
919
+		//now we set the current route to whatever the headers_sent_route is set at
920
+		$this->_req_data['action'] = $new_route;
921
+		//rerun page setup
922
+		$this->_page_setup();
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * _add_query_arg
929
+	 * adds nonce to array of arguments then calls WP add_query_arg function
930
+	 *(internally just uses EEH_URL's function with the same name)
931
+	 *
932
+	 * @access public
933
+	 * @param array  $args
934
+	 * @param string $url
935
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
+	 *                                        url in an associative array indexed by the key 'wp_referer';
937
+	 *                                        Example usage:
938
+	 *                                        If the current page is:
939
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
+	 *                                        &action=default&event_id=20&month_range=March%202015
941
+	 *                                        &_wpnonce=5467821
942
+	 *                                        and you call:
943
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
944
+	 *                                        array(
945
+	 *                                        'action' => 'resend_something',
946
+	 *                                        'page=>espresso_registrations'
947
+	 *                                        ),
948
+	 *                                        $some_url,
949
+	 *                                        true
950
+	 *                                        );
951
+	 *                                        It will produce a url in this structure:
952
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
+	 *                                        month_range]=March%202015
955
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
+	 * @return string
957
+	 */
958
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
+	{
960
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
961
+		if ($sticky) {
962
+			$request = $_REQUEST;
963
+			unset($request['_wp_http_referer']);
964
+			unset($request['wp_referer']);
965
+			foreach ($request as $key => $value) {
966
+				//do not add nonces
967
+				if (strpos($key, 'nonce') !== false) {
968
+					continue;
969
+				}
970
+				$args['wp_referer[' . $key . ']'] = $value;
971
+			}
972
+		}
973
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * This returns a generated link that will load the related help tab.
980
+	 *
981
+	 * @param  string $help_tab_id the id for the connected help tab
982
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
+	 * @uses EEH_Template::get_help_tab_link()
985
+	 * @return string              generated link
986
+	 */
987
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
+	{
989
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
+	}
991
+
992
+
993
+
994
+	/**
995
+	 * _add_help_tabs
996
+	 * Note child classes define their help tabs within the page_config array.
997
+	 *
998
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
+	 * @access protected
1000
+	 * @return void
1001
+	 */
1002
+	protected function _add_help_tabs()
1003
+	{
1004
+		$tour_buttons = '';
1005
+		if (isset($this->_page_config[$this->_req_action])) {
1006
+			$config = $this->_page_config[$this->_req_action];
1007
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1008
+			if (isset($this->_help_tour[$this->_req_action])) {
1009
+				$tb = array();
1010
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
+				foreach ($this->_help_tour['tours'] as $tour) {
1012
+					//if this is the end tour then we don't need to setup a button
1013
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1014
+						continue;
1015
+					}
1016
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
+				}
1018
+				$tour_buttons .= implode('<br />', $tb);
1019
+				$tour_buttons .= '</div></div>';
1020
+			}
1021
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
+			if (is_array($config) && isset($config['help_sidebar'])) {
1023
+				//check that the callback given is valid
1024
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1025
+					throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
+				}
1028
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
+				$content .= $tour_buttons; //add help tour buttons.
1030
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1031
+				$this->_current_screen->set_help_sidebar($content);
1032
+			}
1033
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1036
+			}
1037
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
+				$_ht['id'] = $this->page_slug;
1040
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1041
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
+				$this->_current_screen->add_help_tab($_ht);
1043
+			}/**/
1044
+			if ( ! isset($config['help_tabs'])) {
1045
+				return;
1046
+			} //no help tabs for this route
1047
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
+				//we're here so there ARE help tabs!
1049
+				//make sure we've got what we need
1050
+				if ( ! isset($cfg['title'])) {
1051
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
+				}
1053
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
+					throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1055
+							'event_espresso'));
1056
+				}
1057
+				//first priority goes to content.
1058
+				if ( ! empty($cfg['content'])) {
1059
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
+					//second priority goes to filename
1061
+				} else if ( ! empty($cfg['filename'])) {
1062
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
+						EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1068
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
+						return;
1070
+					}
1071
+					$template_args['admin_page_obj'] = $this;
1072
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1073
+				} else {
1074
+					$content = '';
1075
+				}
1076
+				//check if callback is valid
1077
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
+					EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1079
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
+					return;
1081
+				}
1082
+				//setup config array for help tab method
1083
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
+				$_ht = array(
1085
+						'id'       => $id,
1086
+						'title'    => $cfg['title'],
1087
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
+						'content'  => $content,
1089
+				);
1090
+				$this->_current_screen->add_help_tab($_ht);
1091
+			}
1092
+		}
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
+	 *
1100
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
+	 * @access protected
1103
+	 * @return void
1104
+	 */
1105
+	protected function _add_help_tour()
1106
+	{
1107
+		$tours = array();
1108
+		$this->_help_tour = array();
1109
+		//exit early if help tours are turned off globally
1110
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
+			return;
1112
+		}
1113
+		//loop through _page_config to find any help_tour defined
1114
+		foreach ($this->_page_config as $route => $config) {
1115
+			//we're only going to set things up for this route
1116
+			if ($route !== $this->_req_action) {
1117
+				continue;
1118
+			}
1119
+			if (isset($config['help_tour'])) {
1120
+				foreach ($config['help_tour'] as $tour) {
1121
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
+					if ( ! is_readable($file_path)) {
1126
+						EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1127
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
+						return;
1129
+					}
1130
+					require_once $file_path;
1131
+					if ( ! class_exists($tour)) {
1132
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
+						throw new EE_Error(implode('||', $error_msg));
1136
+					}
1137
+					$a = new ReflectionClass($tour);
1138
+					$tour_obj = $a->newInstance($this->_is_caf);
1139
+					$tours[] = $tour_obj;
1140
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
+				}
1142
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
+				$tours[] = $end_stop_tour;
1145
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
+			}
1147
+		}
1148
+		if ( ! empty($tours)) {
1149
+			$this->_help_tour['tours'] = $tours;
1150
+		}
1151
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * This simply sets up any qtips that have been defined in the page config
1158
+	 *
1159
+	 * @access protected
1160
+	 * @return void
1161
+	 */
1162
+	protected function _add_qtips()
1163
+	{
1164
+		if (isset($this->_route_config['qtips'])) {
1165
+			$qtips = (array)$this->_route_config['qtips'];
1166
+			//load qtip loader
1167
+			$path = array(
1168
+					$this->_get_dir() . '/qtips/',
1169
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
+			);
1171
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
+		}
1173
+	}
1174
+
1175
+
1176
+
1177
+	/**
1178
+	 * _set_nav_tabs
1179
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
+	 *
1181
+	 * @access protected
1182
+	 * @return void
1183
+	 */
1184
+	protected function _set_nav_tabs()
1185
+	{
1186
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
+		$i = 0;
1188
+		foreach ($this->_page_config as $slug => $config) {
1189
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
+				continue;
1191
+			} //no nav tab for this config
1192
+			//check for persistent flag
1193
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
+				continue;
1195
+			} //nav tab is only to appear when route requested.
1196
+			if ( ! $this->check_user_access($slug, true)) {
1197
+				continue;
1198
+			} //no nav tab becasue current user does not have access.
1199
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
+			$this->_nav_tabs[$slug] = array(
1201
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
+			);
1206
+			$i++;
1207
+		}
1208
+		//if $this->_nav_tabs is empty then lets set the default
1209
+		if (empty($this->_nav_tabs)) {
1210
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
+					'url'       => $this->admin_base_url,
1212
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
+					'css_class' => 'nav-tab-active',
1214
+					'order'     => 10,
1215
+			);
1216
+		}
1217
+		//now let's sort the tabs according to order
1218
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
+	}
1220
+
1221
+
1222
+
1223
+	/**
1224
+	 * _set_current_labels
1225
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
+	 *
1227
+	 * @access private
1228
+	 * @return void
1229
+	 */
1230
+	private function _set_current_labels()
1231
+	{
1232
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
+			foreach ($this->_route_config['labels'] as $label => $text) {
1234
+				if (is_array($text)) {
1235
+					foreach ($text as $sublabel => $subtext) {
1236
+						$this->_labels[$label][$sublabel] = $subtext;
1237
+					}
1238
+				} else {
1239
+					$this->_labels[$label] = $text;
1240
+				}
1241
+			}
1242
+		}
1243
+	}
1244
+
1245
+
1246
+
1247
+	/**
1248
+	 *        verifies user access for this admin page
1249
+	 *
1250
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
+	 * @return        BOOL|wp_die()
1253
+	 */
1254
+	public function check_user_access($route_to_check = '', $verify_only = false)
1255
+	{
1256
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1260
+		if (empty($capability) && empty($route_to_check)) {
1261
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
+		} else {
1263
+			$capability = empty($capability) ? 'manage_options' : $capability;
1264
+		}
1265
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
+			if ($verify_only) {
1268
+				return false;
1269
+			} else {
1270
+				if ( is_user_logged_in() ) {
1271
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
+				} else {
1273
+					return false;
1274
+				}
1275
+			}
1276
+		}
1277
+		return true;
1278
+	}
1279
+
1280
+
1281
+
1282
+	/**
1283
+	 * admin_init_global
1284
+	 * This runs all the code that we want executed within the WP admin_init hook.
1285
+	 * This method executes for ALL EE Admin pages.
1286
+	 *
1287
+	 * @access public
1288
+	 * @return void
1289
+	 */
1290
+	public function admin_init_global()
1291
+	{
1292
+	}
1293
+
1294
+
1295
+
1296
+	/**
1297
+	 * wp_loaded_global
1298
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
+	 *
1300
+	 * @access public
1301
+	 * @return void
1302
+	 */
1303
+	public function wp_loaded()
1304
+	{
1305
+	}
1306
+
1307
+
1308
+
1309
+	/**
1310
+	 * admin_notices
1311
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
+	 *
1313
+	 * @access public
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_notices_global()
1317
+	{
1318
+		$this->_display_no_javascript_warning();
1319
+		$this->_display_espresso_notices();
1320
+	}
1321
+
1322
+
1323
+
1324
+	public function network_admin_notices_global()
1325
+	{
1326
+		$this->_display_no_javascript_warning();
1327
+		$this->_display_espresso_notices();
1328
+	}
1329
+
1330
+
1331
+
1332
+	/**
1333
+	 * admin_footer_scripts_global
1334
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
+	 *
1336
+	 * @access public
1337
+	 * @return void
1338
+	 */
1339
+	public function admin_footer_scripts_global()
1340
+	{
1341
+		$this->_add_admin_page_ajax_loading_img();
1342
+		$this->_add_admin_page_overlay();
1343
+		//if metaboxes are present we need to add the nonce field
1344
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
+		}
1348
+	}
1349
+
1350
+
1351
+
1352
+	/**
1353
+	 * admin_footer_global
1354
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
+	 *
1356
+	 * @access  public
1357
+	 * @return  void
1358
+	 */
1359
+	public function admin_footer_global()
1360
+	{
1361
+		//dialog container for dialog helper
1362
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
+		$d_cont .= '<div class="ee-notices"></div>';
1364
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
+		$d_cont .= '</div>';
1366
+		echo $d_cont;
1367
+		//help tour stuff?
1368
+		if (isset($this->_help_tour[$this->_req_action])) {
1369
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
+		}
1371
+		//current set timezone for timezone js
1372
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
+	 * For child classes:
1380
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
+	 *    'help_trigger_id' => array(
1384
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1385
+	 *        'content' => __('localized content for popup', 'event_espresso')
1386
+	 *    )
1387
+	 * );
1388
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
+	 *
1390
+	 * @access protected
1391
+	 * @return string content
1392
+	 */
1393
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1394
+	{
1395
+		$content = '';
1396
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
+		//loop through the array and setup content
1399
+		foreach ($help_array as $trigger => $help) {
1400
+			//make sure the array is setup properly
1401
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
+				throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1403
+						'event_espresso'));
1404
+			}
1405
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
+			$template_args = array(
1407
+					'help_popup_id'      => $trigger,
1408
+					'help_popup_title'   => $help['title'],
1409
+					'help_popup_content' => $help['content'],
1410
+			);
1411
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1412
+		}
1413
+		if ($display) {
1414
+			echo $content;
1415
+		} else {
1416
+			return $content;
1417
+		}
1418
+	}
1419
+
1420
+
1421
+
1422
+	/**
1423
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
+	 *
1425
+	 * @access private
1426
+	 * @return array properly formatted array for help popup content
1427
+	 */
1428
+	private function _get_help_content()
1429
+	{
1430
+		//what is the method we're looking for?
1431
+		$method_name = '_help_popup_content_' . $this->_req_action;
1432
+		//if method doesn't exist let's get out.
1433
+		if ( ! method_exists($this, $method_name)) {
1434
+			return array();
1435
+		}
1436
+		//k we're good to go let's retrieve the help array
1437
+		$help_array = call_user_func(array($this, $method_name));
1438
+		//make sure we've got an array!
1439
+		if ( ! is_array($help_array)) {
1440
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
+		}
1442
+		return $help_array;
1443
+	}
1444
+
1445
+
1446
+
1447
+	/**
1448
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
+	 *
1452
+	 * @access protected
1453
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
+	 * @param boolean $display    if false then we return the trigger string
1455
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
+	 * @return string
1457
+	 */
1458
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
+	{
1460
+		if (defined('DOING_AJAX')) {
1461
+			return;
1462
+		}
1463
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1464
+		$help_array = $this->_get_help_content();
1465
+		$help_content = '';
1466
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
+			$help_array[$trigger_id] = array(
1468
+					'title'   => __('Missing Content', 'event_espresso'),
1469
+					'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1470
+							'event_espresso'),
1471
+			);
1472
+			$help_content = $this->_set_help_popup_content($help_array, false);
1473
+		}
1474
+		//let's setup the trigger
1475
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+		$content = $content . $help_content;
1477
+		if ($display) {
1478
+			echo $content;
1479
+		} else {
1480
+			return $content;
1481
+		}
1482
+	}
1483
+
1484
+
1485
+
1486
+	/**
1487
+	 * _add_global_screen_options
1488
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1490
+	 *
1491
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
+	 *         see also WP_Screen object documents...
1493
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
+	 * @abstract
1495
+	 * @access private
1496
+	 * @return void
1497
+	 */
1498
+	private function _add_global_screen_options()
1499
+	{
1500
+	}
1501
+
1502
+
1503
+
1504
+	/**
1505
+	 * _add_global_feature_pointers
1506
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1509
+	 *
1510
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
+	 * @link   http://eamann.com/tech/wordpress-portland/
1512
+	 * @abstract
1513
+	 * @access protected
1514
+	 * @return void
1515
+	 */
1516
+	private function _add_global_feature_pointers()
1517
+	{
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * load_global_scripts_styles
1524
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
+	 *
1526
+	 * @return void
1527
+	 */
1528
+	public function load_global_scripts_styles()
1529
+	{
1530
+		/** STYLES **/
1531
+		// add debugging styles
1532
+		if (WP_DEBUG) {
1533
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1534
+		}
1535
+		//register all styles
1536
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
+		//helpers styles
1539
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		//enqueue global styles
1541
+		wp_enqueue_style('ee-admin-css');
1542
+		/** SCRIPTS **/
1543
+		//register all scripts
1544
+		wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1545
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1546
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1547
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1548
+		// register jQuery Validate - see /includes/functions/wp_hooks.php
1549
+		add_filter('FHEE_load_jquery_validate', '__return_true');
1550
+		add_filter('FHEE_load_joyride', '__return_true');
1551
+		//script for sorting tables
1552
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1553
+		//script for parsing uri's
1554
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
+		//and parsing associative serialized form elements
1556
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1557
+		//helpers scripts
1558
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1559
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1560
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1561
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1562
+		//google charts
1563
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1564
+		//enqueue global scripts
1565
+		//taking care of metaboxes
1566
+		if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) {
1567
+			wp_enqueue_script('dashboard');
1568
+		}
1569
+		//enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1570
+		if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) {
1571
+			wp_enqueue_script('ee_admin_js');
1572
+			wp_enqueue_style('ee-admin-css');
1573
+		}
1574
+		//localize script for ajax lazy loading
1575
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1576
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1577
+		/**
1578
+		 * help tour stuff
1579
+		 */
1580
+		if ( ! empty($this->_help_tour)) {
1581
+			//register the js for kicking things off
1582
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583
+			//setup tours for the js tour object
1584
+			foreach ($this->_help_tour['tours'] as $tour) {
1585
+				$tours[] = array(
1586
+						'id'      => $tour->get_slug(),
1587
+						'options' => $tour->get_options(),
1588
+				);
1589
+			}
1590
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1591
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1592
+		}
1593
+	}
1594
+
1595
+
1596
+
1597
+	/**
1598
+	 *        admin_footer_scripts_eei18n_js_strings
1599
+	 *
1600
+	 * @access        public
1601
+	 * @return        void
1602
+	 */
1603
+	public function admin_footer_scripts_eei18n_js_strings()
1604
+	{
1605
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1606
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1643
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1644
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1645
+		//setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1646
+		//admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1647
+		//espresso_core is listed as a dependency of ee_admin_js.
1648
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
1649
+	}
1650
+
1651
+
1652
+
1653
+	/**
1654
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1655
+	 *
1656
+	 * @access        public
1657
+	 * @return        void
1658
+	 */
1659
+	public function add_xdebug_style()
1660
+	{
1661
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1662
+	}
1663
+
1664
+
1665
+	/************************/
1666
+	/** LIST TABLE METHODS **/
1667
+	/************************/
1668
+	/**
1669
+	 * this sets up the list table if the current view requires it.
1670
+	 *
1671
+	 * @access protected
1672
+	 * @return void
1673
+	 */
1674
+	protected function _set_list_table()
1675
+	{
1676
+		//first is this a list_table view?
1677
+		if ( ! isset($this->_route_config['list_table'])) {
1678
+			return;
1679
+		} //not a list_table view so get out.
1680
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1681
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1682
+			//user error msg
1683
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1684
+			//developer error msg
1685
+			$error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1686
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1687
+			throw new EE_Error($error_msg);
1688
+		}
1689
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1690
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1691
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1692
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1693
+		$this->_set_list_table_view();
1694
+		$this->_set_list_table_object();
1695
+	}
1696
+
1697
+
1698
+
1699
+	/**
1700
+	 *        set current view for List Table
1701
+	 *
1702
+	 * @access public
1703
+	 * @return array
1704
+	 */
1705
+	protected function _set_list_table_view()
1706
+	{
1707
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1708
+		// looking at active items or dumpster diving ?
1709
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1710
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1711
+		} else {
1712
+			$this->_view = sanitize_key($this->_req_data['status']);
1713
+		}
1714
+	}
1715
+
1716
+
1717
+
1718
+	/**
1719
+	 * _set_list_table_object
1720
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1721
+	 *
1722
+	 * @throws \EE_Error
1723
+	 */
1724
+	protected function _set_list_table_object()
1725
+	{
1726
+		if (isset($this->_route_config['list_table'])) {
1727
+			if ( ! class_exists($this->_route_config['list_table'])) {
1728
+				throw new EE_Error(
1729
+						sprintf(
1730
+								__(
1731
+										'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1732
+										'event_espresso'
1733
+								),
1734
+								$this->_route_config['list_table'],
1735
+								get_class($this)
1736
+						)
1737
+				);
1738
+			}
1739
+			$list_table = $this->_route_config['list_table'];
1740
+			$this->_list_table_object = new $list_table($this);
1741
+		}
1742
+	}
1743
+
1744
+
1745
+
1746
+	/**
1747
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1748
+	 *
1749
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1750
+	 *                                                    urls.  The array should be indexed by the view it is being
1751
+	 *                                                    added to.
1752
+	 * @return array
1753
+	 */
1754
+	public function get_list_table_view_RLs($extra_query_args = array())
1755
+	{
1756
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1757
+		if (empty($this->_views)) {
1758
+			$this->_views = array();
1759
+		}
1760
+		// cycle thru views
1761
+		foreach ($this->_views as $key => $view) {
1762
+			$query_args = array();
1763
+			// check for current view
1764
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1765
+			$query_args['action'] = $this->_req_action;
1766
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1767
+			$query_args['status'] = $view['slug'];
1768
+			//merge any other arguments sent in.
1769
+			if (isset($extra_query_args[$view['slug']])) {
1770
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1771
+			}
1772
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1773
+		}
1774
+		return $this->_views;
1775
+	}
1776
+
1777
+
1778
+
1779
+	/**
1780
+	 * _entries_per_page_dropdown
1781
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1782
+	 *
1783
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1784
+	 * @access protected
1785
+	 * @param int $max_entries total number of rows in the table
1786
+	 * @return string
1787
+	 */
1788
+	protected function _entries_per_page_dropdown($max_entries = false)
1789
+	{
1790
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1791
+		$values = array(10, 25, 50, 100);
1792
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1793
+		if ($max_entries) {
1794
+			$values[] = $max_entries;
1795
+			sort($values);
1796
+		}
1797
+		$entries_per_page_dropdown = '
1798 1798
 			<div id="entries-per-page-dv" class="alignleft actions">
1799 1799
 				<label class="hide-if-no-js">
1800 1800
 					Show
1801 1801
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1802
-        foreach ($values as $value) {
1803
-            if ($value < $max_entries) {
1804
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1805
-                $entries_per_page_dropdown .= '
1802
+		foreach ($values as $value) {
1803
+			if ($value < $max_entries) {
1804
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1805
+				$entries_per_page_dropdown .= '
1806 1806
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1807
-            }
1808
-        }
1809
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1810
-        $entries_per_page_dropdown .= '
1807
+			}
1808
+		}
1809
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1810
+		$entries_per_page_dropdown .= '
1811 1811
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1812
-        $entries_per_page_dropdown .= '
1812
+		$entries_per_page_dropdown .= '
1813 1813
 					</select>
1814 1814
 					entries
1815 1815
 				</label>
1816 1816
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1817 1817
 			</div>
1818 1818
 		';
1819
-        return $entries_per_page_dropdown;
1820
-    }
1821
-
1822
-
1823
-
1824
-    /**
1825
-     *        _set_search_attributes
1826
-     *
1827
-     * @access        protected
1828
-     * @return        void
1829
-     */
1830
-    public function _set_search_attributes()
1831
-    {
1832
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1833
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1834
-    }
1835
-
1836
-    /*** END LIST TABLE METHODS **/
1837
-    /*****************************/
1838
-    /**
1839
-     *        _add_registered_metaboxes
1840
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1841
-     *
1842
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1843
-     * @access private
1844
-     * @return void
1845
-     */
1846
-    private function _add_registered_meta_boxes()
1847
-    {
1848
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1849
-        //we only add meta boxes if the page_route calls for it
1850
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1851
-            && is_array(
1852
-                    $this->_route_config['metaboxes']
1853
-            )
1854
-        ) {
1855
-            // this simply loops through the callbacks provided
1856
-            // and checks if there is a corresponding callback registered by the child
1857
-            // if there is then we go ahead and process the metabox loader.
1858
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1859
-                // first check for Closures
1860
-                if ($metabox_callback instanceof Closure) {
1861
-                    $result = $metabox_callback();
1862
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1863
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1864
-                } else {
1865
-                    $result = call_user_func(array($this, &$metabox_callback));
1866
-                }
1867
-                if ($result === false) {
1868
-                    // user error msg
1869
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1870
-                    // developer error msg
1871
-                    $error_msg .= '||' . sprintf(
1872
-                                    __(
1873
-                                            'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1874
-                                            'event_espresso'
1875
-                                    ),
1876
-                                    $metabox_callback
1877
-                            );
1878
-                    throw new EE_Error($error_msg);
1879
-                }
1880
-            }
1881
-        }
1882
-    }
1883
-
1884
-
1885
-
1886
-    /**
1887
-     * _add_screen_columns
1888
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1889
-     *
1890
-     * @access private
1891
-     * @return void
1892
-     */
1893
-    private function _add_screen_columns()
1894
-    {
1895
-        if (
1896
-                is_array($this->_route_config)
1897
-                && isset($this->_route_config['columns'])
1898
-                && is_array($this->_route_config['columns'])
1899
-                && count($this->_route_config['columns']) === 2
1900
-        ) {
1901
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1902
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1903
-            $screen_id = $this->_current_screen->id;
1904
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1905
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1906
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1907
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1908
-            $this->_template_args['screen'] = $this->_current_screen;
1909
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1910
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1911
-            $this->_route_config['has_metaboxes'] = true;
1912
-        }
1913
-    }
1914
-
1915
-
1916
-
1917
-    /**********************************/
1918
-    /** GLOBALLY AVAILABLE METABOXES **/
1919
-    /**
1920
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1921
-     * loaded on.
1922
-     */
1923
-    private function _espresso_news_post_box()
1924
-    {
1925
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1926
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1927
-                $this,
1928
-                'espresso_news_post_box',
1929
-        ), $this->_wp_page_slug, 'side');
1930
-    }
1931
-
1932
-
1933
-
1934
-    /**
1935
-     * Code for setting up espresso ratings request metabox.
1936
-     */
1937
-    protected function _espresso_ratings_request()
1938
-    {
1939
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1940
-            return '';
1941
-        }
1942
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1943
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1944
-                $this,
1945
-                'espresso_ratings_request',
1946
-        ), $this->_wp_page_slug, 'side');
1947
-    }
1948
-
1949
-
1950
-
1951
-    /**
1952
-     * Code for setting up espresso ratings request metabox content.
1953
-     */
1954
-    public function espresso_ratings_request()
1955
-    {
1956
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1957
-        EEH_Template::display_template($template_path, array());
1958
-    }
1959
-
1960
-
1961
-
1962
-    public static function cached_rss_display($rss_id, $url)
1963
-    {
1964
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1965
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1966
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1967
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1968
-        $post = '</div>' . "\n";
1969
-        $cache_key = 'ee_rss_' . md5($rss_id);
1970
-        if (false != ($output = get_transient($cache_key))) {
1971
-            echo $pre . $output . $post;
1972
-            return true;
1973
-        }
1974
-        if ( ! $doing_ajax) {
1975
-            echo $pre . $loading . $post;
1976
-            return false;
1977
-        }
1978
-        ob_start();
1979
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1980
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1981
-        return true;
1982
-    }
1983
-
1984
-
1985
-
1986
-    public function espresso_news_post_box()
1987
-    {
1988
-        ?>
1819
+		return $entries_per_page_dropdown;
1820
+	}
1821
+
1822
+
1823
+
1824
+	/**
1825
+	 *        _set_search_attributes
1826
+	 *
1827
+	 * @access        protected
1828
+	 * @return        void
1829
+	 */
1830
+	public function _set_search_attributes()
1831
+	{
1832
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1833
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1834
+	}
1835
+
1836
+	/*** END LIST TABLE METHODS **/
1837
+	/*****************************/
1838
+	/**
1839
+	 *        _add_registered_metaboxes
1840
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1841
+	 *
1842
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1843
+	 * @access private
1844
+	 * @return void
1845
+	 */
1846
+	private function _add_registered_meta_boxes()
1847
+	{
1848
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1849
+		//we only add meta boxes if the page_route calls for it
1850
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1851
+			&& is_array(
1852
+					$this->_route_config['metaboxes']
1853
+			)
1854
+		) {
1855
+			// this simply loops through the callbacks provided
1856
+			// and checks if there is a corresponding callback registered by the child
1857
+			// if there is then we go ahead and process the metabox loader.
1858
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1859
+				// first check for Closures
1860
+				if ($metabox_callback instanceof Closure) {
1861
+					$result = $metabox_callback();
1862
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1863
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1864
+				} else {
1865
+					$result = call_user_func(array($this, &$metabox_callback));
1866
+				}
1867
+				if ($result === false) {
1868
+					// user error msg
1869
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1870
+					// developer error msg
1871
+					$error_msg .= '||' . sprintf(
1872
+									__(
1873
+											'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1874
+											'event_espresso'
1875
+									),
1876
+									$metabox_callback
1877
+							);
1878
+					throw new EE_Error($error_msg);
1879
+				}
1880
+			}
1881
+		}
1882
+	}
1883
+
1884
+
1885
+
1886
+	/**
1887
+	 * _add_screen_columns
1888
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1889
+	 *
1890
+	 * @access private
1891
+	 * @return void
1892
+	 */
1893
+	private function _add_screen_columns()
1894
+	{
1895
+		if (
1896
+				is_array($this->_route_config)
1897
+				&& isset($this->_route_config['columns'])
1898
+				&& is_array($this->_route_config['columns'])
1899
+				&& count($this->_route_config['columns']) === 2
1900
+		) {
1901
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1902
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1903
+			$screen_id = $this->_current_screen->id;
1904
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1905
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1906
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1907
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1908
+			$this->_template_args['screen'] = $this->_current_screen;
1909
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1910
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1911
+			$this->_route_config['has_metaboxes'] = true;
1912
+		}
1913
+	}
1914
+
1915
+
1916
+
1917
+	/**********************************/
1918
+	/** GLOBALLY AVAILABLE METABOXES **/
1919
+	/**
1920
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1921
+	 * loaded on.
1922
+	 */
1923
+	private function _espresso_news_post_box()
1924
+	{
1925
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1926
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1927
+				$this,
1928
+				'espresso_news_post_box',
1929
+		), $this->_wp_page_slug, 'side');
1930
+	}
1931
+
1932
+
1933
+
1934
+	/**
1935
+	 * Code for setting up espresso ratings request metabox.
1936
+	 */
1937
+	protected function _espresso_ratings_request()
1938
+	{
1939
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1940
+			return '';
1941
+		}
1942
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1943
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1944
+				$this,
1945
+				'espresso_ratings_request',
1946
+		), $this->_wp_page_slug, 'side');
1947
+	}
1948
+
1949
+
1950
+
1951
+	/**
1952
+	 * Code for setting up espresso ratings request metabox content.
1953
+	 */
1954
+	public function espresso_ratings_request()
1955
+	{
1956
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1957
+		EEH_Template::display_template($template_path, array());
1958
+	}
1959
+
1960
+
1961
+
1962
+	public static function cached_rss_display($rss_id, $url)
1963
+	{
1964
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1965
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1966
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1967
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1968
+		$post = '</div>' . "\n";
1969
+		$cache_key = 'ee_rss_' . md5($rss_id);
1970
+		if (false != ($output = get_transient($cache_key))) {
1971
+			echo $pre . $output . $post;
1972
+			return true;
1973
+		}
1974
+		if ( ! $doing_ajax) {
1975
+			echo $pre . $loading . $post;
1976
+			return false;
1977
+		}
1978
+		ob_start();
1979
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1980
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1981
+		return true;
1982
+	}
1983
+
1984
+
1985
+
1986
+	public function espresso_news_post_box()
1987
+	{
1988
+		?>
1989 1989
         <div class="padding">
1990 1990
             <div id="espresso_news_post_box_content" class="infolinks">
1991 1991
                 <?php
1992
-                // Get RSS Feed(s)
1993
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1994
-                $url = urlencode($feed_url);
1995
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1996
-                ?>
1992
+				// Get RSS Feed(s)
1993
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1994
+				$url = urlencode($feed_url);
1995
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1996
+				?>
1997 1997
             </div>
1998 1998
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1999 1999
         </div>
2000 2000
         <?php
2001
-    }
2002
-
2003
-
2004
-
2005
-    private function _espresso_links_post_box()
2006
-    {
2007
-        //Hiding until we actually have content to put in here...
2008
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2009
-    }
2010
-
2011
-
2012
-
2013
-    public function espresso_links_post_box()
2014
-    {
2015
-        //Hiding until we actually have content to put in here...
2016
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2017
-        //EEH_Template::display_template( $templatepath );
2018
-    }
2019
-
2020
-
2021
-
2022
-    protected function _espresso_sponsors_post_box()
2023
-    {
2024
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2025
-        if ($show_sponsors) {
2026
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2027
-        }
2028
-    }
2029
-
2030
-
2031
-
2032
-    public function espresso_sponsors_post_box()
2033
-    {
2034
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2035
-        EEH_Template::display_template($templatepath);
2036
-    }
2037
-
2038
-
2039
-
2040
-    private function _publish_post_box()
2041
-    {
2042
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2043
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2044
-        if ( ! empty($this->_labels['publishbox'])) {
2045
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2046
-        } else {
2047
-            $box_label = __('Publish', 'event_espresso');
2048
-        }
2049
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2050
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2051
-    }
2052
-
2053
-
2054
-
2055
-    public function editor_overview()
2056
-    {
2057
-        //if we have extra content set let's add it in if not make sure its empty
2058
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2059
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2060
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061
-    }
2062
-
2063
-
2064
-    /** end of globally available metaboxes section **/
2065
-    /*************************************************/
2066
-    /**
2067
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2068
-     * protected method.
2069
-     *
2070
-     * @see   $this->_set_publish_post_box_vars for param details
2071
-     * @since 4.6.0
2072
-     */
2073
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2074
-    {
2075
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2076
-    }
2077
-
2078
-
2079
-
2080
-    /**
2081
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2082
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2083
-     * save, and save and close buttons to work properly, then you will want to include a
2084
-     * values for the name and id arguments.
2085
-     *
2086
-     * @todo  Add in validation for name/id arguments.
2087
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2088
-     * @param    int     $id                      id attached to the item published
2089
-     * @param    string  $delete                  page route callback for the delete action
2090
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2091
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2092
-     * @throws \EE_Error
2093
-     */
2094
-    protected function _set_publish_post_box_vars(
2095
-            $name = '',
2096
-            $id = 0,
2097
-            $delete = '',
2098
-            $save_close_redirect_URL = '',
2099
-            $both_btns = true
2100
-    ) {
2101
-        // if Save & Close, use a custom redirect URL or default to the main page?
2102
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2103
-        // create the Save & Close and Save buttons
2104
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2105
-        //if we have extra content set let's add it in if not make sure its empty
2106
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2107
-        if ($delete && ! empty($id)) {
2108
-            //make sure we have a default if just true is sent.
2109
-            $delete = ! empty($delete) ? $delete : 'delete';
2110
-            $delete_link_args = array($name => $id);
2111
-            $delete = $this->get_action_link_or_button(
2112
-                    $delete,
2113
-                    $delete,
2114
-                    $delete_link_args,
2115
-                    'submitdelete deletion',
2116
-                    '',
2117
-                    false
2118
-            );
2119
-        }
2120
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2121
-        if ( ! empty($name) && ! empty($id)) {
2122
-            $hidden_field_arr[$name] = array(
2123
-                    'type'  => 'hidden',
2124
-                    'value' => $id,
2125
-            );
2126
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2127
-        } else {
2128
-            $hf = '';
2129
-        }
2130
-        // add hidden field
2131
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2132
-    }
2133
-
2134
-
2135
-
2136
-    /**
2137
-     *        displays an error message to ppl who have javascript disabled
2138
-     *
2139
-     * @access        private
2140
-     * @return        string
2141
-     */
2142
-    private function _display_no_javascript_warning()
2143
-    {
2144
-        ?>
2001
+	}
2002
+
2003
+
2004
+
2005
+	private function _espresso_links_post_box()
2006
+	{
2007
+		//Hiding until we actually have content to put in here...
2008
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2009
+	}
2010
+
2011
+
2012
+
2013
+	public function espresso_links_post_box()
2014
+	{
2015
+		//Hiding until we actually have content to put in here...
2016
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2017
+		//EEH_Template::display_template( $templatepath );
2018
+	}
2019
+
2020
+
2021
+
2022
+	protected function _espresso_sponsors_post_box()
2023
+	{
2024
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2025
+		if ($show_sponsors) {
2026
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2027
+		}
2028
+	}
2029
+
2030
+
2031
+
2032
+	public function espresso_sponsors_post_box()
2033
+	{
2034
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2035
+		EEH_Template::display_template($templatepath);
2036
+	}
2037
+
2038
+
2039
+
2040
+	private function _publish_post_box()
2041
+	{
2042
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2043
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2044
+		if ( ! empty($this->_labels['publishbox'])) {
2045
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2046
+		} else {
2047
+			$box_label = __('Publish', 'event_espresso');
2048
+		}
2049
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2050
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2051
+	}
2052
+
2053
+
2054
+
2055
+	public function editor_overview()
2056
+	{
2057
+		//if we have extra content set let's add it in if not make sure its empty
2058
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2059
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2060
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061
+	}
2062
+
2063
+
2064
+	/** end of globally available metaboxes section **/
2065
+	/*************************************************/
2066
+	/**
2067
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2068
+	 * protected method.
2069
+	 *
2070
+	 * @see   $this->_set_publish_post_box_vars for param details
2071
+	 * @since 4.6.0
2072
+	 */
2073
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2074
+	{
2075
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2076
+	}
2077
+
2078
+
2079
+
2080
+	/**
2081
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2082
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2083
+	 * save, and save and close buttons to work properly, then you will want to include a
2084
+	 * values for the name and id arguments.
2085
+	 *
2086
+	 * @todo  Add in validation for name/id arguments.
2087
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2088
+	 * @param    int     $id                      id attached to the item published
2089
+	 * @param    string  $delete                  page route callback for the delete action
2090
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2091
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2092
+	 * @throws \EE_Error
2093
+	 */
2094
+	protected function _set_publish_post_box_vars(
2095
+			$name = '',
2096
+			$id = 0,
2097
+			$delete = '',
2098
+			$save_close_redirect_URL = '',
2099
+			$both_btns = true
2100
+	) {
2101
+		// if Save & Close, use a custom redirect URL or default to the main page?
2102
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2103
+		// create the Save & Close and Save buttons
2104
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2105
+		//if we have extra content set let's add it in if not make sure its empty
2106
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2107
+		if ($delete && ! empty($id)) {
2108
+			//make sure we have a default if just true is sent.
2109
+			$delete = ! empty($delete) ? $delete : 'delete';
2110
+			$delete_link_args = array($name => $id);
2111
+			$delete = $this->get_action_link_or_button(
2112
+					$delete,
2113
+					$delete,
2114
+					$delete_link_args,
2115
+					'submitdelete deletion',
2116
+					'',
2117
+					false
2118
+			);
2119
+		}
2120
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2121
+		if ( ! empty($name) && ! empty($id)) {
2122
+			$hidden_field_arr[$name] = array(
2123
+					'type'  => 'hidden',
2124
+					'value' => $id,
2125
+			);
2126
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2127
+		} else {
2128
+			$hf = '';
2129
+		}
2130
+		// add hidden field
2131
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2132
+	}
2133
+
2134
+
2135
+
2136
+	/**
2137
+	 *        displays an error message to ppl who have javascript disabled
2138
+	 *
2139
+	 * @access        private
2140
+	 * @return        string
2141
+	 */
2142
+	private function _display_no_javascript_warning()
2143
+	{
2144
+		?>
2145 2145
         <noscript>
2146 2146
             <div id="no-js-message" class="error">
2147 2147
                 <p style="font-size:1.3em;">
@@ -2151,1267 +2151,1267 @@  discard block
 block discarded – undo
2151 2151
             </div>
2152 2152
         </noscript>
2153 2153
         <?php
2154
-    }
2154
+	}
2155 2155
 
2156 2156
 
2157 2157
 
2158
-    /**
2159
-     *        displays espresso success and/or error notices
2160
-     *
2161
-     * @access        private
2162
-     * @return        string
2163
-     */
2164
-    private function _display_espresso_notices()
2165
-    {
2166
-        $notices = $this->_get_transient(true);
2167
-        echo stripslashes($notices);
2168
-    }
2158
+	/**
2159
+	 *        displays espresso success and/or error notices
2160
+	 *
2161
+	 * @access        private
2162
+	 * @return        string
2163
+	 */
2164
+	private function _display_espresso_notices()
2165
+	{
2166
+		$notices = $this->_get_transient(true);
2167
+		echo stripslashes($notices);
2168
+	}
2169 2169
 
2170 2170
 
2171 2171
 
2172
-    /**
2173
-     *        spinny things pacify the masses
2174
-     *
2175
-     * @access private
2176
-     * @return string
2177
-     */
2178
-    protected function _add_admin_page_ajax_loading_img()
2179
-    {
2180
-        ?>
2172
+	/**
2173
+	 *        spinny things pacify the masses
2174
+	 *
2175
+	 * @access private
2176
+	 * @return string
2177
+	 */
2178
+	protected function _add_admin_page_ajax_loading_img()
2179
+	{
2180
+		?>
2181 2181
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2182 2182
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2183 2183
         </div>
2184 2184
         <?php
2185
-    }
2185
+	}
2186 2186
 
2187 2187
 
2188 2188
 
2189
-    /**
2190
-     *        add admin page overlay for modal boxes
2191
-     *
2192
-     * @access private
2193
-     * @return string
2194
-     */
2195
-    protected function _add_admin_page_overlay()
2196
-    {
2197
-        ?>
2189
+	/**
2190
+	 *        add admin page overlay for modal boxes
2191
+	 *
2192
+	 * @access private
2193
+	 * @return string
2194
+	 */
2195
+	protected function _add_admin_page_overlay()
2196
+	{
2197
+		?>
2198 2198
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2199 2199
         <?php
2200
-    }
2201
-
2202
-
2203
-
2204
-    /**
2205
-     * facade for add_meta_box
2206
-     *
2207
-     * @param string  $action        where the metabox get's displayed
2208
-     * @param string  $title         Title of Metabox (output in metabox header)
2209
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2210
-     * @param array   $callback_args an array of args supplied for the metabox
2211
-     * @param string  $column        what metabox column
2212
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2213
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2214
-     */
2215
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2216
-    {
2217
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2218
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2219
-        if (empty($callback_args) && $create_func) {
2220
-            $callback_args = array(
2221
-                    'template_path' => $this->_template_path,
2222
-                    'template_args' => $this->_template_args,
2223
-            );
2224
-        }
2225
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2226
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2227
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2228
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2229
-    }
2230
-
2231
-
2232
-
2233
-    /**
2234
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2235
-     *
2236
-     * @return [type] [description]
2237
-     */
2238
-    public function display_admin_page_with_metabox_columns()
2239
-    {
2240
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2241
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2242
-        //the final wrapper
2243
-        $this->admin_page_wrapper();
2244
-    }
2245
-
2246
-
2247
-
2248
-    /**
2249
-     *        generates  HTML wrapper for an admin details page
2250
-     *
2251
-     * @access public
2252
-     * @return void
2253
-     */
2254
-    public function display_admin_page_with_sidebar()
2255
-    {
2256
-        $this->_display_admin_page(true);
2257
-    }
2258
-
2259
-
2260
-
2261
-    /**
2262
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2263
-     *
2264
-     * @access public
2265
-     * @return void
2266
-     */
2267
-    public function display_admin_page_with_no_sidebar()
2268
-    {
2269
-        $this->_display_admin_page();
2270
-    }
2271
-
2272
-
2273
-
2274
-    /**
2275
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2276
-     *
2277
-     * @access public
2278
-     * @return void
2279
-     */
2280
-    public function display_about_admin_page()
2281
-    {
2282
-        $this->_display_admin_page(false, true);
2283
-    }
2284
-
2285
-
2286
-
2287
-    /**
2288
-     * display_admin_page
2289
-     * contains the code for actually displaying an admin page
2290
-     *
2291
-     * @access private
2292
-     * @param  boolean $sidebar true with sidebar, false without
2293
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2294
-     * @return void
2295
-     */
2296
-    private function _display_admin_page($sidebar = false, $about = false)
2297
-    {
2298
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2299
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2300
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2301
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2302
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2303
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2304
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2305
-                ? 'poststuff'
2306
-                : 'espresso-default-admin';
2307
-        $template_path = $sidebar
2308
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2309
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2310
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2311
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2312
-        }
2313
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2314
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2315
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2316
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2317
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2318
-        // the final template wrapper
2319
-        $this->admin_page_wrapper($about);
2320
-    }
2321
-
2322
-
2323
-
2324
-    /**
2325
-     * This is used to display caf preview pages.
2326
-     *
2327
-     * @since 4.3.2
2328
-     * @param string $utm_campaign_source what is the key used for google analytics link
2329
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2330
-     * @return void
2331
-     * @throws \EE_Error
2332
-     */
2333
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2334
-    {
2335
-        //let's generate a default preview action button if there isn't one already present.
2336
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2337
-        $buy_now_url = add_query_arg(
2338
-                array(
2339
-                        'ee_ver'       => 'ee4',
2340
-                        'utm_source'   => 'ee4_plugin_admin',
2341
-                        'utm_medium'   => 'link',
2342
-                        'utm_campaign' => $utm_campaign_source,
2343
-                        'utm_content'  => 'buy_now_button',
2344
-                ),
2345
-                'http://eventespresso.com/pricing/'
2346
-        );
2347
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2348
-                ? $this->get_action_link_or_button(
2349
-                        '',
2350
-                        'buy_now',
2351
-                        array(),
2352
-                        'button-primary button-large',
2353
-                        $buy_now_url,
2354
-                        true
2355
-                )
2356
-                : $this->_template_args['preview_action_button'];
2357
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2358
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2359
-                $template_path,
2360
-                $this->_template_args,
2361
-                true
2362
-        );
2363
-        $this->_display_admin_page($display_sidebar);
2364
-    }
2365
-
2366
-
2367
-
2368
-    /**
2369
-     * display_admin_list_table_page_with_sidebar
2370
-     * generates HTML wrapper for an admin_page with list_table
2371
-     *
2372
-     * @access public
2373
-     * @return void
2374
-     */
2375
-    public function display_admin_list_table_page_with_sidebar()
2376
-    {
2377
-        $this->_display_admin_list_table_page(true);
2378
-    }
2379
-
2380
-
2381
-
2382
-    /**
2383
-     * display_admin_list_table_page_with_no_sidebar
2384
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2385
-     *
2386
-     * @access public
2387
-     * @return void
2388
-     */
2389
-    public function display_admin_list_table_page_with_no_sidebar()
2390
-    {
2391
-        $this->_display_admin_list_table_page();
2392
-    }
2393
-
2394
-
2395
-
2396
-    /**
2397
-     * generates html wrapper for an admin_list_table page
2398
-     *
2399
-     * @access private
2400
-     * @param boolean $sidebar whether to display with sidebar or not.
2401
-     * @return void
2402
-     */
2403
-    private function _display_admin_list_table_page($sidebar = false)
2404
-    {
2405
-        //setup search attributes
2406
-        $this->_set_search_attributes();
2407
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2408
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2409
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2410
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2411
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2412
-        $this->_template_args['list_table'] = $this->_list_table_object;
2413
-        $this->_template_args['current_route'] = $this->_req_action;
2414
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2415
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2416
-        if ( ! empty($ajax_sorting_callback)) {
2417
-            $sortable_list_table_form_fields = wp_nonce_field(
2418
-                    $ajax_sorting_callback . '_nonce',
2419
-                    $ajax_sorting_callback . '_nonce',
2420
-                    false,
2421
-                    false
2422
-            );
2423
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2424
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2425
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2426
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2427
-        } else {
2428
-            $sortable_list_table_form_fields = '';
2429
-        }
2430
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2431
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2432
-        $nonce_ref = $this->_req_action . '_nonce';
2433
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2434
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2435
-        //display message about search results?
2436
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2437
-                ? '<p class="ee-search-results">' . sprintf(
2438
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2439
-                        trim($this->_req_data['s'], '%')
2440
-                ) . '</p>'
2441
-                : '';
2442
-        // filter before_list_table template arg
2443
-        $this->_template_args['before_list_table'] = apply_filters(
2444
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2445
-            $this->_template_args['before_list_table'],
2446
-            $this->page_slug,
2447
-            $this->_req_data,
2448
-            $this->_req_action
2449
-        );
2450
-        // convert to array and filter again
2451
-        // arrays are easier to inject new items in a specific location,
2452
-        // but would not be backwards compatible, so we have to add a new filter
2453
-        $this->_template_args['before_list_table'] = implode(
2454
-            " \n",
2455
-            (array) apply_filters(
2456
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2457
-                (array) $this->_template_args['before_list_table'],
2458
-                $this->page_slug,
2459
-                $this->_req_data,
2460
-                $this->_req_action
2461
-            )
2462
-        );
2463
-        // filter after_list_table template arg
2464
-        $this->_template_args['after_list_table'] = apply_filters(
2465
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2466
-            $this->_template_args['after_list_table'],
2467
-            $this->page_slug,
2468
-            $this->_req_data,
2469
-            $this->_req_action
2470
-        );
2471
-        // convert to array and filter again
2472
-        // arrays are easier to inject new items in a specific location,
2473
-        // but would not be backwards compatible, so we have to add a new filter
2474
-        $this->_template_args['after_list_table'] = implode(
2475
-            " \n",
2476
-            (array) apply_filters(
2477
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2478
-                (array) $this->_template_args['after_list_table'],
2479
-                $this->page_slug,
2480
-                $this->_req_data,
2481
-                $this->_req_action
2482
-            )
2483
-        );
2484
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2485
-                $template_path,
2486
-                $this->_template_args,
2487
-                true
2488
-        );
2489
-        // the final template wrapper
2490
-        if ($sidebar) {
2491
-            $this->display_admin_page_with_sidebar();
2492
-        } else {
2493
-            $this->display_admin_page_with_no_sidebar();
2494
-        }
2495
-    }
2496
-
2497
-
2498
-
2499
-    /**
2500
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2501
-     * $items are expected in an array in the following format:
2502
-     * $legend_items = array(
2503
-     *        'item_id' => array(
2504
-     *            'icon' => 'http://url_to_icon_being_described.png',
2505
-     *            'desc' => __('localized description of item');
2506
-     *        )
2507
-     * );
2508
-     *
2509
-     * @param  array $items see above for format of array
2510
-     * @return string        html string of legend
2511
-     */
2512
-    protected function _display_legend($items)
2513
-    {
2514
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2515
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2516
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2517
-    }
2518
-
2519
-
2520
-
2521
-    /**
2522
-     * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2523
-     *
2524
-     * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2525
-     *                             The returned json object is created from an array in the following format:
2526
-     *                             array(
2527
-     *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2528
-     *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2529
-     *                             'notices' => '', // - contains any EE_Error formatted notices
2530
-     *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2531
-     *                             'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2532
-     *                             specific template args that might be included in here)
2533
-     *                             )
2534
-     *                             The json object is populated by whatever is set in the $_template_args property.
2535
-     * @return void
2536
-     */
2537
-    protected function _return_json($sticky_notices = false)
2538
-    {
2539
-        //make sure any EE_Error notices have been handled.
2540
-        $this->_process_notices(array(), true, $sticky_notices);
2541
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2542
-        unset($this->_template_args['data']);
2543
-        $json = array(
2544
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2545
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2546
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2547
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2548
-                'notices'   => EE_Error::get_notices(),
2549
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2550
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2551
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2552
-        );
2553
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2554
-        if (null === error_get_last() || ! headers_sent()) {
2555
-            header('Content-Type: application/json; charset=UTF-8');
2556
-        }
2557
-        echo wp_json_encode($json);
2558
-
2559
-        exit();
2560
-    }
2561
-
2562
-
2563
-
2564
-    /**
2565
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2566
-     *
2567
-     * @return void
2568
-     * @throws EE_Error
2569
-     */
2570
-    public function return_json()
2571
-    {
2572
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2573
-            $this->_return_json();
2574
-        } else {
2575
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2576
-        }
2577
-    }
2578
-
2579
-
2580
-
2581
-    /**
2582
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2583
-     *
2584
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2585
-     * @access   public
2586
-     */
2587
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2588
-    {
2589
-        $this->_hook_obj = $hook_obj;
2590
-    }
2591
-
2592
-
2593
-
2594
-    /**
2595
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2596
-     *
2597
-     * @access public
2598
-     * @param  boolean $about whether to use the special about page wrapper or default.
2599
-     * @return void
2600
-     */
2601
-    public function admin_page_wrapper($about = false)
2602
-    {
2603
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2604
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2605
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2606
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2607
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2608
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2609
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2610
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2611
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2612
-        // load settings page wrapper template
2613
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2614
-        //about page?
2615
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2616
-        if (defined('DOING_AJAX')) {
2617
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2618
-            $this->_return_json();
2619
-        } else {
2620
-            EEH_Template::display_template($template_path, $this->_template_args);
2621
-        }
2622
-    }
2623
-
2624
-
2625
-
2626
-    /**
2627
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2628
-     *
2629
-     * @return string html
2630
-     */
2631
-    protected function _get_main_nav_tabs()
2632
-    {
2633
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2634
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2635
-    }
2636
-
2637
-
2638
-
2639
-    /**
2640
-     *        sort nav tabs
2641
-     *
2642
-     * @access public
2643
-     * @param $a
2644
-     * @param $b
2645
-     * @return int
2646
-     */
2647
-    private function _sort_nav_tabs($a, $b)
2648
-    {
2649
-        if ($a['order'] == $b['order']) {
2650
-            return 0;
2651
-        }
2652
-        return ($a['order'] < $b['order']) ? -1 : 1;
2653
-    }
2654
-
2655
-
2656
-
2657
-    /**
2658
-     *    generates HTML for the forms used on admin pages
2659
-     *
2660
-     * @access protected
2661
-     * @param    array $input_vars - array of input field details
2662
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2663
-     * @return string
2664
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2665
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2666
-     */
2667
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2668
-    {
2669
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2670
-        return $content;
2671
-    }
2672
-
2673
-
2674
-
2675
-    /**
2676
-     * generates the "Save" and "Save & Close" buttons for edit forms
2677
-     *
2678
-     * @access protected
2679
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2680
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2681
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2682
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2683
-     */
2684
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2685
-    {
2686
-        //make sure $text and $actions are in an array
2687
-        $text = (array)$text;
2688
-        $actions = (array)$actions;
2689
-        $referrer_url = empty($referrer) ? '' : $referrer;
2690
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2691
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2692
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2693
-        $default_names = array('save', 'save_and_close');
2694
-        //add in a hidden index for the current page (so save and close redirects properly)
2695
-        $this->_template_args['save_buttons'] = $referrer_url;
2696
-        foreach ($button_text as $key => $button) {
2697
-            $ref = $default_names[$key];
2698
-            $id = $this->_current_view . '_' . $ref;
2699
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2700
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2701
-            if ( ! $both) {
2702
-                break;
2703
-            }
2704
-        }
2705
-    }
2706
-
2707
-
2708
-
2709
-    /**
2710
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2711
-     *
2712
-     * @see   $this->_set_add_edit_form_tags() for details on params
2713
-     * @since 4.6.0
2714
-     * @param string $route
2715
-     * @param array  $additional_hidden_fields
2716
-     */
2717
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2718
-    {
2719
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2720
-    }
2721
-
2722
-
2723
-
2724
-    /**
2725
-     * set form open and close tags on add/edit pages.
2726
-     *
2727
-     * @access protected
2728
-     * @param string $route                    the route you want the form to direct to
2729
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2730
-     * @return void
2731
-     */
2732
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2733
-    {
2734
-        if (empty($route)) {
2735
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2736
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2737
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2738
-        }
2739
-        // open form
2740
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2741
-        // add nonce
2742
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2743
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2744
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2745
-        // add REQUIRED form action
2746
-        $hidden_fields = array(
2747
-                'action' => array('type' => 'hidden', 'value' => $route),
2748
-        );
2749
-        // merge arrays
2750
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2751
-        // generate form fields
2752
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2753
-        // add fields to form
2754
-        foreach ((array)$form_fields as $field_name => $form_field) {
2755
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2756
-        }
2757
-        // close form
2758
-        $this->_template_args['after_admin_page_content'] = '</form>';
2759
-    }
2760
-
2761
-
2762
-
2763
-    /**
2764
-     * Public Wrapper for _redirect_after_action() method since its
2765
-     * discovered it would be useful for external code to have access.
2766
-     *
2767
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2768
-     * @since 4.5.0
2769
-     */
2770
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2771
-    {
2772
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2773
-    }
2774
-
2775
-
2776
-
2777
-    /**
2778
-     *    _redirect_after_action
2779
-     *
2780
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2781
-     * @param string $what               - what the action was performed on
2782
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2783
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2784
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2785
-     * @access protected
2786
-     * @return void
2787
-     */
2788
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2789
-    {
2790
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2791
-        //class name for actions/filters.
2792
-        $classname = get_class($this);
2793
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2794
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2795
-        $notices = EE_Error::get_notices(false);
2796
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2797
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2798
-            EE_Error::overwrite_success();
2799
-        }
2800
-        if ( ! empty($what) && ! empty($action_desc)) {
2801
-            // how many records affected ? more than one record ? or just one ?
2802
-            if ($success > 1 && empty($notices['errors'])) {
2803
-                // set plural msg
2804
-                EE_Error::add_success(
2805
-                        sprintf(
2806
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2807
-                                $what,
2808
-                                $action_desc
2809
-                        ),
2810
-                        __FILE__, __FUNCTION__, __LINE__
2811
-                );
2812
-            } else if ($success == 1 && empty($notices['errors'])) {
2813
-                // set singular msg
2814
-                EE_Error::add_success(
2815
-                        sprintf(
2816
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2817
-                                $what,
2818
-                                $action_desc
2819
-                        ),
2820
-                        __FILE__, __FUNCTION__, __LINE__
2821
-                );
2822
-            }
2823
-        }
2824
-        // check that $query_args isn't something crazy
2825
-        if ( ! is_array($query_args)) {
2826
-            $query_args = array();
2827
-        }
2828
-        /**
2829
-         * Allow injecting actions before the query_args are modified for possible different
2830
-         * redirections on save and close actions
2831
-         *
2832
-         * @since 4.2.0
2833
-         * @param array $query_args       The original query_args array coming into the
2834
-         *                                method.
2835
-         */
2836
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2837
-        //calculate where we're going (if we have a "save and close" button pushed)
2838
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2839
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2840
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2841
-            // regenerate query args array from referrer URL
2842
-            parse_str($parsed_url['query'], $query_args);
2843
-            // correct page and action will be in the query args now
2844
-            $redirect_url = admin_url('admin.php');
2845
-        }
2846
-        //merge any default query_args set in _default_route_query_args property
2847
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2848
-            $args_to_merge = array();
2849
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2850
-                //is there a wp_referer array in our _default_route_query_args property?
2851
-                if ($query_param == 'wp_referer') {
2852
-                    $query_value = (array)$query_value;
2853
-                    foreach ($query_value as $reference => $value) {
2854
-                        if (strpos($reference, 'nonce') !== false) {
2855
-                            continue;
2856
-                        }
2857
-                        //finally we will override any arguments in the referer with
2858
-                        //what might be set on the _default_route_query_args array.
2859
-                        if (isset($this->_default_route_query_args[$reference])) {
2860
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2861
-                        } else {
2862
-                            $args_to_merge[$reference] = urlencode($value);
2863
-                        }
2864
-                    }
2865
-                    continue;
2866
-                }
2867
-                $args_to_merge[$query_param] = $query_value;
2868
-            }
2869
-            //now let's merge these arguments but override with what was specifically sent in to the
2870
-            //redirect.
2871
-            $query_args = array_merge($args_to_merge, $query_args);
2872
-        }
2873
-        $this->_process_notices($query_args);
2874
-        // generate redirect url
2875
-        // if redirecting to anything other than the main page, add a nonce
2876
-        if (isset($query_args['action'])) {
2877
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2878
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2879
-        }
2880
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2881
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2882
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2883
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2884
-        if (defined('DOING_AJAX')) {
2885
-            $default_data = array(
2886
-                    'close'        => true,
2887
-                    'redirect_url' => $redirect_url,
2888
-                    'where'        => 'main',
2889
-                    'what'         => 'append',
2890
-            );
2891
-            $this->_template_args['success'] = $success;
2892
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2893
-            $this->_return_json();
2894
-        }
2895
-        wp_safe_redirect($redirect_url);
2896
-        exit();
2897
-    }
2898
-
2899
-
2900
-
2901
-    /**
2902
-     * process any notices before redirecting (or returning ajax request)
2903
-     * This method sets the $this->_template_args['notices'] attribute;
2904
-     *
2905
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2906
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2907
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2908
-     * @return void
2909
-     */
2910
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2911
-    {
2912
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2913
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2914
-            $notices = EE_Error::get_notices(false);
2915
-            if (empty($this->_template_args['success'])) {
2916
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2917
-            }
2918
-            if (empty($this->_template_args['errors'])) {
2919
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2920
-            }
2921
-            if (empty($this->_template_args['attention'])) {
2922
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2923
-            }
2924
-        }
2925
-        $this->_template_args['notices'] = EE_Error::get_notices();
2926
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2927
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2928
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2929
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2930
-        }
2931
-    }
2932
-
2933
-
2934
-
2935
-    /**
2936
-     * get_action_link_or_button
2937
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2938
-     *
2939
-     * @param string $action        use this to indicate which action the url is generated with.
2940
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2941
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2942
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2943
-     * @param string $base_url      If this is not provided
2944
-     *                              the _admin_base_url will be used as the default for the button base_url.
2945
-     *                              Otherwise this value will be used.
2946
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2947
-     * @return string
2948
-     * @throws \EE_Error
2949
-     */
2950
-    public function get_action_link_or_button(
2951
-            $action,
2952
-            $type = 'add',
2953
-            $extra_request = array(),
2954
-            $class = 'button-primary',
2955
-            $base_url = '',
2956
-            $exclude_nonce = false
2957
-    ) {
2958
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2959
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2960
-            throw new EE_Error(
2961
-                    sprintf(
2962
-                            __(
2963
-                                    'There is no page route for given action for the button.  This action was given: %s',
2964
-                                    'event_espresso'
2965
-                            ),
2966
-                            $action
2967
-                    )
2968
-            );
2969
-        }
2970
-        if ( ! isset($this->_labels['buttons'][$type])) {
2971
-            throw new EE_Error(
2972
-                    sprintf(
2973
-                            __(
2974
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2975
-                                    'event_espresso'
2976
-                            ),
2977
-                            $type
2978
-                    )
2979
-            );
2980
-        }
2981
-        //finally check user access for this button.
2982
-        $has_access = $this->check_user_access($action, true);
2983
-        if ( ! $has_access) {
2984
-            return '';
2985
-        }
2986
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2987
-        $query_args = array(
2988
-                'action' => $action,
2989
-        );
2990
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2991
-        if ( ! empty($extra_request)) {
2992
-            $query_args = array_merge($extra_request, $query_args);
2993
-        }
2994
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2995
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2996
-    }
2997
-
2998
-
2999
-
3000
-    /**
3001
-     * _per_page_screen_option
3002
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3003
-     *
3004
-     * @return void
3005
-     */
3006
-    protected function _per_page_screen_option()
3007
-    {
3008
-        $option = 'per_page';
3009
-        $args = array(
3010
-                'label'   => $this->_admin_page_title,
3011
-                'default' => 10,
3012
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3013
-        );
3014
-        //ONLY add the screen option if the user has access to it.
3015
-        if ($this->check_user_access($this->_current_view, true)) {
3016
-            add_screen_option($option, $args);
3017
-        }
3018
-    }
3019
-
3020
-
3021
-
3022
-    /**
3023
-     * set_per_page_screen_option
3024
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3025
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3026
-     *
3027
-     * @access private
3028
-     * @return void
3029
-     */
3030
-    private function _set_per_page_screen_options()
3031
-    {
3032
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3033
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3034
-            if ( ! $user = wp_get_current_user()) {
3035
-                return;
3036
-            }
3037
-            $option = $_POST['wp_screen_options']['option'];
3038
-            $value = $_POST['wp_screen_options']['value'];
3039
-            if ($option != sanitize_key($option)) {
3040
-                return;
3041
-            }
3042
-            $map_option = $option;
3043
-            $option = str_replace('-', '_', $option);
3044
-            switch ($map_option) {
3045
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3046
-                    $value = (int)$value;
3047
-                    if ($value < 1 || $value > 999) {
3048
-                        return;
3049
-                    }
3050
-                    break;
3051
-                default:
3052
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3053
-                    if (false === $value) {
3054
-                        return;
3055
-                    }
3056
-                    break;
3057
-            }
3058
-            update_user_meta($user->ID, $option, $value);
3059
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3060
-            exit;
3061
-        }
3062
-    }
3063
-
3064
-
3065
-
3066
-    /**
3067
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3068
-     *
3069
-     * @param array $data array that will be assigned to template args.
3070
-     */
3071
-    public function set_template_args($data)
3072
-    {
3073
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3074
-    }
3075
-
3076
-
3077
-
3078
-    /**
3079
-     * This makes available the WP transient system for temporarily moving data between routes
3080
-     *
3081
-     * @access protected
3082
-     * @param string $route             the route that should receive the transient
3083
-     * @param array  $data              the data that gets sent
3084
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3085
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3086
-     * @return void
3087
-     */
3088
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3089
-    {
3090
-        $user_id = get_current_user_id();
3091
-        if ( ! $skip_route_verify) {
3092
-            $this->_verify_route($route);
3093
-        }
3094
-        //now let's set the string for what kind of transient we're setting
3095
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3096
-        $data = $notices ? array('notices' => $data) : $data;
3097
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3098
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3099
-        if ($existing) {
3100
-            $data = array_merge((array)$data, (array)$existing);
3101
-        }
3102
-        if (is_multisite() && is_network_admin()) {
3103
-            set_site_transient($transient, $data, 8);
3104
-        } else {
3105
-            set_transient($transient, $data, 8);
3106
-        }
3107
-    }
3108
-
3109
-
3110
-
3111
-    /**
3112
-     * this retrieves the temporary transient that has been set for moving data between routes.
3113
-     *
3114
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3115
-     * @return mixed data
3116
-     */
3117
-    protected function _get_transient($notices = false, $route = false)
3118
-    {
3119
-        $user_id = get_current_user_id();
3120
-        $route = ! $route ? $this->_req_action : $route;
3121
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3122
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3123
-        //delete transient after retrieval (just in case it hasn't expired);
3124
-        if (is_multisite() && is_network_admin()) {
3125
-            delete_site_transient($transient);
3126
-        } else {
3127
-            delete_transient($transient);
3128
-        }
3129
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3130
-    }
3131
-
3132
-
3133
-
3134
-    /**
3135
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3136
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3137
-     *
3138
-     * @return void
3139
-     */
3140
-    protected function _transient_garbage_collection()
3141
-    {
3142
-        global $wpdb;
3143
-        //retrieve all existing transients
3144
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3145
-        if ($results = $wpdb->get_results($query)) {
3146
-            foreach ($results as $result) {
3147
-                $transient = str_replace('_transient_', '', $result->option_name);
3148
-                get_transient($transient);
3149
-                if (is_multisite() && is_network_admin()) {
3150
-                    get_site_transient($transient);
3151
-                }
3152
-            }
3153
-        }
3154
-    }
3155
-
3156
-
3157
-
3158
-    /**
3159
-     * get_view
3160
-     *
3161
-     * @access public
3162
-     * @return string content of _view property
3163
-     */
3164
-    public function get_view()
3165
-    {
3166
-        return $this->_view;
3167
-    }
3168
-
3169
-
3170
-
3171
-    /**
3172
-     * getter for the protected $_views property
3173
-     *
3174
-     * @return array
3175
-     */
3176
-    public function get_views()
3177
-    {
3178
-        return $this->_views;
3179
-    }
3180
-
3181
-
3182
-
3183
-    /**
3184
-     * get_current_page
3185
-     *
3186
-     * @access public
3187
-     * @return string _current_page property value
3188
-     */
3189
-    public function get_current_page()
3190
-    {
3191
-        return $this->_current_page;
3192
-    }
3193
-
3194
-
3195
-
3196
-    /**
3197
-     * get_current_view
3198
-     *
3199
-     * @access public
3200
-     * @return string _current_view property value
3201
-     */
3202
-    public function get_current_view()
3203
-    {
3204
-        return $this->_current_view;
3205
-    }
3206
-
3207
-
3208
-
3209
-    /**
3210
-     * get_current_screen
3211
-     *
3212
-     * @access public
3213
-     * @return object The current WP_Screen object
3214
-     */
3215
-    public function get_current_screen()
3216
-    {
3217
-        return $this->_current_screen;
3218
-    }
3219
-
3220
-
3221
-
3222
-    /**
3223
-     * get_current_page_view_url
3224
-     *
3225
-     * @access public
3226
-     * @return string This returns the url for the current_page_view.
3227
-     */
3228
-    public function get_current_page_view_url()
3229
-    {
3230
-        return $this->_current_page_view_url;
3231
-    }
3232
-
3233
-
3234
-
3235
-    /**
3236
-     * just returns the _req_data property
3237
-     *
3238
-     * @return array
3239
-     */
3240
-    public function get_request_data()
3241
-    {
3242
-        return $this->_req_data;
3243
-    }
3244
-
3245
-
3246
-
3247
-    /**
3248
-     * returns the _req_data protected property
3249
-     *
3250
-     * @return string
3251
-     */
3252
-    public function get_req_action()
3253
-    {
3254
-        return $this->_req_action;
3255
-    }
3256
-
3257
-
3258
-
3259
-    /**
3260
-     * @return bool  value of $_is_caf property
3261
-     */
3262
-    public function is_caf()
3263
-    {
3264
-        return $this->_is_caf;
3265
-    }
3266
-
3267
-
3268
-
3269
-    /**
3270
-     * @return mixed
3271
-     */
3272
-    public function default_espresso_metaboxes()
3273
-    {
3274
-        return $this->_default_espresso_metaboxes;
3275
-    }
3276
-
3277
-
3278
-
3279
-    /**
3280
-     * @return mixed
3281
-     */
3282
-    public function admin_base_url()
3283
-    {
3284
-        return $this->_admin_base_url;
3285
-    }
3286
-
3287
-
3288
-
3289
-    /**
3290
-     * @return mixed
3291
-     */
3292
-    public function wp_page_slug()
3293
-    {
3294
-        return $this->_wp_page_slug;
3295
-    }
3296
-
3297
-
3298
-
3299
-    /**
3300
-     * updates  espresso configuration settings
3301
-     *
3302
-     * @access    protected
3303
-     * @param string                   $tab
3304
-     * @param EE_Config_Base|EE_Config $config
3305
-     * @param string                   $file file where error occurred
3306
-     * @param string                   $func function  where error occurred
3307
-     * @param string                   $line line no where error occurred
3308
-     * @return boolean
3309
-     */
3310
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3311
-    {
3312
-        //remove any options that are NOT going to be saved with the config settings.
3313
-        if (isset($config->core->ee_ueip_optin)) {
3314
-            $config->core->ee_ueip_has_notified = true;
3315
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3316
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3317
-            update_option('ee_ueip_has_notified', true);
3318
-        }
3319
-        // and save it (note we're also doing the network save here)
3320
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3321
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3322
-        if ($config_saved && $net_saved) {
3323
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3324
-            return true;
3325
-        } else {
3326
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3327
-            return false;
3328
-        }
3329
-    }
3330
-
3331
-
3332
-
3333
-    /**
3334
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3335
-     *
3336
-     * @return array
3337
-     */
3338
-    public function get_yes_no_values()
3339
-    {
3340
-        return $this->_yes_no_values;
3341
-    }
3342
-
3343
-
3344
-
3345
-    protected function _get_dir()
3346
-    {
3347
-        $reflector = new ReflectionClass(get_class($this));
3348
-        return dirname($reflector->getFileName());
3349
-    }
3350
-
3351
-
3352
-
3353
-    /**
3354
-     * A helper for getting a "next link".
3355
-     *
3356
-     * @param string $url   The url to link to
3357
-     * @param string $class The class to use.
3358
-     * @return string
3359
-     */
3360
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3361
-    {
3362
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3363
-    }
3364
-
3365
-
3366
-
3367
-    /**
3368
-     * A helper for getting a "previous link".
3369
-     *
3370
-     * @param string $url   The url to link to
3371
-     * @param string $class The class to use.
3372
-     * @return string
3373
-     */
3374
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3375
-    {
3376
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3377
-    }
3378
-
3379
-
3380
-
3381
-
3382
-
3383
-
3384
-
3385
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3386
-    /**
3387
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3388
-     * array.
3389
-     *
3390
-     * @return bool success/fail
3391
-     */
3392
-    protected function _process_resend_registration()
3393
-    {
3394
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3395
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3396
-        return $this->_template_args['success'];
3397
-    }
3398
-
3399
-
3400
-
3401
-    /**
3402
-     * This automatically processes any payment message notifications when manual payment has been applied.
3403
-     *
3404
-     * @access protected
3405
-     * @param \EE_Payment $payment
3406
-     * @return bool success/fail
3407
-     */
3408
-    protected function _process_payment_notification(EE_Payment $payment)
3409
-    {
3410
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3411
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3412
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3413
-        return $this->_template_args['success'];
3414
-    }
2200
+	}
2201
+
2202
+
2203
+
2204
+	/**
2205
+	 * facade for add_meta_box
2206
+	 *
2207
+	 * @param string  $action        where the metabox get's displayed
2208
+	 * @param string  $title         Title of Metabox (output in metabox header)
2209
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2210
+	 * @param array   $callback_args an array of args supplied for the metabox
2211
+	 * @param string  $column        what metabox column
2212
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2213
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2214
+	 */
2215
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2216
+	{
2217
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2218
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2219
+		if (empty($callback_args) && $create_func) {
2220
+			$callback_args = array(
2221
+					'template_path' => $this->_template_path,
2222
+					'template_args' => $this->_template_args,
2223
+			);
2224
+		}
2225
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2226
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2227
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2228
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2229
+	}
2230
+
2231
+
2232
+
2233
+	/**
2234
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2235
+	 *
2236
+	 * @return [type] [description]
2237
+	 */
2238
+	public function display_admin_page_with_metabox_columns()
2239
+	{
2240
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2241
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2242
+		//the final wrapper
2243
+		$this->admin_page_wrapper();
2244
+	}
2245
+
2246
+
2247
+
2248
+	/**
2249
+	 *        generates  HTML wrapper for an admin details page
2250
+	 *
2251
+	 * @access public
2252
+	 * @return void
2253
+	 */
2254
+	public function display_admin_page_with_sidebar()
2255
+	{
2256
+		$this->_display_admin_page(true);
2257
+	}
2258
+
2259
+
2260
+
2261
+	/**
2262
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2263
+	 *
2264
+	 * @access public
2265
+	 * @return void
2266
+	 */
2267
+	public function display_admin_page_with_no_sidebar()
2268
+	{
2269
+		$this->_display_admin_page();
2270
+	}
2271
+
2272
+
2273
+
2274
+	/**
2275
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2276
+	 *
2277
+	 * @access public
2278
+	 * @return void
2279
+	 */
2280
+	public function display_about_admin_page()
2281
+	{
2282
+		$this->_display_admin_page(false, true);
2283
+	}
2284
+
2285
+
2286
+
2287
+	/**
2288
+	 * display_admin_page
2289
+	 * contains the code for actually displaying an admin page
2290
+	 *
2291
+	 * @access private
2292
+	 * @param  boolean $sidebar true with sidebar, false without
2293
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2294
+	 * @return void
2295
+	 */
2296
+	private function _display_admin_page($sidebar = false, $about = false)
2297
+	{
2298
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2299
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2300
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2301
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2302
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2303
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2304
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2305
+				? 'poststuff'
2306
+				: 'espresso-default-admin';
2307
+		$template_path = $sidebar
2308
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2309
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2310
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2311
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2312
+		}
2313
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2314
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2315
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2316
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2317
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2318
+		// the final template wrapper
2319
+		$this->admin_page_wrapper($about);
2320
+	}
2321
+
2322
+
2323
+
2324
+	/**
2325
+	 * This is used to display caf preview pages.
2326
+	 *
2327
+	 * @since 4.3.2
2328
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2329
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2330
+	 * @return void
2331
+	 * @throws \EE_Error
2332
+	 */
2333
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2334
+	{
2335
+		//let's generate a default preview action button if there isn't one already present.
2336
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2337
+		$buy_now_url = add_query_arg(
2338
+				array(
2339
+						'ee_ver'       => 'ee4',
2340
+						'utm_source'   => 'ee4_plugin_admin',
2341
+						'utm_medium'   => 'link',
2342
+						'utm_campaign' => $utm_campaign_source,
2343
+						'utm_content'  => 'buy_now_button',
2344
+				),
2345
+				'http://eventespresso.com/pricing/'
2346
+		);
2347
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2348
+				? $this->get_action_link_or_button(
2349
+						'',
2350
+						'buy_now',
2351
+						array(),
2352
+						'button-primary button-large',
2353
+						$buy_now_url,
2354
+						true
2355
+				)
2356
+				: $this->_template_args['preview_action_button'];
2357
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2358
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2359
+				$template_path,
2360
+				$this->_template_args,
2361
+				true
2362
+		);
2363
+		$this->_display_admin_page($display_sidebar);
2364
+	}
2365
+
2366
+
2367
+
2368
+	/**
2369
+	 * display_admin_list_table_page_with_sidebar
2370
+	 * generates HTML wrapper for an admin_page with list_table
2371
+	 *
2372
+	 * @access public
2373
+	 * @return void
2374
+	 */
2375
+	public function display_admin_list_table_page_with_sidebar()
2376
+	{
2377
+		$this->_display_admin_list_table_page(true);
2378
+	}
2379
+
2380
+
2381
+
2382
+	/**
2383
+	 * display_admin_list_table_page_with_no_sidebar
2384
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2385
+	 *
2386
+	 * @access public
2387
+	 * @return void
2388
+	 */
2389
+	public function display_admin_list_table_page_with_no_sidebar()
2390
+	{
2391
+		$this->_display_admin_list_table_page();
2392
+	}
2393
+
2394
+
2395
+
2396
+	/**
2397
+	 * generates html wrapper for an admin_list_table page
2398
+	 *
2399
+	 * @access private
2400
+	 * @param boolean $sidebar whether to display with sidebar or not.
2401
+	 * @return void
2402
+	 */
2403
+	private function _display_admin_list_table_page($sidebar = false)
2404
+	{
2405
+		//setup search attributes
2406
+		$this->_set_search_attributes();
2407
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2408
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2409
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2410
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2411
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2412
+		$this->_template_args['list_table'] = $this->_list_table_object;
2413
+		$this->_template_args['current_route'] = $this->_req_action;
2414
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2415
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2416
+		if ( ! empty($ajax_sorting_callback)) {
2417
+			$sortable_list_table_form_fields = wp_nonce_field(
2418
+					$ajax_sorting_callback . '_nonce',
2419
+					$ajax_sorting_callback . '_nonce',
2420
+					false,
2421
+					false
2422
+			);
2423
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2424
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2425
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2426
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2427
+		} else {
2428
+			$sortable_list_table_form_fields = '';
2429
+		}
2430
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2431
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2432
+		$nonce_ref = $this->_req_action . '_nonce';
2433
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2434
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2435
+		//display message about search results?
2436
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2437
+				? '<p class="ee-search-results">' . sprintf(
2438
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2439
+						trim($this->_req_data['s'], '%')
2440
+				) . '</p>'
2441
+				: '';
2442
+		// filter before_list_table template arg
2443
+		$this->_template_args['before_list_table'] = apply_filters(
2444
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2445
+			$this->_template_args['before_list_table'],
2446
+			$this->page_slug,
2447
+			$this->_req_data,
2448
+			$this->_req_action
2449
+		);
2450
+		// convert to array and filter again
2451
+		// arrays are easier to inject new items in a specific location,
2452
+		// but would not be backwards compatible, so we have to add a new filter
2453
+		$this->_template_args['before_list_table'] = implode(
2454
+			" \n",
2455
+			(array) apply_filters(
2456
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2457
+				(array) $this->_template_args['before_list_table'],
2458
+				$this->page_slug,
2459
+				$this->_req_data,
2460
+				$this->_req_action
2461
+			)
2462
+		);
2463
+		// filter after_list_table template arg
2464
+		$this->_template_args['after_list_table'] = apply_filters(
2465
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2466
+			$this->_template_args['after_list_table'],
2467
+			$this->page_slug,
2468
+			$this->_req_data,
2469
+			$this->_req_action
2470
+		);
2471
+		// convert to array and filter again
2472
+		// arrays are easier to inject new items in a specific location,
2473
+		// but would not be backwards compatible, so we have to add a new filter
2474
+		$this->_template_args['after_list_table'] = implode(
2475
+			" \n",
2476
+			(array) apply_filters(
2477
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2478
+				(array) $this->_template_args['after_list_table'],
2479
+				$this->page_slug,
2480
+				$this->_req_data,
2481
+				$this->_req_action
2482
+			)
2483
+		);
2484
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2485
+				$template_path,
2486
+				$this->_template_args,
2487
+				true
2488
+		);
2489
+		// the final template wrapper
2490
+		if ($sidebar) {
2491
+			$this->display_admin_page_with_sidebar();
2492
+		} else {
2493
+			$this->display_admin_page_with_no_sidebar();
2494
+		}
2495
+	}
2496
+
2497
+
2498
+
2499
+	/**
2500
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2501
+	 * $items are expected in an array in the following format:
2502
+	 * $legend_items = array(
2503
+	 *        'item_id' => array(
2504
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2505
+	 *            'desc' => __('localized description of item');
2506
+	 *        )
2507
+	 * );
2508
+	 *
2509
+	 * @param  array $items see above for format of array
2510
+	 * @return string        html string of legend
2511
+	 */
2512
+	protected function _display_legend($items)
2513
+	{
2514
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2515
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2516
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2517
+	}
2518
+
2519
+
2520
+
2521
+	/**
2522
+	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2523
+	 *
2524
+	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2525
+	 *                             The returned json object is created from an array in the following format:
2526
+	 *                             array(
2527
+	 *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2528
+	 *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2529
+	 *                             'notices' => '', // - contains any EE_Error formatted notices
2530
+	 *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2531
+	 *                             'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2532
+	 *                             specific template args that might be included in here)
2533
+	 *                             )
2534
+	 *                             The json object is populated by whatever is set in the $_template_args property.
2535
+	 * @return void
2536
+	 */
2537
+	protected function _return_json($sticky_notices = false)
2538
+	{
2539
+		//make sure any EE_Error notices have been handled.
2540
+		$this->_process_notices(array(), true, $sticky_notices);
2541
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2542
+		unset($this->_template_args['data']);
2543
+		$json = array(
2544
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2545
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2546
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2547
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2548
+				'notices'   => EE_Error::get_notices(),
2549
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2550
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2551
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2552
+		);
2553
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2554
+		if (null === error_get_last() || ! headers_sent()) {
2555
+			header('Content-Type: application/json; charset=UTF-8');
2556
+		}
2557
+		echo wp_json_encode($json);
2558
+
2559
+		exit();
2560
+	}
2561
+
2562
+
2563
+
2564
+	/**
2565
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2566
+	 *
2567
+	 * @return void
2568
+	 * @throws EE_Error
2569
+	 */
2570
+	public function return_json()
2571
+	{
2572
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2573
+			$this->_return_json();
2574
+		} else {
2575
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2576
+		}
2577
+	}
2578
+
2579
+
2580
+
2581
+	/**
2582
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2583
+	 *
2584
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2585
+	 * @access   public
2586
+	 */
2587
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2588
+	{
2589
+		$this->_hook_obj = $hook_obj;
2590
+	}
2591
+
2592
+
2593
+
2594
+	/**
2595
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2596
+	 *
2597
+	 * @access public
2598
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2599
+	 * @return void
2600
+	 */
2601
+	public function admin_page_wrapper($about = false)
2602
+	{
2603
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2604
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2605
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2606
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2607
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2608
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2609
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2610
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2611
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2612
+		// load settings page wrapper template
2613
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2614
+		//about page?
2615
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2616
+		if (defined('DOING_AJAX')) {
2617
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2618
+			$this->_return_json();
2619
+		} else {
2620
+			EEH_Template::display_template($template_path, $this->_template_args);
2621
+		}
2622
+	}
2623
+
2624
+
2625
+
2626
+	/**
2627
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2628
+	 *
2629
+	 * @return string html
2630
+	 */
2631
+	protected function _get_main_nav_tabs()
2632
+	{
2633
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2634
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2635
+	}
2636
+
2637
+
2638
+
2639
+	/**
2640
+	 *        sort nav tabs
2641
+	 *
2642
+	 * @access public
2643
+	 * @param $a
2644
+	 * @param $b
2645
+	 * @return int
2646
+	 */
2647
+	private function _sort_nav_tabs($a, $b)
2648
+	{
2649
+		if ($a['order'] == $b['order']) {
2650
+			return 0;
2651
+		}
2652
+		return ($a['order'] < $b['order']) ? -1 : 1;
2653
+	}
2654
+
2655
+
2656
+
2657
+	/**
2658
+	 *    generates HTML for the forms used on admin pages
2659
+	 *
2660
+	 * @access protected
2661
+	 * @param    array $input_vars - array of input field details
2662
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2663
+	 * @return string
2664
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2665
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2666
+	 */
2667
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2668
+	{
2669
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2670
+		return $content;
2671
+	}
2672
+
2673
+
2674
+
2675
+	/**
2676
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2677
+	 *
2678
+	 * @access protected
2679
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2680
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2681
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2682
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2683
+	 */
2684
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2685
+	{
2686
+		//make sure $text and $actions are in an array
2687
+		$text = (array)$text;
2688
+		$actions = (array)$actions;
2689
+		$referrer_url = empty($referrer) ? '' : $referrer;
2690
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2691
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2692
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2693
+		$default_names = array('save', 'save_and_close');
2694
+		//add in a hidden index for the current page (so save and close redirects properly)
2695
+		$this->_template_args['save_buttons'] = $referrer_url;
2696
+		foreach ($button_text as $key => $button) {
2697
+			$ref = $default_names[$key];
2698
+			$id = $this->_current_view . '_' . $ref;
2699
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2700
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2701
+			if ( ! $both) {
2702
+				break;
2703
+			}
2704
+		}
2705
+	}
2706
+
2707
+
2708
+
2709
+	/**
2710
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2711
+	 *
2712
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2713
+	 * @since 4.6.0
2714
+	 * @param string $route
2715
+	 * @param array  $additional_hidden_fields
2716
+	 */
2717
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2718
+	{
2719
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2720
+	}
2721
+
2722
+
2723
+
2724
+	/**
2725
+	 * set form open and close tags on add/edit pages.
2726
+	 *
2727
+	 * @access protected
2728
+	 * @param string $route                    the route you want the form to direct to
2729
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2730
+	 * @return void
2731
+	 */
2732
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2733
+	{
2734
+		if (empty($route)) {
2735
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2736
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2737
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2738
+		}
2739
+		// open form
2740
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2741
+		// add nonce
2742
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2743
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2744
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2745
+		// add REQUIRED form action
2746
+		$hidden_fields = array(
2747
+				'action' => array('type' => 'hidden', 'value' => $route),
2748
+		);
2749
+		// merge arrays
2750
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2751
+		// generate form fields
2752
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2753
+		// add fields to form
2754
+		foreach ((array)$form_fields as $field_name => $form_field) {
2755
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2756
+		}
2757
+		// close form
2758
+		$this->_template_args['after_admin_page_content'] = '</form>';
2759
+	}
2760
+
2761
+
2762
+
2763
+	/**
2764
+	 * Public Wrapper for _redirect_after_action() method since its
2765
+	 * discovered it would be useful for external code to have access.
2766
+	 *
2767
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2768
+	 * @since 4.5.0
2769
+	 */
2770
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2771
+	{
2772
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2773
+	}
2774
+
2775
+
2776
+
2777
+	/**
2778
+	 *    _redirect_after_action
2779
+	 *
2780
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2781
+	 * @param string $what               - what the action was performed on
2782
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2783
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2784
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2785
+	 * @access protected
2786
+	 * @return void
2787
+	 */
2788
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2789
+	{
2790
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2791
+		//class name for actions/filters.
2792
+		$classname = get_class($this);
2793
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2794
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2795
+		$notices = EE_Error::get_notices(false);
2796
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2797
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2798
+			EE_Error::overwrite_success();
2799
+		}
2800
+		if ( ! empty($what) && ! empty($action_desc)) {
2801
+			// how many records affected ? more than one record ? or just one ?
2802
+			if ($success > 1 && empty($notices['errors'])) {
2803
+				// set plural msg
2804
+				EE_Error::add_success(
2805
+						sprintf(
2806
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2807
+								$what,
2808
+								$action_desc
2809
+						),
2810
+						__FILE__, __FUNCTION__, __LINE__
2811
+				);
2812
+			} else if ($success == 1 && empty($notices['errors'])) {
2813
+				// set singular msg
2814
+				EE_Error::add_success(
2815
+						sprintf(
2816
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2817
+								$what,
2818
+								$action_desc
2819
+						),
2820
+						__FILE__, __FUNCTION__, __LINE__
2821
+				);
2822
+			}
2823
+		}
2824
+		// check that $query_args isn't something crazy
2825
+		if ( ! is_array($query_args)) {
2826
+			$query_args = array();
2827
+		}
2828
+		/**
2829
+		 * Allow injecting actions before the query_args are modified for possible different
2830
+		 * redirections on save and close actions
2831
+		 *
2832
+		 * @since 4.2.0
2833
+		 * @param array $query_args       The original query_args array coming into the
2834
+		 *                                method.
2835
+		 */
2836
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2837
+		//calculate where we're going (if we have a "save and close" button pushed)
2838
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2839
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2840
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2841
+			// regenerate query args array from referrer URL
2842
+			parse_str($parsed_url['query'], $query_args);
2843
+			// correct page and action will be in the query args now
2844
+			$redirect_url = admin_url('admin.php');
2845
+		}
2846
+		//merge any default query_args set in _default_route_query_args property
2847
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2848
+			$args_to_merge = array();
2849
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2850
+				//is there a wp_referer array in our _default_route_query_args property?
2851
+				if ($query_param == 'wp_referer') {
2852
+					$query_value = (array)$query_value;
2853
+					foreach ($query_value as $reference => $value) {
2854
+						if (strpos($reference, 'nonce') !== false) {
2855
+							continue;
2856
+						}
2857
+						//finally we will override any arguments in the referer with
2858
+						//what might be set on the _default_route_query_args array.
2859
+						if (isset($this->_default_route_query_args[$reference])) {
2860
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2861
+						} else {
2862
+							$args_to_merge[$reference] = urlencode($value);
2863
+						}
2864
+					}
2865
+					continue;
2866
+				}
2867
+				$args_to_merge[$query_param] = $query_value;
2868
+			}
2869
+			//now let's merge these arguments but override with what was specifically sent in to the
2870
+			//redirect.
2871
+			$query_args = array_merge($args_to_merge, $query_args);
2872
+		}
2873
+		$this->_process_notices($query_args);
2874
+		// generate redirect url
2875
+		// if redirecting to anything other than the main page, add a nonce
2876
+		if (isset($query_args['action'])) {
2877
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2878
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2879
+		}
2880
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2881
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2882
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2883
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2884
+		if (defined('DOING_AJAX')) {
2885
+			$default_data = array(
2886
+					'close'        => true,
2887
+					'redirect_url' => $redirect_url,
2888
+					'where'        => 'main',
2889
+					'what'         => 'append',
2890
+			);
2891
+			$this->_template_args['success'] = $success;
2892
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2893
+			$this->_return_json();
2894
+		}
2895
+		wp_safe_redirect($redirect_url);
2896
+		exit();
2897
+	}
2898
+
2899
+
2900
+
2901
+	/**
2902
+	 * process any notices before redirecting (or returning ajax request)
2903
+	 * This method sets the $this->_template_args['notices'] attribute;
2904
+	 *
2905
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2906
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2907
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2908
+	 * @return void
2909
+	 */
2910
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2911
+	{
2912
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2913
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2914
+			$notices = EE_Error::get_notices(false);
2915
+			if (empty($this->_template_args['success'])) {
2916
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2917
+			}
2918
+			if (empty($this->_template_args['errors'])) {
2919
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2920
+			}
2921
+			if (empty($this->_template_args['attention'])) {
2922
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2923
+			}
2924
+		}
2925
+		$this->_template_args['notices'] = EE_Error::get_notices();
2926
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2927
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2928
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2929
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2930
+		}
2931
+	}
2932
+
2933
+
2934
+
2935
+	/**
2936
+	 * get_action_link_or_button
2937
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2938
+	 *
2939
+	 * @param string $action        use this to indicate which action the url is generated with.
2940
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2941
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2942
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2943
+	 * @param string $base_url      If this is not provided
2944
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2945
+	 *                              Otherwise this value will be used.
2946
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2947
+	 * @return string
2948
+	 * @throws \EE_Error
2949
+	 */
2950
+	public function get_action_link_or_button(
2951
+			$action,
2952
+			$type = 'add',
2953
+			$extra_request = array(),
2954
+			$class = 'button-primary',
2955
+			$base_url = '',
2956
+			$exclude_nonce = false
2957
+	) {
2958
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2959
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2960
+			throw new EE_Error(
2961
+					sprintf(
2962
+							__(
2963
+									'There is no page route for given action for the button.  This action was given: %s',
2964
+									'event_espresso'
2965
+							),
2966
+							$action
2967
+					)
2968
+			);
2969
+		}
2970
+		if ( ! isset($this->_labels['buttons'][$type])) {
2971
+			throw new EE_Error(
2972
+					sprintf(
2973
+							__(
2974
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2975
+									'event_espresso'
2976
+							),
2977
+							$type
2978
+					)
2979
+			);
2980
+		}
2981
+		//finally check user access for this button.
2982
+		$has_access = $this->check_user_access($action, true);
2983
+		if ( ! $has_access) {
2984
+			return '';
2985
+		}
2986
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2987
+		$query_args = array(
2988
+				'action' => $action,
2989
+		);
2990
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2991
+		if ( ! empty($extra_request)) {
2992
+			$query_args = array_merge($extra_request, $query_args);
2993
+		}
2994
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2995
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2996
+	}
2997
+
2998
+
2999
+
3000
+	/**
3001
+	 * _per_page_screen_option
3002
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3003
+	 *
3004
+	 * @return void
3005
+	 */
3006
+	protected function _per_page_screen_option()
3007
+	{
3008
+		$option = 'per_page';
3009
+		$args = array(
3010
+				'label'   => $this->_admin_page_title,
3011
+				'default' => 10,
3012
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3013
+		);
3014
+		//ONLY add the screen option if the user has access to it.
3015
+		if ($this->check_user_access($this->_current_view, true)) {
3016
+			add_screen_option($option, $args);
3017
+		}
3018
+	}
3019
+
3020
+
3021
+
3022
+	/**
3023
+	 * set_per_page_screen_option
3024
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3025
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3026
+	 *
3027
+	 * @access private
3028
+	 * @return void
3029
+	 */
3030
+	private function _set_per_page_screen_options()
3031
+	{
3032
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3033
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3034
+			if ( ! $user = wp_get_current_user()) {
3035
+				return;
3036
+			}
3037
+			$option = $_POST['wp_screen_options']['option'];
3038
+			$value = $_POST['wp_screen_options']['value'];
3039
+			if ($option != sanitize_key($option)) {
3040
+				return;
3041
+			}
3042
+			$map_option = $option;
3043
+			$option = str_replace('-', '_', $option);
3044
+			switch ($map_option) {
3045
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3046
+					$value = (int)$value;
3047
+					if ($value < 1 || $value > 999) {
3048
+						return;
3049
+					}
3050
+					break;
3051
+				default:
3052
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3053
+					if (false === $value) {
3054
+						return;
3055
+					}
3056
+					break;
3057
+			}
3058
+			update_user_meta($user->ID, $option, $value);
3059
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3060
+			exit;
3061
+		}
3062
+	}
3063
+
3064
+
3065
+
3066
+	/**
3067
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3068
+	 *
3069
+	 * @param array $data array that will be assigned to template args.
3070
+	 */
3071
+	public function set_template_args($data)
3072
+	{
3073
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3074
+	}
3075
+
3076
+
3077
+
3078
+	/**
3079
+	 * This makes available the WP transient system for temporarily moving data between routes
3080
+	 *
3081
+	 * @access protected
3082
+	 * @param string $route             the route that should receive the transient
3083
+	 * @param array  $data              the data that gets sent
3084
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3085
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3086
+	 * @return void
3087
+	 */
3088
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3089
+	{
3090
+		$user_id = get_current_user_id();
3091
+		if ( ! $skip_route_verify) {
3092
+			$this->_verify_route($route);
3093
+		}
3094
+		//now let's set the string for what kind of transient we're setting
3095
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3096
+		$data = $notices ? array('notices' => $data) : $data;
3097
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3098
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3099
+		if ($existing) {
3100
+			$data = array_merge((array)$data, (array)$existing);
3101
+		}
3102
+		if (is_multisite() && is_network_admin()) {
3103
+			set_site_transient($transient, $data, 8);
3104
+		} else {
3105
+			set_transient($transient, $data, 8);
3106
+		}
3107
+	}
3108
+
3109
+
3110
+
3111
+	/**
3112
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3113
+	 *
3114
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3115
+	 * @return mixed data
3116
+	 */
3117
+	protected function _get_transient($notices = false, $route = false)
3118
+	{
3119
+		$user_id = get_current_user_id();
3120
+		$route = ! $route ? $this->_req_action : $route;
3121
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3122
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3123
+		//delete transient after retrieval (just in case it hasn't expired);
3124
+		if (is_multisite() && is_network_admin()) {
3125
+			delete_site_transient($transient);
3126
+		} else {
3127
+			delete_transient($transient);
3128
+		}
3129
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3130
+	}
3131
+
3132
+
3133
+
3134
+	/**
3135
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3136
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3137
+	 *
3138
+	 * @return void
3139
+	 */
3140
+	protected function _transient_garbage_collection()
3141
+	{
3142
+		global $wpdb;
3143
+		//retrieve all existing transients
3144
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3145
+		if ($results = $wpdb->get_results($query)) {
3146
+			foreach ($results as $result) {
3147
+				$transient = str_replace('_transient_', '', $result->option_name);
3148
+				get_transient($transient);
3149
+				if (is_multisite() && is_network_admin()) {
3150
+					get_site_transient($transient);
3151
+				}
3152
+			}
3153
+		}
3154
+	}
3155
+
3156
+
3157
+
3158
+	/**
3159
+	 * get_view
3160
+	 *
3161
+	 * @access public
3162
+	 * @return string content of _view property
3163
+	 */
3164
+	public function get_view()
3165
+	{
3166
+		return $this->_view;
3167
+	}
3168
+
3169
+
3170
+
3171
+	/**
3172
+	 * getter for the protected $_views property
3173
+	 *
3174
+	 * @return array
3175
+	 */
3176
+	public function get_views()
3177
+	{
3178
+		return $this->_views;
3179
+	}
3180
+
3181
+
3182
+
3183
+	/**
3184
+	 * get_current_page
3185
+	 *
3186
+	 * @access public
3187
+	 * @return string _current_page property value
3188
+	 */
3189
+	public function get_current_page()
3190
+	{
3191
+		return $this->_current_page;
3192
+	}
3193
+
3194
+
3195
+
3196
+	/**
3197
+	 * get_current_view
3198
+	 *
3199
+	 * @access public
3200
+	 * @return string _current_view property value
3201
+	 */
3202
+	public function get_current_view()
3203
+	{
3204
+		return $this->_current_view;
3205
+	}
3206
+
3207
+
3208
+
3209
+	/**
3210
+	 * get_current_screen
3211
+	 *
3212
+	 * @access public
3213
+	 * @return object The current WP_Screen object
3214
+	 */
3215
+	public function get_current_screen()
3216
+	{
3217
+		return $this->_current_screen;
3218
+	}
3219
+
3220
+
3221
+
3222
+	/**
3223
+	 * get_current_page_view_url
3224
+	 *
3225
+	 * @access public
3226
+	 * @return string This returns the url for the current_page_view.
3227
+	 */
3228
+	public function get_current_page_view_url()
3229
+	{
3230
+		return $this->_current_page_view_url;
3231
+	}
3232
+
3233
+
3234
+
3235
+	/**
3236
+	 * just returns the _req_data property
3237
+	 *
3238
+	 * @return array
3239
+	 */
3240
+	public function get_request_data()
3241
+	{
3242
+		return $this->_req_data;
3243
+	}
3244
+
3245
+
3246
+
3247
+	/**
3248
+	 * returns the _req_data protected property
3249
+	 *
3250
+	 * @return string
3251
+	 */
3252
+	public function get_req_action()
3253
+	{
3254
+		return $this->_req_action;
3255
+	}
3256
+
3257
+
3258
+
3259
+	/**
3260
+	 * @return bool  value of $_is_caf property
3261
+	 */
3262
+	public function is_caf()
3263
+	{
3264
+		return $this->_is_caf;
3265
+	}
3266
+
3267
+
3268
+
3269
+	/**
3270
+	 * @return mixed
3271
+	 */
3272
+	public function default_espresso_metaboxes()
3273
+	{
3274
+		return $this->_default_espresso_metaboxes;
3275
+	}
3276
+
3277
+
3278
+
3279
+	/**
3280
+	 * @return mixed
3281
+	 */
3282
+	public function admin_base_url()
3283
+	{
3284
+		return $this->_admin_base_url;
3285
+	}
3286
+
3287
+
3288
+
3289
+	/**
3290
+	 * @return mixed
3291
+	 */
3292
+	public function wp_page_slug()
3293
+	{
3294
+		return $this->_wp_page_slug;
3295
+	}
3296
+
3297
+
3298
+
3299
+	/**
3300
+	 * updates  espresso configuration settings
3301
+	 *
3302
+	 * @access    protected
3303
+	 * @param string                   $tab
3304
+	 * @param EE_Config_Base|EE_Config $config
3305
+	 * @param string                   $file file where error occurred
3306
+	 * @param string                   $func function  where error occurred
3307
+	 * @param string                   $line line no where error occurred
3308
+	 * @return boolean
3309
+	 */
3310
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3311
+	{
3312
+		//remove any options that are NOT going to be saved with the config settings.
3313
+		if (isset($config->core->ee_ueip_optin)) {
3314
+			$config->core->ee_ueip_has_notified = true;
3315
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3316
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3317
+			update_option('ee_ueip_has_notified', true);
3318
+		}
3319
+		// and save it (note we're also doing the network save here)
3320
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3321
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3322
+		if ($config_saved && $net_saved) {
3323
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3324
+			return true;
3325
+		} else {
3326
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3327
+			return false;
3328
+		}
3329
+	}
3330
+
3331
+
3332
+
3333
+	/**
3334
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3335
+	 *
3336
+	 * @return array
3337
+	 */
3338
+	public function get_yes_no_values()
3339
+	{
3340
+		return $this->_yes_no_values;
3341
+	}
3342
+
3343
+
3344
+
3345
+	protected function _get_dir()
3346
+	{
3347
+		$reflector = new ReflectionClass(get_class($this));
3348
+		return dirname($reflector->getFileName());
3349
+	}
3350
+
3351
+
3352
+
3353
+	/**
3354
+	 * A helper for getting a "next link".
3355
+	 *
3356
+	 * @param string $url   The url to link to
3357
+	 * @param string $class The class to use.
3358
+	 * @return string
3359
+	 */
3360
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3361
+	{
3362
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3363
+	}
3364
+
3365
+
3366
+
3367
+	/**
3368
+	 * A helper for getting a "previous link".
3369
+	 *
3370
+	 * @param string $url   The url to link to
3371
+	 * @param string $class The class to use.
3372
+	 * @return string
3373
+	 */
3374
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3375
+	{
3376
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3377
+	}
3378
+
3379
+
3380
+
3381
+
3382
+
3383
+
3384
+
3385
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3386
+	/**
3387
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3388
+	 * array.
3389
+	 *
3390
+	 * @return bool success/fail
3391
+	 */
3392
+	protected function _process_resend_registration()
3393
+	{
3394
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3395
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3396
+		return $this->_template_args['success'];
3397
+	}
3398
+
3399
+
3400
+
3401
+	/**
3402
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3403
+	 *
3404
+	 * @access protected
3405
+	 * @param \EE_Payment $payment
3406
+	 * @return bool success/fail
3407
+	 */
3408
+	protected function _process_payment_notification(EE_Payment $payment)
3409
+	{
3410
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3411
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3412
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3413
+		return $this->_template_args['success'];
3414
+	}
3415 3415
 
3416 3416
 
3417 3417
 }
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475 475
         $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476 476
         global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
477
+        $ee_menu_slugs = (array) $ee_menu_slugs;
478 478
         if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479 479
             return;
480 480
         }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490 490
         $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491 491
         $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
492
+        $this->_req_nonce = $this->_req_action.'_nonce';
493 493
         $this->_define_page_props();
494 494
         $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495 495
         //default things
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
             $this->_extend_page_config_for_cpt();
511 511
         }
512 512
         //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
513
+        $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this);
514
+        $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this);
515 515
         //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
516
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
517
+            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2);
518 518
         }
519 519
         //next route only if routing enabled
520 520
         if ($this->_routing && ! defined('DOING_AJAX')) {
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
             if ($this->_is_UI_request) {
525 525
                 //admin_init stuff - global, all views for this page class, specific view
526 526
                 add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
527
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
528
+                    add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15);
529 529
                 }
530 530
             } else {
531 531
                 //hijack regular WP loading and route admin request immediately
@@ -545,17 +545,17 @@  discard block
 block discarded – undo
545 545
      */
546 546
     private function _do_other_page_hooks()
547 547
     {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array());
549 549
         foreach ($registered_pages as $page) {
550 550
             //now let's setup the file name and class that should be present
551 551
             $classname = str_replace('.class.php', '', $page);
552 552
             //autoloaders should take care of loading file
553 553
             if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
+                $error_msg[] = sprintf(esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555 555
                 $error_msg[] = $error_msg[0]
556 556
                                . "\r\n"
557
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
557
+                               . sprintf(esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
+                                'event_espresso'), $page, '<br />', '<strong>'.$classname.'</strong>');
559 559
                 throw new EE_Error(implode('||', $error_msg));
560 560
             }
561 561
             $a = new ReflectionClass($classname);
@@ -591,13 +591,13 @@  discard block
 block discarded – undo
591 591
         //load admin_notices - global, page class, and view specific
592 592
         add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593 593
         add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
594
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
595
+            add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15);
596 596
         }
597 597
         //load network admin_notices - global, page class, and view specific
598 598
         add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
599
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
600
+            add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view));
601 601
         }
602 602
         //this will save any per_page screen options if they are present
603 603
         $this->_set_per_page_screen_options();
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
         //add screen options - global, page child class, and view specific
610 610
         $this->_add_global_screen_options();
611 611
         $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
612
+        if (method_exists($this, '_add_screen_options_'.$this->_current_view)) {
613
+            call_user_func(array($this, '_add_screen_options_'.$this->_current_view));
614 614
         }
615 615
         //add help tab(s) and tours- set via page_config and qtips.
616 616
         $this->_add_help_tour();
@@ -619,31 +619,31 @@  discard block
 block discarded – undo
619 619
         //add feature_pointers - global, page child class, and view specific
620 620
         $this->_add_feature_pointers();
621 621
         $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
622
+        if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) {
623
+            call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view));
624 624
         }
625 625
         //enqueue scripts/styles - global, page class, and view specific
626 626
         add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627 627
         add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
628
+        if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) {
629
+            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15);
630 630
         }
631 631
         add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632 632
         //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633 633
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634 634
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
635
+        if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) {
636
+            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101);
637 637
         }
638 638
         //admin footer scripts
639 639
         add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640 640
         add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
641
+        if (method_exists($this, 'admin_footer_'.$this->_current_view)) {
642
+            add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101);
643 643
         }
644 644
         do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645 645
         //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
+        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action);
647 647
     }
648 648
 
649 649
 
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
             // user error msg
720 720
             $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721 721
             // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
+            $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723 723
             throw new EE_Error($error_msg);
724 724
         }
725 725
         // and that the requested page route exists
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
             // user error msg
731 731
             $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732 732
             // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
733
+            $error_msg .= '||'.$error_msg.sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734 734
             throw new EE_Error($error_msg);
735 735
         }
736 736
         // and that a default route exists
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
             // user error msg
739 739
             $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740 740
             // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
741
+            $error_msg .= '||'.$error_msg.__(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742 742
             throw new EE_Error($error_msg);
743 743
         }
744 744
         //first lets' catch if the UI request has EVER been set.
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
             // user error msg
768 768
             $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769 769
             // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
770
+            $error_msg .= '||'.$error_msg.sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771 771
             throw new EE_Error($error_msg);
772 772
         }
773 773
     }
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             // these are not the droids you are looking for !!!
790 790
             $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791 791
             if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
792
+                $msg .= "\n  ".sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793 793
             }
794 794
             if ( ! defined('DOING_AJAX')) {
795 795
                 wp_die($msg);
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                 if (strpos($key, 'nonce') !== false) {
968 968
                     continue;
969 969
                 }
970
-                $args['wp_referer[' . $key . ']'] = $value;
970
+                $args['wp_referer['.$key.']'] = $value;
971 971
             }
972 972
         }
973 973
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
                     if ($tour instanceof EE_Help_Tour_final_stop) {
1014 1014
                         continue;
1015 1015
                     }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1016
+                    $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>';
1017 1017
                 }
1018 1018
                 $tour_buttons .= implode('<br />', $tb);
1019 1019
                 $tour_buttons .= '</div></div>';
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
                     throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026 1026
                             'event_espresso'), $config['help_sidebar'], get_class($this)));
1027 1027
                 }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1028
+                $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029 1029
                 $content .= $tour_buttons; //add help tour buttons.
1030 1030
                 //do we have any help tours setup?  Cause if we do we want to add the buttons
1031 1031
                 $this->_current_screen->set_help_sidebar($content);
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
             if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039 1039
                 $_ht['id'] = $this->page_slug;
1040 1040
                 $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1041
+                $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>';
1042 1042
                 $this->_current_screen->add_help_tab($_ht);
1043 1043
             }/**/
1044 1044
             if ( ! isset($config['help_tabs'])) {
1045 1045
                 return;
1046 1046
             } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1047
+            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1048 1048
                 //we're here so there ARE help tabs!
1049 1049
                 //make sure we've got what we need
1050 1050
                 if ( ! isset($cfg['title'])) {
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060 1060
                     //second priority goes to filename
1061 1061
                 } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1062
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1063 1063
                     //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1064
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path;
1065 1065
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066 1066
                     if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067 1067
                         EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
                     return;
1081 1081
                 }
1082 1082
                 //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1083
+                $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1084 1084
                 $_ht = array(
1085 1085
                         'id'       => $id,
1086 1086
                         'title'    => $cfg['title'],
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
             }
1119 1119
             if (isset($config['help_tour'])) {
1120 1120
                 foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1121
+                    $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php';
1122 1122
                     //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1123
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path;
1124 1124
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125 1125
                     if ( ! is_readable($file_path)) {
1126 1126
                         EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                     require_once $file_path;
1131 1131
                     if ( ! class_exists($tour)) {
1132 1132
                         $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1133
+                        $error_msg[] = $error_msg[0]."\r\n".sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134 1134
                                         'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135 1135
                         throw new EE_Error(implode('||', $error_msg));
1136 1136
                     }
@@ -1162,11 +1162,11 @@  discard block
 block discarded – undo
1162 1162
     protected function _add_qtips()
1163 1163
     {
1164 1164
         if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1165
+            $qtips = (array) $this->_route_config['qtips'];
1166 1166
             //load qtip loader
1167 1167
             $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1168
+                    $this->_get_dir().'/qtips/',
1169
+                    EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1170 1170
             );
1171 1171
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1172 1172
         }
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
             if ( ! $this->check_user_access($slug, true)) {
1197 1197
                 continue;
1198 1198
             } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1199
+            $css_class = isset($config['css_class']) ? $config['css_class'].' ' : '';
1200 1200
             $this->_nav_tabs[$slug] = array(
1201 1201
                     'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202 1202
                     'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1203
+                    'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class,
1204 1204
                     'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205 1205
             );
1206 1206
             $i++;
@@ -1263,11 +1263,11 @@  discard block
 block discarded – undo
1263 1263
             $capability = empty($capability) ? 'manage_options' : $capability;
1264 1264
         }
1265 1265
         $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1266
+        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267 1267
             if ($verify_only) {
1268 1268
                 return false;
1269 1269
             } else {
1270
-                if ( is_user_logged_in() ) {
1270
+                if (is_user_logged_in()) {
1271 1271
                     wp_die(__('You do not have access to this route.', 'event_espresso'));
1272 1272
                 } else {
1273 1273
                     return false;
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
     public function admin_footer_global()
1360 1360
     {
1361 1361
         //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1362
+        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n";
1363 1363
         $d_cont .= '<div class="ee-notices"></div>';
1364 1364
         $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365 1365
         $d_cont .= '</div>';
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
             echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370 1370
         }
1371 1371
         //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1372
+        echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>';
1373 1373
     }
1374 1374
 
1375 1375
 
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
     {
1395 1395
         $content = '';
1396 1396
         $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1397
+        $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php';
1398 1398
         //loop through the array and setup content
1399 1399
         foreach ($help_array as $trigger => $help) {
1400 1400
             //make sure the array is setup properly
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
     private function _get_help_content()
1429 1429
     {
1430 1430
         //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1431
+        $method_name = '_help_popup_content_'.$this->_req_action;
1432 1432
         //if method doesn't exist let's get out.
1433 1433
         if ( ! method_exists($this, $method_name)) {
1434 1434
             return array();
@@ -1472,8 +1472,8 @@  discard block
 block discarded – undo
1472 1472
             $help_content = $this->_set_help_popup_content($help_array, false);
1473 1473
         }
1474 1474
         //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1475
+        $content = '<a class="ee-dialog" href="?height='.$dimensions[0].'&width='.$dimensions[1].'&inlineId='.$trigger_id.'" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+        $content = $content.$help_content;
1477 1477
         if ($display) {
1478 1478
             echo $content;
1479 1479
         } else {
@@ -1533,32 +1533,32 @@  discard block
 block discarded – undo
1533 1533
             add_action('admin_head', array($this, 'add_xdebug_style'));
1534 1534
         }
1535 1535
         //register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1536
+        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538 1538
         //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1539
+        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540 1540
         //enqueue global styles
1541 1541
         wp_enqueue_style('ee-admin-css');
1542 1542
         /** SCRIPTS **/
1543 1543
         //register all scripts
1544
-        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1545
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1546
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1547
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1544
+        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1545
+        wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1546
+        wp_register_script('ee_admin_js', EE_ADMIN_URL.'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1547
+        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1548 1548
         // register jQuery Validate - see /includes/functions/wp_hooks.php
1549 1549
         add_filter('FHEE_load_jquery_validate', '__return_true');
1550 1550
         add_filter('FHEE_load_joyride', '__return_true');
1551 1551
         //script for sorting tables
1552
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1552
+        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL."assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1553 1553
         //script for parsing uri's
1554
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1554
+        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1555 1555
         //and parsing associative serialized form elements
1556
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
+        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1557 1557
         //helpers scripts
1558
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1559
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1560
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1561
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1558
+        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1559
+        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1560
+        wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1561
+        wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1562 1562
         //google charts
1563 1563
         wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1564 1564
         //enqueue global scripts
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
          */
1580 1580
         if ( ! empty($this->_help_tour)) {
1581 1581
             //register the js for kicking things off
1582
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1582
+            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1583 1583
             //setup tours for the js tour object
1584 1584
             foreach ($this->_help_tour['tours'] as $tour) {
1585 1585
                 $tours[] = array(
@@ -1678,17 +1678,17 @@  discard block
 block discarded – undo
1678 1678
             return;
1679 1679
         } //not a list_table view so get out.
1680 1680
         //list table functions are per view specific (because some admin pages might have more than one listtable!)
1681
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1681
+        if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) {
1682 1682
             //user error msg
1683 1683
             $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1684 1684
             //developer error msg
1685
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1686
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1685
+            $error_msg .= '||'.sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1686
+                            $this->_req_action, '_set_list_table_views_'.$this->_req_action);
1687 1687
             throw new EE_Error($error_msg);
1688 1688
         }
1689 1689
         //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1690
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1691
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1690
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views);
1691
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1692 1692
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1693 1693
         $this->_set_list_table_view();
1694 1694
         $this->_set_list_table_object();
@@ -1763,7 +1763,7 @@  discard block
 block discarded – undo
1763 1763
             // check for current view
1764 1764
             $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1765 1765
             $query_args['action'] = $this->_req_action;
1766
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1766
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
1767 1767
             $query_args['status'] = $view['slug'];
1768 1768
             //merge any other arguments sent in.
1769 1769
             if (isset($extra_query_args[$view['slug']])) {
@@ -1801,14 +1801,14 @@  discard block
 block discarded – undo
1801 1801
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1802 1802
         foreach ($values as $value) {
1803 1803
             if ($value < $max_entries) {
1804
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1804
+                $selected = $value == $per_page ? ' selected="'.$per_page.'"' : '';
1805 1805
                 $entries_per_page_dropdown .= '
1806
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1806
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1807 1807
             }
1808 1808
         }
1809
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1809
+        $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : '';
1810 1810
         $entries_per_page_dropdown .= '
1811
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1811
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1812 1812
         $entries_per_page_dropdown .= '
1813 1813
 					</select>
1814 1814
 					entries
@@ -1830,7 +1830,7 @@  discard block
 block discarded – undo
1830 1830
     public function _set_search_attributes()
1831 1831
     {
1832 1832
         $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1833
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1833
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
1834 1834
     }
1835 1835
 
1836 1836
     /*** END LIST TABLE METHODS **/
@@ -1868,7 +1868,7 @@  discard block
 block discarded – undo
1868 1868
                     // user error msg
1869 1869
                     $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1870 1870
                     // developer error msg
1871
-                    $error_msg .= '||' . sprintf(
1871
+                    $error_msg .= '||'.sprintf(
1872 1872
                                     __(
1873 1873
                                             'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1874 1874
                                             'event_espresso'
@@ -1898,15 +1898,15 @@  discard block
 block discarded – undo
1898 1898
                 && is_array($this->_route_config['columns'])
1899 1899
                 && count($this->_route_config['columns']) === 2
1900 1900
         ) {
1901
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1901
+            add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1]));
1902 1902
             $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1903 1903
             $screen_id = $this->_current_screen->id;
1904
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1904
+            $screen_columns = (int) get_user_option("screen_layout_$screen_id");
1905 1905
             $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1906
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1906
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
1907 1907
             $this->_template_args['current_page'] = $this->_wp_page_slug;
1908 1908
             $this->_template_args['screen'] = $this->_current_screen;
1909
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1909
+            $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php';
1910 1910
             //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1911 1911
             $this->_route_config['has_metaboxes'] = true;
1912 1912
         }
@@ -1953,7 +1953,7 @@  discard block
 block discarded – undo
1953 1953
      */
1954 1954
     public function espresso_ratings_request()
1955 1955
     {
1956
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1956
+        $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php';
1957 1957
         EEH_Template::display_template($template_path, array());
1958 1958
     }
1959 1959
 
@@ -1961,18 +1961,18 @@  discard block
 block discarded – undo
1961 1961
 
1962 1962
     public static function cached_rss_display($rss_id, $url)
1963 1963
     {
1964
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1964
+        $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading&#8230;').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>';
1965 1965
         $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1966
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1967
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1968
-        $post = '</div>' . "\n";
1969
-        $cache_key = 'ee_rss_' . md5($rss_id);
1966
+        $pre = '<div class="espresso-rss-display">'."\n\t";
1967
+        $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>';
1968
+        $post = '</div>'."\n";
1969
+        $cache_key = 'ee_rss_'.md5($rss_id);
1970 1970
         if (false != ($output = get_transient($cache_key))) {
1971
-            echo $pre . $output . $post;
1971
+            echo $pre.$output.$post;
1972 1972
             return true;
1973 1973
         }
1974 1974
         if ( ! $doing_ajax) {
1975
-            echo $pre . $loading . $post;
1975
+            echo $pre.$loading.$post;
1976 1976
             return false;
1977 1977
         }
1978 1978
         ob_start();
@@ -2031,7 +2031,7 @@  discard block
 block discarded – undo
2031 2031
 
2032 2032
     public function espresso_sponsors_post_box()
2033 2033
     {
2034
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2034
+        $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php';
2035 2035
         EEH_Template::display_template($templatepath);
2036 2036
     }
2037 2037
 
@@ -2039,7 +2039,7 @@  discard block
 block discarded – undo
2039 2039
 
2040 2040
     private function _publish_post_box()
2041 2041
     {
2042
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2042
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2043 2043
         //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2044 2044
         if ( ! empty($this->_labels['publishbox'])) {
2045 2045
             $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
@@ -2056,7 +2056,7 @@  discard block
 block discarded – undo
2056 2056
     {
2057 2057
         //if we have extra content set let's add it in if not make sure its empty
2058 2058
         $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2059
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2059
+        $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php';
2060 2060
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061 2061
     }
2062 2062
 
@@ -2225,7 +2225,7 @@  discard block
 block discarded – undo
2225 2225
         //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2226 2226
         $call_back_func = $create_func ? create_function('$post, $metabox',
2227 2227
                 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2228
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2228
+        add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2229 2229
     }
2230 2230
 
2231 2231
 
@@ -2305,10 +2305,10 @@  discard block
 block discarded – undo
2305 2305
                 ? 'poststuff'
2306 2306
                 : 'espresso-default-admin';
2307 2307
         $template_path = $sidebar
2308
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2309
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2308
+                ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php'
2309
+                : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2310 2310
         if (defined('DOING_AJAX') && DOING_AJAX) {
2311
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2311
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2312 2312
         }
2313 2313
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2314 2314
         $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
@@ -2354,7 +2354,7 @@  discard block
 block discarded – undo
2354 2354
                         true
2355 2355
                 )
2356 2356
                 : $this->_template_args['preview_action_button'];
2357
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2357
+        $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php';
2358 2358
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2359 2359
                 $template_path,
2360 2360
                 $this->_template_args,
@@ -2405,7 +2405,7 @@  discard block
 block discarded – undo
2405 2405
         //setup search attributes
2406 2406
         $this->_set_search_attributes();
2407 2407
         $this->_template_args['current_page'] = $this->_wp_page_slug;
2408
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2408
+        $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2409 2409
         $this->_template_args['table_url'] = defined('DOING_AJAX')
2410 2410
                 ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2411 2411
                 : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
@@ -2415,29 +2415,29 @@  discard block
 block discarded – undo
2415 2415
         $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2416 2416
         if ( ! empty($ajax_sorting_callback)) {
2417 2417
             $sortable_list_table_form_fields = wp_nonce_field(
2418
-                    $ajax_sorting_callback . '_nonce',
2419
-                    $ajax_sorting_callback . '_nonce',
2418
+                    $ajax_sorting_callback.'_nonce',
2419
+                    $ajax_sorting_callback.'_nonce',
2420 2420
                     false,
2421 2421
                     false
2422 2422
             );
2423 2423
             //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2424 2424
             //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2425
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2426
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2425
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />';
2426
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />';
2427 2427
         } else {
2428 2428
             $sortable_list_table_form_fields = '';
2429 2429
         }
2430 2430
         $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2431 2431
         $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2432
-        $nonce_ref = $this->_req_action . '_nonce';
2433
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2432
+        $nonce_ref = $this->_req_action.'_nonce';
2433
+        $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2434 2434
         $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2435 2435
         //display message about search results?
2436 2436
         $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2437
-                ? '<p class="ee-search-results">' . sprintf(
2437
+                ? '<p class="ee-search-results">'.sprintf(
2438 2438
                         esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2439 2439
                         trim($this->_req_data['s'], '%')
2440
-                ) . '</p>'
2440
+                ).'</p>'
2441 2441
                 : '';
2442 2442
         // filter before_list_table template arg
2443 2443
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2511,8 +2511,8 @@  discard block
 block discarded – undo
2511 2511
      */
2512 2512
     protected function _display_legend($items)
2513 2513
     {
2514
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2515
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2514
+        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this);
2515
+        $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php';
2516 2516
         return EEH_Template::display_template($legend_template, $this->_template_args, true);
2517 2517
     }
2518 2518
 
@@ -2604,15 +2604,15 @@  discard block
 block discarded – undo
2604 2604
         $this->_nav_tabs = $this->_get_main_nav_tabs();
2605 2605
         $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2606 2606
         $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2607
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2607
+        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view,
2608 2608
                 isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2609
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2609
+        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view,
2610 2610
                 isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2611 2611
         $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2612 2612
         // load settings page wrapper template
2613
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2613
+        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php';
2614 2614
         //about page?
2615
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2615
+        $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path;
2616 2616
         if (defined('DOING_AJAX')) {
2617 2617
             $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2618 2618
             $this->_return_json();
@@ -2684,20 +2684,20 @@  discard block
 block discarded – undo
2684 2684
     protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2685 2685
     {
2686 2686
         //make sure $text and $actions are in an array
2687
-        $text = (array)$text;
2688
-        $actions = (array)$actions;
2687
+        $text = (array) $text;
2688
+        $actions = (array) $actions;
2689 2689
         $referrer_url = empty($referrer) ? '' : $referrer;
2690
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2691
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2690
+        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />'
2691
+                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />';
2692 2692
         $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2693 2693
         $default_names = array('save', 'save_and_close');
2694 2694
         //add in a hidden index for the current page (so save and close redirects properly)
2695 2695
         $this->_template_args['save_buttons'] = $referrer_url;
2696 2696
         foreach ($button_text as $key => $button) {
2697 2697
             $ref = $default_names[$key];
2698
-            $id = $this->_current_view . '_' . $ref;
2698
+            $id = $this->_current_view.'_'.$ref;
2699 2699
             $name = ! empty($actions) ? $actions[$key] : $ref;
2700
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2700
+            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />';
2701 2701
             if ( ! $both) {
2702 2702
                 break;
2703 2703
             }
@@ -2733,15 +2733,15 @@  discard block
 block discarded – undo
2733 2733
     {
2734 2734
         if (empty($route)) {
2735 2735
             $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2736
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2737
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2736
+            $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2737
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
2738 2738
         }
2739 2739
         // open form
2740
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2740
+        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >';
2741 2741
         // add nonce
2742
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2742
+        $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
2743 2743
         //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2744
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2744
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
2745 2745
         // add REQUIRED form action
2746 2746
         $hidden_fields = array(
2747 2747
                 'action' => array('type' => 'hidden', 'value' => $route),
@@ -2751,8 +2751,8 @@  discard block
 block discarded – undo
2751 2751
         // generate form fields
2752 2752
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2753 2753
         // add fields to form
2754
-        foreach ((array)$form_fields as $field_name => $form_field) {
2755
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2754
+        foreach ((array) $form_fields as $field_name => $form_field) {
2755
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
2756 2756
         }
2757 2757
         // close form
2758 2758
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -2833,7 +2833,7 @@  discard block
 block discarded – undo
2833 2833
          * @param array $query_args       The original query_args array coming into the
2834 2834
          *                                method.
2835 2835
          */
2836
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2836
+        do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args);
2837 2837
         //calculate where we're going (if we have a "save and close" button pushed)
2838 2838
         if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2839 2839
             // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
2850 2850
                 //is there a wp_referer array in our _default_route_query_args property?
2851 2851
                 if ($query_param == 'wp_referer') {
2852
-                    $query_value = (array)$query_value;
2852
+                    $query_value = (array) $query_value;
2853 2853
                     foreach ($query_value as $reference => $value) {
2854 2854
                         if (strpos($reference, 'nonce') !== false) {
2855 2855
                             continue;
@@ -2875,11 +2875,11 @@  discard block
 block discarded – undo
2875 2875
         // if redirecting to anything other than the main page, add a nonce
2876 2876
         if (isset($query_args['action'])) {
2877 2877
             // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2878
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2878
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
2879 2879
         }
2880 2880
         //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2881
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2882
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2881
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
2882
+        $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2883 2883
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2884 2884
         if (defined('DOING_AJAX')) {
2885 2885
             $default_data = array(
@@ -3009,7 +3009,7 @@  discard block
 block discarded – undo
3009 3009
         $args = array(
3010 3010
                 'label'   => $this->_admin_page_title,
3011 3011
                 'default' => 10,
3012
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3012
+                'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3013 3013
         );
3014 3014
         //ONLY add the screen option if the user has access to it.
3015 3015
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3042,8 +3042,8 @@  discard block
 block discarded – undo
3042 3042
             $map_option = $option;
3043 3043
             $option = str_replace('-', '_', $option);
3044 3044
             switch ($map_option) {
3045
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3046
-                    $value = (int)$value;
3045
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3046
+                    $value = (int) $value;
3047 3047
                     if ($value < 1 || $value > 999) {
3048 3048
                         return;
3049 3049
                     }
@@ -3070,7 +3070,7 @@  discard block
 block discarded – undo
3070 3070
      */
3071 3071
     public function set_template_args($data)
3072 3072
     {
3073
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3073
+        $this->_template_args = array_merge($this->_template_args, (array) $data);
3074 3074
     }
3075 3075
 
3076 3076
 
@@ -3092,12 +3092,12 @@  discard block
 block discarded – undo
3092 3092
             $this->_verify_route($route);
3093 3093
         }
3094 3094
         //now let's set the string for what kind of transient we're setting
3095
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3095
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3096 3096
         $data = $notices ? array('notices' => $data) : $data;
3097 3097
         //is there already a transient for this route?  If there is then let's ADD to that transient
3098 3098
         $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3099 3099
         if ($existing) {
3100
-            $data = array_merge((array)$data, (array)$existing);
3100
+            $data = array_merge((array) $data, (array) $existing);
3101 3101
         }
3102 3102
         if (is_multisite() && is_network_admin()) {
3103 3103
             set_site_transient($transient, $data, 8);
@@ -3118,7 +3118,7 @@  discard block
 block discarded – undo
3118 3118
     {
3119 3119
         $user_id = get_current_user_id();
3120 3120
         $route = ! $route ? $this->_req_action : $route;
3121
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3121
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3122 3122
         $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3123 3123
         //delete transient after retrieval (just in case it hasn't expired);
3124 3124
         if (is_multisite() && is_network_admin()) {
@@ -3359,7 +3359,7 @@  discard block
 block discarded – undo
3359 3359
      */
3360 3360
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3361 3361
     {
3362
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3362
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3363 3363
     }
3364 3364
 
3365 3365
 
@@ -3373,7 +3373,7 @@  discard block
 block discarded – undo
3373 3373
      */
3374 3374
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3375 3375
     {
3376
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3376
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3377 3377
     }
3378 3378
 
3379 3379
 
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
 	 * @param string $min_core_version
62 62
 	 * @return string always like '4.3.0.rc.000'
63 63
 	 */
64
-	protected static function _effective_version( $min_core_version ) {
64
+	protected static function _effective_version($min_core_version) {
65 65
 		// versions: 4 . 3 . 1 . p . 123
66 66
 		// offsets:    0 . 1 . 2 . 3 . 4
67
-		$version_parts = explode( '.', $min_core_version );
67
+		$version_parts = explode('.', $min_core_version);
68 68
 		//check they specified the micro version (after 2nd period)
69
-		if ( ! isset( $version_parts[2] ) ) {
69
+		if ( ! isset($version_parts[2])) {
70 70
 			$version_parts[2] = '0';
71 71
 		}
72 72
 		//if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73 73
 		//soon we can assume that's 'rc', but this current version is 'alpha'
74
-		if ( ! isset( $version_parts[3] ) ) {
74
+		if ( ! isset($version_parts[3])) {
75 75
 			$version_parts[3] = 'dev';
76 76
 		}
77
-		if ( ! isset( $version_parts[4] ) ) {
77
+		if ( ! isset($version_parts[4])) {
78 78
 			$version_parts[4] = '000';
79 79
 		}
80
-		return implode( '.', $version_parts );
80
+		return implode('.', $version_parts);
81 81
 	}
82 82
 
83 83
 
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 		$actual_core_version = EVENT_ESPRESSO_VERSION
95 95
 	) {
96 96
 		return version_compare(
97
-			self::_effective_version( $actual_core_version ),
98
-			self::_effective_version( $min_core_version ),
97
+			self::_effective_version($actual_core_version),
98
+			self::_effective_version($min_core_version),
99 99
 			'>='
100 100
 		);
101 101
 	}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @throws EE_Error
218 218
 	 * @return void
219 219
 	 */
220
-	public static function register( $addon_name = '', $setup_args = array() ) {
220
+	public static function register($addon_name = '', $setup_args = array()) {
221 221
 		// required fields MUST be present, so let's make sure they are.
222 222
         \EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
223 223
         // get class name for addon
@@ -227,13 +227,13 @@  discard block
 block discarded – undo
227 227
         // setup PUE
228 228
         \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
229 229
         // does this addon work with this version of core or WordPress ?
230
-        if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) {
230
+        if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
231 231
             return;
232 232
 		}
233 233
 		// register namespaces
234 234
         \EE_Register_Addon::_setup_namespaces($addon_settings);
235 235
         // check if this is an activation request
236
-        if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
236
+        if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
237 237
             // dont bother setting up the rest of the addon atm
238 238
             return;
239 239
         }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
         } else {
327 327
             $class_name = $setup_args['class_name'];
328 328
         }
329
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
329
+        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name;
330 330
     }
331 331
 
332 332
 
@@ -344,105 +344,105 @@  discard block
 block discarded – undo
344 344
             'class_name'            => $class_name,
345 345
             // the addon slug for use in URLs, etc
346 346
             'plugin_slug'           => isset($setup_args['plugin_slug'])
347
-                ? (string)$setup_args['plugin_slug']
347
+                ? (string) $setup_args['plugin_slug']
348 348
                 : '',
349 349
             // page slug to be used when generating the "Settings" link on the WP plugin page
350 350
             'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
351
-                ? (string)$setup_args['plugin_action_slug']
351
+                ? (string) $setup_args['plugin_action_slug']
352 352
                 : '',
353 353
             // the "software" version for the addon
354 354
             'version'               => isset($setup_args['version'])
355
-                ? (string)$setup_args['version']
355
+                ? (string) $setup_args['version']
356 356
                 : '',
357 357
             // the minimum version of EE Core that the addon will work with
358 358
             'min_core_version'      => isset($setup_args['min_core_version'])
359
-                ? (string)$setup_args['min_core_version']
359
+                ? (string) $setup_args['min_core_version']
360 360
                 : '',
361 361
             // the minimum version of WordPress that the addon will work with
362 362
             'min_wp_version'        => isset($setup_args['min_wp_version'])
363
-                ? (string)$setup_args['min_wp_version']
363
+                ? (string) $setup_args['min_wp_version']
364 364
                 : EE_MIN_WP_VER_REQUIRED,
365 365
             // full server path to main file (file loaded directly by WP)
366 366
             'main_file_path'        => isset($setup_args['main_file_path'])
367
-                ? (string)$setup_args['main_file_path']
367
+                ? (string) $setup_args['main_file_path']
368 368
                 : '',
369 369
             // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
370 370
             'admin_path'            => isset($setup_args['admin_path'])
371
-                ? (string)$setup_args['admin_path'] : '',
371
+                ? (string) $setup_args['admin_path'] : '',
372 372
             // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
373 373
             'admin_callback'        => isset($setup_args['admin_callback'])
374
-                ? (string)$setup_args['admin_callback']
374
+                ? (string) $setup_args['admin_callback']
375 375
                 : '',
376 376
             // the section name for this addon's configuration settings section (defaults to "addons")
377 377
             'config_section'        => isset($setup_args['config_section'])
378
-                ? (string)$setup_args['config_section']
378
+                ? (string) $setup_args['config_section']
379 379
                 : 'addons',
380 380
             // the class name for this addon's configuration settings object
381 381
             'config_class'          => isset($setup_args['config_class'])
382
-                ? (string)$setup_args['config_class'] : '',
382
+                ? (string) $setup_args['config_class'] : '',
383 383
             //the name given to the config for this addons' configuration settings object (optional)
384 384
             'config_name'           => isset($setup_args['config_name'])
385
-                ? (string)$setup_args['config_name'] : '',
385
+                ? (string) $setup_args['config_name'] : '',
386 386
             // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
387 387
             'autoloader_paths'      => isset($setup_args['autoloader_paths'])
388
-                ? (array)$setup_args['autoloader_paths']
388
+                ? (array) $setup_args['autoloader_paths']
389 389
                 : array(),
390 390
             // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
391 391
             'autoloader_folders'    => isset($setup_args['autoloader_folders'])
392
-                ? (array)$setup_args['autoloader_folders']
392
+                ? (array) $setup_args['autoloader_folders']
393 393
                 : array(),
394 394
             // array of full server paths to any EE_DMS data migration scripts used by the addon
395 395
             'dms_paths'             => isset($setup_args['dms_paths'])
396
-                ? (array)$setup_args['dms_paths']
396
+                ? (array) $setup_args['dms_paths']
397 397
                 : array(),
398 398
             // array of full server paths to any EED_Modules used by the addon
399 399
             'module_paths'          => isset($setup_args['module_paths'])
400
-                ? (array)$setup_args['module_paths']
400
+                ? (array) $setup_args['module_paths']
401 401
                 : array(),
402 402
             // array of full server paths to any EES_Shortcodes used by the addon
403 403
             'shortcode_paths'       => isset($setup_args['shortcode_paths'])
404
-                ? (array)$setup_args['shortcode_paths']
404
+                ? (array) $setup_args['shortcode_paths']
405 405
                 : array(),
406 406
             // array of full server paths to any WP_Widgets used by the addon
407 407
             'widget_paths'          => isset($setup_args['widget_paths'])
408
-                ? (array)$setup_args['widget_paths']
408
+                ? (array) $setup_args['widget_paths']
409 409
                 : array(),
410 410
             // array of PUE options used by the addon
411 411
             'pue_options'           => isset($setup_args['pue_options'])
412
-                ? (array)$setup_args['pue_options']
412
+                ? (array) $setup_args['pue_options']
413 413
                 : array(),
414 414
             'message_types'         => isset($setup_args['message_types'])
415
-                ? (array)$setup_args['message_types']
415
+                ? (array) $setup_args['message_types']
416 416
                 : array(),
417 417
             'capabilities'          => isset($setup_args['capabilities'])
418
-                ? (array)$setup_args['capabilities']
418
+                ? (array) $setup_args['capabilities']
419 419
                 : array(),
420 420
             'capability_maps'       => isset($setup_args['capability_maps'])
421
-                ? (array)$setup_args['capability_maps']
421
+                ? (array) $setup_args['capability_maps']
422 422
                 : array(),
423 423
             'model_paths'           => isset($setup_args['model_paths'])
424
-                ? (array)$setup_args['model_paths']
424
+                ? (array) $setup_args['model_paths']
425 425
                 : array(),
426 426
             'class_paths'           => isset($setup_args['class_paths'])
427
-                ? (array)$setup_args['class_paths']
427
+                ? (array) $setup_args['class_paths']
428 428
                 : array(),
429 429
             'model_extension_paths' => isset($setup_args['model_extension_paths'])
430
-                ? (array)$setup_args['model_extension_paths']
430
+                ? (array) $setup_args['model_extension_paths']
431 431
                 : array(),
432 432
             'class_extension_paths' => isset($setup_args['class_extension_paths'])
433
-                ? (array)$setup_args['class_extension_paths']
433
+                ? (array) $setup_args['class_extension_paths']
434 434
                 : array(),
435 435
             'custom_post_types'     => isset($setup_args['custom_post_types'])
436
-                ? (array)$setup_args['custom_post_types']
436
+                ? (array) $setup_args['custom_post_types']
437 437
                 : array(),
438 438
             'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
439
-                ? (array)$setup_args['custom_taxonomies']
439
+                ? (array) $setup_args['custom_taxonomies']
440 440
                 : array(),
441 441
             'payment_method_paths'  => isset($setup_args['payment_method_paths'])
442
-                ? (array)$setup_args['payment_method_paths']
442
+                ? (array) $setup_args['payment_method_paths']
443 443
                 : array(),
444 444
             'default_terms'         => isset($setup_args['default_terms'])
445
-                ? (array)$setup_args['default_terms']
445
+                ? (array) $setup_args['default_terms']
446 446
                 : array(),
447 447
             // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
448 448
             // that can be used for adding upgrading/marketing info
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
                 $setup_args['namespace']['FQNS'],
455 455
                 $setup_args['namespace']['DIR']
456 456
             )
457
-                ? (array)$setup_args['namespace']
457
+                ? (array) $setup_args['namespace']
458 458
                 : array(),
459 459
         );
460 460
         // if plugin_action_slug is NOT set, but an admin page path IS set,
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
      * @param array  $addon_settings
476 476
      * @return boolean
477 477
      */
478
-	private static function _addon_is_compatible( $addon_name, array $addon_settings ) {
478
+	private static function _addon_is_compatible($addon_name, array $addon_settings) {
479 479
         global $wp_version;
480 480
         $incompatibility_message = '';
481 481
         //check whether this addon version is compatible with EE core
@@ -551,20 +551,20 @@  discard block
 block discarded – undo
551 551
      * @param array  $setup_args
552 552
      * @return void
553 553
      */
554
-	private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) {
554
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args) {
555 555
         if ( ! empty($setup_args['pue_options'])) {
556 556
             self::$_settings[$addon_name]['pue_options'] = array(
557 557
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
558
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
559
-                    : 'espresso_' . strtolower($class_name),
558
+                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
559
+                    : 'espresso_'.strtolower($class_name),
560 560
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
561
-                    ? (string)$setup_args['pue_options']['plugin_basename']
561
+                    ? (string) $setup_args['pue_options']['plugin_basename']
562 562
                     : plugin_basename($setup_args['main_file_path']),
563 563
                 'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
564
-                    ? (string)$setup_args['pue_options']['checkPeriod']
564
+                    ? (string) $setup_args['pue_options']['checkPeriod']
565 565
                     : '24',
566 566
                 'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
567
-                    ? (string)$setup_args['pue_options']['use_wp_update']
567
+                    ? (string) $setup_args['pue_options']['use_wp_update']
568 568
                     : false,
569 569
             );
570 570
             add_action(
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
      * @param array  $addon_settings
607 607
      * @return bool
608 608
      */
609
-	private static function _addon_activation( $addon_name, array $addon_settings ) {
609
+	private static function _addon_activation($addon_name, array $addon_settings) {
610 610
         // this is an activation request
611 611
         if (did_action('activate_plugin')) {
612 612
             //to find if THIS is the addon that was activated,
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
         }
664 664
         // setup autoloaders for folders
665 665
         if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
666
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
666
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
667 667
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
668 668
             }
669 669
         }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
      * @return void
679 679
      * @throws \EE_Error
680 680
      */
681
-	private static function _register_models_and_extensions( $addon_name ) {
681
+	private static function _register_models_and_extensions($addon_name) {
682 682
         // register new models
683 683
         if (
684 684
             ! empty(self::$_settings[$addon_name]['model_paths'])
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
      * @return void
715 715
      * @throws \EE_Error
716 716
      */
717
-	private static function _register_data_migration_scripts( $addon_name ) {
717
+	private static function _register_data_migration_scripts($addon_name) {
718 718
         // setup DMS
719 719
         if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
720 720
             EE_Register_Data_Migration_Scripts::register(
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
      * @return void
731 731
      * @throws \EE_Error
732 732
      */
733
-	private static function _register_config( $addon_name ) {
733
+	private static function _register_config($addon_name) {
734 734
         // if config_class is present let's register config.
735 735
         if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
736 736
             EE_Register_Config::register(
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
      * @return void
750 750
      * @throws \EE_Error
751 751
      */
752
-	private static function _register_admin_pages( $addon_name ) {
752
+	private static function _register_admin_pages($addon_name) {
753 753
         if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
754 754
             EE_Register_Admin_Page::register(
755 755
                 $addon_name,
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
      * @return void
765 765
      * @throws \EE_Error
766 766
      */
767
-	private static function _register_modules( $addon_name ) {
767
+	private static function _register_modules($addon_name) {
768 768
         if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
769 769
             EE_Register_Module::register(
770 770
                 $addon_name,
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
      * @return void
780 780
      * @throws \EE_Error
781 781
      */
782
-	private static function _register_shortcodes( $addon_name ) {
782
+	private static function _register_shortcodes($addon_name) {
783 783
         if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
784 784
             EE_Register_Shortcode::register(
785 785
                 $addon_name,
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
      * @return void
795 795
      * @throws \EE_Error
796 796
      */
797
-	private static function _register_widgets( $addon_name ) {
797
+	private static function _register_widgets($addon_name) {
798 798
         if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
799 799
             EE_Register_Widget::register(
800 800
                 $addon_name,
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
      * @return void
810 810
      * @throws \EE_Error
811 811
      */
812
-	private static function _register_capabilities( $addon_name ) {
812
+	private static function _register_capabilities($addon_name) {
813 813
         if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
814 814
             EE_Register_Capabilities::register(
815 815
                 $addon_name,
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
      * @return void
828 828
      * @throws \EE_Error
829 829
      */
830
-	private static function _register_message_types( $addon_name ) {
830
+	private static function _register_message_types($addon_name) {
831 831
         if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
832 832
             add_action(
833 833
                 'EE_Brewing_Regular___messages_caf',
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
      * @return void
843 843
      * @throws \EE_Error
844 844
      */
845
-	private static function _register_custom_post_types( $addon_name ) {
845
+	private static function _register_custom_post_types($addon_name) {
846 846
         if (
847 847
             ! empty(self::$_settings[$addon_name]['custom_post_types'])
848 848
             || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
      * @return void
865 865
      * @throws \EE_Error
866 866
      */
867
-	private static function _register_payment_methods( $addon_name ) {
867
+	private static function _register_payment_methods($addon_name) {
868 868
         if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
869 869
             EE_Register_Payment_Method::register(
870 870
                 $addon_name,
@@ -881,25 +881,25 @@  discard block
 block discarded – undo
881 881
 	 * @param string $addon_name
882 882
 	 * @return EE_Addon
883 883
 	 */
884
-	private static function _load_and_init_addon_class( $addon_name ) {
884
+	private static function _load_and_init_addon_class($addon_name) {
885 885
 		$addon = EE_Registry::instance()->load_addon(
886
-			dirname( self::$_settings[ $addon_name ]['main_file_path'] ),
887
-			self::$_settings[ $addon_name ]['class_name']
886
+			dirname(self::$_settings[$addon_name]['main_file_path']),
887
+			self::$_settings[$addon_name]['class_name']
888 888
 		);
889
-		$addon->set_name( $addon_name );
890
-		$addon->set_plugin_slug( self::$_settings[ $addon_name ]['plugin_slug'] );
891
-		$addon->set_plugin_basename( self::$_settings[ $addon_name ]['plugin_basename'] );
892
-		$addon->set_main_plugin_file( self::$_settings[ $addon_name ]['main_file_path'] );
893
-		$addon->set_plugin_action_slug( self::$_settings[ $addon_name ]['plugin_action_slug'] );
894
-		$addon->set_plugins_page_row( self::$_settings[ $addon_name ]['plugins_page_row'] );
895
-		$addon->set_version( self::$_settings[ $addon_name ]['version'] );
896
-		$addon->set_min_core_version( self::_effective_version( self::$_settings[ $addon_name ]['min_core_version'] ) );
897
-		$addon->set_config_section( self::$_settings[ $addon_name ]['config_section'] );
898
-		$addon->set_config_class( self::$_settings[ $addon_name ]['config_class'] );
899
-		$addon->set_config_name( self::$_settings[ $addon_name ]['config_name'] );
889
+		$addon->set_name($addon_name);
890
+		$addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
891
+		$addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
892
+		$addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
893
+		$addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
894
+		$addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
895
+		$addon->set_version(self::$_settings[$addon_name]['version']);
896
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
897
+		$addon->set_config_section(self::$_settings[$addon_name]['config_section']);
898
+		$addon->set_config_class(self::$_settings[$addon_name]['config_class']);
899
+		$addon->set_config_name(self::$_settings[$addon_name]['config_name']);
900 900
 		//unfortunately this can't be hooked in upon construction, because we don't have
901 901
 		//the plugin mainfile's path upon construction.
902
-		register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) );
902
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
903 903
         // call any additional admin_callback functions during load_admin_controller hook
904 904
         if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
905 905
             add_action(
@@ -919,18 +919,18 @@  discard block
 block discarded – undo
919 919
 	 */
920 920
 	public static function load_pue_update() {
921 921
 		// load PUE client
922
-		require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
922
+		require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php';
923 923
 		// cycle thru settings
924
-		foreach ( self::$_settings as $settings ) {
925
-			if ( ! empty( $settings['pue_options'] ) ) {
924
+		foreach (self::$_settings as $settings) {
925
+			if ( ! empty($settings['pue_options'])) {
926 926
                 // initiate the class and start the plugin update engine!
927 927
 				new PluginUpdateEngineChecker(
928 928
 				// host file URL
929 929
 					'https://eventespresso.com',
930 930
 					// plugin slug(s)
931 931
 					array(
932
-						'premium'    => array( 'p' => $settings['pue_options']['pue_plugin_slug'] ),
933
-						'prerelease' => array( 'beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr' ),
932
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
933
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
934 934
 					),
935 935
 					// options
936 936
 					array(
@@ -958,9 +958,9 @@  discard block
 block discarded – undo
958 958
 	 * @throws \EE_Error
959 959
 	 */
960 960
 	public static function register_message_types() {
961
-		foreach ( self::$_settings as $addon_name => $settings ) {
961
+		foreach (self::$_settings as $addon_name => $settings) {
962 962
 		    if ( ! empty($settings['message_types'])) {
963
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
963
+                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
964 964
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
965 965
                 }
966 966
             }
@@ -977,73 +977,73 @@  discard block
 block discarded – undo
977 977
 	 * @throws EE_Error
978 978
 	 * @return void
979 979
 	 */
980
-	public static function deregister( $addon_name = null ) {
981
-		if ( isset( self::$_settings[ $addon_name ] ) ) {
982
-			$class_name = self::$_settings[ $addon_name ]['class_name'];
983
-			if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) {
980
+	public static function deregister($addon_name = null) {
981
+		if (isset(self::$_settings[$addon_name])) {
982
+			$class_name = self::$_settings[$addon_name]['class_name'];
983
+			if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
984 984
 				// setup DMS
985
-				EE_Register_Data_Migration_Scripts::deregister( $addon_name );
985
+				EE_Register_Data_Migration_Scripts::deregister($addon_name);
986 986
 			}
987
-			if ( ! empty( self::$_settings[ $addon_name ]['admin_path'] ) ) {
987
+			if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
988 988
 				// register admin page
989
-				EE_Register_Admin_Page::deregister( $addon_name );
989
+				EE_Register_Admin_Page::deregister($addon_name);
990 990
 			}
991
-			if ( ! empty( self::$_settings[ $addon_name ]['module_paths'] ) ) {
991
+			if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
992 992
 				// add to list of modules to be registered
993
-				EE_Register_Module::deregister( $addon_name );
993
+				EE_Register_Module::deregister($addon_name);
994 994
 			}
995
-			if ( ! empty( self::$_settings[ $addon_name ]['shortcode_paths'] ) ) {
995
+			if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
996 996
 				// add to list of shortcodes to be registered
997
-				EE_Register_Shortcode::deregister( $addon_name );
997
+				EE_Register_Shortcode::deregister($addon_name);
998 998
 			}
999
-			if ( ! empty( self::$_settings[ $addon_name ]['config_class'] ) ) {
999
+			if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1000 1000
 				// if config_class present let's register config.
1001
-				EE_Register_Config::deregister( self::$_settings[ $addon_name ]['config_class'] );
1001
+				EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1002 1002
 			}
1003
-			if ( ! empty( self::$_settings[ $addon_name ]['widget_paths'] ) ) {
1003
+			if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1004 1004
 				// add to list of widgets to be registered
1005
-				EE_Register_Widget::deregister( $addon_name );
1005
+				EE_Register_Widget::deregister($addon_name);
1006 1006
 			}
1007
-			if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] )
1007
+			if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1008 1008
 			     ||
1009
-			     ! empty( self::$_settings[ $addon_name ]['class_paths'] )
1009
+			     ! empty(self::$_settings[$addon_name]['class_paths'])
1010 1010
 			) {
1011 1011
 				// add to list of shortcodes to be registered
1012
-				EE_Register_Model::deregister( $addon_name );
1012
+				EE_Register_Model::deregister($addon_name);
1013 1013
 			}
1014
-			if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] )
1014
+			if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1015 1015
 			     ||
1016
-			     ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] )
1016
+			     ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1017 1017
 			) {
1018 1018
 				// add to list of shortcodes to be registered
1019
-				EE_Register_Model_Extensions::deregister( $addon_name );
1019
+				EE_Register_Model_Extensions::deregister($addon_name);
1020 1020
 			}
1021
-			if ( ! empty( self::$_settings[ $addon_name ]['message_types'] ) ) {
1022
-				foreach ((array)self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings )
1021
+			if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1022
+				foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings)
1023 1023
 				{
1024
-					EE_Register_Message_Type::deregister( $message_type );
1024
+					EE_Register_Message_Type::deregister($message_type);
1025 1025
 				}
1026 1026
 			}
1027 1027
 			//deregister capabilities for addon
1028 1028
 			if (
1029
-				! empty( self::$_settings[ $addon_name ]['capabilities'] )
1030
-				|| ! empty( self::$_settings[ $addon_name ]['capability_maps'] )
1029
+				! empty(self::$_settings[$addon_name]['capabilities'])
1030
+				|| ! empty(self::$_settings[$addon_name]['capability_maps'])
1031 1031
 			) {
1032
-				EE_Register_Capabilities::deregister( $addon_name );
1032
+				EE_Register_Capabilities::deregister($addon_name);
1033 1033
 			}
1034 1034
 			//deregister custom_post_types for addon
1035
-			if ( ! empty( self::$_settings[ $addon_name ]['custom_post_types'] ) ) {
1036
-				EE_Register_CPT::deregister( $addon_name );
1035
+			if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1036
+				EE_Register_CPT::deregister($addon_name);
1037 1037
 			}
1038 1038
 			remove_action(
1039
-				'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1040
-				array( EE_Registry::instance()->addons->{$class_name}, 'deactivation' )
1039
+				'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1040
+				array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1041 1041
 			);
1042 1042
 			remove_action(
1043 1043
 				'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1044
-				array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' )
1044
+				array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1045 1045
 			);
1046
-			unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] );
1046
+			unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1047 1047
 		}
1048 1048
 	}
1049 1049
 
Please login to merge, or discard this patch.
Indentation   +637 added lines, -637 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	protected static $_incompatible_addons = array(
49 49
 		'Multi_Event_Registration' => '2.0.11.rc.002',
50 50
 		'Promotions' => '1.0.0.rc.084',
51
-    );
51
+	);
52 52
 
53 53
 
54 54
 
@@ -219,660 +219,660 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	public static function register( $addon_name = '', $setup_args = array() ) {
221 221
 		// required fields MUST be present, so let's make sure they are.
222
-        \EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
223
-        // get class name for addon
222
+		\EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
223
+		// get class name for addon
224 224
 		$class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
225 225
 		//setup $_settings array from incoming values.
226
-        $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
227
-        // setup PUE
228
-        \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
229
-        // does this addon work with this version of core or WordPress ?
230
-        if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) {
231
-            return;
226
+		$addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
227
+		// setup PUE
228
+		\EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
229
+		// does this addon work with this version of core or WordPress ?
230
+		if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) {
231
+			return;
232 232
 		}
233 233
 		// register namespaces
234
-        \EE_Register_Addon::_setup_namespaces($addon_settings);
235
-        // check if this is an activation request
236
-        if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
237
-            // dont bother setting up the rest of the addon atm
238
-            return;
239
-        }
240
-        // we need cars
241
-        \EE_Register_Addon::_setup_autoloaders($addon_name);
242
-        // register new models and extensions
243
-        \EE_Register_Addon::_register_models_and_extensions($addon_name);
244
-        // setup DMS
245
-        \EE_Register_Addon::_register_data_migration_scripts($addon_name);
246
-        // if config_class is present let's register config.
247
-        \EE_Register_Addon::_register_config($addon_name);
248
-        // register admin pages
249
-        \EE_Register_Addon::_register_admin_pages($addon_name);
250
-        // add to list of modules to be registered
251
-        \EE_Register_Addon::_register_modules($addon_name);
252
-        // add to list of shortcodes to be registered
253
-        \EE_Register_Addon::_register_shortcodes($addon_name);
254
-        // add to list of widgets to be registered
255
-        \EE_Register_Addon::_register_widgets($addon_name);
256
-        // register capability related stuff.
257
-        \EE_Register_Addon::_register_capabilities($addon_name);
258
-        // any message type to register?
259
-        \EE_Register_Addon::_register_message_types($addon_name);
234
+		\EE_Register_Addon::_setup_namespaces($addon_settings);
235
+		// check if this is an activation request
236
+		if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
237
+			// dont bother setting up the rest of the addon atm
238
+			return;
239
+		}
240
+		// we need cars
241
+		\EE_Register_Addon::_setup_autoloaders($addon_name);
242
+		// register new models and extensions
243
+		\EE_Register_Addon::_register_models_and_extensions($addon_name);
244
+		// setup DMS
245
+		\EE_Register_Addon::_register_data_migration_scripts($addon_name);
246
+		// if config_class is present let's register config.
247
+		\EE_Register_Addon::_register_config($addon_name);
248
+		// register admin pages
249
+		\EE_Register_Addon::_register_admin_pages($addon_name);
250
+		// add to list of modules to be registered
251
+		\EE_Register_Addon::_register_modules($addon_name);
252
+		// add to list of shortcodes to be registered
253
+		\EE_Register_Addon::_register_shortcodes($addon_name);
254
+		// add to list of widgets to be registered
255
+		\EE_Register_Addon::_register_widgets($addon_name);
256
+		// register capability related stuff.
257
+		\EE_Register_Addon::_register_capabilities($addon_name);
258
+		// any message type to register?
259
+		\EE_Register_Addon::_register_message_types($addon_name);
260 260
 		// any custom post type/ custom capabilities or default terms to register
261
-        \EE_Register_Addon::_register_custom_post_types($addon_name);
262
-        // and any payment methods
263
-        \EE_Register_Addon::_register_payment_methods($addon_name);
261
+		\EE_Register_Addon::_register_custom_post_types($addon_name);
262
+		// and any payment methods
263
+		\EE_Register_Addon::_register_payment_methods($addon_name);
264 264
 		// load and instantiate main addon class
265
-        $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
266
-        $addon->after_registration();
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * @param string $addon_name
273
-     * @param array  $setup_args
274
-     * @return void
275
-     * @throws \EE_Error
276
-     */
277
-    private static function _verify_parameters($addon_name, array $setup_args)
278
-    {
279
-        // required fields MUST be present, so let's make sure they are.
280
-        if (empty($addon_name) || ! is_array($setup_args)) {
281
-            throw new EE_Error(
282
-                __(
283
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
284
-                    'event_espresso'
285
-                )
286
-            );
287
-        }
288
-        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
289
-            throw new EE_Error(
290
-                sprintf(
291
-                    __(
292
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
293
-                        'event_espresso'
294
-                    ),
295
-                    implode(',', array_keys($setup_args))
296
-                )
297
-            );
298
-        }
299
-        // check that addon has not already been registered with that name
300
-        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
301
-            throw new EE_Error(
302
-                sprintf(
303
-                    __(
304
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
305
-                        'event_espresso'
306
-                    ),
307
-                    $addon_name
308
-                )
309
-            );
310
-        }
265
+		$addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
266
+		$addon->after_registration();
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * @param string $addon_name
273
+	 * @param array  $setup_args
274
+	 * @return void
275
+	 * @throws \EE_Error
276
+	 */
277
+	private static function _verify_parameters($addon_name, array $setup_args)
278
+	{
279
+		// required fields MUST be present, so let's make sure they are.
280
+		if (empty($addon_name) || ! is_array($setup_args)) {
281
+			throw new EE_Error(
282
+				__(
283
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
284
+					'event_espresso'
285
+				)
286
+			);
287
+		}
288
+		if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
289
+			throw new EE_Error(
290
+				sprintf(
291
+					__(
292
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
293
+						'event_espresso'
294
+					),
295
+					implode(',', array_keys($setup_args))
296
+				)
297
+			);
298
+		}
299
+		// check that addon has not already been registered with that name
300
+		if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
301
+			throw new EE_Error(
302
+				sprintf(
303
+					__(
304
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
305
+						'event_espresso'
306
+					),
307
+					$addon_name
308
+				)
309
+			);
310
+		}
311 311
 	}
312 312
 
313 313
 
314 314
 
315
-    /**
316
-     * @param string $addon_name
317
-     * @param array  $setup_args
318
-     * @return string
319
-     */
320
-    private static function _parse_class_name($addon_name, array $setup_args)
321
-    {
322
-        if (empty($setup_args['class_name'])) {
323
-            // generate one by first separating name with spaces
324
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
325
-            //capitalize, then replace spaces with underscores
326
-            $class_name = str_replace(' ', '_', ucwords($class_name));
327
-        } else {
328
-            $class_name = $setup_args['class_name'];
329
-        }
330
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * @param string $class_name
337
-     * @param array  $setup_args
338
-     * @return array
339
-     */
340
-    private static function _get_addon_settings($class_name, array $setup_args)
341
-    {
342
-        //setup $_settings array from incoming values.
343
-        $addon_settings = array(
344
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
345
-            'class_name'            => $class_name,
346
-            // the addon slug for use in URLs, etc
347
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
348
-                ? (string)$setup_args['plugin_slug']
349
-                : '',
350
-            // page slug to be used when generating the "Settings" link on the WP plugin page
351
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
352
-                ? (string)$setup_args['plugin_action_slug']
353
-                : '',
354
-            // the "software" version for the addon
355
-            'version'               => isset($setup_args['version'])
356
-                ? (string)$setup_args['version']
357
-                : '',
358
-            // the minimum version of EE Core that the addon will work with
359
-            'min_core_version'      => isset($setup_args['min_core_version'])
360
-                ? (string)$setup_args['min_core_version']
361
-                : '',
362
-            // the minimum version of WordPress that the addon will work with
363
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
364
-                ? (string)$setup_args['min_wp_version']
365
-                : EE_MIN_WP_VER_REQUIRED,
366
-            // full server path to main file (file loaded directly by WP)
367
-            'main_file_path'        => isset($setup_args['main_file_path'])
368
-                ? (string)$setup_args['main_file_path']
369
-                : '',
370
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
371
-            'admin_path'            => isset($setup_args['admin_path'])
372
-                ? (string)$setup_args['admin_path'] : '',
373
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
374
-            'admin_callback'        => isset($setup_args['admin_callback'])
375
-                ? (string)$setup_args['admin_callback']
376
-                : '',
377
-            // the section name for this addon's configuration settings section (defaults to "addons")
378
-            'config_section'        => isset($setup_args['config_section'])
379
-                ? (string)$setup_args['config_section']
380
-                : 'addons',
381
-            // the class name for this addon's configuration settings object
382
-            'config_class'          => isset($setup_args['config_class'])
383
-                ? (string)$setup_args['config_class'] : '',
384
-            //the name given to the config for this addons' configuration settings object (optional)
385
-            'config_name'           => isset($setup_args['config_name'])
386
-                ? (string)$setup_args['config_name'] : '',
387
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
388
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
389
-                ? (array)$setup_args['autoloader_paths']
390
-                : array(),
391
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
392
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
393
-                ? (array)$setup_args['autoloader_folders']
394
-                : array(),
395
-            // array of full server paths to any EE_DMS data migration scripts used by the addon
396
-            'dms_paths'             => isset($setup_args['dms_paths'])
397
-                ? (array)$setup_args['dms_paths']
398
-                : array(),
399
-            // array of full server paths to any EED_Modules used by the addon
400
-            'module_paths'          => isset($setup_args['module_paths'])
401
-                ? (array)$setup_args['module_paths']
402
-                : array(),
403
-            // array of full server paths to any EES_Shortcodes used by the addon
404
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
405
-                ? (array)$setup_args['shortcode_paths']
406
-                : array(),
407
-            // array of full server paths to any WP_Widgets used by the addon
408
-            'widget_paths'          => isset($setup_args['widget_paths'])
409
-                ? (array)$setup_args['widget_paths']
410
-                : array(),
411
-            // array of PUE options used by the addon
412
-            'pue_options'           => isset($setup_args['pue_options'])
413
-                ? (array)$setup_args['pue_options']
414
-                : array(),
415
-            'message_types'         => isset($setup_args['message_types'])
416
-                ? (array)$setup_args['message_types']
417
-                : array(),
418
-            'capabilities'          => isset($setup_args['capabilities'])
419
-                ? (array)$setup_args['capabilities']
420
-                : array(),
421
-            'capability_maps'       => isset($setup_args['capability_maps'])
422
-                ? (array)$setup_args['capability_maps']
423
-                : array(),
424
-            'model_paths'           => isset($setup_args['model_paths'])
425
-                ? (array)$setup_args['model_paths']
426
-                : array(),
427
-            'class_paths'           => isset($setup_args['class_paths'])
428
-                ? (array)$setup_args['class_paths']
429
-                : array(),
430
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
431
-                ? (array)$setup_args['model_extension_paths']
432
-                : array(),
433
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
434
-                ? (array)$setup_args['class_extension_paths']
435
-                : array(),
436
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
437
-                ? (array)$setup_args['custom_post_types']
438
-                : array(),
439
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
440
-                ? (array)$setup_args['custom_taxonomies']
441
-                : array(),
442
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
443
-                ? (array)$setup_args['payment_method_paths']
444
-                : array(),
445
-            'default_terms'         => isset($setup_args['default_terms'])
446
-                ? (array)$setup_args['default_terms']
447
-                : array(),
448
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
449
-            // that can be used for adding upgrading/marketing info
450
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
451
-                ? $setup_args['plugins_page_row']
452
-                : '',
453
-            'namespace'             => isset(
454
-                $setup_args['namespace'],
455
-                $setup_args['namespace']['FQNS'],
456
-                $setup_args['namespace']['DIR']
457
-            )
458
-                ? (array)$setup_args['namespace']
459
-                : array(),
460
-        );
461
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
462
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
463
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
464
-                                                && ! empty($addon_settings['admin_path'])
465
-            ? $addon_settings['plugin_slug']
466
-            : $addon_settings['plugin_action_slug'];
467
-        // full server path to main file (file loaded directly by WP)
468
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
469
-        return $addon_settings;
315
+	/**
316
+	 * @param string $addon_name
317
+	 * @param array  $setup_args
318
+	 * @return string
319
+	 */
320
+	private static function _parse_class_name($addon_name, array $setup_args)
321
+	{
322
+		if (empty($setup_args['class_name'])) {
323
+			// generate one by first separating name with spaces
324
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
325
+			//capitalize, then replace spaces with underscores
326
+			$class_name = str_replace(' ', '_', ucwords($class_name));
327
+		} else {
328
+			$class_name = $setup_args['class_name'];
329
+		}
330
+		return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
470 331
 	}
471 332
 
472 333
 
473 334
 
474
-    /**
475
-     * @param string $addon_name
476
-     * @param array  $addon_settings
477
-     * @return boolean
478
-     */
335
+	/**
336
+	 * @param string $class_name
337
+	 * @param array  $setup_args
338
+	 * @return array
339
+	 */
340
+	private static function _get_addon_settings($class_name, array $setup_args)
341
+	{
342
+		//setup $_settings array from incoming values.
343
+		$addon_settings = array(
344
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
345
+			'class_name'            => $class_name,
346
+			// the addon slug for use in URLs, etc
347
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
348
+				? (string)$setup_args['plugin_slug']
349
+				: '',
350
+			// page slug to be used when generating the "Settings" link on the WP plugin page
351
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
352
+				? (string)$setup_args['plugin_action_slug']
353
+				: '',
354
+			// the "software" version for the addon
355
+			'version'               => isset($setup_args['version'])
356
+				? (string)$setup_args['version']
357
+				: '',
358
+			// the minimum version of EE Core that the addon will work with
359
+			'min_core_version'      => isset($setup_args['min_core_version'])
360
+				? (string)$setup_args['min_core_version']
361
+				: '',
362
+			// the minimum version of WordPress that the addon will work with
363
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
364
+				? (string)$setup_args['min_wp_version']
365
+				: EE_MIN_WP_VER_REQUIRED,
366
+			// full server path to main file (file loaded directly by WP)
367
+			'main_file_path'        => isset($setup_args['main_file_path'])
368
+				? (string)$setup_args['main_file_path']
369
+				: '',
370
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
371
+			'admin_path'            => isset($setup_args['admin_path'])
372
+				? (string)$setup_args['admin_path'] : '',
373
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
374
+			'admin_callback'        => isset($setup_args['admin_callback'])
375
+				? (string)$setup_args['admin_callback']
376
+				: '',
377
+			// the section name for this addon's configuration settings section (defaults to "addons")
378
+			'config_section'        => isset($setup_args['config_section'])
379
+				? (string)$setup_args['config_section']
380
+				: 'addons',
381
+			// the class name for this addon's configuration settings object
382
+			'config_class'          => isset($setup_args['config_class'])
383
+				? (string)$setup_args['config_class'] : '',
384
+			//the name given to the config for this addons' configuration settings object (optional)
385
+			'config_name'           => isset($setup_args['config_name'])
386
+				? (string)$setup_args['config_name'] : '',
387
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
388
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
389
+				? (array)$setup_args['autoloader_paths']
390
+				: array(),
391
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
392
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
393
+				? (array)$setup_args['autoloader_folders']
394
+				: array(),
395
+			// array of full server paths to any EE_DMS data migration scripts used by the addon
396
+			'dms_paths'             => isset($setup_args['dms_paths'])
397
+				? (array)$setup_args['dms_paths']
398
+				: array(),
399
+			// array of full server paths to any EED_Modules used by the addon
400
+			'module_paths'          => isset($setup_args['module_paths'])
401
+				? (array)$setup_args['module_paths']
402
+				: array(),
403
+			// array of full server paths to any EES_Shortcodes used by the addon
404
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
405
+				? (array)$setup_args['shortcode_paths']
406
+				: array(),
407
+			// array of full server paths to any WP_Widgets used by the addon
408
+			'widget_paths'          => isset($setup_args['widget_paths'])
409
+				? (array)$setup_args['widget_paths']
410
+				: array(),
411
+			// array of PUE options used by the addon
412
+			'pue_options'           => isset($setup_args['pue_options'])
413
+				? (array)$setup_args['pue_options']
414
+				: array(),
415
+			'message_types'         => isset($setup_args['message_types'])
416
+				? (array)$setup_args['message_types']
417
+				: array(),
418
+			'capabilities'          => isset($setup_args['capabilities'])
419
+				? (array)$setup_args['capabilities']
420
+				: array(),
421
+			'capability_maps'       => isset($setup_args['capability_maps'])
422
+				? (array)$setup_args['capability_maps']
423
+				: array(),
424
+			'model_paths'           => isset($setup_args['model_paths'])
425
+				? (array)$setup_args['model_paths']
426
+				: array(),
427
+			'class_paths'           => isset($setup_args['class_paths'])
428
+				? (array)$setup_args['class_paths']
429
+				: array(),
430
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
431
+				? (array)$setup_args['model_extension_paths']
432
+				: array(),
433
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
434
+				? (array)$setup_args['class_extension_paths']
435
+				: array(),
436
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
437
+				? (array)$setup_args['custom_post_types']
438
+				: array(),
439
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
440
+				? (array)$setup_args['custom_taxonomies']
441
+				: array(),
442
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
443
+				? (array)$setup_args['payment_method_paths']
444
+				: array(),
445
+			'default_terms'         => isset($setup_args['default_terms'])
446
+				? (array)$setup_args['default_terms']
447
+				: array(),
448
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
449
+			// that can be used for adding upgrading/marketing info
450
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
451
+				? $setup_args['plugins_page_row']
452
+				: '',
453
+			'namespace'             => isset(
454
+				$setup_args['namespace'],
455
+				$setup_args['namespace']['FQNS'],
456
+				$setup_args['namespace']['DIR']
457
+			)
458
+				? (array)$setup_args['namespace']
459
+				: array(),
460
+		);
461
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
462
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
463
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
464
+												&& ! empty($addon_settings['admin_path'])
465
+			? $addon_settings['plugin_slug']
466
+			: $addon_settings['plugin_action_slug'];
467
+		// full server path to main file (file loaded directly by WP)
468
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
469
+		return $addon_settings;
470
+	}
471
+
472
+
473
+
474
+	/**
475
+	 * @param string $addon_name
476
+	 * @param array  $addon_settings
477
+	 * @return boolean
478
+	 */
479 479
 	private static function _addon_is_compatible( $addon_name, array $addon_settings ) {
480
-        global $wp_version;
481
-        $incompatibility_message = '';
482
-        //check whether this addon version is compatible with EE core
483
-        if (
484
-            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
485
-            && ! self::_meets_min_core_version_requirement(
486
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
487
-                $addon_settings['version']
488
-            )
489
-        ) {
490
-            $incompatibility_message = sprintf(
491
-                __(
492
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
493
-                ),
494
-                $addon_name,
495
-                '<br />',
496
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
497
-                '<span style="font-weight: bold; color: #D54E21;">',
498
-                '</span><br />'
499
-            );
500
-        } else if (
501
-            ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
502
-        ) {
503
-            $incompatibility_message = sprintf(
504
-                __(
505
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
506
-                    'event_espresso'
507
-                ),
508
-                $addon_name,
509
-                self::_effective_version($addon_settings['min_core_version']),
510
-                self::_effective_version(espresso_version()),
511
-                '<br />',
512
-                '<span style="font-weight: bold; color: #D54E21;">',
513
-                '</span><br />'
514
-            );
515
-        } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
516
-            $incompatibility_message = sprintf(
517
-                __(
518
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
519
-                    'event_espresso'
520
-                ),
521
-                $addon_name,
522
-                $addon_settings['min_wp_version'],
523
-                '<br />',
524
-                '<span style="font-weight: bold; color: #D54E21;">',
525
-                '</span><br />'
526
-            );
527
-        }
528
-        if ( ! empty($incompatibility_message)) {
529
-            // remove 'activate' from the REQUEST
530
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
531
-            unset($_GET['activate'], $_REQUEST['activate']);
532
-            if (current_user_can('activate_plugins')) {
533
-                // show an error message indicating the plugin didn't activate properly
534
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
535
-            }
536
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
537
-            return false;
538
-        }
539
-        // addon IS compatible
540
-        return true;
480
+		global $wp_version;
481
+		$incompatibility_message = '';
482
+		//check whether this addon version is compatible with EE core
483
+		if (
484
+			isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
485
+			&& ! self::_meets_min_core_version_requirement(
486
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
487
+				$addon_settings['version']
488
+			)
489
+		) {
490
+			$incompatibility_message = sprintf(
491
+				__(
492
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
493
+				),
494
+				$addon_name,
495
+				'<br />',
496
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
497
+				'<span style="font-weight: bold; color: #D54E21;">',
498
+				'</span><br />'
499
+			);
500
+		} else if (
501
+			! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
502
+		) {
503
+			$incompatibility_message = sprintf(
504
+				__(
505
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
506
+					'event_espresso'
507
+				),
508
+				$addon_name,
509
+				self::_effective_version($addon_settings['min_core_version']),
510
+				self::_effective_version(espresso_version()),
511
+				'<br />',
512
+				'<span style="font-weight: bold; color: #D54E21;">',
513
+				'</span><br />'
514
+			);
515
+		} else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
516
+			$incompatibility_message = sprintf(
517
+				__(
518
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
519
+					'event_espresso'
520
+				),
521
+				$addon_name,
522
+				$addon_settings['min_wp_version'],
523
+				'<br />',
524
+				'<span style="font-weight: bold; color: #D54E21;">',
525
+				'</span><br />'
526
+			);
527
+		}
528
+		if ( ! empty($incompatibility_message)) {
529
+			// remove 'activate' from the REQUEST
530
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
531
+			unset($_GET['activate'], $_REQUEST['activate']);
532
+			if (current_user_can('activate_plugins')) {
533
+				// show an error message indicating the plugin didn't activate properly
534
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
535
+			}
536
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
537
+			return false;
538
+		}
539
+		// addon IS compatible
540
+		return true;
541 541
 	}
542 542
 
543 543
 
544 544
 
545
-    /**
546
-     * if plugin update engine is being used for auto-updates,
547
-     * then let's set that up now before going any further so that ALL addons can be updated
548
-     * (not needed if PUE is not being used)
549
-     *
550
-     * @param string $addon_name
551
-     * @param string $class_name
552
-     * @param array  $setup_args
553
-     * @return void
554
-     */
545
+	/**
546
+	 * if plugin update engine is being used for auto-updates,
547
+	 * then let's set that up now before going any further so that ALL addons can be updated
548
+	 * (not needed if PUE is not being used)
549
+	 *
550
+	 * @param string $addon_name
551
+	 * @param string $class_name
552
+	 * @param array  $setup_args
553
+	 * @return void
554
+	 */
555 555
 	private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) {
556
-        if ( ! empty($setup_args['pue_options'])) {
557
-            self::$_settings[$addon_name]['pue_options'] = array(
558
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
559
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
560
-                    : 'espresso_' . strtolower($class_name),
561
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
562
-                    ? (string)$setup_args['pue_options']['plugin_basename']
563
-                    : plugin_basename($setup_args['main_file_path']),
564
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
565
-                    ? (string)$setup_args['pue_options']['checkPeriod']
566
-                    : '24',
567
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
568
-                    ? (string)$setup_args['pue_options']['use_wp_update']
569
-                    : false,
570
-            );
571
-            add_action(
572
-                'AHEE__EE_System__brew_espresso__after_pue_init',
573
-                array('EE_Register_Addon', 'load_pue_update')
574
-            );
575
-        }
556
+		if ( ! empty($setup_args['pue_options'])) {
557
+			self::$_settings[$addon_name]['pue_options'] = array(
558
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
559
+					? (string)$setup_args['pue_options']['pue_plugin_slug']
560
+					: 'espresso_' . strtolower($class_name),
561
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
562
+					? (string)$setup_args['pue_options']['plugin_basename']
563
+					: plugin_basename($setup_args['main_file_path']),
564
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
565
+					? (string)$setup_args['pue_options']['checkPeriod']
566
+					: '24',
567
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
568
+					? (string)$setup_args['pue_options']['use_wp_update']
569
+					: false,
570
+			);
571
+			add_action(
572
+				'AHEE__EE_System__brew_espresso__after_pue_init',
573
+				array('EE_Register_Addon', 'load_pue_update')
574
+			);
575
+		}
576 576
 	}
577 577
 
578 578
 
579 579
 
580
-    /**
581
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
582
-     *
583
-     * @param array $addon_settings
584
-     * @return void
585
-     */
586
-    private static function _setup_namespaces(array $addon_settings)
587
-    {
588
-        //
589
-        if (
590
-        isset(
591
-            $addon_settings['namespace'],
592
-            $addon_settings['namespace']['FQNS'],
593
-            $addon_settings['namespace']['DIR']
594
-        )
595
-        ) {
596
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
597
-                $addon_settings['namespace']['FQNS'],
598
-                $addon_settings['namespace']['DIR']
599
-            );
600
-        }
601
-    }
602
-
603
-
604
-
605
-    /**
606
-     * @param string $addon_name
607
-     * @param array  $addon_settings
608
-     * @return bool
609
-     */
580
+	/**
581
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
582
+	 *
583
+	 * @param array $addon_settings
584
+	 * @return void
585
+	 */
586
+	private static function _setup_namespaces(array $addon_settings)
587
+	{
588
+		//
589
+		if (
590
+		isset(
591
+			$addon_settings['namespace'],
592
+			$addon_settings['namespace']['FQNS'],
593
+			$addon_settings['namespace']['DIR']
594
+		)
595
+		) {
596
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
597
+				$addon_settings['namespace']['FQNS'],
598
+				$addon_settings['namespace']['DIR']
599
+			);
600
+		}
601
+	}
602
+
603
+
604
+
605
+	/**
606
+	 * @param string $addon_name
607
+	 * @param array  $addon_settings
608
+	 * @return bool
609
+	 */
610 610
 	private static function _addon_activation( $addon_name, array $addon_settings ) {
611
-        // this is an activation request
612
-        if (did_action('activate_plugin')) {
613
-            //to find if THIS is the addon that was activated,
614
-            //just check if we have already registered it or not
615
-            //(as the newly-activated addon wasn't around the first time addons were registered)
616
-            if ( ! isset(self::$_settings[$addon_name])) {
617
-                self::$_settings[$addon_name] = $addon_settings;
618
-                $addon = self::_load_and_init_addon_class($addon_name);
619
-                $addon->set_activation_indicator_option();
620
-                // dont bother setting up the rest of the addon.
621
-                // we know it was just activated and the request will end soon
622
-            }
623
-            return true;
624
-        } else {
625
-            // make sure this was called in the right place!
626
-            if (
627
-                ! did_action('AHEE__EE_System__load_espresso_addons')
628
-                || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
629
-            ) {
630
-                EE_Error::doing_it_wrong(
631
-                    __METHOD__,
632
-                    sprintf(
633
-                        __(
634
-                            'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
635
-                            'event_espresso'
636
-                        ),
637
-                        $addon_name
638
-                    ),
639
-                    '4.3.0'
640
-                );
641
-            }
642
-            // make sure addon settings are set correctly without overwriting anything existing
643
-            if (isset(self::$_settings[$addon_name])) {
644
-                self::$_settings[$addon_name] += $addon_settings;
645
-            } else {
646
-                self::$_settings[$addon_name] = $addon_settings;
647
-            }
648
-        }
649
-        return false;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * @param string $addon_name
656
-     * @return void
657
-     * @throws \EE_Error
658
-     */
659
-    private static function _setup_autoloaders($addon_name)
660
-    {
661
-        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
662
-            // setup autoloader for single file
663
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
664
-        }
665
-        // setup autoloaders for folders
666
-        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
667
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
668
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
669
-            }
670
-        }
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * register new models and extensions
677
-     *
678
-     * @param string $addon_name
679
-     * @return void
680
-     * @throws \EE_Error
681
-     */
611
+		// this is an activation request
612
+		if (did_action('activate_plugin')) {
613
+			//to find if THIS is the addon that was activated,
614
+			//just check if we have already registered it or not
615
+			//(as the newly-activated addon wasn't around the first time addons were registered)
616
+			if ( ! isset(self::$_settings[$addon_name])) {
617
+				self::$_settings[$addon_name] = $addon_settings;
618
+				$addon = self::_load_and_init_addon_class($addon_name);
619
+				$addon->set_activation_indicator_option();
620
+				// dont bother setting up the rest of the addon.
621
+				// we know it was just activated and the request will end soon
622
+			}
623
+			return true;
624
+		} else {
625
+			// make sure this was called in the right place!
626
+			if (
627
+				! did_action('AHEE__EE_System__load_espresso_addons')
628
+				|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
629
+			) {
630
+				EE_Error::doing_it_wrong(
631
+					__METHOD__,
632
+					sprintf(
633
+						__(
634
+							'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
635
+							'event_espresso'
636
+						),
637
+						$addon_name
638
+					),
639
+					'4.3.0'
640
+				);
641
+			}
642
+			// make sure addon settings are set correctly without overwriting anything existing
643
+			if (isset(self::$_settings[$addon_name])) {
644
+				self::$_settings[$addon_name] += $addon_settings;
645
+			} else {
646
+				self::$_settings[$addon_name] = $addon_settings;
647
+			}
648
+		}
649
+		return false;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * @param string $addon_name
656
+	 * @return void
657
+	 * @throws \EE_Error
658
+	 */
659
+	private static function _setup_autoloaders($addon_name)
660
+	{
661
+		if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
662
+			// setup autoloader for single file
663
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
664
+		}
665
+		// setup autoloaders for folders
666
+		if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
667
+			foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
668
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
669
+			}
670
+		}
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * register new models and extensions
677
+	 *
678
+	 * @param string $addon_name
679
+	 * @return void
680
+	 * @throws \EE_Error
681
+	 */
682 682
 	private static function _register_models_and_extensions( $addon_name ) {
683
-        // register new models
684
-        if (
685
-            ! empty(self::$_settings[$addon_name]['model_paths'])
686
-            || ! empty(self::$_settings[$addon_name]['class_paths'])
687
-        ) {
688
-            EE_Register_Model::register(
689
-                $addon_name,
690
-                array(
691
-                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
692
-                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
693
-                )
694
-            );
695
-        }
696
-        // register model extensions
697
-        if (
698
-            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
699
-            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
700
-        ) {
701
-            EE_Register_Model_Extensions::register(
702
-                $addon_name,
703
-                array(
704
-                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
705
-                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
706
-                )
707
-            );
708
-        }
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     * @param string $addon_name
715
-     * @return void
716
-     * @throws \EE_Error
717
-     */
683
+		// register new models
684
+		if (
685
+			! empty(self::$_settings[$addon_name]['model_paths'])
686
+			|| ! empty(self::$_settings[$addon_name]['class_paths'])
687
+		) {
688
+			EE_Register_Model::register(
689
+				$addon_name,
690
+				array(
691
+					'model_paths' => self::$_settings[$addon_name]['model_paths'],
692
+					'class_paths' => self::$_settings[$addon_name]['class_paths'],
693
+				)
694
+			);
695
+		}
696
+		// register model extensions
697
+		if (
698
+			! empty(self::$_settings[$addon_name]['model_extension_paths'])
699
+			|| ! empty(self::$_settings[$addon_name]['class_extension_paths'])
700
+		) {
701
+			EE_Register_Model_Extensions::register(
702
+				$addon_name,
703
+				array(
704
+					'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
705
+					'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
706
+				)
707
+			);
708
+		}
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 * @param string $addon_name
715
+	 * @return void
716
+	 * @throws \EE_Error
717
+	 */
718 718
 	private static function _register_data_migration_scripts( $addon_name ) {
719
-        // setup DMS
720
-        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
721
-            EE_Register_Data_Migration_Scripts::register(
722
-                $addon_name,
723
-                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
724
-            );
725
-        }
726
-    }
727
-
728
-
729
-    /**
730
-     * @param string $addon_name
731
-     * @return void
732
-     * @throws \EE_Error
733
-     */
719
+		// setup DMS
720
+		if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
721
+			EE_Register_Data_Migration_Scripts::register(
722
+				$addon_name,
723
+				array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
724
+			);
725
+		}
726
+	}
727
+
728
+
729
+	/**
730
+	 * @param string $addon_name
731
+	 * @return void
732
+	 * @throws \EE_Error
733
+	 */
734 734
 	private static function _register_config( $addon_name ) {
735
-        // if config_class is present let's register config.
736
-        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
737
-            EE_Register_Config::register(
738
-                self::$_settings[$addon_name]['config_class'],
739
-                array(
740
-                    'config_section' => self::$_settings[$addon_name]['config_section'],
741
-                    'config_name'    => self::$_settings[$addon_name]['config_name'],
742
-                )
743
-            );
744
-        }
745
-    }
746
-
747
-
748
-    /**
749
-     * @param string $addon_name
750
-     * @return void
751
-     * @throws \EE_Error
752
-     */
735
+		// if config_class is present let's register config.
736
+		if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
737
+			EE_Register_Config::register(
738
+				self::$_settings[$addon_name]['config_class'],
739
+				array(
740
+					'config_section' => self::$_settings[$addon_name]['config_section'],
741
+					'config_name'    => self::$_settings[$addon_name]['config_name'],
742
+				)
743
+			);
744
+		}
745
+	}
746
+
747
+
748
+	/**
749
+	 * @param string $addon_name
750
+	 * @return void
751
+	 * @throws \EE_Error
752
+	 */
753 753
 	private static function _register_admin_pages( $addon_name ) {
754
-        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
755
-            EE_Register_Admin_Page::register(
756
-                $addon_name,
757
-                array('page_path' => self::$_settings[$addon_name]['admin_path'])
758
-            );
759
-        }
760
-    }
761
-
762
-
763
-    /**
764
-     * @param string $addon_name
765
-     * @return void
766
-     * @throws \EE_Error
767
-     */
754
+		if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
755
+			EE_Register_Admin_Page::register(
756
+				$addon_name,
757
+				array('page_path' => self::$_settings[$addon_name]['admin_path'])
758
+			);
759
+		}
760
+	}
761
+
762
+
763
+	/**
764
+	 * @param string $addon_name
765
+	 * @return void
766
+	 * @throws \EE_Error
767
+	 */
768 768
 	private static function _register_modules( $addon_name ) {
769
-        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
770
-            EE_Register_Module::register(
771
-                $addon_name,
772
-                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
773
-            );
774
-        }
775
-    }
776
-
777
-
778
-    /**
779
-     * @param string $addon_name
780
-     * @return void
781
-     * @throws \EE_Error
782
-     */
769
+		if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
770
+			EE_Register_Module::register(
771
+				$addon_name,
772
+				array('module_paths' => self::$_settings[$addon_name]['module_paths'])
773
+			);
774
+		}
775
+	}
776
+
777
+
778
+	/**
779
+	 * @param string $addon_name
780
+	 * @return void
781
+	 * @throws \EE_Error
782
+	 */
783 783
 	private static function _register_shortcodes( $addon_name ) {
784
-        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
785
-            EE_Register_Shortcode::register(
786
-                $addon_name,
787
-                array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'])
788
-            );
789
-        }
790
-    }
791
-
792
-
793
-    /**
794
-     * @param string $addon_name
795
-     * @return void
796
-     * @throws \EE_Error
797
-     */
784
+		if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
785
+			EE_Register_Shortcode::register(
786
+				$addon_name,
787
+				array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'])
788
+			);
789
+		}
790
+	}
791
+
792
+
793
+	/**
794
+	 * @param string $addon_name
795
+	 * @return void
796
+	 * @throws \EE_Error
797
+	 */
798 798
 	private static function _register_widgets( $addon_name ) {
799
-        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
800
-            EE_Register_Widget::register(
801
-                $addon_name,
802
-                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
803
-            );
804
-        }
805
-    }
806
-
807
-
808
-    /**
809
-     * @param string $addon_name
810
-     * @return void
811
-     * @throws \EE_Error
812
-     */
799
+		if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
800
+			EE_Register_Widget::register(
801
+				$addon_name,
802
+				array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
803
+			);
804
+		}
805
+	}
806
+
807
+
808
+	/**
809
+	 * @param string $addon_name
810
+	 * @return void
811
+	 * @throws \EE_Error
812
+	 */
813 813
 	private static function _register_capabilities( $addon_name ) {
814
-        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
815
-            EE_Register_Capabilities::register(
816
-                $addon_name,
817
-                array(
818
-                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
819
-                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
820
-                )
821
-            );
822
-        }
823
-    }
824
-
825
-
826
-    /**
827
-     * @param string $addon_name
828
-     * @return void
829
-     * @throws \EE_Error
830
-     */
814
+		if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
815
+			EE_Register_Capabilities::register(
816
+				$addon_name,
817
+				array(
818
+					'capabilities'    => self::$_settings[$addon_name]['capabilities'],
819
+					'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
820
+				)
821
+			);
822
+		}
823
+	}
824
+
825
+
826
+	/**
827
+	 * @param string $addon_name
828
+	 * @return void
829
+	 * @throws \EE_Error
830
+	 */
831 831
 	private static function _register_message_types( $addon_name ) {
832
-        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
833
-            add_action(
834
-                'EE_Brewing_Regular___messages_caf',
835
-                array('EE_Register_Addon', 'register_message_types')
836
-            );
837
-        }
838
-    }
839
-
840
-
841
-    /**
842
-     * @param string $addon_name
843
-     * @return void
844
-     * @throws \EE_Error
845
-     */
832
+		if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
833
+			add_action(
834
+				'EE_Brewing_Regular___messages_caf',
835
+				array('EE_Register_Addon', 'register_message_types')
836
+			);
837
+		}
838
+	}
839
+
840
+
841
+	/**
842
+	 * @param string $addon_name
843
+	 * @return void
844
+	 * @throws \EE_Error
845
+	 */
846 846
 	private static function _register_custom_post_types( $addon_name ) {
847
-        if (
848
-            ! empty(self::$_settings[$addon_name]['custom_post_types'])
849
-            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
850
-        ) {
851
-            EE_Register_CPT::register(
852
-                $addon_name,
853
-                array(
854
-                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
855
-                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
856
-                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
857
-                )
858
-            );
859
-        }
860
-    }
861
-
862
-
863
-    /**
864
-     * @param string $addon_name
865
-     * @return void
866
-     * @throws \EE_Error
867
-     */
847
+		if (
848
+			! empty(self::$_settings[$addon_name]['custom_post_types'])
849
+			|| ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
850
+		) {
851
+			EE_Register_CPT::register(
852
+				$addon_name,
853
+				array(
854
+					'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
855
+					'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
856
+					'default_terms' => self::$_settings[$addon_name]['default_terms'],
857
+				)
858
+			);
859
+		}
860
+	}
861
+
862
+
863
+	/**
864
+	 * @param string $addon_name
865
+	 * @return void
866
+	 * @throws \EE_Error
867
+	 */
868 868
 	private static function _register_payment_methods( $addon_name ) {
869
-        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
870
-            EE_Register_Payment_Method::register(
871
-                $addon_name,
872
-                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
873
-            );
874
-        }
875
-    }
869
+		if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
870
+			EE_Register_Payment_Method::register(
871
+				$addon_name,
872
+				array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
873
+			);
874
+		}
875
+	}
876 876
 
877 877
 
878 878
 
@@ -901,14 +901,14 @@  discard block
 block discarded – undo
901 901
 		//unfortunately this can't be hooked in upon construction, because we don't have
902 902
 		//the plugin mainfile's path upon construction.
903 903
 		register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) );
904
-        // call any additional admin_callback functions during load_admin_controller hook
905
-        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
906
-            add_action(
907
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
908
-                array($addon, self::$_settings[$addon_name]['admin_callback'])
909
-            );
910
-        }
911
-        return $addon;
904
+		// call any additional admin_callback functions during load_admin_controller hook
905
+		if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
906
+			add_action(
907
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
908
+				array($addon, self::$_settings[$addon_name]['admin_callback'])
909
+			);
910
+		}
911
+		return $addon;
912 912
 	}
913 913
 
914 914
 
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 		// cycle thru settings
925 925
 		foreach ( self::$_settings as $settings ) {
926 926
 			if ( ! empty( $settings['pue_options'] ) ) {
927
-                // initiate the class and start the plugin update engine!
927
+				// initiate the class and start the plugin update engine!
928 928
 				new PluginUpdateEngineChecker(
929 929
 				// host file URL
930 930
 					'https://eventespresso.com',
@@ -960,11 +960,11 @@  discard block
 block discarded – undo
960 960
 	 */
961 961
 	public static function register_message_types() {
962 962
 		foreach ( self::$_settings as $addon_name => $settings ) {
963
-		    if ( ! empty($settings['message_types'])) {
964
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
965
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
966
-                }
967
-            }
963
+			if ( ! empty($settings['message_types'])) {
964
+				foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
965
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
966
+				}
967
+			}
968 968
 		}
969 969
 	}
970 970
 
@@ -1006,15 +1006,15 @@  discard block
 block discarded – undo
1006 1006
 				EE_Register_Widget::deregister( $addon_name );
1007 1007
 			}
1008 1008
 			if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] )
1009
-			     ||
1010
-			     ! empty( self::$_settings[ $addon_name ]['class_paths'] )
1009
+				 ||
1010
+				 ! empty( self::$_settings[ $addon_name ]['class_paths'] )
1011 1011
 			) {
1012 1012
 				// add to list of shortcodes to be registered
1013 1013
 				EE_Register_Model::deregister( $addon_name );
1014 1014
 			}
1015 1015
 			if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] )
1016
-			     ||
1017
-			     ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] )
1016
+				 ||
1017
+				 ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] )
1018 1018
 			) {
1019 1019
 				// add to list of shortcodes to be registered
1020 1020
 				EE_Register_Model_Extensions::deregister( $addon_name );
Please login to merge, or discard this patch.