Completed
Branch master (2441b9)
by
unknown
34:00 queued 27:57
created
espresso.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -37,138 +37,138 @@
 block discarded – undo
37 37
  * @since       4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time.
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time.
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
 <div class="error">
49 49
     <p>
50 50
         <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
     </p>
56 56
 </div>
57 57
 <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '7.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
 <div class="error">
74 74
     <p>
75 75
         <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. 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.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
-                    );
86
-        ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. 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.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>'
85
+					);
86
+		?>
87 87
     </p>
88 88
 </div>
89 89
 <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96 96
 
97
-        require_once __DIR__ . '/vendor/autoload.php';
97
+		require_once __DIR__ . '/vendor/autoload.php';
98 98
 
99
-        /**
100
-         * espresso_version
101
-         * Returns the plugin version
102
-         *
103
-         * @return string
104
-         */
105
-        function espresso_version(): string
106
-        {
107
-            return apply_filters('FHEE__espresso__espresso_version', '5.0.37.rc.000');
108
-        }
99
+		/**
100
+		 * espresso_version
101
+		 * Returns the plugin version
102
+		 *
103
+		 * @return string
104
+		 */
105
+		function espresso_version(): string
106
+		{
107
+			return apply_filters('FHEE__espresso__espresso_version', '5.0.37.rc.000');
108
+		}
109 109
 
110
-        /**
111
-         * espresso_plugin_activation
112
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
-         */
114
-        function espresso_plugin_activation()
115
-        {
116
-            update_option('ee_espresso_activation', true);
117
-            update_option('event-espresso-core_allow_tracking', 'no');
118
-            update_option('event-espresso-core_tracking_notice', 'hide');
119
-            // Run WP GraphQL activation callback
120
-            espressoLoadWpGraphQL();
121
-            graphql_activation_callback();
122
-        }
110
+		/**
111
+		 * espresso_plugin_activation
112
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
113
+		 */
114
+		function espresso_plugin_activation()
115
+		{
116
+			update_option('ee_espresso_activation', true);
117
+			update_option('event-espresso-core_allow_tracking', 'no');
118
+			update_option('event-espresso-core_tracking_notice', 'hide');
119
+			// Run WP GraphQL activation callback
120
+			espressoLoadWpGraphQL();
121
+			graphql_activation_callback();
122
+		}
123 123
 
124
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
124
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
125 125
 
126
-        /**
127
-         * espresso_plugin_deactivation
128
-         */
129
-        function espresso_plugin_deactivation()
130
-        {
131
-            // Run WP GraphQL deactivation callback
132
-            espressoLoadWpGraphQL();
133
-            graphql_deactivation_callback();
134
-            delete_option('event-espresso-core_allow_tracking');
135
-            delete_option('event-espresso-core_tracking_notice');
136
-        }
137
-        register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
126
+		/**
127
+		 * espresso_plugin_deactivation
128
+		 */
129
+		function espresso_plugin_deactivation()
130
+		{
131
+			// Run WP GraphQL deactivation callback
132
+			espressoLoadWpGraphQL();
133
+			graphql_deactivation_callback();
134
+			delete_option('event-espresso-core_allow_tracking');
135
+			delete_option('event-espresso-core_tracking_notice');
136
+		}
137
+		register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation');
138 138
 
139
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
140
-        bootstrap_espresso();
141
-    }
139
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
140
+		bootstrap_espresso();
141
+	}
142 142
 }
143 143
 
