Completed
Branch BUG/4.10-migrations-fails (c52cc0)
by
unknown
16:39 queued 09:02
created
core/services/privacy/export/PersonalDataExporterManager.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -23,68 +23,68 @@
 block discarded – undo
23 23
 class PersonalDataExporterManager
24 24
 {
25 25
 
26
-    public function __construct()
27
-    {
28
-        add_filter(
29
-            'wp_privacy_personal_data_exporters',
30
-            array($this, 'hookInExporters')
31
-        );
32
-    }
26
+	public function __construct()
27
+	{
28
+		add_filter(
29
+			'wp_privacy_personal_data_exporters',
30
+			array($this, 'hookInExporters')
31
+		);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Adds EE's exporters to the list of WP exporters
37
-     *
38
-     * @param array $exporters
39
-     * @return array
40
-     */
41
-    public function hookInExporters($exporters)
42
-    {
43
-        // load all the privacy policy stuff
44
-        // add post policy text
45
-        foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
46
-            $exporters[ get_class($exporter) ] = array(
47
-                'exporter_friendly_name' => $exporter->name(),
48
-                'callback'               => array($exporter, 'export'),
49
-            );
50
-        }
51
-        return $exporters;
52
-    }
35
+	/**
36
+	 * Adds EE's exporters to the list of WP exporters
37
+	 *
38
+	 * @param array $exporters
39
+	 * @return array
40
+	 */
41
+	public function hookInExporters($exporters)
42
+	{
43
+		// load all the privacy policy stuff
44
+		// add post policy text
45
+		foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
46
+			$exporters[ get_class($exporter) ] = array(
47
+				'exporter_friendly_name' => $exporter->name(),
48
+				'callback'               => array($exporter, 'export'),
49
+			);
50
+		}
51
+		return $exporters;
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * @return CollectionInterface|PersonalDataExporterInterface[]
57
-     * @throws InvalidIdentifierException
58
-     * @throws InvalidInterfaceException
59
-     * @throws InvalidFilePathException
60
-     * @throws InvalidEntityException
61
-     * @throws InvalidDataTypeException
62
-     * @throws InvalidClassException
63
-     */
64
-    protected function loadPrivateDataExporterCollection()
65
-    {
66
-        $loader = new CollectionLoader(
67
-            new CollectionDetails(
68
-                // collection name
69
-                'personal_data_exporters',
70
-                // collection interface
71
-                'EventEspresso\core\services\privacy\export\PersonalDataExporterInterface',
72
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
73
-                apply_filters(
74
-                    'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
75
-                    array('EventEspresso\core\domain\services\admin\privacy\export')
76
-                ),
77
-                // filepaths to classes to add
78
-                array(),
79
-                // file mask to use if parsing folder for files to add
80
-                '',
81
-                // what to use as identifier for collection entities
82
-                // using CLASS NAME prevents duplicates (works like a singleton)
83
-                CollectionDetails::ID_CLASS_NAME
84
-            )
85
-        );
86
-        return $loader->getCollection();
87
-    }
55
+	/**
56
+	 * @return CollectionInterface|PersonalDataExporterInterface[]
57
+	 * @throws InvalidIdentifierException
58
+	 * @throws InvalidInterfaceException
59
+	 * @throws InvalidFilePathException
60
+	 * @throws InvalidEntityException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws InvalidClassException
63
+	 */
64
+	protected function loadPrivateDataExporterCollection()
65
+	{
66
+		$loader = new CollectionLoader(
67
+			new CollectionDetails(
68
+				// collection name
69
+				'personal_data_exporters',
70
+				// collection interface
71
+				'EventEspresso\core\services\privacy\export\PersonalDataExporterInterface',
72
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
73
+				apply_filters(
74
+					'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters',
75
+					array('EventEspresso\core\domain\services\admin\privacy\export')
76
+				),
77
+				// filepaths to classes to add
78
+				array(),
79
+				// file mask to use if parsing folder for files to add
80
+				'',
81
+				// what to use as identifier for collection entities
82
+				// using CLASS NAME prevents duplicates (works like a singleton)
83
+				CollectionDetails::ID_CLASS_NAME
84
+			)
85
+		);
86
+		return $loader->getCollection();
87
+	}
88 88
 }
89 89
 
90 90
 // End of file PersonalDataExporterManager.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
         // load all the privacy policy stuff
44 44
         // add post policy text
45 45
         foreach ($this->loadPrivateDataExporterCollection() as $exporter) {
46
-            $exporters[ get_class($exporter) ] = array(
46
+            $exporters[get_class($exporter)] = array(
47 47
                 'exporter_friendly_name' => $exporter->name(),
48 48
                 'callback'               => array($exporter, 'export'),
49 49
             );
Please login to merge, or discard this patch.
core/services/privacy/erasure/PersonalDataEraserManager.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
         // load all the privacy policy stuff
41 41
         // add post policy text
42 42
         foreach ($this->loadPrivateDataEraserCollection() as $eraser) {
43
-            $erasers[ get_class($eraser) ] = array(
43
+            $erasers[get_class($eraser)] = array(
44 44
                 'eraser_friendly_name' => $eraser->name(),
45 45
                 'callback'             => array($eraser, 'erase'),
46 46
             );
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -23,65 +23,65 @@
 block discarded – undo
23 23
 class PersonalDataEraserManager
24 24
 {
25 25
 
26
-    public function __construct()
27
-    {
28
-        add_filter(
29
-            'wp_privacy_personal_data_erasers',
30
-            array($this, 'hookInErasers')
31
-        );
32
-    }
26
+	public function __construct()
27
+	{
28
+		add_filter(
29
+			'wp_privacy_personal_data_erasers',
30
+			array($this, 'hookInErasers')
31
+		);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * For all the registered `PrivateDataEraserInterface`s, add them as erasers
37
-     */
38
-    public function hookInErasers($erasers)
39
-    {
40
-        // load all the privacy policy stuff
41
-        // add post policy text
42
-        foreach ($this->loadPrivateDataEraserCollection() as $eraser) {
43
-            $erasers[ get_class($eraser) ] = array(
44
-                'eraser_friendly_name' => $eraser->name(),
45
-                'callback'             => array($eraser, 'erase'),
46
-            );
47
-        }
48
-        return $erasers;
49
-    }
35
+	/**
36
+	 * For all the registered `PrivateDataEraserInterface`s, add them as erasers
37
+	 */
38
+	public function hookInErasers($erasers)
39
+	{
40
+		// load all the privacy policy stuff
41
+		// add post policy text
42
+		foreach ($this->loadPrivateDataEraserCollection() as $eraser) {
43
+			$erasers[ get_class($eraser) ] = array(
44
+				'eraser_friendly_name' => $eraser->name(),
45
+				'callback'             => array($eraser, 'erase'),
46
+			);
47
+		}
48
+		return $erasers;
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * @return CollectionInterface|PersonalDataEraserInterface[]
54
-     * @throws InvalidIdentifierException
55
-     * @throws InvalidInterfaceException
56
-     * @throws InvalidFilePathException
57
-     * @throws InvalidEntityException
58
-     * @throws InvalidDataTypeException
59
-     * @throws InvalidClassException
60
-     */
61
-    protected function loadPrivateDataEraserCollection()
62
-    {
63
-        $loader = new CollectionLoader(
64
-            new CollectionDetails(
65
-                // collection name
66
-                'privacy_erasers',
67
-                // collection interface
68
-                'EventEspresso\core\services\privacy\erasure\PersonalDataEraserInterface',
69
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
70
-                apply_filters(
71
-                    'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
72
-                    array('EventEspresso\core\domain\services\admin\privacy\erasure')
73
-                ),
74
-                // filepaths to classes to add
75
-                array(),
76
-                // file mask to use if parsing folder for files to add
77
-                '',
78
-                // what to use as identifier for collection entities
79
-                // using CLASS NAME prevents duplicates (works like a singleton)
80
-                CollectionDetails::ID_CLASS_NAME
81
-            )
82
-        );
83
-        return $loader->getCollection();
84
-    }
52
+	/**
53
+	 * @return CollectionInterface|PersonalDataEraserInterface[]
54
+	 * @throws InvalidIdentifierException
55
+	 * @throws InvalidInterfaceException
56
+	 * @throws InvalidFilePathException
57
+	 * @throws InvalidEntityException
58
+	 * @throws InvalidDataTypeException
59
+	 * @throws InvalidClassException
60
+	 */
61
+	protected function loadPrivateDataEraserCollection()
62
+	{
63
+		$loader = new CollectionLoader(
64
+			new CollectionDetails(
65
+				// collection name
66
+				'privacy_erasers',
67
+				// collection interface
68
+				'EventEspresso\core\services\privacy\erasure\PersonalDataEraserInterface',
69
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
70
+				apply_filters(
71
+					'FHEE__EventEspresso_core_services_privacy_erasure_PersonalDataEraserManager__erasers',
72
+					array('EventEspresso\core\domain\services\admin\privacy\erasure')
73
+				),
74
+				// filepaths to classes to add
75
+				array(),
76
+				// file mask to use if parsing folder for files to add
77
+				'',
78
+				// what to use as identifier for collection entities
79
+				// using CLASS NAME prevents duplicates (works like a singleton)
80
+				CollectionDetails::ID_CLASS_NAME
81
+			)
82
+		);
83
+		return $loader->getCollection();
84
+	}
85 85
 }
86 86
 // End of file PersonalDataEraserManager.php
87 87
 // Location: EventEspresso\core\domain\services\admin/PersonalDataEraserManager.php
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -85,63 +85,63 @@  discard block
 block discarded – undo
85 85
             }
86 86
         }
87 87
         // set default wp post statuses if child has not already set.
88
-        if (! isset($this->_fields[ $primary_table_name ]['status'])) {
89
-            $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
88
+        if ( ! isset($this->_fields[$primary_table_name]['status'])) {
89
+            $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field(
90 90
                 'post_status',
91 91
                 __("Event Status", "event_espresso"),
92 92
                 false,
93 93
                 'draft'
94 94
             );
95 95
         }
96
-        if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
97
-            $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
96
+        if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
97
+            $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field(
98 98
                 'to_ping',
99 99
                 __('To Ping', 'event_espresso'),
100 100
                 false,
101 101
                 ''
102 102
             );
103 103
         }
104
-        if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
105
-            $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
104
+        if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
105
+            $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field(
106 106
                 'pinged',
107 107
                 __('Pinged', 'event_espresso'),
108 108
                 false,
109 109
                 ''
110 110
             );
111 111
         }
112
-        if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
113
-            $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
112
+        if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
113
+            $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field(
114 114
                 'comment_status',
115 115
                 __('Comment Status', 'event_espresso'),
116 116
                 false,
117 117
                 'open'
118 118
             );
119 119
         }
120
-        if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
121
-            $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
120
+        if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
121
+            $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field(
122 122
                 'ping_status',
123 123
                 __('Ping Status', 'event_espresso'),
124 124
                 false,
125 125
                 'open'
126 126
             );
127 127
         }
128
-        if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
129
-            $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
128
+        if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
129
+            $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field(
130 130
                 'post_content_filtered',
131 131
                 __('Post Content Filtered', 'event_espresso'),
132 132
                 false,
133 133
                 ''
134 134
             );
135 135
         }
136
-        if (! isset($this->_model_relations['Post_Meta'])) {
136
+        if ( ! isset($this->_model_relations['Post_Meta'])) {
137 137
             // don't block deletes though because we want to maintain the current behaviour
138 138
             $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
139 139
         }
140
-        if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
140
+        if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
141 141
             // nothing was set during child constructor, so set default
142 142
             $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
143 143
         }
144
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
144
+        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
145 145
             // nothing was set during child constructor, so set default
146 146
             // it's ok for child classes to specify this, but generally this is more DRY
147 147
             $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
     protected function _alter_query_params_so_only_trashed_items_included($query_params)
216 216
     {
217 217
         $post_status_field_name = $this->post_status_field_name();
218
-        $query_params[0][ $post_status_field_name ] = self::post_status_trashed;
218
+        $query_params[0][$post_status_field_name] = self::post_status_trashed;
219 219
         return $query_params;
220 220
     }
221 221
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
284 284
             }
285 285
         }