144 144
 if (! function_exists('espresso_deactivate_plugin')) {
145
-    /**
146
-     *    deactivate_plugin
147
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
-     *
149
-     * @access public
150
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
-     * @return    void
152
-     */
153
-    function espresso_deactivate_plugin(string $plugin_basename = '')
154
-    {
155
-        if (! function_exists('deactivate_plugins')) {
156
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
-        }
158
-        unset($_GET['activate'], $_REQUEST['activate']);
159
-        deactivate_plugins($plugin_basename);
160
-    }
145
+	/**
146
+	 *    deactivate_plugin
147
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
148
+	 *
149
+	 * @access public
150
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
151
+	 * @return    void
152
+	 */
153
+	function espresso_deactivate_plugin(string $plugin_basename = '')
154
+	{
155
+		if (! function_exists('deactivate_plugins')) {
156
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
157
+		}
158
+		unset($_GET['activate'], $_REQUEST['activate']);
159
+		deactivate_plugins($plugin_basename);
160
+	}
161 161
 }
162 162
 
163 163
 
164 164
 if (! function_exists('espressoLoadWpGraphQL')) {
165
-    function espressoLoadWpGraphQL()
166
-    {
167
-        if (
168
-            ! class_exists('WPGraphQL')
169
-            && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
-        ) {
171
-            require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
-        }
173
-    }
165
+	function espressoLoadWpGraphQL()
166
+	{
167
+		if (
168
+			! class_exists('WPGraphQL')
169
+			&& is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php')
170
+		) {
171
+			require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php';
172
+		}
173
+	}
174 174
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Status_Field.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -2,120 +2,120 @@
 block discarded – undo
2 2
 
3 3
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
4 4
 {
5
-    protected $_wp_post_stati;
5
+	protected $_wp_post_stati;
6 6
 
7 7
 
8
-    /**
9
-     * constructor
10
-     *
11
-     * @param string $table_column        column on table
12
-     * @param string $nicename            nice name for column(field)
13
-     * @param bool   $nullable            is this field nullable
14
-     * @param string $default_value       default status
15
-     * @param array  $new_stati           If additional stati are to be used other than the default WP statuses then
16
-     *                                    they can be registered via this property.  The format of the array should be
17
-     *                                    as follows: array(
18
-     *                                    'status_reference' => array(
19
-     *                                    'label' => esc_html__('Status Reference Label', 'event_espresso')
20
-     *                                    'public' => true, //'Whether posts of this status should be shown on the
21
-     *                                    frontend of the site'
22
-     *                                    'exclude_from_search' => false, //'Whether posts of this status should be
23
-     *                                    excluded from wp searches'
24
-     *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
25
-     *                                    in queries for the admin "all" view in list table views.
26
-     *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
27
-     *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
28
-     *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
29
-     *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
30
-     *                                    on the admin screen( or you won't see your status count ).
31
-     *                                    )
32
-     *                                    )
33
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
34
-     */
35
-    public function __construct($table_column, $nicename, $nullable, $default_value, array $new_stati = [])
36
-    {
37
-        $this->_register_new_stati($new_stati);
38
-        $this->_set_allowed_enum_values();
39
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
40
-    }
8
+	/**
9
+	 * constructor
10
+	 *
11
+	 * @param string $table_column        column on table
12
+	 * @param string $nicename            nice name for column(field)
13
+	 * @param bool   $nullable            is this field nullable
14
+	 * @param string $default_value       default status
15
+	 * @param array  $new_stati           If additional stati are to be used other than the default WP statuses then
16
+	 *                                    they can be registered via this property.  The format of the array should be
17
+	 *                                    as follows: array(
18
+	 *                                    'status_reference' => array(
19
+	 *                                    'label' => esc_html__('Status Reference Label', 'event_espresso')
20
+	 *                                    'public' => true, //'Whether posts of this status should be shown on the
21
+	 *                                    frontend of the site'
22
+	 *                                    'exclude_from_search' => false, //'Whether posts of this status should be
23
+	 *                                    excluded from wp searches'
24
+	 *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
25
+	 *                                    in queries for the admin "all" view in list table views.
26
+	 *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
27
+	 *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
28
+	 *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
29
+	 *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
30
+	 *                                    on the admin screen( or you won't see your status count ).
31
+	 *                                    )
32
+	 *                                    )
33
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
34
+	 */
35
+	public function __construct($table_column, $nicename, $nullable, $default_value, array $new_stati = [])
36
+	{
37
+		$this->_register_new_stati($new_stati);
38
+		$this->_set_allowed_enum_values();
39
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * This registers any new statuses sent via the $new_stati array on construct
45
-     *
46
-     * @access protected
47
-     * @param array $new_stati statuses
48
-     * @return void
49
-     */
50
-    protected function _register_new_stati($new_stati)
51
-    {
52
-        foreach ((array) $new_stati as $status_key => $status_args) {
53
-            $args = [
54
-                'label'                     => $status_args['label'] ?? $status_key,
55
-                'public'                    => ! (isset($status_args['public']) && is_bool($status_args['public']))
56
-                                               || $status_args['public'],
57
-                'exclude_from_search'       => isset($status_args['exclude_from_search'])
58
-                                               && is_bool($status_args['exclude_from_search'])
59
-                                               && $status_args['exclude_from_search'],
60
-                'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list'])
61
-                                               && is_bool($status_args['show_in_admin_all_list'])
62
-                                               && $status_args['show_in_admin_all_list'],
63
-                'show_in_admin_status_list' => ! (
64
-                        isset($status_args['show_in_admin_status_list'])
65
-                        && is_bool($status_args['show_in_admin_status_list'])
66
-                    ) || $status_args['show_in_admin_status_list'],
67
-                'label_count'               => $status_args['label_count'] ?? false,
68
-            ];
69
-            register_post_status($status_key, $args);
70
-        }
71
-    }
43
+	/**
44
+	 * This registers any new statuses sent via the $new_stati array on construct
45
+	 *
46
+	 * @access protected
47
+	 * @param array $new_stati statuses
48
+	 * @return void
49
+	 */
50
+	protected function _register_new_stati($new_stati)
51
+	{
52
+		foreach ((array) $new_stati as $status_key => $status_args) {
53
+			$args = [
54
+				'label'                     => $status_args['label'] ?? $status_key,
55
+				'public'                    => ! (isset($status_args['public']) && is_bool($status_args['public']))
56
+											   || $status_args['public'],
57
+				'exclude_from_search'       => isset($status_args['exclude_from_search'])
58
+											   && is_bool($status_args['exclude_from_search'])
59
+											   && $status_args['exclude_from_search'],
60
+				'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list'])
61
+											   && is_bool($status_args['show_in_admin_all_list'])
62
+											   && $status_args['show_in_admin_all_list'],
63
+				'show_in_admin_status_list' => ! (
64
+						isset($status_args['show_in_admin_status_list'])
65
+						&& is_bool($status_args['show_in_admin_status_list'])
66
+					) || $status_args['show_in_admin_status_list'],
67
+				'label_count'               => $status_args['label_count'] ?? false,
68
+			];
69
+			register_post_status($status_key, $args);
70
+		}
71
+	}
72 72
 
73 73
 
74
-    /**
75
-     * This sets the _allowed_enum_values property using the $wp_post_stati array
76
-     *
77
-     * @access protected
78
-     * @regurn void
79
-     */
80
-    protected function _set_allowed_enum_values()
81
-    {
82
-        // first let's get the post_statuses
83
-        global $wp_post_statuses;
84
-        $this->_wp_post_stati = $wp_post_statuses;
74
+	/**
75
+	 * This sets the _allowed_enum_values property using the $wp_post_stati array
76
+	 *
77
+	 * @access protected
78
+	 * @regurn void
79
+	 */
80
+	protected function _set_allowed_enum_values()
81
+	{
82
+		// first let's get the post_statuses
83
+		global $wp_post_statuses;
84
+		$this->_wp_post_stati = $wp_post_statuses;
85 85
 
86
-        foreach ($this->_wp_post_stati as $post_status => $args_object) {
87
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
88
-        }
89
-    }
86
+		foreach ($this->_wp_post_stati as $post_status => $args_object) {
87
+			$this->_allowed_enum_values[ $post_status ] = $args_object->label;
88
+		}
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * Before calling parent, first double-checks our list of acceptable post
94
-     * types is up-to-date
95
-     *
96
-     * @param string $value_inputted_for_field_on_model_object
97
-     * @return string
98
-     */
99
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
100
-    {
101
-        $this->_set_allowed_enum_values();
102
-        return parent::prepare_for_set($value_inputted_for_field_on_model_object);
103
-    }
92
+	/**
93
+	 * Before calling parent, first double-checks our list of acceptable post
94
+	 * types is up-to-date
95
+	 *
96
+	 * @param string $value_inputted_for_field_on_model_object
97
+	 * @return string
98
+	 */
99
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
100
+	{
101
+		$this->_set_allowed_enum_values();
102
+		return parent::prepare_for_set($value_inputted_for_field_on_model_object);
103
+	}
104 104
 
105 105
 
106 106
 
107
-    // helper methods for getting various $wp_post_statuses stuff.
107
+	// helper methods for getting various $wp_post_statuses stuff.
108 108
 
109 109
 
110
-    /**
111
-     * This just returns the status object for the given status
112
-     *
113
-     * @param string $status What status object you want
114
-     * @return object|null         the status object or FALSE if it doesn't exist.
115
-     * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
116
-     */
117
-    public function get_status_object($status)
118
-    {
119
-        return $this->_wp_post_stati[ $status ] ?? null;
120
-    }
110
+	/**
111
+	 * This just returns the status object for the given status
112
+	 *
113
+	 * @param string $status What status object you want
114
+	 * @return object|null         the status object or FALSE if it doesn't exist.
115
+	 * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
116
+	 */
117
+	public function get_status_object($status)
118
+	{
119
+		return $this->_wp_post_stati[ $status ] ?? null;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
core/domain/services/wp_queries/EventListQuery.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -16,183 +16,183 @@
 block discarded – undo
16 16
  */
17 17
 class EventListQuery extends WP_Query
18 18
 {
19
-    private ?string $title = '';
20
-
21
-    private int $limit = 10;
22
-
23
-    private ?string $css_class = '';
24
-
25
-    private bool $show_expired = false;
26
-
27
-    private ?string $month = '';
28
-
29
-    private ?string $category_slug = '';
30
-
31
-    /**
32
-     * @var array|string|null
33
-     */
34
-    private $order_by = [];
35
-
36
-    private ?string $sort = '';
37
-
38
-    private bool $show_title = true;
39
-
40
-
41
-    /**
42
-     * EE_Event_List_Query Constructor     *
43
-     *
44
-     * @param array $args
45
-     */
46
-    public function __construct($args = [])
47
-    {
48
-        $args = $this->parseArgs((array) $args);
49
-        $this->setupEventQueryHelper();
50
-        $this->setupFilters();
51
-        $args = $this->getQueryArgs($args);
52
-        // run the query
53
-        parent::__construct($args);
54
-    }
55
-
56
-
57
-    /**
58
-     * @param array $args
59
-     * @return array
60
-     */
61
-    private function parseArgs(array $args): array
62
-    {
63
-        // incoming args could be a mix of WP query args + EE shortcode args
64
-        foreach ($args as $property => $value) {
65
-            // if the arg is a property of this class, then it's an EE shortcode arg
66
-            if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) {
67
-                // get the property type
68
-                $type = gettype($this->{$property});
69
-                // set the property value
70
-                switch ($type) {
71
-                    case 'integer':
72
-                        $this->{$property} = (int) $value;
73
-                        break;
74
-                    case 'boolean':
75
-                        $this->{$property} = filter_var($value, FILTER_VALIDATE_BOOLEAN);
76
-                        break;
77
-                    case 'string':
78
-                        $this->{$property} = sanitize_text_field($value);
79
-                        break;
80
-                    default:
81
-                        $this->{$property} = $value;
82
-                        break;
83
-                }
84
-                // then remove it from the array of args that will later be passed to WP_Query()
85
-                unset($args[ $property ]);
86
-            }
87
-        }
88
-        return $args;
89
-    }
90
-
91
-
92
-    private function setupEventQueryHelper()
93
-    {
94
-        // add query filters
95
-        EEH_Event_Query::add_query_filters();
96
-        // set params that will get used by the filters
97
-        EEH_Event_Query::set_query_params(
98
-            $this->month,
99
-            $this->category_slug,
100
-            $this->show_expired,
101
-            $this->order_by,
102
-            $this->sort
103
-        );
104
-    }
105
-
106
-
107
-    private function setupFilters()
108
-    {
109
-        // first off, let's remove any filters from previous queries
110
-        remove_filter(
111
-            'FHEE__archive_espresso_events_template__show_header',
112
-            [$this, 'show_event_list_title']
113
-        );
114
-        remove_filter(
115
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
116
-            [$this, 'event_list_title']
117
-        );
118
-        remove_all_filters('FHEE__content_espresso_events__event_class');
119
-        // Event List Title ?
120
-        add_filter(
121
-            'FHEE__archive_espresso_events_template__show_header',
122
-            [$this, 'show_event_list_title']
123
-        );
124
-        add_filter(
125
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
126
-            [$this, 'event_list_title']
127
-        );
128
-        // add the css class
129
-        add_filter(
130
-            'FHEE__content_espresso_events__event_class',
131
-            [$this, 'event_list_css']
132
-        );
133
-    }
134
-
135
-
136
-    private function getQueryArgs(array $args): array
137
-    {
138
-        // the current "page" we are viewing
139
-        $paged = max(1, get_query_var('paged'));
140
-        // Force these args
141
-        return array_merge(
142
-            $args,
143
-            [
144
-                'post_type'              => EspressoPostType::EVENTS,
145
-                'posts_per_page'         => $this->limit,
146
-                'update_post_term_cache' => false,
147
-                'update_post_meta_cache' => false,
148
-                'paged'                  => $paged,
149
-                'offset'                 => ($paged - 1) * $this->limit,
150
-            ]
151
-        );
152
-    }
153
-
154
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
155
-
156
-
157
-    /**
158
-     * show_event_list_title
159
-     *
160
-     * @return boolean
161
-     */
162
-    public function show_event_list_title(): bool
163
-    {
164
-        return filter_var($this->show_title, FILTER_VALIDATE_BOOLEAN);
165
-    }
166
-
167
-
168
-    /**
169
-     * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter
170
-     *
171
-     * @param string $event_list_title
172
-     * @return    string
173
-     */
174
-    public function event_list_title(string $event_list_title = ''): string
175
-    {
176
-        if (! empty($this->title)) {
177
-            return $this->title;
178
-        }
179
-        return $event_list_title;
180
-    }
181
-
182
-
183
-    /**
184
-     * callback for FHEE__content_espresso_events__event_class filter
185
-     *
186
-     * @param string $event_list_css
187
-     * @return string
188
-     */
189
-    public function event_list_css(string $event_list_css = ''): string
190
-    {
191
-        $event_list_css .= ! empty($event_list_css) ? ' ' : '';
192
-        $event_list_css .= ! empty($this->css_class) ? $this->css_class : '';
193
-        $event_list_css .= ! empty($event_list_css) ? ' ' : '';
194
-        $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : '';
195
-        return $event_list_css;
196
-    }
197
-    // phpcs:enable
19
+	private ?string $title = '';
20
+
21
+	private int $limit = 10;
22
+
23
+	private ?string $css_class = '';
24
+
25
+	private bool $show_expired = false;
26
+
27
+	private ?string $month = '';
28
+
29
+	private ?string $category_slug = '';
30
+
31
+	/**
32
+	 * @var array|string|null
33
+	 */
34
+	private $order_by = [];
35
+
36
+	private ?string $sort = '';
37
+
38
+	private bool $show_title = true;
39
+
40
+
41
+	/**
42
+	 * EE_Event_List_Query Constructor     *
43
+	 *
44
+	 * @param array $args
45
+	 */
46
+	public function __construct($args = [])
47
+	{
48
+		$args = $this->parseArgs((array) $args);
49
+		$this->setupEventQueryHelper();
50
+		$this->setupFilters();
51
+		$args = $this->getQueryArgs($args);
52
+		// run the query
53
+		parent::__construct($args);
54
+	}
55
+
56
+
57
+	/**
58
+	 * @param array $args
59
+	 * @return array
60
+	 */
61
+	private function parseArgs(array $args): array
62
+	{
63
+		// incoming args could be a mix of WP query args + EE shortcode args
64
+		foreach ($args as $property => $value) {
65
+			// if the arg is a property of this class, then it's an EE shortcode arg
66
+			if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) {
67
+				// get the property type
68
+				$type = gettype($this->{$property});
69
+				// set the property value
70
+				switch ($type) {
71
+					case 'integer':
72
+						$this->{$property} = (int) $value;
73
+						break;
74
+					case 'boolean':
75
+						$this->{$property} = filter_var($value, FILTER_VALIDATE_BOOLEAN);
76
+						break;
77
+					case 'string':
78
+						$this->{$property} = sanitize_text_field($value);
79
+						break;
80
+					default:
81
+						$this->{$property} = $value;
82
+						break;
83
+				}
84
+				// then remove it from the array of args that will later be passed to WP_Query()
85
+				unset($args[ $property ]);
86
+			}
87
+		}
88
+		return $args;
89
+	}
90
+
91
+
92
+	private function setupEventQueryHelper()
93
+	{
94
+		// add query filters
95
+		EEH_Event_Query::add_query_filters();
96
+		// set params that will get used by the filters
97
+		EEH_Event_Query::set_query_params(
98
+			$this->month,
99
+			$this->category_slug,
100
+			$this->show_expired,
101
+			$this->order_by,
102
+			$this->sort
103
+		);
104
+	}
105
+
106
+
107
+	private function setupFilters()
108
+	{
109
+		// first off, let's remove any filters from previous queries
110
+		remove_filter(
111
+			'FHEE__archive_espresso_events_template__show_header',
112
+			[$this, 'show_event_list_title']
113
+		);
114
+		remove_filter(
115
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
116
+			[$this, 'event_list_title']
117
+		);
118
+		remove_all_filters('FHEE__content_espresso_events__event_class');
119
+		// Event List Title ?
120
+		add_filter(
121
+			'FHEE__archive_espresso_events_template__show_header',
122
+			[$this, 'show_event_list_title']
123
+		);
124
+		add_filter(
125
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
126
+			[$this, 'event_list_title']
127
+		);
128
+		// add the css class
129
+		add_filter(
130
+			'FHEE__content_espresso_events__event_class',
131
+			[$this, 'event_list_css']
132
+		);
133
+	}
134
+
135
+
136
+	private function getQueryArgs(array $args): array
137
+	{
138
+		// the current "page" we are viewing
139
+		$paged = max(1, get_query_var('paged'));
140
+		// Force these args
141
+		return array_merge(
142
+			$args,
143
+			[
144
+				'post_type'              => EspressoPostType::EVENTS,
145
+				'posts_per_page'         => $this->limit,
146
+				'update_post_term_cache' => false,
147
+				'update_post_meta_cache' => false,
148
+				'paged'                  => $paged,
149
+				'offset'                 => ($paged - 1) * $this->limit,
150
+			]
151
+		);
152
+	}
153
+
154
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
155
+
156
+
157
+	/**
158
+	 * show_event_list_title
159
+	 *
160
+	 * @return boolean
161
+	 */
162
+	public function show_event_list_title(): bool
163
+	{
164
+		return filter_var($this->show_title, FILTER_VALIDATE_BOOLEAN);
165
+	}
166
+
167
+
168
+	/**
169
+	 * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter
170
+	 *
171
+	 * @param string $event_list_title
172
+	 * @return    string
173
+	 */
174
+	public function event_list_title(string $event_list_title = ''): string
175
+	{
176
+		if (! empty($this->title)) {
177
+			return $this->title;
178
+		}
179
+		return $event_list_title;
180
+	}
181
+
182
+
183
+	/**
184
+	 * callback for FHEE__content_espresso_events__event_class filter
185
+	 *
186
+	 * @param string $event_list_css
187
+	 * @return string
188
+	 */
189
+	public function event_list_css(string $event_list_css = ''): string
190
+	{
191
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
192
+		$event_list_css .= ! empty($this->css_class) ? $this->css_class : '';
193
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
194
+		$event_list_css .= ! empty($this->category_slug) ? $this->category_slug : '';
195
+		return $event_list_css;
196
+	}
197
+	// phpcs:enable
198 198
 }
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTicketSelector.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -23,106 +23,106 @@
 block discarded – undo