286
-        if (! $all) {
286
+        if ( ! $all) {
287 287
             foreach ($all_fields as $name => $obj) {
288 288
                 if ($obj instanceof EE_DB_Only_Field_Base) {
289 289
                     continue;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
         $parent_term_taxonomy_id = null
316 316
     ) {
317 317
         // create term
318
-        require_once(EE_MODELS . 'EEM_Term.model.php');
318
+        require_once(EE_MODELS.'EEM_Term.model.php');
319 319
         // first, check for a term by the same name or slug
320 320
         $category_slug = sanitize_title($category_name);
321 321
         $term = EEM_Term::instance()->get_one(
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 ),
329 329
             )
330 330
         );
331
-        if (! $term) {
331
+        if ( ! $term) {
332 332
             $term = EE_Term::new_instance(
333 333
                 array(
334 334
                     'name' => $category_name,
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
             $term->save();
339 339
         }
340 340
         // make sure there's a term-taxonomy entry too
341
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
341
+        require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
342 342
         $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
343 343
             array(
344 344
                 array(
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
             )
349 349
         );
350 350
         /** @var $term_taxonomy EE_Term_Taxonomy */
351
-        if (! $term_taxonomy) {
351
+        if ( ! $term_taxonomy) {
352 352
             $term_taxonomy = EE_Term_Taxonomy::new_instance(
353 353
                 array(
354 354
                     'term_id'     => $term->ID(),
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         global $wp_post_statuses;
422 422
         $statuses = array();
423 423
         foreach ($wp_post_statuses as $post_status => $args_object) {
424
-            $statuses[ $post_status ] = $args_object->label;
424
+            $statuses[$post_status] = $args_object->label;
425 425
         }
426 426
         return $statuses;
427 427
     }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
         // first the global filter
439 439
         $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
440 440
         // now the class specific filter
441
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
441
+        $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
442 442
         return $statuses;
443 443
     }
444 444
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
     {
453 453
         $new_stati = array();
454 454
         foreach ($this->_custom_stati as $status => $props) {
455
-            $new_stati[ $status ] = $props['label'];
455
+            $new_stati[$status] = $props['label'];
456 456
         }
457 457
         return $new_stati;
458 458
     }
@@ -475,15 +475,15 @@  discard block
 block discarded – undo
475 475
         foreach ($this->_get_other_tables() as $table_obj) {
476 476
             $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
477 477
             foreach ($fields_for_that_table as $field_obj) {
478
-                if (! isset($post[ $field_obj->get_table_column() ])
479
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
478
+                if ( ! isset($post[$field_obj->get_table_column()])
479
+                    && ! isset($post[$field_obj->get_qualified_column()])
480 480
                 ) {
481 481
                     $has_all_necessary_fields_for_table = false;
482 482
                 }
483 483
             }
484 484
         }
485 485
         // if we don't have all the fields we need, then just fetch the proper model from the DB
486
-        if (! $has_all_necessary_fields_for_table) {
486
+        if ( ! $has_all_necessary_fields_for_table) {
487 487
             return $this->get_one_by_ID($post['ID']);
488 488
         } else {
489 489
             return $this->instantiate_class_from_array_or_object($post);
@@ -506,10 +506,10 @@  discard block
 block discarded – undo
506 506
         foreach ($this->get_tables() as $table_obj) {
507 507
             $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
508 508
             foreach ($fields_for_that_table as $field_obj) {
509
-                if (! isset($post[ $field_obj->get_table_column() ])
510
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
509
+                if ( ! isset($post[$field_obj->get_table_column()])
510
+                    && ! isset($post[$field_obj->get_qualified_column()])
511 511
                 ) {
512
-                    $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
512
+                    $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
513 513
                 }
514 514
             }
515 515
         }
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
                         ARRAY_A,
535 535
                     )
536 536
                 );
537
-                if (! empty($missing_data)) {
537
+                if ( ! empty($missing_data)) {
538 538
                     $post = array_merge($post, $missing_data);
539 539
                 }
540 540
             } else {
Please login to merge, or discard this patch.
Indentation   +558 added lines, -558 removed lines patch added patch discarded remove patch
@@ -16,562 +16,562 @@
 block discarded – undo
16 16
 abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base
17 17
 {
18 18
 
19
-    const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories';
20
-
21
-    /**
22
-     * @var string post_status_publish - the wp post status for published cpts
23
-     */
24
-    const post_status_publish = 'publish';
25
-
26
-    /**
27
-     * @var string post_status_future - the wp post status for scheduled cpts
28
-     */
29
-    const post_status_future = 'future';
30
-
31
-    /**
32
-     * @var string post_status_draft - the wp post status for draft cpts
33
-     */
34
-    const post_status_draft = 'draft';
35
-
36
-    /**
37
-     * @var string post_status_pending - the wp post status for pending cpts
38
-     */
39
-    const post_status_pending = 'pending';
40
-
41
-    /**
42
-     * @var string post_status_private - the wp post status for private cpts
43
-     */
44
-    const post_status_private = 'private';
45
-
46
-    /**
47
-     * @var string post_status_trashed - the wp post status for trashed cpts
48
-     */
49
-    const post_status_trashed = 'trash';
50
-
51
-    /**
52
-     * This is an array of custom statuses for the given CPT model (modified by children)
53
-     * format:
54
-     * array(
55
-     *        'status_name' => array(
56
-     *            'label' => __('Status Name', 'event_espresso'),
57
-     *            'public' => TRUE //whether a public status or not.
58
-     *        )
59
-     * )
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_custom_stati = array();
64
-
65
-
66
-    /**
67
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
68
-     *
69
-     * @param string $timezone
70
-     * @throws \EE_Error
71
-     */
72
-    protected function __construct($timezone = null)
73
-    {
74
-        // adds a relationship to Term_Taxonomy for all these models. For this to work
75
-        // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
76
-        // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
77
-        // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
78
-        // must also be new EE_HABTM_Relation('Term_Relationship');
79
-        $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
80
-        $primary_table_name = null;
81
-        // add  the common _status field to all CPT primary tables.
82
-        foreach ($this->_tables as $alias => $table_obj) {
83
-            if ($table_obj instanceof EE_Primary_Table) {
84
-                $primary_table_name = $alias;
85
-            }
86
-        }
87
-        // set default wp post statuses if child has not already set.
88
-        if (! isset($this->_fields[ $primary_table_name ]['status'])) {
89
-            $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
90
-                'post_status',
91
-                __("Event Status", "event_espresso"),
92
-                false,
93
-                'draft'
94
-            );
95
-        }
96
-        if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
97
-            $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
98
-                'to_ping',
99
-                __('To Ping', 'event_espresso'),
100
-                false,
101
-                ''
102
-            );
103
-        }
104
-        if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
105
-            $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
106
-                'pinged',
107
-                __('Pinged', 'event_espresso'),
108
-                false,
109
-                ''
110
-            );
111
-        }
112
-        if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
113
-            $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
114
-                'comment_status',
115
-                __('Comment Status', 'event_espresso'),
116
-                false,
117
-                'open'
118
-            );
119
-        }
120
-        if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
121
-            $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
122
-                'ping_status',
123
-                __('Ping Status', 'event_espresso'),
124
-                false,
125
-                'open'
126
-            );
127
-        }
128
-        if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
129
-            $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
130
-                'post_content_filtered',
131
-                __('Post Content Filtered', 'event_espresso'),
132
-                false,
133
-                ''
134
-            );
135
-        }
136
-        if (! isset($this->_model_relations['Post_Meta'])) {
137
-            // don't block deletes though because we want to maintain the current behaviour
138
-            $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
139
-        }
140
-        if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
141
-            // nothing was set during child constructor, so set default
142
-            $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
143
-        }
144
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
145
-            // nothing was set during child constructor, so set default
146
-            // it's ok for child classes to specify this, but generally this is more DRY
147
-            $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
148
-        }
149
-        parent::__construct($timezone);
150
-    }
151
-
152
-
153
-    /**
154
-     * @return array
155
-     */
156
-    public function public_event_stati()
157
-    {
158
-        // @see wp-includes/post.php
159
-        return get_post_stati(array('public' => true));
160
-    }
161
-
162
-
163
-    /**
164
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
165
-     * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
166
-     *
167
-     * @return string
168
-     * @throws EE_Error
169
-     */
170
-    public function deleted_field_name()
171
-    {
172
-        throw new EE_Error(
173
-            sprintf(
174
-                __(
175
-                    "EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
176
-                    "event_espresso"
177
-                )
178
-            )
179
-        );
180
-    }
181
-
182
-
183
-    /**
184
-     * Gets the field's name that sets the post status
185
-     *
186
-     * @return string
187
-     * @throws EE_Error
188
-     */
189
-    public function post_status_field_name()
190
-    {
191
-        $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
192
-        if ($field) {
193
-            return $field->get_name();
194
-        } else {
195
-            throw new EE_Error(
196
-                sprintf(
197
-                    __(
198
-                        'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
199
-                        'event_espresso'
200
-                    ),
201
-                    get_class($this),
202
-                    get_class($this)
203
-                )
204
-            );
205
-        }
206
-    }
207
-
208
-
209
-    /**
210
-     * Alters the query params so that only trashed/soft-deleted items are considered
211
-     *
212
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
213
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
214
-     */
215
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
216
-    {
217
-        $post_status_field_name = $this->post_status_field_name();
218
-        $query_params[0][ $post_status_field_name ] = self::post_status_trashed;
219
-        return $query_params;
220
-    }
221
-
222
-
223
-    /**
224
-     * Alters the query params so each item's deleted status is ignored.
225
-     *
226
-     * @param array $query_params
227
-     * @return array
228
-     */
229
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
230
-    {
231
-        $query_params['default_where_conditions'] = 'minimum';
232
-        return $query_params;
233
-    }
234
-
235
-
236
-    /**
237
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
238
-     *
239
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
240
-     * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
241
-     * @return boolean success
242
-     */
243
-    public function delete_or_restore($delete = true, $query_params = array())
244
-    {
245
-        $post_status_field_name = $this->post_status_field_name();
246
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
247
-        $new_status = $delete ? self::post_status_trashed : 'draft';
248
-        if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
249
-            return true;
250
-        } else {
251
-            return false;
252
-        }
253
-    }
254
-
255
-
256
-    /**
257
-     * meta_table
258
-     * returns first EE_Secondary_Table table name
259
-     *
260
-     * @access public
261
-     * @return string
262
-     */
263
-    public function meta_table()
264
-    {
265
-        $meta_table = $this->_get_other_tables();
266
-        $meta_table = reset($meta_table);
267
-        return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
268
-    }
269
-
270
-
271
-    /**
272
-     * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
273
-     *
274
-     * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
275
-     *                   db only fields)
276
-     * @return array
277
-     */
278
-    public function get_meta_table_fields($all = false)
279
-    {
280
-        $all_fields = $fields_to_return = array();
281
-        foreach ($this->_tables as $alias => $table_obj) {
282
-            if ($table_obj instanceof EE_Secondary_Table) {
283
-                $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
284
-            }
285
-        }
286
-        if (! $all) {
287
-            foreach ($all_fields as $name => $obj) {
288
-                if ($obj instanceof EE_DB_Only_Field_Base) {
289
-                    continue;
290
-                }
291
-                $fields_to_return[] = $name;
292
-            }
293
-        } else {
294
-            $fields_to_return = array_keys($all_fields);
295
-        }
296
-        return $fields_to_return;
297
-    }
298
-
299
-
300
-    /**
301
-     * Adds an event category with the specified name and description to the specified
302
-     * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
303
-     * and adds an entry in the term_relationship if necessary.
304
-     *
305
-     * @param EE_CPT_Base $cpt_model_object
306
-     * @param string      $category_name (used to derive the term slug too)
307
-     * @param string      $category_description
308
-     * @param int         $parent_term_taxonomy_id
309
-     * @return EE_Term_Taxonomy
310
-     */
311
-    public function add_event_category(
312
-        EE_CPT_Base $cpt_model_object,
313
-        $category_name,
314
-        $category_description = '',
315
-        $parent_term_taxonomy_id = null
316
-    ) {
317
-        // create term
318
-        require_once(EE_MODELS . 'EEM_Term.model.php');
319
-        // first, check for a term by the same name or slug
320
-        $category_slug = sanitize_title($category_name);
321
-        $term = EEM_Term::instance()->get_one(
322
-            array(
323
-                array(
324
-                    'OR' => array(
325
-                        'name' => $category_name,
326
-                        'slug' => $category_slug,
327
-                    ),
328
-                    'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY
329
-                ),
330
-            )
331
-        );
332
-        if (! $term) {
333
-            $term = EE_Term::new_instance(
334
-                array(
335
-                    'name' => $category_name,
336
-                    'slug' => $category_slug,
337
-                )
338
-            );
339
-            $term->save();
340
-        }
341
-        // make sure there's a term-taxonomy entry too
342
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
343
-        $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
344
-            array(
345
-                array(
346
-                    'term_id'  => $term->ID(),
347
-                    'taxonomy' => self::EVENT_CATEGORY_TAXONOMY,
348
-                ),
349
-            )
350
-        );
351
-        /** @var $term_taxonomy EE_Term_Taxonomy */
352
-        if (! $term_taxonomy) {
353
-            $term_taxonomy = EE_Term_Taxonomy::new_instance(
354
-                array(
355
-                    'term_id'     => $term->ID(),
356
-                    'taxonomy'    => self::EVENT_CATEGORY_TAXONOMY,
357
-                    'description' => $category_description,
358
-                    'term_count'       => 1,
359
-                    'parent'      => $parent_term_taxonomy_id,
360
-                )
361
-            );
362
-            $term_taxonomy->save();
363
-        } else {
364
-            $term_taxonomy->set_count($term_taxonomy->count() + 1);
365
-            $term_taxonomy->save();
366
-        }
367
-        return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
368
-    }
369
-
370
-
371
-    /**
372
-     * Removed the category specified by name as having a relation to this event.
373
-     * Does not remove the term or term_taxonomy.
374
-     *
375
-     * @param EE_CPT_Base $cpt_model_object_event
376
-     * @param string      $category_name name of the event category (term)
377
-     * @return bool
378
-     */
379
-    public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
380
-    {
381
-        // find the term_taxonomy by that name
382
-        $term_taxonomy = $this->get_first_related(
383
-            $cpt_model_object_event,
384
-            'Term_Taxonomy',
385
-            array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY))
386
-        );
387
-        /** @var $term_taxonomy EE_Term_Taxonomy */
388
-        if ($term_taxonomy) {
389
-            $term_taxonomy->set_count($term_taxonomy->count() - 1);
390
-            $term_taxonomy->save();
391
-        }
392
-        return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
393
-    }
394
-
395
-
396
-    /**
397
-     * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
398
-     * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
399
-     *
400
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
401
-     * @access public
402
-     * @param int          $id   the ID for the cpt we want the feature image for
403
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
404
-     *                           representing width and height in pixels (i.e. array(32,32) ).
405
-     * @param string|array $attr Optional. Query string or array of attributes.
406
-     * @return string HTML image element
407
-     */
408
-    public function get_feature_image($id, $size = 'thumbnail', $attr = '')
409
-    {
410
-        return get_the_post_thumbnail($id, $size, $attr);
411
-    }
412
-
413
-
414
-    /**
415
-     * Just a handy way to get the list of post statuses currently registered with WP.
416
-     *
417
-     * @global array $wp_post_statuses set in wp core for storing all the post stati
418
-     * @return array
419
-     */
420
-    public function get_post_statuses()
421
-    {
422
-        global $wp_post_statuses;
423
-        $statuses = array();
424
-        foreach ($wp_post_statuses as $post_status => $args_object) {
425
-            $statuses[ $post_status ] = $args_object->label;
426
-        }
427
-        return $statuses;
428
-    }
429
-
430
-
431
-    /**
432
-     * public method that can be used to retrieve the protected status array on the instantiated cpt model
433
-     *
434
-     * @return array array of statuses.
435
-     */
436
-    public function get_status_array()
437
-    {
438
-        $statuses = $this->get_post_statuses();
439
-        // first the global filter
440
-        $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
441
-        // now the class specific filter
442
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
443
-        return $statuses;
444
-    }
445
-
446
-
447
-    /**
448
-     * this returns the post statuses that are NOT the default wordpress status
449
-     *
450
-     * @return array
451
-     */
452
-    public function get_custom_post_statuses()
453
-    {
454
-        $new_stati = array();
455
-        foreach ($this->_custom_stati as $status => $props) {
456
-            $new_stati[ $status ] = $props['label'];
457
-        }
458
-        return $new_stati;
459
-    }
460
-
461
-
462
-    /**
463
-     * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
464
-     * are a row from the posts table. If we're missing any fields required for the model,
465
-     * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
466
-     * make sure you are attaching all the model's fields onto the post)
467
-     *
468
-     * @param WP_Post|array $post
469
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
470
-     */
471
-    public function instantiate_class_from_post_object_orig($post)
472
-    {
473
-        $post = (array) $post;
474
-        $has_all_necessary_fields_for_table = true;
475
-        // check if the post has fields on the meta table already
476
-        foreach ($this->_get_other_tables() as $table_obj) {
477
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
478
-            foreach ($fields_for_that_table as $field_obj) {
479
-                if (! isset($post[ $field_obj->get_table_column() ])
480
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
481
-                ) {
482
-                    $has_all_necessary_fields_for_table = false;
483
-                }
484
-            }
485
-        }
486
-        // if we don't have all the fields we need, then just fetch the proper model from the DB
487
-        if (! $has_all_necessary_fields_for_table) {
488
-            return $this->get_one_by_ID($post['ID']);
489
-        } else {
490
-            return $this->instantiate_class_from_array_or_object($post);
491
-        }
492
-    }
493
-
494
-
495
-    /**
496
-     * @param null $post
497
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
498
-     */
499
-    public function instantiate_class_from_post_object($post = null)
500
-    {
501
-        if (empty($post)) {
502
-            global $post;
503
-        }
504
-        $post = (array) $post;
505
-        $tables_needing_to_be_queried = array();
506
-        // check if the post has fields on the meta table already
507
-        foreach ($this->get_tables() as $table_obj) {
508
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
509
-            foreach ($fields_for_that_table as $field_obj) {
510
-                if (! isset($post[ $field_obj->get_table_column() ])
511
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
512
-                ) {
513
-                    $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
514
-                }
515
-            }
516
-        }
517
-        // if we don't have all the fields we need, then just fetch the proper model from the DB
518
-        if ($tables_needing_to_be_queried) {
519
-            if (count($tables_needing_to_be_queried) == 1
520
-                && reset($tables_needing_to_be_queried)
521
-                   instanceof
522
-                   EE_Secondary_Table
523
-            ) {
524
-                // so we're only missing data from a secondary table. Well that's not too hard to query for
525
-                $table_to_query = reset($tables_needing_to_be_queried);
526
-                $missing_data = $this->_do_wpdb_query(
527
-                    'get_row',
528
-                    array(
529
-                        'SELECT * FROM '
530
-                        . $table_to_query->get_table_name()
531
-                        . ' WHERE '
532
-                        . $table_to_query->get_fk_on_table()
533
-                        . ' = '
534
-                        . $post['ID'],
535
-                        ARRAY_A,
536
-                    )
537
-                );
538
-                if (! empty($missing_data)) {
539
-                    $post = array_merge($post, $missing_data);
540
-                }
541
-            } else {
542
-                return $this->get_one_by_ID($post['ID']);
543
-            }
544
-        }
545
-        return $this->instantiate_class_from_array_or_object($post);
546
-    }
547
-
548
-
549
-    /**
550
-     * Gets the post type associated with this
551
-     *
552
-     * @throws EE_Error
553
-     * @return string
554
-     */
555
-    public function post_type()
556
-    {
557
-        $post_type_field = null;
558
-        foreach ($this->field_settings(true) as $field_obj) {
559
-            if ($field_obj instanceof EE_WP_Post_Type_Field) {
560
-                $post_type_field = $field_obj;
561
-                break;
562
-            }
563
-        }
564
-        if ($post_type_field == null) {
565
-            throw new EE_Error(
566
-                sprintf(
567
-                    __(
568
-                        "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
569
-                        "event_espresso"
570
-                    ),
571
-                    get_class($this)
572
-                )
573
-            );
574
-        }
575
-        return $post_type_field->get_default_value();
576
-    }
19
+	const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories';
20
+
21
+	/**
22
+	 * @var string post_status_publish - the wp post status for published cpts
23
+	 */
24
+	const post_status_publish = 'publish';
25
+
26
+	/**
27
+	 * @var string post_status_future - the wp post status for scheduled cpts
28
+	 */
29
+	const post_status_future = 'future';
30
+
31
+	/**
32
+	 * @var string post_status_draft - the wp post status for draft cpts
33
+	 */
34
+	const post_status_draft = 'draft';
35
+
36
+	/**
37
+	 * @var string post_status_pending - the wp post status for pending cpts
38
+	 */
39
+	const post_status_pending = 'pending';
40
+
41
+	/**
42
+	 * @var string post_status_private - the wp post status for private cpts
43
+	 */
44
+	const post_status_private = 'private';
45
+
46
+	/**
47
+	 * @var string post_status_trashed - the wp post status for trashed cpts
48
+	 */
49
+	const post_status_trashed = 'trash';
50
+
51
+	/**
52
+	 * This is an array of custom statuses for the given CPT model (modified by children)
53
+	 * format:
54
+	 * array(
55
+	 *        'status_name' => array(
56
+	 *            'label' => __('Status Name', 'event_espresso'),
57
+	 *            'public' => TRUE //whether a public status or not.
58
+	 *        )
59
+	 * )
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_custom_stati = array();
64
+
65
+
66
+	/**
67
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
68
+	 *
69
+	 * @param string $timezone
70
+	 * @throws \EE_Error
71
+	 */
72
+	protected function __construct($timezone = null)
73
+	{
74
+		// adds a relationship to Term_Taxonomy for all these models. For this to work
75
+		// Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
76
+		// eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
77
+		// with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
78
+		// must also be new EE_HABTM_Relation('Term_Relationship');
79
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
80
+		$primary_table_name = null;
81
+		// add  the common _status field to all CPT primary tables.
82
+		foreach ($this->_tables as $alias => $table_obj) {
83
+			if ($table_obj instanceof EE_Primary_Table) {
84
+				$primary_table_name = $alias;
85
+			}
86
+		}
87
+		// set default wp post statuses if child has not already set.
88
+		if (! isset($this->_fields[ $primary_table_name ]['status'])) {
89
+			$this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
90
+				'post_status',
91
+				__("Event Status", "event_espresso"),
92
+				false,
93
+				'draft'
94
+			);
95
+		}
96
+		if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
97
+			$this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
98
+				'to_ping',
99
+				__('To Ping', 'event_espresso'),
100
+				false,
101
+				''
102
+			);
103
+		}
104
+		if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
105
+			$this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
106
+				'pinged',
107
+				__('Pinged', 'event_espresso'),
108
+				false,
109
+				''
110
+			);
111
+		}
112
+		if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
113
+			$this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
114
+				'comment_status',
115
+				__('Comment Status', 'event_espresso'),
116
+				false,
117
+				'open'
118
+			);
119
+		}
120
+		if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
121
+			$this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
122
+				'ping_status',
123
+				__('Ping Status', 'event_espresso'),
124
+				false,
125
+				'open'
126
+			);
127
+		}
128
+		if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
129
+			$this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
130
+				'post_content_filtered',
131
+				__('Post Content Filtered', 'event_espresso'),
132
+				false,
133
+				''
134
+			);
135
+		}
136
+		if (! isset($this->_model_relations['Post_Meta'])) {
137
+			// don't block deletes though because we want to maintain the current behaviour
138
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
139
+		}
140
+		if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
141
+			// nothing was set during child constructor, so set default
142
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
143
+		}
144
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
145
+			// nothing was set during child constructor, so set default
146
+			// it's ok for child classes to specify this, but generally this is more DRY
147
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
148
+		}
149
+		parent::__construct($timezone);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function public_event_stati()
157
+	{
158
+		// @see wp-includes/post.php
159
+		return get_post_stati(array('public' => true));
160
+	}
161
+
162
+
163
+	/**
164
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
165
+	 * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
166
+	 *
167
+	 * @return string
168
+	 * @throws EE_Error
169
+	 */
170
+	public function deleted_field_name()
171
+	{
172
+		throw new EE_Error(
173
+			sprintf(
174
+				__(
175
+					"EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
176
+					"event_espresso"
177
+				)
178
+			)
179
+		);
180
+	}
181
+
182
+
183
+	/**
184
+	 * Gets the field's name that sets the post status
185
+	 *
186
+	 * @return string
187
+	 * @throws EE_Error
188
+	 */
189
+	public function post_status_field_name()
190
+	{
191
+		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
192
+		if ($field) {
193
+			return $field->get_name();
194
+		} else {
195
+			throw new EE_Error(
196
+				sprintf(
197
+					__(
198
+						'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
199
+						'event_espresso'
200
+					),
201
+					get_class($this),
202
+					get_class($this)
203
+				)
204
+			);
205
+		}
206
+	}
207
+
208
+
209
+	/**
210
+	 * Alters the query params so that only trashed/soft-deleted items are considered
211
+	 *
212
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
213
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
214
+	 */
215
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
216
+	{
217
+		$post_status_field_name = $this->post_status_field_name();
218
+		$query_params[0][ $post_status_field_name ] = self::post_status_trashed;
219
+		return $query_params;
220
+	}
221
+
222
+
223
+	/**
224
+	 * Alters the query params so each item's deleted status is ignored.
225
+	 *
226
+	 * @param array $query_params
227
+	 * @return array
228
+	 */
229
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
230
+	{
231
+		$query_params['default_where_conditions'] = 'minimum';
232
+		return $query_params;
233
+	}
234
+
235
+
236
+	/**
237
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
238
+	 *
239
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
240
+	 * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
241
+	 * @return boolean success
242
+	 */
243
+	public function delete_or_restore($delete = true, $query_params = array())
244
+	{
245
+		$post_status_field_name = $this->post_status_field_name();
246
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
247
+		$new_status = $delete ? self::post_status_trashed : 'draft';
248
+		if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
249
+			return true;
250
+		} else {
251
+			return false;
252
+		}
253
+	}
254
+
255
+
256
+	/**
257
+	 * meta_table
258
+	 * returns first EE_Secondary_Table table name
259
+	 *
260
+	 * @access public
261
+	 * @return string
262
+	 */
263
+	public function meta_table()
264
+	{
265
+		$meta_table = $this->_get_other_tables();
266
+		$meta_table = reset($meta_table);
267
+		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
268
+	}
269
+
270
+
271
+	/**
272
+	 * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
273
+	 *
274
+	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
275
+	 *                   db only fields)
276
+	 * @return array
277
+	 */
278
+	public function get_meta_table_fields($all = false)
279
+	{
280
+		$all_fields = $fields_to_return = array();
281
+		foreach ($this->_tables as $alias => $table_obj) {
282
+			if ($table_obj instanceof EE_Secondary_Table) {
283
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
284
+			}
285
+		}
286
+		if (! $all) {
287
+			foreach ($all_fields as $name => $obj) {
288
+				if ($obj instanceof EE_DB_Only_Field_Base) {
289
+					continue;
290
+				}
291
+				$fields_to_return[] = $name;
292
+			}
293
+		} else {
294
+			$fields_to_return = array_keys($all_fields);
295
+		}
296
+		return $fields_to_return;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Adds an event category with the specified name and description to the specified
302
+	 * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
303
+	 * and adds an entry in the term_relationship if necessary.
304
+	 *
305
+	 * @param EE_CPT_Base $cpt_model_object
306
+	 * @param string      $category_name (used to derive the term slug too)
307
+	 * @param string      $category_description
308
+	 * @param int         $parent_term_taxonomy_id
309
+	 * @return EE_Term_Taxonomy
310
+	 */
311
+	public function add_event_category(
312
+		EE_CPT_Base $cpt_model_object,
313
+		$category_name,
314
+		$category_description = '',
315
+		$parent_term_taxonomy_id = null
316
+	) {
317
+		// create term
318
+		require_once(EE_MODELS . 'EEM_Term.model.php');
319
+		// first, check for a term by the same name or slug
320
+		$category_slug = sanitize_title($category_name);
321
+		$term = EEM_Term::instance()->get_one(
322
+			array(
323
+				array(
324
+					'OR' => array(
325
+						'name' => $category_name,
326
+						'slug' => $category_slug,
327
+					),
328
+					'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY
329
+				),
330
+			)
331
+		);
332
+		if (! $term) {
333
+			$term = EE_Term::new_instance(
334
+				array(
335
+					'name' => $category_name,
336
+					'slug' => $category_slug,
337
+				)
338
+			);
339
+			$term->save();
340
+		}
341
+		// make sure there's a term-taxonomy entry too
342
+		require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
343
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
344
+			array(
345
+				array(
346
+					'term_id'  => $term->ID(),
347
+					'taxonomy' => self::EVENT_CATEGORY_TAXONOMY,
348
+				),
349
+			)
350
+		);
351
+		/** @var $term_taxonomy EE_Term_Taxonomy */
352
+		if (! $term_taxonomy) {
353
+			$term_taxonomy = EE_Term_Taxonomy::new_instance(
354
+				array(
355
+					'term_id'     => $term->ID(),
356
+					'taxonomy'    => self::EVENT_CATEGORY_TAXONOMY,
357
+					'description' => $category_description,
358
+					'term_count'       => 1,
359
+					'parent'      => $parent_term_taxonomy_id,
360
+				)
361
+			);
362
+			$term_taxonomy->save();
363
+		} else {
364
+			$term_taxonomy->set_count($term_taxonomy->count() + 1);
365
+			$term_taxonomy->save();
366
+		}
367
+		return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
368
+	}
369
+
370
+
371
+	/**
372
+	 * Removed the category specified by name as having a relation to this event.
373
+	 * Does not remove the term or term_taxonomy.
374
+	 *
375
+	 * @param EE_CPT_Base $cpt_model_object_event
376
+	 * @param string      $category_name name of the event category (term)
377
+	 * @return bool
378
+	 */
379
+	public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
380
+	{
381
+		// find the term_taxonomy by that name
382
+		$term_taxonomy = $this->get_first_related(
383
+			$cpt_model_object_event,
384
+			'Term_Taxonomy',
385
+			array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY))
386
+		);
387
+		/** @var $term_taxonomy EE_Term_Taxonomy */
388
+		if ($term_taxonomy) {
389
+			$term_taxonomy->set_count($term_taxonomy->count() - 1);
390
+			$term_taxonomy->save();
391
+		}
392
+		return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
393
+	}
394
+
395
+
396
+	/**
397
+	 * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
398
+	 * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
399
+	 *
400
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
401
+	 * @access public
402
+	 * @param int          $id   the ID for the cpt we want the feature image for
403
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
404
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
405
+	 * @param string|array $attr Optional. Query string or array of attributes.
406
+	 * @return string HTML image element
407
+	 */
408
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '')
409
+	{
410
+		return get_the_post_thumbnail($id, $size, $attr);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Just a handy way to get the list of post statuses currently registered with WP.
416
+	 *
417
+	 * @global array $wp_post_statuses set in wp core for storing all the post stati
418
+	 * @return array
419
+	 */
420
+	public function get_post_statuses()
421
+	{
422
+		global $wp_post_statuses;
423
+		$statuses = array();
424
+		foreach ($wp_post_statuses as $post_status => $args_object) {
425
+			$statuses[ $post_status ] = $args_object->label;
426
+		}
427
+		return $statuses;
428
+	}
429
+
430
+
431
+	/**
432
+	 * public method that can be used to retrieve the protected status array on the instantiated cpt model
433
+	 *
434
+	 * @return array array of statuses.
435
+	 */
436
+	public function get_status_array()
437
+	{
438
+		$statuses = $this->get_post_statuses();
439
+		// first the global filter
440
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
441
+		// now the class specific filter
442
+		$statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
443
+		return $statuses;
444
+	}
445
+
446
+
447
+	/**
448
+	 * this returns the post statuses that are NOT the default wordpress status
449
+	 *
450
+	 * @return array
451
+	 */
452
+	public function get_custom_post_statuses()
453
+	{
454
+		$new_stati = array();
455
+		foreach ($this->_custom_stati as $status => $props) {
456
+			$new_stati[ $status ] = $props['label'];
457
+		}
458
+		return $new_stati;
459
+	}
460
+
461
+
462
+	/**
463
+	 * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
464
+	 * are a row from the posts table. If we're missing any fields required for the model,
465
+	 * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
466
+	 * make sure you are attaching all the model's fields onto the post)
467
+	 *
468
+	 * @param WP_Post|array $post
469
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
470
+	 */
471
+	public function instantiate_class_from_post_object_orig($post)
472
+	{
473
+		$post = (array) $post;
474
+		$has_all_necessary_fields_for_table = true;
475
+		// check if the post has fields on the meta table already
476
+		foreach ($this->_get_other_tables() as $table_obj) {
477
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
478
+			foreach ($fields_for_that_table as $field_obj) {
479
+				if (! isset($post[ $field_obj->get_table_column() ])
480
+					&& ! isset($post[ $field_obj->get_qualified_column() ])
481
+				) {
482
+					$has_all_necessary_fields_for_table = false;
483
+				}
484
+			}
485
+		}
486
+		// if we don't have all the fields we need, then just fetch the proper model from the DB
487
+		if (! $has_all_necessary_fields_for_table) {
488
+			return $this->get_one_by_ID($post['ID']);
489
+		} else {
490
+			return $this->instantiate_class_from_array_or_object($post);
491
+		}
492
+	}
493
+
494
+
495
+	/**
496
+	 * @param null $post
497
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
498
+	 */
499
+	public function instantiate_class_from_post_object($post = null)
500
+	{
501
+		if (empty($post)) {
502
+			global $post;
503
+		}
504
+		$post = (array) $post;
505
+		$tables_needing_to_be_queried = array();
506
+		// check if the post has fields on the meta table already
507
+		foreach ($this->get_tables() as $table_obj) {
508
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
509
+			foreach ($fields_for_that_table as $field_obj) {
510
+				if (! isset($post[ $field_obj->get_table_column() ])
511
+					&& ! isset($post[ $field_obj->get_qualified_column() ])
512
+				) {
513
+					$tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
514
+				}
515
+			}
516
+		}
517
+		// if we don't have all the fields we need, then just fetch the proper model from the DB
518
+		if ($tables_needing_to_be_queried) {
519
+			if (count($tables_needing_to_be_queried) == 1
520
+				&& reset($tables_needing_to_be_queried)
521
+				   instanceof
522
+				   EE_Secondary_Table
523
+			) {
524
+				// so we're only missing data from a secondary table. Well that's not too hard to query for
525
+				$table_to_query = reset($tables_needing_to_be_queried);
526
+				$missing_data = $this->_do_wpdb_query(
527
+					'get_row',
528
+					array(
529
+						'SELECT * FROM '
530
+						. $table_to_query->get_table_name()
531
+						. ' WHERE '
532
+						. $table_to_query->get_fk_on_table()
533
+						. ' = '
534
+						. $post['ID'],
535
+						ARRAY_A,
536
+					)
537
+				);
538
+				if (! empty($missing_data)) {
539
+					$post = array_merge($post, $missing_data);
540
+				}
541
+			} else {
542
+				return $this->get_one_by_ID($post['ID']);
543
+			}
544
+		}
545
+		return $this->instantiate_class_from_array_or_object($post);
546
+	}
547
+
548
+
549
+	/**
550
+	 * Gets the post type associated with this
551
+	 *
552
+	 * @throws EE_Error
553
+	 * @return string
554
+	 */
555
+	public function post_type()
556
+	{
557
+		$post_type_field = null;
558
+		foreach ($this->field_settings(true) as $field_obj) {
559
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
560
+				$post_type_field = $field_obj;
561
+				break;
562
+			}
563
+		}
564
+		if ($post_type_field == null) {
565
+			throw new EE_Error(
566
+				sprintf(
567
+					__(
568
+						"CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
569
+						"event_espresso"
570
+					),
571
+					get_class($this)
572
+				)
573
+			);
574
+		}
575
+		return $post_type_field->get_default_value();
576
+	}
577 577
 }
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 
3 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5
-use EventEspresso\core\services\loaders\Loader;
6 5
 use EventEspresso\core\services\loaders\LoaderFactory;
7 6
 
8 7
 /**
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public static function instance()
40 40
     {
41
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
41
+        if ( ! self::$_instance instanceof EE_Cron_Tasks) {
42 42
             self::$_instance = new self();
43 43
         }
44 44
         return self::$_instance;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
              */
72 72
             add_action(
73 73
                 'AHEE__EE_System__load_core_configuration__complete',
74
-                function () {
74
+                function() {
75 75
                     EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76 76
                     EE_Registry::instance()->NET_CFG->update_config(true, false);
77 77
                     add_option('ee_disabled_wp_cron_check', 1, '', false);
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
             'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124 124
         );
125 125
         $crons = (array) get_option('cron');
126
-        if (! is_array($crons)) {
126
+        if ( ! is_array($crons)) {
127 127
             return;
128 128
         }
129 129
         foreach ($crons as $timestamp => $cron) {
130 130
             /** @var array[] $cron */
131 131
             foreach ($ee_crons as $ee_cron) {
132
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
132
+                if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) {
133 133
                     do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
-                        if (! empty($ee_cron_details['args'])) {
134
+                    foreach ($cron[$ee_cron] as $ee_cron_details) {
135
+                        if ( ! empty($ee_cron_details['args'])) {
136 136
                             do_action(
137 137
                                 'AHEE_log',
138 138
                                 __CLASS__,
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161 161
     {
162
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
162
+        if ( ! method_exists('EE_Cron_Tasks', $cron_task)) {
163 163
             throw new DomainException(
164 164
                 sprintf(
165 165
                     __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             );
169 169
         }
170 170
         // reschedule the cron if we can't hit the db right now
171
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
171
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
172 172
             foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173 173
                 // ensure $additional_vars is an array
174 174
                 $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     {
250 250
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251 251
         if (absint($TXN_ID)) {
252
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
252
+            self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
253 253
             add_action(
254 254
                 'shutdown',
255 255
                 array('EE_Cron_Tasks', 'update_transaction_with_payment'),
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
         EE_Registry::instance()->load_model('Transaction');
296 296
         foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
297 297
             // reschedule the cron if we can't hit the db right now
298
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
298
+            if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
299 299
                 // reset cron job for updating the TXN
300 300
                 EE_Cron_Tasks::schedule_update_transaction_with_payment(
301 301
                     time() + EE_Cron_Tasks::reschedule_timeout,
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                 // now try to update the TXN with any payments
312 312
                 $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
313 313
             }
314
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
314
+            unset(self::$_update_transactions_with_payment[$TXN_ID]);
315 315
         }
316 316
     }
317 317
 
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
     public static function expired_transaction_check($TXN_ID = 0)
373 373
     {
374 374
         if (absint($TXN_ID)) {
375
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
375
+            self::$_expired_transactions[$TXN_ID] = $TXN_ID;
376 376
             add_action(
377 377
                 'shutdown',
378 378
                 array('EE_Cron_Tasks', 'process_expired_transactions'),
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
                         break;
487 487
                 }
488 488
             }
489
-            unset(self::$_expired_transactions[ $TXN_ID ]);
489
+            unset(self::$_expired_transactions[$TXN_ID]);
490 490
         }
491 491
     }
492 492
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
             $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
534 534
             $time_diff_for_comparison = apply_filters(
535 535
                 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
536
-                '-' . $reg_config->gateway_log_lifespan
536
+                '-'.$reg_config->gateway_log_lifespan
537 537
             );
538 538
             EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
539 539
         }
Please login to merge, or discard this patch.
Indentation   +592 added lines, -592 removed lines patch added patch discarded remove patch
@@ -15,596 +15,596 @@
 block discarded – undo
15 15
 class EE_Cron_Tasks extends EE_Base
16 16
 {
17 17
 
18
-    /**
19
-     * WordPress doesn't allow duplicate crons within 10 minutes of the original,
20
-     * so we'll set our retry time for just over 10 minutes to avoid that
21
-     */
22
-    const reschedule_timeout = 605;
23
-
24
-
25
-    /**
26
-     * @var EE_Cron_Tasks
27
-     */
28
-    private static $_instance;
29
-
30
-
31
-    /**
32
-     * @return EE_Cron_Tasks
33
-     * @throws ReflectionException
34
-     * @throws EE_Error
35
-     * @throws InvalidArgumentException
36
-     * @throws InvalidInterfaceException
37
-     * @throws InvalidDataTypeException
38
-     */
39
-    public static function instance()
40
-    {
41
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
42
-            self::$_instance = new self();
43
-        }
44
-        return self::$_instance;
45
-    }
46
-
47
-
48
-    /**
49
-     * @access private
50
-     * @throws InvalidDataTypeException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidArgumentException
53
-     * @throws EE_Error
54
-     * @throws ReflectionException
55
-     */
56
-    private function __construct()
57
-    {
58
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
59
-        // verify that WP Cron is enabled
60
-        if (defined('DISABLE_WP_CRON')
61
-            && DISABLE_WP_CRON
62
-            && is_admin()
63
-            && ! get_option('ee_disabled_wp_cron_check')
64
-        ) {
65
-            /**
66
-             * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
67
-             * config is loaded.
68
-             * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
69
-             * wanting to not have this functionality can just register its own action at a priority after this one to
70
-             * reverse any changes.
71
-             */
72
-            add_action(
73
-                'AHEE__EE_System__load_core_configuration__complete',
74
-                function () {
75
-                    EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76
-                    EE_Registry::instance()->NET_CFG->update_config(true, false);
77
-                    add_option('ee_disabled_wp_cron_check', 1, '', false);
78
-                }
79
-            );
80
-        }
81
-        // UPDATE TRANSACTION WITH PAYMENT
82
-        add_action(
83
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
84
-            array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
85
-            10,
86
-            2
87
-        );
88
-        // ABANDONED / EXPIRED TRANSACTION CHECK
89
-        add_action(
90
-            'AHEE__EE_Cron_Tasks__expired_transaction_check',
91
-            array('EE_Cron_Tasks', 'expired_transaction_check'),
92
-            10,
93
-            1
94
-        );
95
-        // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
96
-        add_action(
97
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
98
-            array('EE_Cron_Tasks', 'clean_out_junk_transactions')
99
-        );
100
-        // logging
101
-        add_action(
102
-            'AHEE__EE_System__load_core_configuration__complete',
103
-            array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
104
-        );
105
-        EE_Registry::instance()->load_lib('Messages_Scheduler');
106
-        // clean out old gateway logs
107
-        add_action(
108
-            'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
109
-            array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
110
-        );
111
-    }
112
-
113
-
114
-    /**
115
-     * @access protected
116
-     * @return void
117
-     */
118
-    public static function log_scheduled_ee_crons()
119
-    {
120
-        $ee_crons = array(
121
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
122
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
123
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124
-        );
125
-        $crons = (array) get_option('cron');
126
-        if (! is_array($crons)) {
127
-            return;
128
-        }
129
-        foreach ($crons as $timestamp => $cron) {
130
-            /** @var array[] $cron */
131
-            foreach ($ee_crons as $ee_cron) {
132
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
-                    do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
-                        if (! empty($ee_cron_details['args'])) {
136
-                            do_action(
137
-                                'AHEE_log',
138
-                                __CLASS__,
139
-                                __FUNCTION__,
140
-                                print_r($ee_cron_details['args'], true),
141
-                                "{$ee_cron} args"
142
-                            );
143
-                        }
144
-                    }
145
-                }
146
-            }
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * reschedule_cron_for_transactions_if_maintenance_mode
153
-     * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
154
-     *
155
-     * @param string $cron_task
156
-     * @param array  $TXN_IDs
157
-     * @return bool
158
-     * @throws DomainException
159
-     */
160
-    public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161
-    {
162
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
-            throw new DomainException(
164
-                sprintf(
165
-                    __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
166
-                    $cron_task
167
-                )
168
-            );
169
-        }
170
-        // reschedule the cron if we can't hit the db right now
171
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
-            foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173
-                // ensure $additional_vars is an array
174
-                $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
175
-                // reset cron job for the TXN
176
-                call_user_func_array(
177
-                    array('EE_Cron_Tasks', $cron_task),
178
-                    array_merge(
179
-                        array(
180
-                            time() + (10 * MINUTE_IN_SECONDS),
181
-                            $TXN_ID,
182
-                        ),
183
-                        $additional_vars
184
-                    )
185
-                );
186
-            }
187
-            return true;
188
-        }
189
-        return false;
190
-    }
191
-
192
-
193
-
194
-
195
-    /****************  UPDATE TRANSACTION WITH PAYMENT ****************/
196
-
197
-
198
-    /**
199
-     * array of TXN IDs and the payment
200
-     *
201
-     * @var array
202
-     */
203
-    protected static $_update_transactions_with_payment = array();
204
-
205
-
206
-    /**
207
-     * schedule_update_transaction_with_payment
208
-     * sets a wp_schedule_single_event() for updating any TXNs that may
209
-     * require updating due to recently received payments
210
-     *
211
-     * @param int $timestamp
212
-     * @param int $TXN_ID
213
-     * @param int $PAY_ID
214
-     */
215
-    public static function schedule_update_transaction_with_payment(
216
-        $timestamp,
217
-        $TXN_ID,
218
-        $PAY_ID
219
-    ) {
220
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
221
-        // validate $TXN_ID and $timestamp
222
-        $TXN_ID = absint($TXN_ID);
223
-        $timestamp = absint($timestamp);
224
-        if ($TXN_ID && $timestamp) {
225
-            wp_schedule_single_event(
226
-                $timestamp,
227
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
228
-                array($TXN_ID, $PAY_ID)
229
-            );
230
-        }
231
-    }
232
-
233
-
234
-    /**
235
-     * setup_update_for_transaction_with_payment
236
-     * this is the callback for the action hook:
237
-     * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
238
-     * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
239
-     * The passed TXN_ID and associated payment gets added to an array, and then
240
-     * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
241
-     * 'shutdown' which will actually handle the processing of any
242
-     * transactions requiring updating, because doing so now would be too early
243
-     * and the required resources may not be available
244
-     *
245
-     * @param int $TXN_ID
246
-     * @param int $PAY_ID
247
-     */
248
-    public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
249
-    {
250
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251
-        if (absint($TXN_ID)) {
252
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
-            add_action(
254
-                'shutdown',
255
-                array('EE_Cron_Tasks', 'update_transaction_with_payment'),
256
-                5
257
-            );
258
-        }
259
-    }
260
-
261
-
262
-    /**
263
-     * update_transaction_with_payment
264
-     * loops through the self::$_abandoned_transactions array
265
-     * and attempts to finalize any TXNs that have not been completed
266
-     * but have had their sessions expired, most likely due to a user not
267
-     * returning from an off-site payment gateway
268
-     *
269
-     * @throws EE_Error
270
-     * @throws DomainException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws RuntimeException
276
-     */
277
-    public static function update_transaction_with_payment()
278
-    {
279
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
280
-        if (// are there any TXNs that need cleaning up ?
281
-            empty(self::$_update_transactions_with_payment)
282
-            // reschedule the cron if we can't hit the db right now
283
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
284
-                'schedule_update_transaction_with_payment',
285
-                self::$_update_transactions_with_payment
286
-            )
287
-        ) {
288
-            return;
289
-        }
290
-        /** @type EE_Payment_Processor $payment_processor */
291
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
292
-        // set revisit flag for payment processor
293
-        $payment_processor->set_revisit();
294
-        // load EEM_Transaction
295
-        EE_Registry::instance()->load_model('Transaction');
296
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
297
-            // reschedule the cron if we can't hit the db right now
298
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
299
-                // reset cron job for updating the TXN
300
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
301
-                    time() + EE_Cron_Tasks::reschedule_timeout,
302
-                    $TXN_ID,
303
-                    $PAY_ID
304
-                );
305
-                continue;
306
-            }
307
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
308
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
309
-            // verify transaction
310
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
311
-                // now try to update the TXN with any payments
312
-                $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
313
-            }
314
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
315
-        }
316
-    }
317
-
318
-
319
-
320
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
321
-
322
-
323
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
324
-
325
-
326
-    /**
327
-     * array of TXN IDs
328
-     *
329
-     * @var array
330
-     */
331
-    protected static $_expired_transactions = array();
332
-
333
-
334
-    /**
335
-     * schedule_expired_transaction_check
336
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
337
-     *
338
-     * @param int $timestamp
339
-     * @param int $TXN_ID
340
-     */
341
-    public static function schedule_expired_transaction_check(
342
-        $timestamp,
343
-        $TXN_ID
344
-    ) {
345
-        // validate $TXN_ID and $timestamp
346
-        $TXN_ID = absint($TXN_ID);
347
-        $timestamp = absint($timestamp);
348
-        if ($TXN_ID && $timestamp) {
349
-            wp_schedule_single_event(
350
-                $timestamp,
351
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
352
-                array($TXN_ID)
353
-            );
354
-        }
355
-    }
356
-
357
-
358
-    /**
359
-     * expired_transaction_check
360
-     * this is the callback for the action hook:
361
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
362
-     * which is utilized by wp_schedule_single_event()
363
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
364
-     * The passed TXN_ID gets added to an array, and then the
365
-     * process_expired_transactions() function is hooked into
366
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
367
-     * processing of any failed transactions, because doing so now would be
368
-     * too early and the required resources may not be available
369
-     *
370
-     * @param int $TXN_ID
371
-     */
372
-    public static function expired_transaction_check($TXN_ID = 0)
373
-    {
374
-        if (absint($TXN_ID)) {
375
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
376
-            add_action(
377
-                'shutdown',
378
-                array('EE_Cron_Tasks', 'process_expired_transactions'),
379
-                5
380
-            );
381
-        }
382
-    }
383
-
384
-
385
-    /**
386
-     * process_expired_transactions
387
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
388
-     *
389
-     * @throws EE_Error
390
-     * @throws InvalidDataTypeException
391
-     * @throws InvalidInterfaceException
392
-     * @throws InvalidArgumentException
393
-     * @throws ReflectionException
394
-     * @throws DomainException
395
-     * @throws RuntimeException
396
-     */
397
-    public static function process_expired_transactions()
398
-    {
399
-        if (// are there any TXNs that need cleaning up ?
400
-            empty(self::$_expired_transactions)
401
-            // reschedule the cron if we can't hit the db right now
402
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
403
-                'schedule_expired_transaction_check',
404
-                self::$_expired_transactions
405
-            )
406
-        ) {
407
-            return;
408
-        }
409
-        /** @type EE_Transaction_Processor $transaction_processor */
410
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
411
-        // set revisit flag for txn processor
412
-        $transaction_processor->set_revisit();
413
-        // load EEM_Transaction
414
-        EE_Registry::instance()->load_model('Transaction');
415
-        foreach (self::$_expired_transactions as $TXN_ID) {
416
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
417
-            // verify transaction and whether it is failed or not
418
-            if ($transaction instanceof EE_Transaction) {
419
-                switch ($transaction->status_ID()) {
420
-                    // Completed TXNs
421
-                    case EEM_Transaction::complete_status_code:
422
-                        /** @type EE_Transaction_Processor $transaction_processor */
423
-                        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
424
-                        $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
425
-                            $transaction,
426
-                            $transaction->last_payment()
427
-                        );
428
-                        do_action(
429
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
430
-                            $transaction
431
-                        );
432
-                        break;
433
-                    // Overpaid TXNs
434
-                    case EEM_Transaction::overpaid_status_code:
435
-                        do_action(
436
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
437
-                            $transaction
438
-                        );
439
-                        break;
440
-                    // Incomplete TXNs
441
-                    case EEM_Transaction::incomplete_status_code:
442
-                        do_action(
443
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
444
-                            $transaction
445
-                        );
446
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
447
-                        break;
448
-                    // Abandoned TXNs
449
-                    case EEM_Transaction::abandoned_status_code:
450
-                        // run hook before updating transaction, primarily so
451
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
452
-                        do_action(
453
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
454
-                            $transaction
455
-                        );
456
-                        // don't finalize the TXN if it has already been completed
457
-                        if ($transaction->all_reg_steps_completed() !== true) {
458
-                            /** @type EE_Payment_Processor $payment_processor */
459
-                            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
460
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
461
-                            $payment_processor->update_txn_based_on_payment(
462
-                                $transaction,
463
-                                $transaction->last_payment(),
464
-                                true,
465
-                                true
466
-                            );
467
-                        }
468
-                        break;
469
-                    // Failed TXNs
470
-                    case EEM_Transaction::failed_status_code:
471
-                        do_action(
472
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
473
-                            $transaction
474
-                        );
475
-                        // todo :
476
-                        // perform garbage collection here and remove clean_out_junk_transactions()
477
-                        // $registrations = $transaction->registrations();
478
-                        // if (! empty($registrations)) {
479
-                        //     foreach ($registrations as $registration) {
480
-                        //         if ($registration instanceof EE_Registration) {
481
-                        //             $delete_registration = true;
482
-                        //             if ($registration->attendee() instanceof EE_Attendee) {
483
-                        //                 $delete_registration = false;
484
-                        //             }
485
-                        //             if ($delete_registration) {
486
-                        //                 $registration->delete_permanently();
487
-                        //                 $registration->delete_related_permanently();
488
-                        //             }
489
-                        //         }
490
-                        //     }
491
-                        // }
492
-                        break;
493
-                }
494
-            }
495
-            unset(self::$_expired_transactions[ $TXN_ID ]);
496
-        }
497
-    }
498
-
499
-
500
-
501
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
502
-
503
-
504
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
505
-
506
-
507
-    /**
508
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
509
-     * which is setup during activation to run on an hourly cron
510
-     *
511
-     * @throws EE_Error
512
-     * @throws InvalidArgumentException
513
-     * @throws InvalidDataTypeException
514
-     * @throws InvalidInterfaceException
515
-     * @throws DomainException
516
-     */
517
-    public static function clean_out_junk_transactions()
518
-    {
519
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
520
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
521
-            EEM_Transaction::instance('')->delete_junk_transactions();
522
-            EEM_Registration::instance('')->delete_registrations_with_no_transaction();
523
-            EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
524
-        }
525
-    }
526
-
527
-
528
-    /**
529
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
530
-     *
531
-     * @throws EE_Error
532
-     * @throws InvalidDataTypeException
533
-     * @throws InvalidInterfaceException
534
-     * @throws InvalidArgumentException
535
-     */
536
-    public static function clean_out_old_gateway_logs()
537
-    {
538
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
539
-            $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
540
-            $time_diff_for_comparison = apply_filters(
541
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
542
-                '-' . $reg_config->gateway_log_lifespan
543
-            );
544
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
545
-        }
546
-    }
547
-
548
-
549
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
550
-
551
-
552
-    /**
553
-     * @var array
554
-     */
555
-    protected static $_abandoned_transactions = array();
556
-
557
-
558
-    /**
559
-     * @deprecated
560
-     * @param int $timestamp
561
-     * @param int $TXN_ID
562
-     */
563
-    public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
564
-    {
565
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
566
-    }
567
-
568
-
569
-    /**
570
-     * @deprecated
571
-     * @param int $TXN_ID
572
-     */
573
-    public static function check_for_abandoned_transactions($TXN_ID = 0)
574
-    {
575
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
576
-    }
577
-
578
-
579
-    /**
580
-     * @deprecated
581
-     * @throws EE_Error
582
-     * @throws DomainException
583
-     * @throws InvalidDataTypeException
584
-     * @throws InvalidInterfaceException
585
-     * @throws InvalidArgumentException
586
-     * @throws ReflectionException
587
-     * @throws RuntimeException
588
-     */
589
-    public static function finalize_abandoned_transactions()
590
-    {
591
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
592
-        if (// are there any TXNs that need cleaning up ?
593
-            empty(self::$_abandoned_transactions)
594
-            // reschedule the cron if we can't hit the db right now
595
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
596
-                'schedule_expired_transaction_check',
597
-                self::$_abandoned_transactions
598
-            )
599
-        ) {
600
-            return;
601
-        }
602
-        // combine our arrays of transaction IDs
603
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
604
-        // and deal with abandoned transactions here now...
605
-        EE_Cron_Tasks::process_expired_transactions();
606
-    }
607
-
608
-
609
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
18
+	/**
19
+	 * WordPress doesn't allow duplicate crons within 10 minutes of the original,
20
+	 * so we'll set our retry time for just over 10 minutes to avoid that
21
+	 */
22
+	const reschedule_timeout = 605;
23
+
24
+
25
+	/**
26
+	 * @var EE_Cron_Tasks
27
+	 */
28
+	private static $_instance;
29
+
30
+
31
+	/**
32
+	 * @return EE_Cron_Tasks
33
+	 * @throws ReflectionException
34
+	 * @throws EE_Error
35
+	 * @throws InvalidArgumentException
36
+	 * @throws InvalidInterfaceException
37
+	 * @throws InvalidDataTypeException
38
+	 */
39
+	public static function instance()
40
+	{
41
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
42
+			self::$_instance = new self();
43
+		}
44
+		return self::$_instance;
45
+	}
46
+
47
+
48
+	/**
49
+	 * @access private
50
+	 * @throws InvalidDataTypeException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidArgumentException
53
+	 * @throws EE_Error
54
+	 * @throws ReflectionException
55
+	 */
56
+	private function __construct()
57
+	{
58
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
59
+		// verify that WP Cron is enabled
60
+		if (defined('DISABLE_WP_CRON')
61
+			&& DISABLE_WP_CRON
62
+			&& is_admin()
63
+			&& ! get_option('ee_disabled_wp_cron_check')
64
+		) {
65
+			/**
66
+			 * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
67
+			 * config is loaded.
68
+			 * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
69
+			 * wanting to not have this functionality can just register its own action at a priority after this one to
70
+			 * reverse any changes.
71
+			 */
72
+			add_action(
73
+				'AHEE__EE_System__load_core_configuration__complete',
74
+				function () {
75
+					EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76
+					EE_Registry::instance()->NET_CFG->update_config(true, false);
77
+					add_option('ee_disabled_wp_cron_check', 1, '', false);
78
+				}
79
+			);
80
+		}
81
+		// UPDATE TRANSACTION WITH PAYMENT
82
+		add_action(
83
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
84
+			array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
85
+			10,
86
+			2
87
+		);
88
+		// ABANDONED / EXPIRED TRANSACTION CHECK
89
+		add_action(
90
+			'AHEE__EE_Cron_Tasks__expired_transaction_check',
91
+			array('EE_Cron_Tasks', 'expired_transaction_check'),
92
+			10,
93
+			1
94
+		);
95
+		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
96
+		add_action(
97
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
98
+			array('EE_Cron_Tasks', 'clean_out_junk_transactions')
99
+		);
100
+		// logging
101
+		add_action(
102
+			'AHEE__EE_System__load_core_configuration__complete',
103
+			array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
104
+		);
105
+		EE_Registry::instance()->load_lib('Messages_Scheduler');
106
+		// clean out old gateway logs
107
+		add_action(
108
+			'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
109
+			array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
110
+		);
111
+	}
112
+
113
+
114
+	/**
115
+	 * @access protected
116
+	 * @return void
117
+	 */
118
+	public static function log_scheduled_ee_crons()
119
+	{
120
+		$ee_crons = array(
121
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
122
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
123
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124
+		);
125
+		$crons = (array) get_option('cron');
126
+		if (! is_array($crons)) {
127
+			return;
128
+		}
129
+		foreach ($crons as $timestamp => $cron) {
130
+			/** @var array[] $cron */
131
+			foreach ($ee_crons as $ee_cron) {
132
+				if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
+					do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
+					foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
+						if (! empty($ee_cron_details['args'])) {
136
+							do_action(
137
+								'AHEE_log',
138
+								__CLASS__,
139
+								__FUNCTION__,
140
+								print_r($ee_cron_details['args'], true),
141
+								"{$ee_cron} args"
142
+							);
143
+						}
144
+					}
145
+				}
146
+			}
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * reschedule_cron_for_transactions_if_maintenance_mode
153
+	 * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
154
+	 *
155
+	 * @param string $cron_task
156
+	 * @param array  $TXN_IDs
157
+	 * @return bool
158
+	 * @throws DomainException
159
+	 */
160
+	public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161
+	{
162
+		if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
+			throw new DomainException(
164
+				sprintf(
165
+					__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
166
+					$cron_task
167
+				)
168
+			);
169
+		}
170
+		// reschedule the cron if we can't hit the db right now
171
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
+			foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173
+				// ensure $additional_vars is an array
174
+				$additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
175
+				// reset cron job for the TXN
176
+				call_user_func_array(
177
+					array('EE_Cron_Tasks', $cron_task),
178
+					array_merge(
179
+						array(
180
+							time() + (10 * MINUTE_IN_SECONDS),
181
+							$TXN_ID,
182
+						),
183
+						$additional_vars
184
+					)
185
+				);
186
+			}
187
+			return true;
188
+		}
189
+		return false;
190
+	}
191
+
192
+
193
+
194
+
195
+	/****************  UPDATE TRANSACTION WITH PAYMENT ****************/
196
+
197
+
198
+	/**
199
+	 * array of TXN IDs and the payment
200
+	 *
201
+	 * @var array
202
+	 */
203
+	protected static $_update_transactions_with_payment = array();
204
+
205
+
206
+	/**
207
+	 * schedule_update_transaction_with_payment
208
+	 * sets a wp_schedule_single_event() for updating any TXNs that may
209
+	 * require updating due to recently received payments
210
+	 *
211
+	 * @param int $timestamp
212
+	 * @param int $TXN_ID
213
+	 * @param int $PAY_ID
214
+	 */
215
+	public static function schedule_update_transaction_with_payment(
216
+		$timestamp,
217
+		$TXN_ID,
218
+		$PAY_ID
219
+	) {
220
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
221
+		// validate $TXN_ID and $timestamp
222
+		$TXN_ID = absint($TXN_ID);
223
+		$timestamp = absint($timestamp);
224
+		if ($TXN_ID && $timestamp) {
225
+			wp_schedule_single_event(
226
+				$timestamp,
227
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
228
+				array($TXN_ID, $PAY_ID)
229
+			);
230
+		}
231
+	}
232
+
233
+
234
+	/**
235
+	 * setup_update_for_transaction_with_payment
236
+	 * this is the callback for the action hook:
237
+	 * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
238
+	 * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
239
+	 * The passed TXN_ID and associated payment gets added to an array, and then
240
+	 * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
241
+	 * 'shutdown' which will actually handle the processing of any
242
+	 * transactions requiring updating, because doing so now would be too early
243
+	 * and the required resources may not be available
244
+	 *
245
+	 * @param int $TXN_ID
246
+	 * @param int $PAY_ID
247
+	 */
248
+	public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
249
+	{
250
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251
+		if (absint($TXN_ID)) {
252
+			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
+			add_action(
254
+				'shutdown',
255
+				array('EE_Cron_Tasks', 'update_transaction_with_payment'),
256
+				5
257
+			);
258
+		}
259
+	}
260
+
261
+
262
+	/**
263
+	 * update_transaction_with_payment
264
+	 * loops through the self::$_abandoned_transactions array
265
+	 * and attempts to finalize any TXNs that have not been completed
266
+	 * but have had their sessions expired, most likely due to a user not
267
+	 * returning from an off-site payment gateway
268
+	 *
269
+	 * @throws EE_Error
270
+	 * @throws DomainException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws RuntimeException
276
+	 */
277
+	public static function update_transaction_with_payment()
278
+	{
279
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
280
+		if (// are there any TXNs that need cleaning up ?
281
+			empty(self::$_update_transactions_with_payment)
282
+			// reschedule the cron if we can't hit the db right now
283
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
284
+				'schedule_update_transaction_with_payment',
285
+				self::$_update_transactions_with_payment
286
+			)
287
+		) {
288
+			return;
289
+		}
290
+		/** @type EE_Payment_Processor $payment_processor */
291
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
292
+		// set revisit flag for payment processor
293
+		$payment_processor->set_revisit();
294
+		// load EEM_Transaction
295
+		EE_Registry::instance()->load_model('Transaction');
296
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
297
+			// reschedule the cron if we can't hit the db right now
298
+			if (! EE_Maintenance_Mode::instance()->models_can_query()) {
299
+				// reset cron job for updating the TXN
300
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
301
+					time() + EE_Cron_Tasks::reschedule_timeout,
302
+					$TXN_ID,
303
+					$PAY_ID
304
+				);
305
+				continue;
306
+			}
307
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
308
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
309
+			// verify transaction
310
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
311
+				// now try to update the TXN with any payments
312
+				$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
313
+			}
314
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
315
+		}
316
+	}
317
+
318
+
319
+
320
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
321
+
322
+
323
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
324
+
325
+
326
+	/**
327
+	 * array of TXN IDs
328
+	 *
329
+	 * @var array
330
+	 */
331
+	protected static $_expired_transactions = array();
332
+
333
+
334
+	/**
335
+	 * schedule_expired_transaction_check
336
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
337
+	 *
338
+	 * @param int $timestamp
339
+	 * @param int $TXN_ID
340
+	 */
341
+	public static function schedule_expired_transaction_check(
342
+		$timestamp,
343
+		$TXN_ID
344
+	) {
345
+		// validate $TXN_ID and $timestamp
346
+		$TXN_ID = absint($TXN_ID);
347
+		$timestamp = absint($timestamp);
348
+		if ($TXN_ID && $timestamp) {
349
+			wp_schedule_single_event(
350
+				$timestamp,
351
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
352
+				array($TXN_ID)
353
+			);
354
+		}
355
+	}
356
+
357
+
358
+	/**
359
+	 * expired_transaction_check
360
+	 * this is the callback for the action hook:
361
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
362
+	 * which is utilized by wp_schedule_single_event()
363
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
364
+	 * The passed TXN_ID gets added to an array, and then the
365
+	 * process_expired_transactions() function is hooked into
366
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
367
+	 * processing of any failed transactions, because doing so now would be
368
+	 * too early and the required resources may not be available
369
+	 *
370
+	 * @param int $TXN_ID
371
+	 */
372
+	public static function expired_transaction_check($TXN_ID = 0)
373
+	{
374
+		if (absint($TXN_ID)) {
375
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
376
+			add_action(
377
+				'shutdown',
378
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
379
+				5
380
+			);
381
+		}
382
+	}
383
+
384
+
385
+	/**
386
+	 * process_expired_transactions
387
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
388
+	 *
389
+	 * @throws EE_Error
390
+	 * @throws InvalidDataTypeException
391
+	 * @throws InvalidInterfaceException
392
+	 * @throws InvalidArgumentException
393
+	 * @throws ReflectionException
394
+	 * @throws DomainException
395
+	 * @throws RuntimeException
396
+	 */
397
+	public static function process_expired_transactions()
398
+	{
399
+		if (// are there any TXNs that need cleaning up ?
400
+			empty(self::$_expired_transactions)
401
+			// reschedule the cron if we can't hit the db right now
402
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
403
+				'schedule_expired_transaction_check',
404
+				self::$_expired_transactions
405
+			)
406
+		) {
407
+			return;
408
+		}
409
+		/** @type EE_Transaction_Processor $transaction_processor */
410
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
411
+		// set revisit flag for txn processor
412
+		$transaction_processor->set_revisit();
413
+		// load EEM_Transaction
414
+		EE_Registry::instance()->load_model('Transaction');
415
+		foreach (self::$_expired_transactions as $TXN_ID) {
416
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
417
+			// verify transaction and whether it is failed or not
418
+			if ($transaction instanceof EE_Transaction) {
419
+				switch ($transaction->status_ID()) {
420
+					// Completed TXNs
421
+					case EEM_Transaction::complete_status_code:
422
+						/** @type EE_Transaction_Processor $transaction_processor */
423
+						$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
424
+						$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
425
+							$transaction,
426
+							$transaction->last_payment()
427
+						);
428
+						do_action(
429
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
430
+							$transaction
431
+						);
432
+						break;
433
+					// Overpaid TXNs
434
+					case EEM_Transaction::overpaid_status_code:
435
+						do_action(
436
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
437
+							$transaction
438
+						);
439
+						break;
440
+					// Incomplete TXNs
441
+					case EEM_Transaction::incomplete_status_code:
442
+						do_action(
443
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
444
+							$transaction
445
+						);
446
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
447
+						break;
448
+					// Abandoned TXNs
449
+					case EEM_Transaction::abandoned_status_code:
450
+						// run hook before updating transaction, primarily so
451
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
452
+						do_action(
453
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
454
+							$transaction
455
+						);
456
+						// don't finalize the TXN if it has already been completed
457
+						if ($transaction->all_reg_steps_completed() !== true) {
458
+							/** @type EE_Payment_Processor $payment_processor */
459
+							$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
460
+							// let's simulate an IPN here which will trigger any notifications that need to go out
461
+							$payment_processor->update_txn_based_on_payment(
462
+								$transaction,
463
+								$transaction->last_payment(),
464
+								true,
465
+								true
466
+							);
467
+						}
468
+						break;
469
+					// Failed TXNs
470
+					case EEM_Transaction::failed_status_code:
471
+						do_action(
472
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
473
+							$transaction
474
+						);
475
+						// todo :
476
+						// perform garbage collection here and remove clean_out_junk_transactions()
477
+						// $registrations = $transaction->registrations();
478
+						// if (! empty($registrations)) {
479
+						//     foreach ($registrations as $registration) {
480
+						//         if ($registration instanceof EE_Registration) {
481
+						//             $delete_registration = true;
482
+						//             if ($registration->attendee() instanceof EE_Attendee) {
483
+						//                 $delete_registration = false;
484
+						//             }
485
+						//             if ($delete_registration) {
486
+						//                 $registration->delete_permanently();
487
+						//                 $registration->delete_related_permanently();
488
+						//             }
489
+						//         }
490
+						//     }
491
+						// }
492
+						break;
493
+				}
494
+			}
495
+			unset(self::$_expired_transactions[ $TXN_ID ]);
496
+		}
497
+	}
498
+
499
+
500
+
501
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
502
+
503
+
504
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
505
+
506
+
507
+	/**
508
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
509
+	 * which is setup during activation to run on an hourly cron
510
+	 *
511
+	 * @throws EE_Error
512
+	 * @throws InvalidArgumentException
513
+	 * @throws InvalidDataTypeException
514
+	 * @throws InvalidInterfaceException
515
+	 * @throws DomainException
516
+	 */
517
+	public static function clean_out_junk_transactions()
518
+	{
519
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
520
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
521
+			EEM_Transaction::instance('')->delete_junk_transactions();
522
+			EEM_Registration::instance('')->delete_registrations_with_no_transaction();
523
+			EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
524
+		}
525
+	}
526
+
527
+
528
+	/**
529
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
530
+	 *
531
+	 * @throws EE_Error
532
+	 * @throws InvalidDataTypeException
533
+	 * @throws InvalidInterfaceException
534
+	 * @throws InvalidArgumentException
535
+	 */
536
+	public static function clean_out_old_gateway_logs()
537
+	{
538
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
539
+			$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
540
+			$time_diff_for_comparison = apply_filters(
541
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
542
+				'-' . $reg_config->gateway_log_lifespan
543
+			);
544
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
545
+		}
546
+	}
547
+
548
+
549
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
550
+
551
+
552
+	/**
553
+	 * @var array
554
+	 */
555
+	protected static $_abandoned_transactions = array();
556
+
557
+
558
+	/**
559
+	 * @deprecated
560
+	 * @param int $timestamp
561
+	 * @param int $TXN_ID
562
+	 */
563
+	public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
564
+	{
565
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
566
+	}
567
+
568
+
569
+	/**
570
+	 * @deprecated
571
+	 * @param int $TXN_ID
572
+	 */
573
+	public static function check_for_abandoned_transactions($TXN_ID = 0)
574
+	{
575
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
576
+	}
577
+
578
+
579
+	/**
580
+	 * @deprecated
581
+	 * @throws EE_Error
582
+	 * @throws DomainException
583
+	 * @throws InvalidDataTypeException
584
+	 * @throws InvalidInterfaceException
585
+	 * @throws InvalidArgumentException
586
+	 * @throws ReflectionException
587
+	 * @throws RuntimeException
588
+	 */
589
+	public static function finalize_abandoned_transactions()
590
+	{
591
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
592
+		if (// are there any TXNs that need cleaning up ?
593
+			empty(self::$_abandoned_transactions)
594
+			// reschedule the cron if we can't hit the db right now
595
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
596
+				'schedule_expired_transaction_check',
597
+				self::$_abandoned_transactions
598
+			)
599
+		) {
600
+			return;
601
+		}
602
+		// combine our arrays of transaction IDs
603
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
604
+		// and deal with abandoned transactions here now...
605
+		EE_Cron_Tasks::process_expired_transactions();
606
+	}
607
+
608
+
609
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
610 610
 }