23 23
  */
24 24
 class EspressoTicketSelector extends EspressoShortcode
25 25
 {
26
-    /**
27
-     * the actual shortcode tag that gets registered with WordPress
28
-     *
29
-     * @return string
30
-     */
31
-    public function getTag()
32
-    {
33
-        return 'ESPRESSO_TICKET_SELECTOR';
34
-    }
26
+	/**
27
+	 * the actual shortcode tag that gets registered with WordPress
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function getTag()
32
+	{
33
+		return 'ESPRESSO_TICKET_SELECTOR';
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * the time in seconds to cache the results of the processShortcode() method
39
-     * 0 means the processShortcode() results will NOT be cached at all
40
-     *
41
-     * @return int
42
-     */
43
-    public function cacheExpiration()
44
-    {
45
-        return 0;
46
-    }
37
+	/**
38
+	 * the time in seconds to cache the results of the processShortcode() method
39
+	 * 0 means the processShortcode() results will NOT be cached at all
40
+	 *
41
+	 * @return int
42
+	 */
43
+	public function cacheExpiration()
44
+	{
45
+		return 0;
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * a place for adding any initialization code that needs to run prior to wp_header().
51
-     * this may be required for shortcodes that utilize a corresponding module,
52
-     * and need to enqueue assets for that module
53
-     *
54
-     * @return void
55
-     */
56
-    public function initializeShortcode()
57
-    {
58
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
59
-        $this->shortcodeHasBeenInitialized();
60
-    }
49
+	/**
50
+	 * a place for adding any initialization code that needs to run prior to wp_header().
51
+	 * this may be required for shortcodes that utilize a corresponding module,
52
+	 * and need to enqueue assets for that module
53
+	 *
54
+	 * @return void
55
+	 */
56
+	public function initializeShortcode()
57
+	{
58
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
59
+		$this->shortcodeHasBeenInitialized();
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * callback that runs when the shortcode is encountered in post content.
65
-     * IMPORTANT !!!
66
-     * remember that shortcode content should be RETURNED and NOT echoed out
67
-     *
68
-     * @param array|string $attributes
69
-     * @return string
70
-     * @throws InvalidArgumentException
71
-     * @throws EE_Error
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidInterfaceException
74
-     * @throws ReflectionException
75
-     * @throws Exception
76
-     */
77
-    public function processShortcode($attributes = array())
78
-    {
79
-        extract((array) $attributes);
80
-        $event_id = $event_id ?? 0;
81
-        $event = $event_id ?
82
-            EEM_Event::instance()->get_one_by_ID($event_id) :
83
-            EEH_Event_View::get_event();
84
-        if (! $event instanceof EE_Event) {
85
-            return $this->processInvalidEvent($event_id);
86
-        }
87
-        ob_start();
88
-        do_action('AHEE_event_details_before_post', $event_id);
89
-        espresso_ticket_selector($event);
90
-        do_action('AHEE_event_details_after_post');
91
-        return ob_get_clean();
92
-    }
63
+	/**
64
+	 * callback that runs when the shortcode is encountered in post content.
65
+	 * IMPORTANT !!!
66
+	 * remember that shortcode content should be RETURNED and NOT echoed out
67
+	 *
68
+	 * @param array|string $attributes
69
+	 * @return string
70
+	 * @throws InvalidArgumentException
71
+	 * @throws EE_Error
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidInterfaceException
74
+	 * @throws ReflectionException
75
+	 * @throws Exception
76
+	 */
77
+	public function processShortcode($attributes = array())
78
+	{
79
+		extract((array) $attributes);
80
+		$event_id = $event_id ?? 0;
81
+		$event = $event_id ?
82
+			EEM_Event::instance()->get_one_by_ID($event_id) :
83
+			EEH_Event_View::get_event();
84
+		if (! $event instanceof EE_Event) {
85
+			return $this->processInvalidEvent($event_id);
86
+		}
87
+		ob_start();
88
+		do_action('AHEE_event_details_before_post', $event_id);
89
+		espresso_ticket_selector($event);
90
+		do_action('AHEE_event_details_after_post');
91
+		return ob_get_clean();
92
+	}
93 93
 
94 94
 
95
-    /**
96
-     * @param string $event_id
97
-     * @return string
98
-     * @throws Exception
99
-     * @since 5.0.0.p
100
-     */
101
-    private function processInvalidEvent(string $event_id): string
102
-    {
103
-        if (WP_DEBUG === true && current_user_can('edit_pages')) {
104
-            new ExceptionStackTraceDisplay(
105
-                new InvalidArgumentException(
106
-                    sprintf(
107
-                        esc_html__(
108
-                            'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that its value corresponds to a valid Event ID.',
109
-                            'event_espresso'
110
-                        ),
111
-                        $this->getTag(),
112
-                        $event_id,
113
-                        'event_id',
114
-                        '<br />'
115
-                    )
116
-                )
117
-            );
118
-            return '';
119
-        }
120
-        return sprintf(
121
-            esc_html__(
122
-                'An Event with an ID of "%s" could not be found. Please contact the event administrator for assistance.',
123
-                'event_espresso'
124
-            ),
125
-            $event_id
126
-        );
127
-    }
95
+	/**
96
+	 * @param string $event_id
97
+	 * @return string
98
+	 * @throws Exception
99
+	 * @since 5.0.0.p
100
+	 */
101
+	private function processInvalidEvent(string $event_id): string
102
+	{
103
+		if (WP_DEBUG === true && current_user_can('edit_pages')) {
104
+			new ExceptionStackTraceDisplay(
105
+				new InvalidArgumentException(
106
+					sprintf(
107
+						esc_html__(
108
+							'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that its value corresponds to a valid Event ID.',
109
+							'event_espresso'
110
+						),
111
+						$this->getTag(),
112
+						$event_id,
113
+						'event_id',
114
+						'<br />'
115
+					)
116
+				)
117
+			);
118
+			return '';
119
+		}
120
+		return sprintf(
121
+			esc_html__(
122
+				'An Event with an ID of "%s" could not be found. Please contact the event administrator for assistance.',
123
+				'event_espresso'
124
+			),
125
+			$event_id
126
+		);
127
+	}
128 128
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -79,9 +79,8 @@
 block discarded – undo
79 79
         extract((array) $attributes);
80 80
         $event_id = $event_id ?? 0;
81 81
         $event = $event_id ?
82
-            EEM_Event::instance()->get_one_by_ID($event_id) :
83
-            EEH_Event_View::get_event();
84
-        if (! $event instanceof EE_Event) {
82
+            EEM_Event::instance()->get_one_by_ID($event_id) : EEH_Event_View::get_event();
83
+        if ( ! $event instanceof EE_Event) {
85 84
             return $this->processInvalidEvent($event_id);
86 85
         }
87 86
         ob_start();
Please login to merge, or discard this patch.