Please login to merge, or discard this patch.
core/domain/services/custom_post_types/RegisterCustomTaxonomies.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -17,97 +17,97 @@
 block discarded – undo
17 17
 class RegisterCustomTaxonomies
18 18
 {
19 19
 
20
-    /**
21
-     * @var CustomTaxonomyDefinitions $custom_taxonomies
22
-     */
23
-    public $custom_taxonomies;
20
+	/**
21
+	 * @var CustomTaxonomyDefinitions $custom_taxonomies
22
+	 */
23
+	public $custom_taxonomies;
24 24
 
25 25
 
26
-    /**
27
-     * RegisterCustomTaxonomies constructor.
28
-     *
29
-     * @param CustomTaxonomyDefinitions $custom_taxonomies
30
-     */
31
-    public function __construct(CustomTaxonomyDefinitions $custom_taxonomies)
32
-    {
33
-        $this->custom_taxonomies = $custom_taxonomies;
34
-    }
26
+	/**
27
+	 * RegisterCustomTaxonomies constructor.
28
+	 *
29
+	 * @param CustomTaxonomyDefinitions $custom_taxonomies
30
+	 */
31
+	public function __construct(CustomTaxonomyDefinitions $custom_taxonomies)
32
+	{
33
+		$this->custom_taxonomies = $custom_taxonomies;
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * @return void
39
-     * @throws DomainException
40
-     */
41
-    public function registerCustomTaxonomies()
42
-    {
43
-        $custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions();
44
-        foreach ($custom_taxonomies as $taxonomy => $tax) {
45
-            $this->registerCustomTaxonomy(
46
-                $taxonomy,
47
-                $tax['singular_name'],
48
-                $tax['plural_name'],
49
-                $tax['args']
50
-            );
51
-        }
52
-    }
37
+	/**
38
+	 * @return void
39
+	 * @throws DomainException
40
+	 */
41
+	public function registerCustomTaxonomies()
42
+	{
43
+		$custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions();
44
+		foreach ($custom_taxonomies as $taxonomy => $tax) {
45
+			$this->registerCustomTaxonomy(
46
+				$taxonomy,
47
+				$tax['singular_name'],
48
+				$tax['plural_name'],
49
+				$tax['args']
50
+			);
51
+		}
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Registers a custom taxonomy. Should be called before registering custom post types,
57
-     * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
58
-     *
59
-     * @param string $taxonomy_name      , eg 'books'
60
-     * @param string $singular_name      internationalized singular name
61
-     * @param string $plural_name        internationalized plural name
62
-     * @param array  $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
63
-     * @throws DomainException
64
-     */
65
-    public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments)
66
-    {
67
-        $result = register_taxonomy(
68
-            $taxonomy_name,
69
-            null,
70
-            $this->prepareArguments(
71
-                $singular_name,
72
-                $plural_name,
73
-                $override_arguments
74
-            )
75
-        );
76
-        if ($result instanceof WP_Error) {
77
-            throw new DomainException($result->get_error_message());
78
-        }
79
-    }
55
+	/**
56
+	 * Registers a custom taxonomy. Should be called before registering custom post types,
57
+	 * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
58
+	 *
59
+	 * @param string $taxonomy_name      , eg 'books'
60
+	 * @param string $singular_name      internationalized singular name
61
+	 * @param string $plural_name        internationalized plural name
62
+	 * @param array  $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
63
+	 * @throws DomainException
64
+	 */
65
+	public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments)
66
+	{
67
+		$result = register_taxonomy(
68
+			$taxonomy_name,
69
+			null,
70
+			$this->prepareArguments(
71
+				$singular_name,
72
+				$plural_name,
73
+				$override_arguments
74
+			)
75
+		);
76
+		if ($result instanceof WP_Error) {
77
+			throw new DomainException($result->get_error_message());
78
+		}
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * @param string $singular_name
84
-     * @param string $plural_name
85
-     * @param array  $override_arguments
86
-     * @since 4.9.62.p
87
-     * @return array
88
-     */
89
-    protected function prepareArguments($singular_name, $plural_name, array $override_arguments)
90
-    {
91
-        $arguments = array(
92
-            'hierarchical'      => true,
93
-            'labels'            => array(
94
-                'name'          => $plural_name,
95
-                'singular_name' => $singular_name,
96
-            ),
97
-            'show_ui'           => true,
98
-            'show_ee_ui'        => true,
99
-            'show_admin_column' => true,
100
-            'query_var'         => true,
101
-            'show_in_nav_menus' => false,
102
-            'map_meta_cap'      => true,
103
-        );
104
-        if ($override_arguments) {
105
-            if (isset($override_args['labels'])) {
106
-                $labels = array_merge($arguments['labels'], $override_arguments['labels']);
107
-                $arguments['labels'] = $labels;
108
-            }
109
-            $arguments = array_merge($arguments, $override_arguments);
110
-        }
111
-        return $arguments;
112
-    }
82
+	/**
83
+	 * @param string $singular_name
84
+	 * @param string $plural_name
85
+	 * @param array  $override_arguments
86
+	 * @since 4.9.62.p
87
+	 * @return array
88
+	 */
89
+	protected function prepareArguments($singular_name, $plural_name, array $override_arguments)
90
+	{
91
+		$arguments = array(
92
+			'hierarchical'      => true,
93
+			'labels'            => array(
94
+				'name'          => $plural_name,
95
+				'singular_name' => $singular_name,
96
+			),
97
+			'show_ui'           => true,
98
+			'show_ee_ui'        => true,
99
+			'show_admin_column' => true,
100
+			'query_var'         => true,
101
+			'show_in_nav_menus' => false,
102
+			'map_meta_cap'      => true,
103
+		);
104
+		if ($override_arguments) {
105
+			if (isset($override_args['labels'])) {
106
+				$labels = array_merge($arguments['labels'], $override_arguments['labels']);
107
+				$arguments['labels'] = $labels;
108
+			}
109
+			$arguments = array_merge($arguments, $override_arguments);
110
+		}
111
+		return $arguments;
112
+	}
113 113
 }
Please login to merge, or discard this patch.
core/CPTs/EE_Register_CPTs.core.php 1 patch
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -19,303 +19,303 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * instantiated at init priority 5
24
-     *
25
-     * @deprecated 4.9.62.p
26
-     */
27
-    public function __construct()
28
-    {
29
-        do_action('AHEE__EE_Register_CPTs__construct_end', $this);
30
-    }
31
-
32
-
33
-    /**
34
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
35
-     *
36
-     * @deprecated 4.9.62.p
37
-     * @return void
38
-     * @throws InvalidInterfaceException
39
-     * @throws InvalidDataTypeException
40
-     * @throws InvalidArgumentException
41
-     */
42
-    public static function maybe_flush_rewrite_rules()
43
-    {
44
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
45
-        $rewrite_rules = LoaderFactory::getLoader()->getShared(
46
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
47
-        );
48
-        $rewrite_rules->flushRewriteRules();
49
-    }
50
-
51
-
52
-    /**
53
-     * @return CustomTaxonomyDefinitions
54
-     * @throws InvalidArgumentException
55
-     * @throws InvalidDataTypeException
56
-     * @throws InvalidInterfaceException
57
-     */
58
-    public static function getTaxonomyDefinitions()
59
-    {
60
-        return LoaderFactory::getLoader()->getShared(
61
-            'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
62
-        );
63
-    }
64
-
65
-
66
-    /**
67
-     * @deprecated 4.9.62.p
68
-     * @param string $description The description content.
69
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
70
-     * @return string
71
-     * @throws InvalidArgumentException
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidInterfaceException
74
-     */
75
-    public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
76
-    {
77
-        $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
78
-        return $taxonomies->filterCustomTermDescription($description, $taxonomy);
79
-    }
80
-
81
-
82
-    /**
83
-     * @deprecated 4.9.62.p
84
-     * @return array
85
-     * @throws InvalidArgumentException
86
-     * @throws InvalidDataTypeException
87
-     * @throws InvalidInterfaceException
88
-     */
89
-    public static function get_taxonomies()
90
-    {
91
-        $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
92
-        return $taxonomies->getCustomTaxonomyDefinitions();
93
-    }
94
-
95
-
96
-    /**
97
-     * @return CustomPostTypeDefinitions
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     */
102
-    public static function getCustomPostTypeDefinitions()
103
-    {
104
-        return LoaderFactory::getLoader()->getShared(
105
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
106
-        );
107
-    }
108
-
109
-
110
-    /**
111
-     * @deprecated 4.9.62.p
112
-     * @return array
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    public static function get_CPTs()
118
-    {
119
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
120
-        return $custom_post_types->getDefinitions();
121
-    }
122
-
123
-
124
-    /**
125
-     * @deprecated 4.9.62.p
126
-     * @return array
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidDataTypeException
129
-     * @throws InvalidInterfaceException
130
-     */
131
-    public static function get_private_CPTs()
132
-    {
133
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
134
-        return $custom_post_types->getPrivateCustomPostTypes();
135
-    }
136
-
137
-
138
-    /**
139
-     * @deprecated 4.9.62.p
140
-     * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
141
-     *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
142
-     *                                            model names for cpts registered in EE.
143
-     * @return array           Empty array if no matching model names for the given slug or an array of model
144
-     *                                            names indexed by post type slug.
145
-     * @throws InvalidArgumentException
146
-     * @throws InvalidDataTypeException
147
-     * @throws InvalidInterfaceException
148
-     */
149
-    public static function get_cpt_model_names($post_type_slug = '')
150
-    {
151
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
152
-        return $custom_post_types->getCustomPostTypeModelNames($post_type_slug);
153
-    }
154
-
155
-
156
-    /**
157
-     * @deprecated 4.9.62.p
158
-     * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
159
-     *                               the cpt matching the given slug.  Otherwise all cpt models will be
160
-     *                               instantiated (if possible).
161
-     * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
162
-     *                               EEM models indexed by post slug.
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     */
167
-    public static function instantiate_cpt_models($post_type_slug = '')
168
-    {
169
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
170
-        return $custom_post_types->getCustomPostTypeModels($post_type_slug);
171
-    }
172
-
173
-
174
-    /**
175
-     * @deprecated 4.9.62.p
176
-     * @param string $taxonomy_name , eg 'books'
177
-     * @param string $singular_name internationalized singular name
178
-     * @param string $plural_name   internationalized plural name
179
-     * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     * @throws DomainException
184
-     */
185
-    public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
186
-    {
187
-        /** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */
188
-        $taxonomies = LoaderFactory::getLoader()->getShared(
189
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
190
-        );
191
-        $taxonomies->registerCustomTaxonomy(
192
-            $taxonomy_name,
193
-            $singular_name,
194
-            $plural_name,
195
-            $override_args
196
-        );
197
-    }
198
-
199
-
200
-    /**
201
-     * @deprecated 4.9.62.p
202
-     * @param string $post_type     the actual post type name
203
-     *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
204
-     *                              cpt Also any models must use this slug as well)
205
-     * @param string $singular_name a pre-internationalized string for the singular name of the objects
206
-     * @param string $plural_name   a pre-internalized string for the plural name of the objects
207
-     * @param array  $override_args exactly like $args as described in
208
-     *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
209
-     *                              set in this function will be overridden by whatever you set in $override_args
210
-     * @param string $singular_slug
211
-     * @param string $plural_slug
212
-     * @return void , but registers the custom post type
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws DomainException
217
-     */
218
-    public function register_CPT(
219
-        $post_type,
220
-        $singular_name,
221
-        $plural_name,
222
-        $override_args = array(),
223
-        $singular_slug = '',
224
-        $plural_slug = ''
225
-    ) {
226
-        /** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
227
-        $register_custom_post_types = LoaderFactory::getLoader()->getShared(
228
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
229
-        );
230
-        $register_custom_post_types->registerCustomPostType(
231
-            $post_type,
232
-            $singular_name,
233
-            $plural_name,
234
-            $singular_slug,
235
-            $plural_slug,
236
-            $override_args
237
-        );
238
-    }
239
-
240
-
241
-    /**
242
-     * @return RegisterCustomTaxonomyTerms
243
-     * @throws InvalidArgumentException
244
-     * @throws InvalidDataTypeException
245
-     * @throws InvalidInterfaceException
246
-     */
247
-    public static function getRegisterCustomTaxonomyTerms()
248
-    {
249
-        return LoaderFactory::getLoader()->getShared(
250
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
251
-        );
252
-    }
253
-
254
-
255
-    /**
256
-     * @deprecated 4.9.62.p
257
-     * @throws InvalidArgumentException
258
-     * @throws InvalidDataTypeException
259
-     * @throws InvalidInterfaceException
260
-     */
261
-    public function set_must_use_event_types()
262
-    {
263
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
264
-        $register_custom_taxonomy_terms->setMustUseEventTypes();
265
-    }
266
-
267
-
268
-    /**
269
-     * @deprecated 4.9.62.p
270
-     * @param string $taxonomy     The name of the taxonomy
271
-     * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
272
-     *                             description as the elements in the array
273
-     * @return void
274
-     * @throws InvalidArgumentException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function set_must_use_terms($taxonomy, $term_details)
279
-    {
280
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
281
-        $register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details);
282
-    }
283
-
284
-
285
-    /**
286
-     * @deprecated 4.9.62.p
287
-     * @param string $taxonomy  The taxonomy we're using for the default term
288
-     * @param string $term_slug The slug of the term that will be the default.
289
-     * @param array  $cpt_slugs An array of custom post types we want the default assigned to
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
295
-    {
296
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
297
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
298
-            $taxonomy,
299
-            $term_slug,
300
-            $cpt_slugs
301
-        );
302
-    }
303
-
304
-
305
-    /**
306
-     * @deprecated 4.9.62.p
307
-     * @param  int     $post_id ID of CPT being saved
308
-     * @param  WP_Post $post    Post object
309
-     * @return void
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
314
-    public function save_default_term($post_id, $post)
315
-    {
316
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
317
-        $register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post);
318
-    }
22
+	/**
23
+	 * instantiated at init priority 5
24
+	 *
25
+	 * @deprecated 4.9.62.p
26
+	 */
27
+	public function __construct()
28
+	{
29
+		do_action('AHEE__EE_Register_CPTs__construct_end', $this);
30
+	}
31
+
32
+
33
+	/**
34
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
35
+	 *
36
+	 * @deprecated 4.9.62.p
37
+	 * @return void
38
+	 * @throws InvalidInterfaceException
39
+	 * @throws InvalidDataTypeException
40
+	 * @throws InvalidArgumentException
41
+	 */
42
+	public static function maybe_flush_rewrite_rules()
43
+	{
44
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
45
+		$rewrite_rules = LoaderFactory::getLoader()->getShared(
46
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
47
+		);
48
+		$rewrite_rules->flushRewriteRules();
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return CustomTaxonomyDefinitions
54
+	 * @throws InvalidArgumentException
55
+	 * @throws InvalidDataTypeException
56
+	 * @throws InvalidInterfaceException
57
+	 */
58
+	public static function getTaxonomyDefinitions()
59
+	{
60
+		return LoaderFactory::getLoader()->getShared(
61
+			'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
62
+		);
63
+	}
64
+
65
+
66
+	/**
67
+	 * @deprecated 4.9.62.p
68
+	 * @param string $description The description content.
69
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
70
+	 * @return string
71
+	 * @throws InvalidArgumentException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidInterfaceException
74
+	 */
75
+	public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
76
+	{
77
+		$taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
78
+		return $taxonomies->filterCustomTermDescription($description, $taxonomy);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @deprecated 4.9.62.p
84
+	 * @return array
85
+	 * @throws InvalidArgumentException
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws InvalidInterfaceException
88
+	 */
89
+	public static function get_taxonomies()
90
+	{
91
+		$taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
92
+		return $taxonomies->getCustomTaxonomyDefinitions();
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return CustomPostTypeDefinitions
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 */
102
+	public static function getCustomPostTypeDefinitions()
103
+	{
104
+		return LoaderFactory::getLoader()->getShared(
105
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
106
+		);
107
+	}
108
+
109
+
110
+	/**
111
+	 * @deprecated 4.9.62.p
112
+	 * @return array
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	public static function get_CPTs()
118
+	{
119
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
120
+		return $custom_post_types->getDefinitions();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @deprecated 4.9.62.p
126
+	 * @return array
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidDataTypeException
129
+	 * @throws InvalidInterfaceException
130
+	 */
131
+	public static function get_private_CPTs()
132
+	{
133
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
134
+		return $custom_post_types->getPrivateCustomPostTypes();
135
+	}
136
+
137
+
138
+	/**
139
+	 * @deprecated 4.9.62.p
140
+	 * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
141
+	 *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
142
+	 *                                            model names for cpts registered in EE.
143
+	 * @return array           Empty array if no matching model names for the given slug or an array of model
144
+	 *                                            names indexed by post type slug.
145
+	 * @throws InvalidArgumentException
146
+	 * @throws InvalidDataTypeException
147
+	 * @throws InvalidInterfaceException
148
+	 */
149
+	public static function get_cpt_model_names($post_type_slug = '')
150
+	{
151
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
152
+		return $custom_post_types->getCustomPostTypeModelNames($post_type_slug);
153
+	}
154
+
155
+
156
+	/**
157
+	 * @deprecated 4.9.62.p
158
+	 * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
159
+	 *                               the cpt matching the given slug.  Otherwise all cpt models will be
160
+	 *                               instantiated (if possible).
161
+	 * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
162
+	 *                               EEM models indexed by post slug.
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 */
167
+	public static function instantiate_cpt_models($post_type_slug = '')
168
+	{
169
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
170
+		return $custom_post_types->getCustomPostTypeModels($post_type_slug);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @deprecated 4.9.62.p
176
+	 * @param string $taxonomy_name , eg 'books'
177
+	 * @param string $singular_name internationalized singular name
178
+	 * @param string $plural_name   internationalized plural name
179
+	 * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 * @throws DomainException
184
+	 */
185
+	public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
186
+	{
187
+		/** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */
188
+		$taxonomies = LoaderFactory::getLoader()->getShared(
189
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
190
+		);
191
+		$taxonomies->registerCustomTaxonomy(
192
+			$taxonomy_name,
193
+			$singular_name,
194
+			$plural_name,
195
+			$override_args
196
+		);
197
+	}
198
+
199
+
200
+	/**
201
+	 * @deprecated 4.9.62.p
202
+	 * @param string $post_type     the actual post type name
203
+	 *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
204
+	 *                              cpt Also any models must use this slug as well)
205
+	 * @param string $singular_name a pre-internationalized string for the singular name of the objects
206
+	 * @param string $plural_name   a pre-internalized string for the plural name of the objects
207
+	 * @param array  $override_args exactly like $args as described in
208
+	 *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
209
+	 *                              set in this function will be overridden by whatever you set in $override_args
210
+	 * @param string $singular_slug
211
+	 * @param string $plural_slug
212
+	 * @return void , but registers the custom post type
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws DomainException
217
+	 */
218
+	public function register_CPT(
219
+		$post_type,
220
+		$singular_name,
221
+		$plural_name,
222
+		$override_args = array(),
223
+		$singular_slug = '',
224
+		$plural_slug = ''
225
+	) {
226
+		/** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
227
+		$register_custom_post_types = LoaderFactory::getLoader()->getShared(
228
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
229
+		);
230
+		$register_custom_post_types->registerCustomPostType(
231
+			$post_type,
232
+			$singular_name,
233
+			$plural_name,
234
+			$singular_slug,
235
+			$plural_slug,
236
+			$override_args
237
+		);
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return RegisterCustomTaxonomyTerms
243
+	 * @throws InvalidArgumentException
244
+	 * @throws InvalidDataTypeException
245
+	 * @throws InvalidInterfaceException
246
+	 */
247
+	public static function getRegisterCustomTaxonomyTerms()
248
+	{
249
+		return LoaderFactory::getLoader()->getShared(
250
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
251
+		);
252
+	}
253
+
254
+
255
+	/**
256
+	 * @deprecated 4.9.62.p
257
+	 * @throws InvalidArgumentException
258
+	 * @throws InvalidDataTypeException
259
+	 * @throws InvalidInterfaceException
260
+	 */
261
+	public function set_must_use_event_types()
262
+	{
263
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
264
+		$register_custom_taxonomy_terms->setMustUseEventTypes();
265
+	}
266
+
267
+
268
+	/**
269
+	 * @deprecated 4.9.62.p
270
+	 * @param string $taxonomy     The name of the taxonomy
271
+	 * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
272
+	 *                             description as the elements in the array
273
+	 * @return void
274
+	 * @throws InvalidArgumentException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function set_must_use_terms($taxonomy, $term_details)
279
+	{
280
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
281
+		$register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details);
282
+	}
283
+
284
+
285
+	/**
286
+	 * @deprecated 4.9.62.p
287
+	 * @param string $taxonomy  The taxonomy we're using for the default term
288
+	 * @param string $term_slug The slug of the term that will be the default.
289
+	 * @param array  $cpt_slugs An array of custom post types we want the default assigned to
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
295
+	{
296
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
297
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
298
+			$taxonomy,
299
+			$term_slug,
300
+			$cpt_slugs
301
+		);
302
+	}
303
+
304
+
305
+	/**
306
+	 * @deprecated 4.9.62.p
307
+	 * @param  int     $post_id ID of CPT being saved
308
+	 * @param  WP_Post $post    Post object
309
+	 * @return void
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314
+	public function save_default_term($post_id, $post)
315
+	{
316
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
317
+		$register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post);
318
+	}
319 319
 }
320 320
 
321 321
 /**
@@ -327,24 +327,24 @@  discard block
 block discarded – undo
327 327
 class EE_Default_Term
328 328
 {
329 329
 
330
-    // props holding the items
331
-    public $taxonomy = '';
330
+	// props holding the items
331
+	public $taxonomy = '';
332 332
 
333
-    public $cpt_slugs = array();
333
+	public $cpt_slugs = array();
334 334
 
335
-    public $term_slug = '';
335
+	public $term_slug = '';
336 336
 
337 337
 
338
-    /**
339
-     * @deprecated 4.9.62.p
340
-     * @param string $taxonomy  The taxonomy the default term belongs to
341
-     * @param string $term_slug The slug of the term that will be the default.
342
-     * @param array  $cpt_slugs The custom post type the default term gets saved with
343
-     */
344
-    public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
345
-    {
346
-        $this->taxonomy = $taxonomy;
347
-        $this->cpt_slugs = (array) $cpt_slugs;
348
-        $this->term_slug = $term_slug;
349
-    }
338
+	/**
339
+	 * @deprecated 4.9.62.p
340
+	 * @param string $taxonomy  The taxonomy the default term belongs to
341
+	 * @param string $term_slug The slug of the term that will be the default.
342
+	 * @param array  $cpt_slugs The custom post type the default term gets saved with
343
+	 */
344
+	public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
345
+	{
346
+		$this->taxonomy = $taxonomy;
347
+		$this->cpt_slugs = (array) $cpt_slugs;
348
+		$this->term_slug = $term_slug;
349
+	}
350 350
 }
Please login to merge, or discard this patch.
core/services/assets/I18nRegistry.php 2 patches
Spacing   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function registerScriptI18n($handle, $domain = 'event_espresso')
77 77
     {
78
-        if(! isset($this->registered_i18n[$handle])) {
79
-            $this->registered_i18n[ $handle ] = 1;
80
-            $this->queued_scripts[ $handle ] = $domain;
78
+        if ( ! isset($this->registered_i18n[$handle])) {
79
+            $this->registered_i18n[$handle] = 1;
80
+            $this->queued_scripts[$handle] = $domain;
81 81
         }
82 82
     }
83 83
 
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
     protected function registerInlineScript($handle, array $translations, $domain)
122 122
     {
123 123
         $script = $domain ?
124
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
124
+            'eejs.i18n.setLocaleData( '.wp_json_encode($translations).', "'.$domain.'" );' : 'eejs.i18n.setLocaleData( '.wp_json_encode($translations).' );';
126 125
         wp_add_inline_script($handle, $script, 'before');
127 126
     }
128 127
 
@@ -158,9 +157,9 @@  discard block
 block discarded – undo
158 157
     private function setI18nMap(array $i18n_map)
159 158
     {
160 159
         if (empty($i18n_map)) {
161
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
160
+            $i18n_map = file_exists($this->domain->pluginPath().'translation-map.json')
162 161
                 ? json_decode(
163
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
162
+                        file_get_contents($this->domain->pluginPath().'translation-map.json'),
164 163
                         true
165 164
                     )
166 165
                 : array();
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
             ),
239 238
         );
240 239
 
241
-        if (! empty($translations->headers['Plural-Forms'])) {
240
+        if ( ! empty($translations->headers['Plural-Forms'])) {
242 241
             $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243 242
         }
244 243
 
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -15,239 +15,239 @@
 block discarded – undo
15 15
  */
16 16
 class I18nRegistry
17 17
 {
18
-    /**
19
-     * @var DomainInterface
20
-     */
21
-    private $domain;
22
-
23
-    /**
24
-     * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
25
-     *
26
-     * @var array
27
-     */
28
-    private $registered_i18n = array();
29
-
30
-
31
-    /**
32
-     * Used to hold queued translations for the chunks loading in a view.
33
-     *
34
-     * @var array
35
-     */
36
-    private $queued_handle_translations = array();
37
-
38
-    /**
39
-     * Used to track script handles queued for adding translation strings as inline data in the dom.
40
-     *
41
-     * @var array
42
-     */
43
-    private $queued_scripts = array();
44
-
45
-
46
-    /**
47
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
48
-     * translation strings.
49
-     *
50
-     * @var array
51
-     */
52
-    private $i18n_map;
53
-
54
-
55
-    /**
56
-     * I18nRegistry constructor.
57
-     *
58
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
59
-     *                            provided, the class will look for map in root of plugin with filename of
60
-     *                            'translation-map.json'.
61
-     * @param DomainInterface $domain
62
-     */
63
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
64
-    {
65
-        $this->domain = $domain;
66
-        $this->setI18nMap($i18n_map);
67
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
68
-    }
69
-
70
-
71
-    /**
72
-     * Used to register a script that has i18n strings for its $handle
73
-     *
74
-     * @param string $handle The script handle reference.
75
-     * @param string $domain The i18n domain for the strings.
76
-     */
77
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
78
-    {
79
-        if(! isset($this->registered_i18n[$handle])) {
80
-            $this->registered_i18n[ $handle ] = 1;
81
-            $this->queued_scripts[ $handle ] = $domain;
82
-        }
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
89
-     *
90
-     * @param array $handles Array of registered script handles.
91
-     * @return array
92
-     */
93
-    public function queueI18n(array $handles)
94
-    {
95
-        if (empty($this->queued_scripts)) {
96
-            return $handles;
97
-        }
98
-        foreach ($handles as $handle) {
99
-            $this->queueI18nTranslationsForHandle($handle);
100
-        }
101
-        if ($this->queued_handle_translations) {
102
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
103
-                $this->registerInlineScript(
104
-                    $handle,
105
-                    $translations_for_domain['translations'],
106
-                    $translations_for_domain['domain']
107
-                );
108
-                unset($this->queued_handle_translations[$handle]);
109
-            }
110
-        }
111
-        return $handles;
112
-    }
113
-
114
-
115
-    /**
116
-     * Registers inline script with translations for given handle and domain.
117
-     *
118
-     * @param string $handle       Handle used to register javascript file containing translations.
119
-     * @param array  $translations Array of string translations.
120
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
121
-     *                             domain for the javascript.
122
-     */
123
-    protected function registerInlineScript($handle, array $translations, $domain)
124
-    {
125
-        $script = $domain ?
126
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
127
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
128
-        wp_add_inline_script($handle, $script, 'before');
129
-    }
130
-
131
-
132
-    /**
133
-     * Queues up the translation strings for the given handle.
134
-     *
135
-     * @param string $handle The script handle being queued up.
136
-     */
137
-    private function queueI18nTranslationsForHandle($handle)
138
-    {
139
-        if (isset($this->queued_scripts[$handle])) {
140
-            $domain = $this->queued_scripts[$handle];
141
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
142
-            if (count($translations) > 0) {
143
-                $this->queued_handle_translations[$handle] = array(
144
-                    'domain'       => $domain,
145
-                    'translations' => $translations,
146
-                );
147
-            }
148
-            unset($this->queued_scripts[$handle]);
149
-        }
150
-    }
151
-
152
-
153
-    /**
154
-     * Sets the internal i18n_map property.
155
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
156
-     *
157
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
158
-     *                         correspond to.
159
-     */
160
-    private function setI18nMap(array $i18n_map)
161
-    {
162
-        if (empty($i18n_map)) {
163
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
164
-                ? json_decode(
165
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
166
-                        true
167
-                    )
168
-                : array();
169
-        }
170
-        $this->i18n_map = $i18n_map;
171
-    }
172
-
173
-
174
-    /**
175
-     * Get the jed locale data for a given $handle and domain
176
-     *
177
-     * @param string $handle The name for the script handle we want strings returned for.
178
-     * @param string $domain The i18n domain.
179
-     * @return array
180
-     */
181
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
182
-    {
183
-        $translations = $this->getJedLocaleData($domain);
184
-        // get index for adding back after extracting strings for this $chunk.
185
-        $index = $translations[''];
186
-        $translations = $this->getLocaleDataMatchingMap(
187
-            $this->getOriginalStringsForHandleFromMap($handle),
188
-            $translations
189
-        );
190
-        $translations[''] = $index;
191
-        return $translations;
192
-    }
193
-
194
-
195
-    /**
196
-     * Get locale data for given strings from given translations
197
-     *
198
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
199
-     * @param array $translations Translation data to extra strings from.
200
-     * @return array
201
-     */
202
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
203
-    {
204
-        if (empty($string_set)) {
205
-            return array();
206
-        }
207
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
208
-        // slashed also filter falsey values.
209
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
210
-        return array_intersect_key($translations, array_flip($string_set));
211
-    }
212
-
213
-
214
-    /**
215
-     * Get original strings to translate for the given chunk from the map
216
-     *
217
-     * @param string $handle The script handle name to get strings from the map for.
218
-     * @return array
219
-     */
220
-    protected function getOriginalStringsForHandleFromMap($handle)
221
-    {
222
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
223
-    }
224
-
225
-
226
-    /**
227
-     * Returns Jed-formatted localization data.
228
-     *
229
-     * @param  string $domain Translation domain.
230
-     * @return array
231
-     */
232
-    private function getJedLocaleData($domain)
233
-    {
234
-        $translations = get_translations_for_domain($domain);
235
-
236
-        $locale = array(
237
-            '' => array(
238
-                'domain' => $domain,
239
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
240
-            ),
241
-        );
242
-
243
-        if (! empty($translations->headers['Plural-Forms'])) {
244
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
245
-        }
246
-
247
-        foreach ($translations->entries as $msgid => $entry) {
248
-            $locale[$msgid] = $entry->translations;
249
-        }
250
-
251
-        return $locale;
252
-    }
18
+	/**
19
+	 * @var DomainInterface
20
+	 */
21
+	private $domain;
22
+
23
+	/**
24
+	 * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
25
+	 *
26
+	 * @var array
27
+	 */
28
+	private $registered_i18n = array();
29
+
30
+
31
+	/**
32
+	 * Used to hold queued translations for the chunks loading in a view.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	private $queued_handle_translations = array();
37
+
38
+	/**
39
+	 * Used to track script handles queued for adding translation strings as inline data in the dom.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	private $queued_scripts = array();
44
+
45
+
46
+	/**
47
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
48
+	 * translation strings.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	private $i18n_map;
53
+
54
+
55
+	/**
56
+	 * I18nRegistry constructor.
57
+	 *
58
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
59
+	 *                            provided, the class will look for map in root of plugin with filename of
60
+	 *                            'translation-map.json'.
61
+	 * @param DomainInterface $domain
62
+	 */
63
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
64
+	{
65
+		$this->domain = $domain;
66
+		$this->setI18nMap($i18n_map);
67
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
68
+	}
69
+
70
+
71
+	/**
72
+	 * Used to register a script that has i18n strings for its $handle
73
+	 *
74
+	 * @param string $handle The script handle reference.
75
+	 * @param string $domain The i18n domain for the strings.
76
+	 */
77
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
78
+	{
79
+		if(! isset($this->registered_i18n[$handle])) {
80
+			$this->registered_i18n[ $handle ] = 1;
81
+			$this->queued_scripts[ $handle ] = $domain;
82
+		}
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
89
+	 *
90
+	 * @param array $handles Array of registered script handles.
91
+	 * @return array
92
+	 */
93
+	public function queueI18n(array $handles)
94
+	{
95
+		if (empty($this->queued_scripts)) {
96
+			return $handles;
97
+		}
98
+		foreach ($handles as $handle) {
99
+			$this->queueI18nTranslationsForHandle($handle);
100
+		}
101
+		if ($this->queued_handle_translations) {
102
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
103
+				$this->registerInlineScript(
104
+					$handle,
105
+					$translations_for_domain['translations'],
106
+					$translations_for_domain['domain']
107
+				);
108
+				unset($this->queued_handle_translations[$handle]);
109
+			}
110
+		}
111
+		return $handles;
112
+	}
113
+
114
+
115
+	/**
116
+	 * Registers inline script with translations for given handle and domain.
117
+	 *
118
+	 * @param string $handle       Handle used to register javascript file containing translations.
119
+	 * @param array  $translations Array of string translations.
120
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
121
+	 *                             domain for the javascript.
122
+	 */
123
+	protected function registerInlineScript($handle, array $translations, $domain)
124
+	{
125
+		$script = $domain ?
126
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
127
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
128
+		wp_add_inline_script($handle, $script, 'before');
129
+	}
130
+
131
+
132
+	/**
133
+	 * Queues up the translation strings for the given handle.
134
+	 *
135
+	 * @param string $handle The script handle being queued up.
136
+	 */
137
+	private function queueI18nTranslationsForHandle($handle)
138
+	{
139
+		if (isset($this->queued_scripts[$handle])) {
140
+			$domain = $this->queued_scripts[$handle];
141
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
142
+			if (count($translations) > 0) {
143
+				$this->queued_handle_translations[$handle] = array(
144
+					'domain'       => $domain,
145
+					'translations' => $translations,
146
+				);
147
+			}
148
+			unset($this->queued_scripts[$handle]);
149
+		}
150
+	}
151
+
152
+
153
+	/**
154
+	 * Sets the internal i18n_map property.
155
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
156
+	 *
157
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
158
+	 *                         correspond to.
159
+	 */
160
+	private function setI18nMap(array $i18n_map)
161
+	{
162
+		if (empty($i18n_map)) {
163
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
164
+				? json_decode(
165
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
166
+						true
167
+					)
168
+				: array();
169
+		}
170
+		$this->i18n_map = $i18n_map;
171
+	}
172
+
173
+
174
+	/**
175
+	 * Get the jed locale data for a given $handle and domain
176
+	 *
177
+	 * @param string $handle The name for the script handle we want strings returned for.
178
+	 * @param string $domain The i18n domain.
179
+	 * @return array
180
+	 */
181
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
182
+	{
183
+		$translations = $this->getJedLocaleData($domain);
184
+		// get index for adding back after extracting strings for this $chunk.
185
+		$index = $translations[''];
186
+		$translations = $this->getLocaleDataMatchingMap(
187
+			$this->getOriginalStringsForHandleFromMap($handle),
188
+			$translations
189
+		);
190
+		$translations[''] = $index;
191
+		return $translations;
192
+	}
193
+
194
+
195
+	/**
196
+	 * Get locale data for given strings from given translations
197
+	 *
198
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
199
+	 * @param array $translations Translation data to extra strings from.
200
+	 * @return array
201
+	 */
202
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
203
+	{
204
+		if (empty($string_set)) {
205
+			return array();
206
+		}
207
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
208
+		// slashed also filter falsey values.
209
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
210
+		return array_intersect_key($translations, array_flip($string_set));
211
+	}
212
+
213
+
214
+	/**
215
+	 * Get original strings to translate for the given chunk from the map
216
+	 *
217
+	 * @param string $handle The script handle name to get strings from the map for.
218
+	 * @return array
219
+	 */
220
+	protected function getOriginalStringsForHandleFromMap($handle)
221
+	{
222
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
223
+	}
224
+
225
+
226
+	/**
227
+	 * Returns Jed-formatted localization data.
228
+	 *
229
+	 * @param  string $domain Translation domain.
230
+	 * @return array
231
+	 */
232
+	private function getJedLocaleData($domain)
233
+	{
234
+		$translations = get_translations_for_domain($domain);
235
+
236
+		$locale = array(
237
+			'' => array(
238
+				'domain' => $domain,
239
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
240
+			),
241
+		);
242
+
243
+		if (! empty($translations->headers['Plural-Forms'])) {
244
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
245
+		}
246
+
247
+		foreach ($translations->entries as $msgid => $entry) {
248
+			$locale[$msgid] = $entry->translations;
249
+		}
250
+
251
+		return $locale;
252
+	}
253 253
 }
254 254
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/request/middleware/RecommendedVersions.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -19,182 +19,182 @@
 block discarded – undo
19 19
 class RecommendedVersions extends Middleware
20 20
 {
21 21
 
22
-    /**
23
-     * converts a Request to a Response
24
-     *
25
-     * @param RequestInterface  $request
26
-     * @param ResponseInterface $response
27
-     * @return ResponseInterface
28
-     * @throws InvalidDataTypeException
29
-     */
30
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
31
-    {
32
-        $this->request = $request;
33
-        $this->response = $response;
34
-        // check required WP version
35
-        if (! $this->minimumWordPressVersionRequired()) {
36
-            $this->request->unSetRequestParam('activate', true);
37
-            add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
38
-            $this->response->terminateRequest();
39
-            $this->response->deactivatePlugin();
40
-        }
41
-        // check recommended PHP version
42
-        if (! $this->minimumPhpVersionRecommended()) {
43
-            $this->displayMinimumRecommendedPhpVersionNotice();
44
-        }
45
-        // upcoming required version
46
-        if (! $this->upcomingRequiredPhpVersion()) {
47
-            $this->displayUpcomingRequiredVersion();
48
-        }
49
-        $this->response = $this->processRequestStack($this->request, $this->response);
50
-        return $this->response;
51
-    }
52
-
53
-
54
-    /**
55
-     * Helper method to assess installed wp version against given values.
56
-     * By default this compares the required minimum version of WP for EE against the installed version of WP
57
-     * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
58
-     * against) so consider that when sending in your values.
59
-     *
60
-     * @param string $version_to_check
61
-     * @param string $operator
62
-     * @return bool
63
-     */
64
-    public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
65
-    {
66
-        global $wp_version;
67
-        return version_compare(
68
-            // first account for wp_version being pre-release
69
-            // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
70
-            strpos($wp_version, '-') > 0
71
-                ? substr($wp_version, 0, strpos($wp_version, '-'))
72
-                : $wp_version,
73
-            $version_to_check,
74
-            $operator
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * @return boolean
81
-     */
82
-    private function minimumWordPressVersionRequired()
83
-    {
84
-        return RecommendedVersions::compareWordPressVersion();
85
-    }
86
-
87
-
88
-    /**
89
-     * @param string $min_version
90
-     * @return boolean
91
-     */
92
-    private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED)
93
-    {
94
-        return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
95
-    }
96
-
97
-
98
-    /**
99
-     * @return boolean
100
-     */
101
-    private function minimumPhpVersionRecommended()
102
-    {
103
-        return $this->checkPhpVersion();
104
-    }
105
-
106
-
107
-    /**
108
-     * @return void
109
-     */
110
-    public function minimumWpVersionError()
111
-    {
112
-        global $wp_version;
113
-        ?>
22
+	/**
23
+	 * converts a Request to a Response
24
+	 *
25
+	 * @param RequestInterface  $request
26
+	 * @param ResponseInterface $response
27
+	 * @return ResponseInterface
28
+	 * @throws InvalidDataTypeException
29
+	 */
30
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
31
+	{
32
+		$this->request = $request;
33
+		$this->response = $response;
34
+		// check required WP version
35
+		if (! $this->minimumWordPressVersionRequired()) {
36
+			$this->request->unSetRequestParam('activate', true);
37
+			add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
38
+			$this->response->terminateRequest();
39
+			$this->response->deactivatePlugin();
40
+		}
41
+		// check recommended PHP version
42
+		if (! $this->minimumPhpVersionRecommended()) {
43
+			$this->displayMinimumRecommendedPhpVersionNotice();
44
+		}
45
+		// upcoming required version
46
+		if (! $this->upcomingRequiredPhpVersion()) {
47
+			$this->displayUpcomingRequiredVersion();
48
+		}
49
+		$this->response = $this->processRequestStack($this->request, $this->response);
50
+		return $this->response;
51
+	}
52
+
53
+
54
+	/**
55
+	 * Helper method to assess installed wp version against given values.
56
+	 * By default this compares the required minimum version of WP for EE against the installed version of WP
57
+	 * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked
58
+	 * against) so consider that when sending in your values.
59
+	 *
60
+	 * @param string $version_to_check
61
+	 * @param string $operator
62
+	 * @return bool
63
+	 */
64
+	public static function compareWordPressVersion($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=')
65
+	{
66
+		global $wp_version;
67
+		return version_compare(
68
+			// first account for wp_version being pre-release
69
+			// (like RC, beta etc) which are usually in the format like 4.7-RC3-39519
70
+			strpos($wp_version, '-') > 0
71
+				? substr($wp_version, 0, strpos($wp_version, '-'))
72
+				: $wp_version,
73
+			$version_to_check,
74
+			$operator
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * @return boolean
81
+	 */
82
+	private function minimumWordPressVersionRequired()
83
+	{
84
+		return RecommendedVersions::compareWordPressVersion();
85
+	}
86
+
87
+
88
+	/**
89
+	 * @param string $min_version
90
+	 * @return boolean
91
+	 */
92
+	private function checkPhpVersion($min_version = EE_MIN_PHP_VER_RECOMMENDED)
93
+	{
94
+		return version_compare(PHP_VERSION, $min_version, '>=') ? true : false;
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return boolean
100
+	 */
101
+	private function minimumPhpVersionRecommended()
102
+	{
103
+		return $this->checkPhpVersion();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return void
109
+	 */
110
+	public function minimumWpVersionError()
111
+	{
112
+		global $wp_version;
113
+		?>
114 114
         <div class="error">
115 115
             <p>
116 116
                 <?php
117
-                printf(
118
-                    __(
119
-                        'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
120
-                        'event_espresso'
121
-                    ),
122
-                    EE_MIN_WP_VER_REQUIRED,
123
-                    $wp_version,
124
-                    '<br/>',
125
-                    '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
126
-                );
127
-                ?>
117
+				printf(
118
+					__(
119
+						'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.',
120
+						'event_espresso'
121
+					),
122
+					EE_MIN_WP_VER_REQUIRED,
123
+					$wp_version,
124
+					'<br/>',
125
+					'<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
126
+				);
127
+				?>
128 128
             </p>
129 129
         </div>
130 130
         <?php
131
-    }
132
-
133
-
134
-    /**
135
-     *    _display_minimum_recommended_php_version_notice
136
-     *
137
-     * @access private
138
-     * @return void
139
-     * @throws InvalidDataTypeException
140
-     */
141
-    private function displayMinimumRecommendedPhpVersionNotice()
142
-    {
143
-        if ($this->request->isAdmin()) {
144
-            new PersistentAdminNotice(
145
-                'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
146
-                sprintf(
147
-                    esc_html__(
148
-                        'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
149
-                        'event_espresso'
150
-                    ),
151
-                    EE_MIN_PHP_VER_RECOMMENDED,
152
-                    PHP_VERSION,
153
-                    '<br/>',
154
-                    '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
155
-                )
156
-            );
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Returns whether the provided php version number is less than the current version of php installed on the server.
163
-     *
164
-     * @param string $version_required
165
-     * @return bool
166
-     */
167
-    private function upcomingRequiredPhpVersion($version_required = '5.5')
168
-    {
169
-        return true;
170
-        // return $this->checkPhpVersion($version_required);
171
-    }
172
-
173
-
174
-    /**
175
-     *  Sets a notice for an upcoming required version of PHP in the next update of EE core.
176
-     */
177
-    private function displayUpcomingRequiredVersion()
178
-    {
179
-        if ($this->request->isAdmin()
180
-            && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181
-            && current_user_can('update_plugins')
182
-        ) {
183
-            add_action('admin_notices', function () {
184
-                echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185
-                     . sprintf(
186
-                         esc_html__(
187
-                             'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater.  Your web server\'s PHP version is %3$s.  You can contact your host and ask them to update your PHP version to at least PHP 5.6.  Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s',
188
-                             'event_espresso'
189
-                         ),
190
-                         '<strong>',
191
-                         '</strong>',
192
-                         PHP_VERSION,
193
-                         '<a href="https://wordpress.org/support/upgrade-php/">',
194
-                         '</a>'
195
-                     )
196
-                     . '</p></div>';
197
-            });
198
-        }
199
-    }
131
+	}
132
+
133
+
134
+	/**
135
+	 *    _display_minimum_recommended_php_version_notice
136
+	 *
137
+	 * @access private
138
+	 * @return void
139
+	 * @throws InvalidDataTypeException
140
+	 */
141
+	private function displayMinimumRecommendedPhpVersionNotice()
142
+	{
143
+		if ($this->request->isAdmin()) {
144
+			new PersistentAdminNotice(
145
+				'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
146
+				sprintf(
147
+					esc_html__(
148
+						'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
149
+						'event_espresso'
150
+					),
151
+					EE_MIN_PHP_VER_RECOMMENDED,
152
+					PHP_VERSION,
153
+					'<br/>',
154
+					'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
155
+				)
156
+			);
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Returns whether the provided php version number is less than the current version of php installed on the server.
163
+	 *
164
+	 * @param string $version_required
165
+	 * @return bool
166
+	 */
167
+	private function upcomingRequiredPhpVersion($version_required = '5.5')
168
+	{
169
+		return true;
170
+		// return $this->checkPhpVersion($version_required);
171
+	}
172
+
173
+
174
+	/**
175
+	 *  Sets a notice for an upcoming required version of PHP in the next update of EE core.
176
+	 */
177
+	private function displayUpcomingRequiredVersion()
178
+	{
179
+		if ($this->request->isAdmin()
180
+			&& apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181
+			&& current_user_can('update_plugins')
182
+		) {
183
+			add_action('admin_notices', function () {
184
+				echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185
+					 . sprintf(
186
+						 esc_html__(
187
+							 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater.  Your web server\'s PHP version is %3$s.  You can contact your host and ask them to update your PHP version to at least PHP 5.6.  Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s',
188
+							 'event_espresso'
189
+						 ),
190
+						 '<strong>',
191
+						 '</strong>',
192
+						 PHP_VERSION,
193
+						 '<a href="https://wordpress.org/support/upgrade-php/">',
194
+						 '</a>'
195
+					 )
196
+					 . '</p></div>';
197
+			});
198
+		}
199
+	}
200 200
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
         $this->request = $request;
33 33
         $this->response = $response;
34 34
         // check required WP version
35
-        if (! $this->minimumWordPressVersionRequired()) {
35
+        if ( ! $this->minimumWordPressVersionRequired()) {
36 36
             $this->request->unSetRequestParam('activate', true);
37 37
             add_action('admin_notices', array($this, 'minimumWpVersionError'), 1);
38 38
             $this->response->terminateRequest();
39 39
             $this->response->deactivatePlugin();
40 40
         }
41 41
         // check recommended PHP version
42
-        if (! $this->minimumPhpVersionRecommended()) {
42
+        if ( ! $this->minimumPhpVersionRecommended()) {
43 43
             $this->displayMinimumRecommendedPhpVersionNotice();
44 44
         }
45 45
         // upcoming required version
46
-        if (! $this->upcomingRequiredPhpVersion()) {
46
+        if ( ! $this->upcomingRequiredPhpVersion()) {
47 47
             $this->displayUpcomingRequiredVersion();
48 48
         }
49 49
         $this->response = $this->processRequestStack($this->request, $this->response);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     {
143 143
         if ($this->request->isAdmin()) {
144 144
             new PersistentAdminNotice(
145
-                'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended',
145
+                'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended',
146 146
                 sprintf(
147 147
                     esc_html__(
148 148
                         'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
             && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->request)
181 181
             && current_user_can('update_plugins')
182 182
         ) {
183
-            add_action('admin_notices', function () {
183
+            add_action('admin_notices', function() {
184 184
                 echo '<div class="notice event-espresso-admin-notice notice-warning"><p>'
185 185
                      . sprintf(
186 186
                          esc_html__(
Please login to merge, or discard this patch.
core/helpers/EEH_HTML.helper.php 2 patches
Indentation   +862 added lines, -862 removed lines patch added patch discarded remove patch
@@ -1,875 +1,875 @@
 block discarded – undo
1 1
 <?php
2 2
  /**
3
- *
4
- * Class EEH_HTML
5
- *
3
+  *
4
+  * Class EEH_HTML
5
+  *
6 6
   * Sometimes when writing PHP you need to generate some standard HTML,
7 7
   * but either not enough to warrant creating a template file,
8 8
   * or the amount of PHP conditionals and/or loops peppered throughout the HTML
9 9
   * just make it really ugly and difficult to read.
10 10
   * This class simply adds a bunch of methods for generating basic HTML tags.
11 11
   * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters.
12
- *
13
- * @package         Event Espresso
14
- * @subpackage    core
15
- * @author              Brent Christensen
16
- *
17
- *
18
- */
12
+  *
13
+  * @package         Event Espresso
14
+  * @subpackage    core
15
+  * @author              Brent Christensen
16
+  *
17
+  *
18
+  */
19 19
 class EEH_HTML
20 20
 {
21 21
 
22
-    /**
23
-     *  instance of the EEH_Autoloader object
24
-     *  @var    $_instance
25
-     *  @access     private
26
-     */
27
-    private static $_instance;
28
-
29
-    /**
30
-     *  @var array  $_indent
31
-     *  @access     private
32
-     */
33
-    private static $_indent = array();
34
-
35
-
36
-
37
-    /**
38
-     *  @singleton method used to instantiate class object
39
-     *  @access public
40
-     *  @return EEH_HTML
41
-     */
42
-    public static function instance()
43
-    {
44
-        // check if class object is instantiated, and instantiated properly
45
-        if (! self::$_instance instanceof EEH_HTML) {
46
-            self::$_instance = new EEH_HTML();
47
-        }
48
-        return self::$_instance;
49
-    }
50
-
51
-
52
-
53
-    /**
54
-     *  class constructor
55
-     *
56
-     * @access    private
57
-     * @return \EEH_HTML
58
-     */
59
-    private function __construct()
60
-    {
61
-        // set some initial formatting for table indentation
62
-        EEH_HTML::$_indent = array(
63
-            'table'     => 0,
64
-            'thead' => 1,
65
-            'tbody' => 1,
66
-            'tr'    => 2,
67
-            'th'    => 3,
68
-            'td'    => 3,
69
-            'div'   => 0,
70
-            'h1'    => 0,
71
-            'h2'    => 0,
72
-            'h3'    => 0,
73
-            'h4'    => 0,
74
-            'h5'    => 0,
75
-            'h6'    => 0,
76
-            'p'     => 0,
77
-            'ul'    => 0,
78
-            'li'    => 1
79
-        );
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Generates an opening HTML <XX> tag and adds any passed attributes
86
-     * if passed content, it will also add that, as well as the closing </XX> tag
87
-     *
88
-     * @access protected
89
-     * @param string $tag
90
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
91
-     * @param string $id - html id attribute
92
-     * @param string $class - html class attribute
93
-     * @param string $style - html style attribute for applying inline styles
94
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
95
-     * @param bool   $force_close
96
-     * @return string
97
-     */
98
-    protected static function _open_tag(
99
-        $tag = 'div',
100
-        $content = '',
101
-        $id = '',
102
-        $class = '',
103
-        $style = '',
104
-        $other_attributes = '',
105
-        $force_close = false
106
-    ) {
107
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
108
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
109
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
110
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
111
-        $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
112
-        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
113
-        $indent = ! empty($content) || $force_close ? true : false;
114
-        $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
115
-        return $html;
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     * Generates HTML closing </XX> tag - if passed the id or class attribute
122
-     * used for the opening tag, will append a comment
123
-     *
22
+	/**
23
+	 *  instance of the EEH_Autoloader object
24
+	 *  @var    $_instance
25
+	 *  @access     private
26
+	 */
27
+	private static $_instance;
28
+
29
+	/**
30
+	 *  @var array  $_indent
31
+	 *  @access     private
32
+	 */
33
+	private static $_indent = array();
34
+
35
+
36
+
37
+	/**
38
+	 *  @singleton method used to instantiate class object
39
+	 *  @access public
40
+	 *  @return EEH_HTML
41
+	 */
42
+	public static function instance()
43
+	{
44
+		// check if class object is instantiated, and instantiated properly
45
+		if (! self::$_instance instanceof EEH_HTML) {
46
+			self::$_instance = new EEH_HTML();
47
+		}
48
+		return self::$_instance;
49
+	}
50
+
51
+
52
+
53
+	/**
54
+	 *  class constructor
55
+	 *
56
+	 * @access    private
57
+	 * @return \EEH_HTML
58
+	 */
59
+	private function __construct()
60
+	{
61
+		// set some initial formatting for table indentation
62
+		EEH_HTML::$_indent = array(
63
+			'table'     => 0,
64
+			'thead' => 1,
65
+			'tbody' => 1,
66
+			'tr'    => 2,
67
+			'th'    => 3,
68
+			'td'    => 3,
69
+			'div'   => 0,
70
+			'h1'    => 0,
71
+			'h2'    => 0,
72
+			'h3'    => 0,
73
+			'h4'    => 0,
74
+			'h5'    => 0,
75
+			'h6'    => 0,
76
+			'p'     => 0,
77
+			'ul'    => 0,
78
+			'li'    => 1
79
+		);
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Generates an opening HTML <XX> tag and adds any passed attributes
86
+	 * if passed content, it will also add that, as well as the closing </XX> tag
87
+	 *
88
+	 * @access protected
89
+	 * @param string $tag
90
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
91
+	 * @param string $id - html id attribute
92
+	 * @param string $class - html class attribute
93
+	 * @param string $style - html style attribute for applying inline styles
94
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
95
+	 * @param bool   $force_close
96
+	 * @return string
97
+	 */
98
+	protected static function _open_tag(
99
+		$tag = 'div',
100
+		$content = '',
101
+		$id = '',
102
+		$class = '',
103
+		$style = '',
104
+		$other_attributes = '',
105
+		$force_close = false
106
+	) {
107
+		$attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
108
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
109
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
110
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
111
+		$html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
112
+		$html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
113
+		$indent = ! empty($content) || $force_close ? true : false;
114
+		$html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
115
+		return $html;
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 * Generates HTML closing </XX> tag - if passed the id or class attribute
122
+	 * used for the opening tag, will append a comment
123
+	 *
124 124
 *@access protected
125
-     * @param string $tag
126
-     * @param string $id - html id attribute
127
-     * @param string $class - html class attribute
128
-     * @param bool   $indent
129
-     * @return string
130
-     */
131
-    protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true)
132
-    {
133
-        $comment = '';
134
-        if ($id) {
135
-            $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
136
-        } elseif ($class) {
137
-            $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
138
-        }
139
-        $html = $indent ? EEH_HTML::nl(-1, $tag) : '';
140
-        $html .= '</' . $tag . '>' . $comment;
141
-        return $html;
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *  div - generates HTML opening <div> tag and adds any passed attributes
148
-     *  to add an id use:       echo EEH_HTML::div( 'this is some content', 'footer' );
149
-     *  to add a class use:     echo EEH_HTML::div( 'this is some content', '', 'float_left' );
150
-     *  to add a both an id and a class use:    echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' );
151
-     *
152
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
153
-     * @param string $id - html id attribute
154
-     * @param string $class - html class attribute
155
-     * @param string $style - html style attribute for applying inline styles
156
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
157
-     * @return string
158
-     */
159
-    public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
160
-    {
161
-        return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes);
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment
168
-     * usage: echo EEH_HTML::divx();
169
-     *
170
-     * @param string $id - html id attribute
171
-     * @param string $class - html class attribute
172
-     * @return string
173
-     */
174
-    public static function divx($id = '', $class = '')
175
-    {
176
-        return EEH_HTML::_close_tag('div', $id, $class);
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes
183
-     * usage: echo EEH_HTML::h1( 'This is a Heading' );
184
-     *
185
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
186
-     * @param string $id - html id attribute
187
-     * @param string $class - html class attribute
188
-     * @param string $style - html style attribute for applying inline styles
189
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
190
-     * @return string
191
-     */
192
-    public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
193
-    {
194
-        return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true);
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes
201
-     * usage: echo EEH_HTML::h2( 'This is a Heading' );
202
-     *
203
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
204
-     * @param string $id               - html id attribute
205
-     * @param string $class            - html class attribute
206
-     * @param string $style            - html style attribute for applying inline styles
207
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
208
-     * @return string
209
-     */
210
-    public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
211
-    {
212
-        return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes
219
-     * usage: echo EEH_HTML::h3( 'This is a Heading' );
220
-     *
221
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
222
-     * @param string $id               - html id attribute
223
-     * @param string $class            - html class attribute
224
-     * @param string $style            - html style attribute for applying inline styles
225
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
226
-     * @return string
227
-     */
228
-    public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
229
-    {
230
-        return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true);
231
-    }
232
-
233
-
234
-
235
-    /**
236
-     * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes
237
-     * usage: echo EEH_HTML::h4( 'This is a Heading' );
238
-     *
239
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
240
-     * @param string $id               - html id attribute
241
-     * @param string $class            - html class attribute
242
-     * @param string $style            - html style attribute for applying inline styles
243
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
244
-     * @return string
245
-     */
246
-    public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
247
-    {
248
-        return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true);
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes
255
-     * usage: echo EEH_HTML::h5( 'This is a Heading' );
256
-     *
257
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
258
-     * @param string $id               - html id attribute
259
-     * @param string $class            - html class attribute
260
-     * @param string $style            - html style attribute for applying inline styles
261
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
262
-     * @return string
263
-     */
264
-    public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
265
-    {
266
-        return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true);
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes
273
-     * usage: echo EEH_HTML::h6( 'This is a Heading' );
274
-     *
275
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
276
-     * @param string $id               - html id attribute
277
-     * @param string $class            - html class attribute
278
-     * @param string $style            - html style attribute for applying inline styles
279
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
280
-     * @return string
281
-     */
282
-    public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
283
-    {
284
-        return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true);
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Generates HTML <p></p> tags, inserts content, and adds any passed attributes
291
-     * usage: echo EEH_HTML::p( 'this is a paragraph' );
292
-     *
293
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
294
-     * @param string $id - html id attribute
295
-     * @param string $class - html class attribute
296
-     * @param string $style - html style attribute for applying inline styles
297
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
298
-     * @return string
299
-     */
300
-    public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
301
-    {
302
-        return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true);
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     *  ul - generates HTML opening <ul> tag and adds any passed attributes
309
-     *  usage:      echo EEH_HTML::ul( 'my-list-id', 'my-list-class' );
310
-     *
311
-     * @param string $id - html id attribute
312
-     * @param string $class - html class attribute
313
-     * @param string $style - html style attribute for applying inline styles
314
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
315
-     * @return string
316
-     */
317
-    public static function ul($id = '', $class = '', $style = '', $other_attributes = '')
318
-    {
319
-        return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes);
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
326
-     * usage: echo EEH_HTML::ulx();
327
-     *
328
-     * @param string $id - html id attribute
329
-     * @param string $class - html class attribute
330
-     * @return string
331
-     */
332
-    public static function ulx($id = '', $class = '')
333
-    {
334
-        return EEH_HTML::_close_tag('ul', $id, $class);
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * Generates HTML <li> tag, inserts content, and adds any passed attributes
341
-     * if passed content, it will also add that, as well as the closing </li> tag
342
-     * usage: echo EEH_HTML::li( 'this is a line item' );
343
-     *
344
-     * @param string $id - html id attribute
345
-     * @param string $class - html class attribute
346
-     * @param string $style - html style attribute for applying inline styles
347
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
348
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
349
-     * @return string
350
-     */
351
-    public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
352
-    {
353
-        return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
360
-     * usage: echo EEH_HTML::lix();
361
-     *
362
-     * @param string $id - html id attribute
363
-     * @param string $class - html class attribute
364
-     * @return string
365
-     */
366
-    public static function lix($id = '', $class = '')
367
-    {
368
-        return EEH_HTML::_close_tag('li', $id, $class);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     *    table - generates an HTML <table> tag and adds any passed attributes
375
-     *    usage: echo EEH_HTML::table();
376
-     *
377
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
378
-     * @param string $id - html id attribute
379
-     * @param string $class - html class attribute
380
-     * @param string $style - html style attribute for applying inline styles
381
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
382
-     * @return string
383
-     */
384
-    public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
385
-    {
386
-        return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes);
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
393
-     *
394
-     * @param string $id - html id attribute
395
-     * @param string $class - html class attribute
396
-     * @return string
397
-     */
398
-    public static function tablex($id = '', $class = '')
399
-    {
400
-        return EEH_HTML::_close_tag('table', $id, $class);
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     *    thead - generates an HTML <thead> tag and adds any passed attributes
407
-     *    usage: echo EEH_HTML::thead();
408
-     *
409
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
410
-     * @param string $id - html id attribute
411
-     * @param string $class - html class attribute
412
-     * @param string $style - html style attribute for applying inline styles
413
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
414
-     * @return string
415
-     */
416
-    public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
417
-    {
418
-        return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes);
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
425
-     *
426
-     * @param string $id - html id attribute
427
-     * @param string $class - html class attribute
428
-     * @return string
429
-     */
430
-    public static function theadx($id = '', $class = '')
431
-    {
432
-        return EEH_HTML::_close_tag('thead', $id, $class);
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     *    tbody - generates an HTML <tbody> tag and adds any passed attributes
439
-     *    usage: echo EEH_HTML::tbody();
440
-     *
441
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
442
-     * @param string $id - html id attribute
443
-     * @param string $class - html class attribute
444
-     * @param string $style - html style attribute for applying inline styles
445
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
446
-     * @return string
447
-     */
448
-    public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
449
-    {
450
-        return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes);
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
457
-     *
458
-     * @param string $id - html id attribute
459
-     * @param string $class - html class attribute
460
-     * @return string
461
-     */
462
-    public static function tbodyx($id = '', $class = '')
463
-    {
464
-        return EEH_HTML::_close_tag('tbody', $id, $class);
465
-    }
466
-
467
-
468
-
469
-    /**
470
-     *    tr - generates an HTML <tr> tag and adds any passed attributes
471
-     *    usage: echo EEH_HTML::tr();
472
-     *
473
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
474
-     * @param string $id - html id attribute
475
-     * @param string $class - html class attribute
476
-     * @param string $style - html style attribute for applying inline styles
477
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
478
-     * @return string
479
-     */
480
-    public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
481
-    {
482
-        return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes);
483
-    }
484
-
485
-
486
-
487
-    /**
488
-     * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
489
-     *
490
-     * @param string $id - html id attribute
491
-     * @param string $class - html class attribute
492
-     * @return string
493
-     */
494
-    public static function trx($id = '', $class = '')
495
-    {
496
-        return EEH_HTML::_close_tag('tr', $id, $class);
497
-    }
498
-
499
-
500
-
501
-    /**
502
-     *    th - generates an HTML <th> tag and adds any passed attributes
503
-     *    usage: echo EEH_HTML::th();
504
-     *
505
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
506
-     * @param string $id - html id attribute
507
-     * @param string $class - html class attribute
508
-     * @param string $style - html style attribute for applying inline styles
509
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
510
-     * @return string
511
-     */
512
-    public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
513
-    {
514
-        return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes);
515
-    }
516
-
517
-
518
-
519
-    /**
520
-     * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
521
-     *
522
-     * @param string $id - html id attribute
523
-     * @param string $class - html class attribute
524
-     * @return string
525
-     */
526
-    public static function thx($id = '', $class = '')
527
-    {
528
-        return EEH_HTML::_close_tag('th', $id, $class);
529
-    }
530
-
531
-
532
-
533
-    /**
534
-     *    td - generates an HTML <td> tag and adds any passed attributes
535
-     *    usage: echo EEH_HTML::td();
536
-     *
537
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
538
-     * @param string $id - html id attribute
539
-     * @param string $class - html class attribute
540
-     * @param string $style - html style attribute for applying inline styles
541
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
542
-     * @return string
543
-     */
544
-    public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
545
-    {
546
-        return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes);
547
-    }
548
-
549
-
550
-
551
-    /**
552
-     * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
553
-     *
554
-     * @param string $id - html id attribute
555
-     * @param string $class - html class attribute
556
-     * @return string
557
-     */
558
-    public static function tdx($id = '', $class = '')
559
-    {
560
-        return EEH_HTML::_close_tag('td', $id, $class);
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     * no_row - for generating a "hidden" table row, good for embedding tables within tables
567
-     * generates a new table row with one td cell that spans however many columns you set
568
-     * removes all styles from the tr and td
569
-     *
570
-     * @param string $content
571
-     * @param int    $colspan
572
-     * @return string
573
-     */
574
-    public static function no_row($content = '', $colspan = 2)
575
-    {
576
-        return EEH_HTML::tr(
577
-            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
578
-            '',
579
-            '',
580
-            'padding:0; border:none;'
581
-        );
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
588
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
589
-     *
590
-     * @access public
591
-     * @param string $href URL to link to
592
-     * @param string $link_text - the text that will become "hyperlinked"
593
-     * @param string $title - html title attribute
594
-     * @param string $id - html id attribute
595
-     * @param string $class - html class attribute
596
-     * @param string $style - html style attribute for applying inline styles
597
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
598
-     * @return string
599
-     */
600
-    public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
601
-    {
602
-        $link_text = ! empty($link_text) ? $link_text : $href;
603
-        $attributes = ! empty($href) ? ' href="' . $href . '"' : '';
604
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
605
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
606
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
607
-        $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
608
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
609
-        return "<a{$attributes}>{$link_text}</a>";
610
-    }
611
-
612
-
613
-
614
-    /**
615
-     *    img - generates an HTML <img> tag and adds any passed attributes
616
-     *    usage: echo EEH_HTML::img();
617
-     *
618
-     * @param string $src - html src attribute ie: the path or URL to the image
619
-     * @param string $alt - html alt attribute
620
-     * @param string $id - html id attribute
621
-     * @param string $class - html class attribute
622
-     * @param string $style - html style attribute for applying inline styles
623
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
624
-     * @return string
625
-     */
626
-    public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
627
-    {
628
-        $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
629
-        $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
630
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
631
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
632
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
633
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
634
-        return '<img' . $attributes  . '/>';
635
-    }
636
-
637
-
638
-
639
-    /**
640
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
641
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
642
-     *
643
-     * @access protected
644
-     * @param string $tag
645
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
646
-     * @param string $id - html id attribute
647
-     * @param string $class - html class attribute
648
-     * @param string $style - html style attribute for applying inline styles
649
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
650
-     * @return string
651
-     */
652
-    protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
653
-    {
654
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
655
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
656
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
657
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
658
-        return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
665
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
666
-     *
667
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
668
-     * @param string $id - html id attribute
669
-     * @param string $class - html class attribute
670
-     * @param string $style - html style attribute for applying inline styles
671
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
672
-     * @return string
673
-     */
674
-    public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
675
-    {
676
-        return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes);
677
-    }
678
-
679
-
680
-
681
-    /**
682
-     * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
683
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
684
-     *
685
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
686
-     * @param string $id - html id attribute
687
-     * @param string $class - html class attribute
688
-     * @param string $style - html style attribute for applying inline styles
689
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
690
-     * @return string
691
-     */
692
-    public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
693
-    {
694
-        return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes);
695
-    }
696
-
697
-
698
-
699
-    /**
700
-     * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
701
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
702
-     *
703
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
704
-     * @param string $id - html id attribute
705
-     * @param string $class - html class attribute
706
-     * @param string $style - html style attribute for applying inline styles
707
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
708
-     * @return string
709
-     */
710
-    public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
711
-    {
712
-        return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes);
713
-    }
714
-
715
-
716
-
717
-    /**
718
-     * Generates an html <--  comment --> tag
719
-     *  usage: echo comment( 'this is a comment' );
720
-     *
721
-     * @param string $comment
722
-     * @return string
723
-     */
724
-    public static function comment($comment = '')
725
-    {
726
-        return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
727
-    }
728
-
729
-
730
-
731
-    /**
732
-     * br - generates a line break
733
-     *
734
-     * @param int $nmbr - the number of line breaks to return
735
-     * @return string
736
-     */
737
-    public static function br($nmbr = 1)
738
-    {
739
-        return str_repeat('<br />', $nmbr);
740
-    }
741
-
742
-
743
-
744
-    /**
745
-     * nbsp - generates non-breaking space entities based on number supplied
746
-     *
747
-     * @param int $nmbr - the number of non-breaking spaces to return
748
-     * @return string
749
-     */
750
-    public static function nbsp($nmbr = 1)
751
-    {
752
-        return str_repeat('&nbsp;', $nmbr);
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * sanitize_id
759
-     *
760
-     * functionally does the same as the wp_core function sanitize_key except it does NOT use
761
-     * strtolower and allows capitals.
762
-     *
763
-     * @param string $id
764
-     * @return string
765
-     */
766
-    public static function sanitize_id($id = '')
767
-    {
768
-        $key = str_replace(' ', '-', trim($id));
769
-        return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
770
-    }
771
-
772
-
773
-
774
-    /**
775
-     * return a newline and tabs ("nl" stands for "new line")
776
-     *
777
-     * @param int    $indent the number of tabs to ADD to the current indent (can be negative or zero)
778
-     * @param string $tag
779
-     * @return string - newline character plus # of indents passed (can be + or -)
780
-     */
781
-    public static function nl($indent = 0, $tag = 'none')
782
-    {
783
-        $html = "\n";
784
-        EEH_HTML::indent($indent, $tag);
785
-        for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
786
-            $html .= "\t";
787
-        }
788
-        return $html;
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     * Changes the indents used in EEH_HTML::nl. Often its convenient to change
795
-     * the indentation level without actually creating a new line
796
-     *
797
-     * @param int    $indent can be negative to decrease the indentation level
798
-     * @param string $tag
799
-     */
800
-    public static function indent($indent, $tag = 'none')
801
-    {
802
-        static $default_indentation = false;
803
-        if (! $default_indentation) {
804
-            EEH_HTML::_set_default_indentation();
805
-            $default_indentation = true;
806
-        }
807
-        if (! isset(EEH_HTML::$_indent[ $tag ])) {
808
-            EEH_HTML::$_indent[ $tag ] = 0;
809
-        }
810
-        EEH_HTML::$_indent[ $tag ] += (int) $indent;
811
-        EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
812
-    }
813
-
814
-
815
-    /**
816
-     *  class _set_default_indentation
817
-     *
818
-     * @access    private
819
-     */
820
-    private static function _set_default_indentation()
821
-    {
822
-        // set some initial formatting for table indentation
823
-        EEH_HTML::$_indent = array(
824
-            'none'  => 0,
825
-            'form'  => 0,
826
-            'radio'     => 0,
827
-            'checkbox'  => 0,
828
-            'select'    => 0,
829
-            'option' => 0,
830
-            'optgroup' => 0,
831
-            'table'     => 1,
832
-            'thead' => 2,
833
-            'tbody' => 2,
834
-            'tr'    => 3,
835
-            'th'    => 4,
836
-            'td'    => 4,
837
-            'div'   => 0,
838
-            'h1'    => 0,
839
-            'h2'    => 0,
840
-            'h3'    => 0,
841
-            'h4'    => 0,
842
-            'h5'    => 0,
843
-            'h6'    => 0,
844
-            'p'     => 0,
845
-            'ul'    => 0,
846
-            'li'    => 1
847
-        );
848
-    }
849
-
850
-
851
-
852
-    /**
853
-     * Retrieves the list of tags considered "simple", that are probably safe for
854
-     * use in inputs
855
-     * @global array $allowedtags
856
-     * @return array
857
-     */
858
-    public static function get_simple_tags()
859
-    {
860
-        global $allowedtags;
861
-        $tags_we_allow['p']=array();
862
-        $tags_we_allow = array_merge_recursive(
863
-            $allowedtags,
864
-            array(
865
-                'ol' => array(),
866
-                'ul' => array(),
867
-                'li' => array(),
868
-                'br' => array(),
869
-                'p' => array(),
870
-                'a' => array('target')
871
-            )
872
-        );
873
-        return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow);
874
-    }
125
+	 * @param string $tag
126
+	 * @param string $id - html id attribute
127
+	 * @param string $class - html class attribute
128
+	 * @param bool   $indent
129
+	 * @return string
130
+	 */
131
+	protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true)
132
+	{
133
+		$comment = '';
134
+		if ($id) {
135
+			$comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
136
+		} elseif ($class) {
137
+			$comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
138
+		}
139
+		$html = $indent ? EEH_HTML::nl(-1, $tag) : '';
140
+		$html .= '</' . $tag . '>' . $comment;
141
+		return $html;
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *  div - generates HTML opening <div> tag and adds any passed attributes
148
+	 *  to add an id use:       echo EEH_HTML::div( 'this is some content', 'footer' );
149
+	 *  to add a class use:     echo EEH_HTML::div( 'this is some content', '', 'float_left' );
150
+	 *  to add a both an id and a class use:    echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' );
151
+	 *
152
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
153
+	 * @param string $id - html id attribute
154
+	 * @param string $class - html class attribute
155
+	 * @param string $style - html style attribute for applying inline styles
156
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
157
+	 * @return string
158
+	 */
159
+	public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
160
+	{
161
+		return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes);
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment
168
+	 * usage: echo EEH_HTML::divx();
169
+	 *
170
+	 * @param string $id - html id attribute
171
+	 * @param string $class - html class attribute
172
+	 * @return string
173
+	 */
174
+	public static function divx($id = '', $class = '')
175
+	{
176
+		return EEH_HTML::_close_tag('div', $id, $class);
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes
183
+	 * usage: echo EEH_HTML::h1( 'This is a Heading' );
184
+	 *
185
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
186
+	 * @param string $id - html id attribute
187
+	 * @param string $class - html class attribute
188
+	 * @param string $style - html style attribute for applying inline styles
189
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
190
+	 * @return string
191
+	 */
192
+	public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
193
+	{
194
+		return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true);
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes
201
+	 * usage: echo EEH_HTML::h2( 'This is a Heading' );
202
+	 *
203
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
204
+	 * @param string $id               - html id attribute
205
+	 * @param string $class            - html class attribute
206
+	 * @param string $style            - html style attribute for applying inline styles
207
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
208
+	 * @return string
209
+	 */
210
+	public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
211
+	{
212
+		return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes
219
+	 * usage: echo EEH_HTML::h3( 'This is a Heading' );
220
+	 *
221
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
222
+	 * @param string $id               - html id attribute
223
+	 * @param string $class            - html class attribute
224
+	 * @param string $style            - html style attribute for applying inline styles
225
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
226
+	 * @return string
227
+	 */
228
+	public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
229
+	{
230
+		return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true);
231
+	}
232
+
233
+
234
+
235
+	/**
236
+	 * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes
237
+	 * usage: echo EEH_HTML::h4( 'This is a Heading' );
238
+	 *
239
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
240
+	 * @param string $id               - html id attribute
241
+	 * @param string $class            - html class attribute
242
+	 * @param string $style            - html style attribute for applying inline styles
243
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
244
+	 * @return string
245
+	 */
246
+	public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
247
+	{
248
+		return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true);
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes
255
+	 * usage: echo EEH_HTML::h5( 'This is a Heading' );
256
+	 *
257
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
258
+	 * @param string $id               - html id attribute
259
+	 * @param string $class            - html class attribute
260
+	 * @param string $style            - html style attribute for applying inline styles
261
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
262
+	 * @return string
263
+	 */
264
+	public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
265
+	{
266
+		return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes
273
+	 * usage: echo EEH_HTML::h6( 'This is a Heading' );
274
+	 *
275
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
276
+	 * @param string $id               - html id attribute
277
+	 * @param string $class            - html class attribute
278
+	 * @param string $style            - html style attribute for applying inline styles
279
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
280
+	 * @return string
281
+	 */
282
+	public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
283
+	{
284
+		return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true);
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * Generates HTML <p></p> tags, inserts content, and adds any passed attributes
291
+	 * usage: echo EEH_HTML::p( 'this is a paragraph' );
292
+	 *
293
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
294
+	 * @param string $id - html id attribute
295
+	 * @param string $class - html class attribute
296
+	 * @param string $style - html style attribute for applying inline styles
297
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
298
+	 * @return string
299
+	 */
300
+	public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
301
+	{
302
+		return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true);
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 *  ul - generates HTML opening <ul> tag and adds any passed attributes
309
+	 *  usage:      echo EEH_HTML::ul( 'my-list-id', 'my-list-class' );
310
+	 *
311
+	 * @param string $id - html id attribute
312
+	 * @param string $class - html class attribute
313
+	 * @param string $style - html style attribute for applying inline styles
314
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
315
+	 * @return string
316
+	 */
317
+	public static function ul($id = '', $class = '', $style = '', $other_attributes = '')
318
+	{
319
+		return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes);
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
326
+	 * usage: echo EEH_HTML::ulx();
327
+	 *
328
+	 * @param string $id - html id attribute
329
+	 * @param string $class - html class attribute
330
+	 * @return string
331
+	 */
332
+	public static function ulx($id = '', $class = '')
333
+	{
334
+		return EEH_HTML::_close_tag('ul', $id, $class);
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * Generates HTML <li> tag, inserts content, and adds any passed attributes
341
+	 * if passed content, it will also add that, as well as the closing </li> tag
342
+	 * usage: echo EEH_HTML::li( 'this is a line item' );
343
+	 *
344
+	 * @param string $id - html id attribute
345
+	 * @param string $class - html class attribute
346
+	 * @param string $style - html style attribute for applying inline styles
347
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
348
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
349
+	 * @return string
350
+	 */
351
+	public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
352
+	{
353
+		return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
360
+	 * usage: echo EEH_HTML::lix();
361
+	 *
362
+	 * @param string $id - html id attribute
363
+	 * @param string $class - html class attribute
364
+	 * @return string
365
+	 */
366
+	public static function lix($id = '', $class = '')
367
+	{
368
+		return EEH_HTML::_close_tag('li', $id, $class);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 *    table - generates an HTML <table> tag and adds any passed attributes
375
+	 *    usage: echo EEH_HTML::table();
376
+	 *
377
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
378
+	 * @param string $id - html id attribute
379
+	 * @param string $class - html class attribute
380
+	 * @param string $style - html style attribute for applying inline styles
381
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
382
+	 * @return string
383
+	 */
384
+	public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
385
+	{
386
+		return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes);
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
393
+	 *
394
+	 * @param string $id - html id attribute
395
+	 * @param string $class - html class attribute
396
+	 * @return string
397
+	 */
398
+	public static function tablex($id = '', $class = '')
399
+	{
400
+		return EEH_HTML::_close_tag('table', $id, $class);
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 *    thead - generates an HTML <thead> tag and adds any passed attributes
407
+	 *    usage: echo EEH_HTML::thead();
408
+	 *
409
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
410
+	 * @param string $id - html id attribute
411
+	 * @param string $class - html class attribute
412
+	 * @param string $style - html style attribute for applying inline styles
413
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
414
+	 * @return string
415
+	 */
416
+	public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
417
+	{
418
+		return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes);
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
425
+	 *
426
+	 * @param string $id - html id attribute
427
+	 * @param string $class - html class attribute
428
+	 * @return string
429
+	 */
430
+	public static function theadx($id = '', $class = '')
431
+	{
432
+		return EEH_HTML::_close_tag('thead', $id, $class);
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 *    tbody - generates an HTML <tbody> tag and adds any passed attributes
439
+	 *    usage: echo EEH_HTML::tbody();
440
+	 *
441
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
442
+	 * @param string $id - html id attribute
443
+	 * @param string $class - html class attribute
444
+	 * @param string $style - html style attribute for applying inline styles
445
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
446
+	 * @return string
447
+	 */
448
+	public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
449
+	{
450
+		return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
457
+	 *
458
+	 * @param string $id - html id attribute
459
+	 * @param string $class - html class attribute
460
+	 * @return string
461
+	 */
462
+	public static function tbodyx($id = '', $class = '')
463
+	{
464
+		return EEH_HTML::_close_tag('tbody', $id, $class);
465
+	}
466
+
467
+
468
+
469
+	/**
470
+	 *    tr - generates an HTML <tr> tag and adds any passed attributes
471
+	 *    usage: echo EEH_HTML::tr();
472
+	 *
473
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
474
+	 * @param string $id - html id attribute
475
+	 * @param string $class - html class attribute
476
+	 * @param string $style - html style attribute for applying inline styles
477
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
478
+	 * @return string
479
+	 */
480
+	public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
481
+	{
482
+		return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes);
483
+	}
484
+
485
+
486
+
487
+	/**
488
+	 * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
489
+	 *
490
+	 * @param string $id - html id attribute
491
+	 * @param string $class - html class attribute
492
+	 * @return string
493
+	 */
494
+	public static function trx($id = '', $class = '')
495
+	{
496
+		return EEH_HTML::_close_tag('tr', $id, $class);
497
+	}
498
+
499
+
500
+
501
+	/**
502
+	 *    th - generates an HTML <th> tag and adds any passed attributes
503
+	 *    usage: echo EEH_HTML::th();
504
+	 *
505
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
506
+	 * @param string $id - html id attribute
507
+	 * @param string $class - html class attribute
508
+	 * @param string $style - html style attribute for applying inline styles
509
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
510
+	 * @return string
511
+	 */
512
+	public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
513
+	{
514
+		return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes);
515
+	}
516
+
517
+
518
+
519
+	/**
520
+	 * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
521
+	 *
522
+	 * @param string $id - html id attribute
523
+	 * @param string $class - html class attribute
524
+	 * @return string
525
+	 */
526
+	public static function thx($id = '', $class = '')
527
+	{
528
+		return EEH_HTML::_close_tag('th', $id, $class);
529
+	}
530
+
531
+
532
+
533
+	/**
534
+	 *    td - generates an HTML <td> tag and adds any passed attributes
535
+	 *    usage: echo EEH_HTML::td();
536
+	 *
537
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
538
+	 * @param string $id - html id attribute
539
+	 * @param string $class - html class attribute
540
+	 * @param string $style - html style attribute for applying inline styles
541
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
542
+	 * @return string
543
+	 */
544
+	public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
545
+	{
546
+		return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes);
547
+	}
548
+
549
+
550
+
551
+	/**
552
+	 * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
553
+	 *
554
+	 * @param string $id - html id attribute
555
+	 * @param string $class - html class attribute
556
+	 * @return string
557
+	 */
558
+	public static function tdx($id = '', $class = '')
559
+	{
560
+		return EEH_HTML::_close_tag('td', $id, $class);
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 * no_row - for generating a "hidden" table row, good for embedding tables within tables
567
+	 * generates a new table row with one td cell that spans however many columns you set
568
+	 * removes all styles from the tr and td
569
+	 *
570
+	 * @param string $content
571
+	 * @param int    $colspan
572
+	 * @return string
573
+	 */
574
+	public static function no_row($content = '', $colspan = 2)
575
+	{
576
+		return EEH_HTML::tr(
577
+			EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
578
+			'',
579
+			'',
580
+			'padding:0; border:none;'
581
+		);
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
588
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
589
+	 *
590
+	 * @access public
591
+	 * @param string $href URL to link to
592
+	 * @param string $link_text - the text that will become "hyperlinked"
593
+	 * @param string $title - html title attribute
594
+	 * @param string $id - html id attribute
595
+	 * @param string $class - html class attribute
596
+	 * @param string $style - html style attribute for applying inline styles
597
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
598
+	 * @return string
599
+	 */
600
+	public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
601
+	{
602
+		$link_text = ! empty($link_text) ? $link_text : $href;
603
+		$attributes = ! empty($href) ? ' href="' . $href . '"' : '';
604
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
605
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
606
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
607
+		$attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
608
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
609
+		return "<a{$attributes}>{$link_text}</a>";
610
+	}
611
+
612
+
613
+
614
+	/**
615
+	 *    img - generates an HTML <img> tag and adds any passed attributes
616
+	 *    usage: echo EEH_HTML::img();
617
+	 *
618
+	 * @param string $src - html src attribute ie: the path or URL to the image
619
+	 * @param string $alt - html alt attribute
620
+	 * @param string $id - html id attribute
621
+	 * @param string $class - html class attribute
622
+	 * @param string $style - html style attribute for applying inline styles
623
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
624
+	 * @return string
625
+	 */
626
+	public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
627
+	{
628
+		$attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
629
+		$attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
630
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
631
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
632
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
633
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
634
+		return '<img' . $attributes  . '/>';
635
+	}
636
+
637
+
638
+
639
+	/**
640
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
641
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
642
+	 *
643
+	 * @access protected
644
+	 * @param string $tag
645
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
646
+	 * @param string $id - html id attribute
647
+	 * @param string $class - html class attribute
648
+	 * @param string $style - html style attribute for applying inline styles
649
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
650
+	 * @return string
651
+	 */
652
+	protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
653
+	{
654
+		$attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
655
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
656
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
657
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
658
+		return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
665
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
666
+	 *
667
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
668
+	 * @param string $id - html id attribute
669
+	 * @param string $class - html class attribute
670
+	 * @param string $style - html style attribute for applying inline styles
671
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
672
+	 * @return string
673
+	 */
674
+	public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
675
+	{
676
+		return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes);
677
+	}
678
+
679
+
680
+
681
+	/**
682
+	 * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
683
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
684
+	 *
685
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
686
+	 * @param string $id - html id attribute
687
+	 * @param string $class - html class attribute
688
+	 * @param string $style - html style attribute for applying inline styles
689
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
690
+	 * @return string
691
+	 */
692
+	public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
693
+	{
694
+		return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes);
695
+	}
696
+
697
+
698
+
699
+	/**
700
+	 * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
701
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
702
+	 *
703
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
704
+	 * @param string $id - html id attribute
705
+	 * @param string $class - html class attribute
706
+	 * @param string $style - html style attribute for applying inline styles
707
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
708
+	 * @return string
709
+	 */
710
+	public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
711
+	{
712
+		return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes);
713
+	}
714
+
715
+
716
+
717
+	/**
718
+	 * Generates an html <--  comment --> tag
719
+	 *  usage: echo comment( 'this is a comment' );
720
+	 *
721
+	 * @param string $comment
722
+	 * @return string
723
+	 */
724
+	public static function comment($comment = '')
725
+	{
726
+		return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
727
+	}
728
+
729
+
730
+
731
+	/**
732
+	 * br - generates a line break
733
+	 *
734
+	 * @param int $nmbr - the number of line breaks to return
735
+	 * @return string
736
+	 */
737
+	public static function br($nmbr = 1)
738
+	{
739
+		return str_repeat('<br />', $nmbr);
740
+	}
741
+
742
+
743
+
744
+	/**
745
+	 * nbsp - generates non-breaking space entities based on number supplied
746
+	 *
747
+	 * @param int $nmbr - the number of non-breaking spaces to return
748
+	 * @return string
749
+	 */
750
+	public static function nbsp($nmbr = 1)
751
+	{
752
+		return str_repeat('&nbsp;', $nmbr);
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * sanitize_id
759
+	 *
760
+	 * functionally does the same as the wp_core function sanitize_key except it does NOT use
761
+	 * strtolower and allows capitals.
762
+	 *
763
+	 * @param string $id
764
+	 * @return string
765
+	 */
766
+	public static function sanitize_id($id = '')
767
+	{
768
+		$key = str_replace(' ', '-', trim($id));
769
+		return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
770
+	}
771
+
772
+
773
+
774
+	/**
775
+	 * return a newline and tabs ("nl" stands for "new line")
776
+	 *
777
+	 * @param int    $indent the number of tabs to ADD to the current indent (can be negative or zero)
778
+	 * @param string $tag
779
+	 * @return string - newline character plus # of indents passed (can be + or -)
780
+	 */
781
+	public static function nl($indent = 0, $tag = 'none')
782
+	{
783
+		$html = "\n";
784
+		EEH_HTML::indent($indent, $tag);
785
+		for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
786
+			$html .= "\t";
787
+		}
788
+		return $html;
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 * Changes the indents used in EEH_HTML::nl. Often its convenient to change
795
+	 * the indentation level without actually creating a new line
796
+	 *
797
+	 * @param int    $indent can be negative to decrease the indentation level
798
+	 * @param string $tag
799
+	 */
800
+	public static function indent($indent, $tag = 'none')
801
+	{
802
+		static $default_indentation = false;
803
+		if (! $default_indentation) {
804
+			EEH_HTML::_set_default_indentation();
805
+			$default_indentation = true;
806
+		}
807
+		if (! isset(EEH_HTML::$_indent[ $tag ])) {
808
+			EEH_HTML::$_indent[ $tag ] = 0;
809
+		}
810
+		EEH_HTML::$_indent[ $tag ] += (int) $indent;
811
+		EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
812
+	}
813
+
814
+
815
+	/**
816
+	 *  class _set_default_indentation
817
+	 *
818
+	 * @access    private
819
+	 */
820
+	private static function _set_default_indentation()
821
+	{
822
+		// set some initial formatting for table indentation
823
+		EEH_HTML::$_indent = array(
824
+			'none'  => 0,
825
+			'form'  => 0,
826
+			'radio'     => 0,
827
+			'checkbox'  => 0,
828
+			'select'    => 0,
829
+			'option' => 0,
830
+			'optgroup' => 0,
831
+			'table'     => 1,
832
+			'thead' => 2,
833
+			'tbody' => 2,
834
+			'tr'    => 3,
835
+			'th'    => 4,
836
+			'td'    => 4,
837
+			'div'   => 0,
838
+			'h1'    => 0,
839
+			'h2'    => 0,
840
+			'h3'    => 0,
841
+			'h4'    => 0,
842
+			'h5'    => 0,
843
+			'h6'    => 0,
844
+			'p'     => 0,
845
+			'ul'    => 0,
846
+			'li'    => 1
847
+		);
848
+	}
849
+
850
+
851
+
852
+	/**
853
+	 * Retrieves the list of tags considered "simple", that are probably safe for
854
+	 * use in inputs
855
+	 * @global array $allowedtags
856
+	 * @return array
857
+	 */
858
+	public static function get_simple_tags()
859
+	{
860
+		global $allowedtags;
861
+		$tags_we_allow['p']=array();
862
+		$tags_we_allow = array_merge_recursive(
863
+			$allowedtags,
864
+			array(
865
+				'ol' => array(),
866
+				'ul' => array(),
867
+				'li' => array(),
868
+				'br' => array(),
869
+				'p' => array(),
870
+				'a' => array('target')
871
+			)
872
+		);
873
+		return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow);
874
+	}
875 875
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public static function instance()
43 43
     {
44 44
         // check if class object is instantiated, and instantiated properly
45
-        if (! self::$_instance instanceof EEH_HTML) {
45
+        if ( ! self::$_instance instanceof EEH_HTML) {
46 46
             self::$_instance = new EEH_HTML();
47 47
         }
48 48
         return self::$_instance;
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
         $other_attributes = '',
105 105
         $force_close = false
106 106
     ) {
107
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
108
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
109
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
110
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
111
-        $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
112
-        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
107
+        $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
108
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
109
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
110
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
111
+        $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>';
112
+        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : '';
113 113
         $indent = ! empty($content) || $force_close ? true : false;
114 114
         $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
115 115
         return $html;
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
     {
133 133
         $comment = '';
134 134
         if ($id) {
135
-            $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
135
+            $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag);
136 136
         } elseif ($class) {
137
-            $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
137
+            $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag);
138 138
         }
139 139
         $html = $indent ? EEH_HTML::nl(-1, $tag) : '';
140
-        $html .= '</' . $tag . '>' . $comment;
140
+        $html .= '</'.$tag.'>'.$comment;
141 141
         return $html;
142 142
     }
143 143
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
     public static function no_row($content = '', $colspan = 2)
575 575
     {
576 576
         return EEH_HTML::tr(
577
-            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
577
+            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'),
578 578
             '',
579 579
             '',
580 580
             'padding:0; border:none;'
@@ -600,12 +600,12 @@  discard block
 block discarded – undo
600 600
     public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
601 601
     {
602 602
         $link_text = ! empty($link_text) ? $link_text : $href;
603
-        $attributes = ! empty($href) ? ' href="' . $href . '"' : '';
604
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
605
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
606
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
607
-        $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
608
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
603
+        $attributes = ! empty($href) ? ' href="'.$href.'"' : '';
604
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
605
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
606
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
607
+        $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : '';
608
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
609 609
         return "<a{$attributes}>{$link_text}</a>";
610 610
     }
611 611
 
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
      */
626 626
     public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
627 627
     {
628
-        $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
629
-        $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
630
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
631
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
632
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
633
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
634
-        return '<img' . $attributes  . '/>';
628
+        $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : '';
629
+        $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : '';
630
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
631
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
632
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
633
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
634
+        return '<img'.$attributes.'/>';
635 635
     }
636 636
 
637 637
 
@@ -651,11 +651,11 @@  discard block
 block discarded – undo
651 651
      */
652 652
     protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
653 653
     {
654
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
655
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
656
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
657
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
658
-        return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
654
+        $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
655
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
656
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
657
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
658
+        return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>';
659 659
     }
660 660
 
661 661
 
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
      */
724 724
     public static function comment($comment = '')
725 725
     {
726
-        return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
726
+        return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : '';
727 727
     }
728 728
 
729 729
 
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
     {
783 783
         $html = "\n";
784 784
         EEH_HTML::indent($indent, $tag);
785
-        for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
785
+        for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) {
786 786
             $html .= "\t";
787 787
         }
788 788
         return $html;
@@ -800,15 +800,15 @@  discard block
 block discarded – undo
800 800
     public static function indent($indent, $tag = 'none')
801 801
     {
802 802
         static $default_indentation = false;
803
-        if (! $default_indentation) {
803
+        if ( ! $default_indentation) {
804 804
             EEH_HTML::_set_default_indentation();
805 805
             $default_indentation = true;
806 806
         }
807
-        if (! isset(EEH_HTML::$_indent[ $tag ])) {
808
-            EEH_HTML::$_indent[ $tag ] = 0;
807
+        if ( ! isset(EEH_HTML::$_indent[$tag])) {
808
+            EEH_HTML::$_indent[$tag] = 0;
809 809
         }
810
-        EEH_HTML::$_indent[ $tag ] += (int) $indent;
811
-        EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
810
+        EEH_HTML::$_indent[$tag] += (int) $indent;
811
+        EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0;
812 812
     }
813 813
 
814 814
 
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
     public static function get_simple_tags()
859 859
     {
860 860
         global $allowedtags;
861
-        $tags_we_allow['p']=array();
861
+        $tags_we_allow['p'] = array();
862 862
         $tags_we_allow = array_merge_recursive(
863 863
             $allowedtags,
864 864
             array(
Please login to merge, or discard this patch.