Completed
Branch BUG-10738-inconsistency-in-ses... (a1eed8)
by
unknown
24:27 queued 12:29
created

espresso.php ➔ bootstrap_espresso()   A

Complexity

Conditions 2
Paths 14

Size

Total Lines 54
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 39
nc 14
nop 0
dl 0
loc 54
rs 9.6716
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php defined('ABSPATH') || exit('No direct script access allowed');
2
/*
3
  Plugin Name:		Event Espresso
4
  Plugin URI:  		http://eventespresso.com/pricing/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=wordpress_plugins_page&utm_content=support_link
5
  Description: 		Manage events, sell tickets, and receive payments from your WordPress website. Reduce event administration time, cut-out ticketing fees, and own your customer data. | <a href="https://eventespresso.com/add-ons/?utm_source=plugin_activation_screen&utm_medium=link&utm_campaign=plugin_description">Extensions</a> | <a href="https://eventespresso.com/pricing/?utm_source=plugin_activation_screen&utm_medium=link&utm_campaign=plugin_description">Sales</a> | <a href="admin.php?page=espresso_support">Support</a>
6
  Version:			4.9.49.rc.001
7
  Author:			Event Espresso
8
  Author URI: 		http://eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=wordpress_plugins_page&utm_content=support_link
9
  License: 		     GPLv2
10
  Text Domain: 		 event_espresso
11
  GitHub Plugin URI: https://github.com/eventespresso/event-espresso-core
12
  Copyright 		(c) 2008-2017 Event Espresso  All Rights Reserved.
13
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License as published by
16
  the Free Software Foundation; either version 2 of the License, or
17
  (at your option) any later version.
18
19
  This program is distributed in the hope that it will be useful,
20
  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
  GNU General Public License for more details.
23
24
  You should have received a copy of the GNU General Public License
25
  along with this program; if not, write to the Free Software
26
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
 */
28
/**
29
 * Event Espresso
30
 * Event Registration and Management Plugin for WordPress
31
 *
32
 * @package     Event Espresso
33
 * @author      Seth Shoultes
34
 * @copyright   (c) 2008-2017 Event Espresso  All Rights Reserved.
35
 * @license     {@link http://eventespresso.com/support/terms-conditions/}
36
 * @see         Plugin Licensing
37
 * @link        {@link http://www.eventespresso.com}
38
 * @since       4.0
39
 */
40
if (function_exists('espresso_version')) {
41
    if (! function_exists('espresso_duplicate_plugin_error')) {
42
        /**
43
         *    espresso_duplicate_plugin_error
44
         *    displays if more than one version of EE is activated at the same time
45
         */
46
        function espresso_duplicate_plugin_error()
47
        {
48
            ?>
49
            <div class="error">
50
                <p>
51
                    <?php
52
                    echo esc_html__(
53
                        '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.',
54
                        'event_espresso'
55
                    ); ?>
56
                </p>
57
            </div>
58
            <?php
59
            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
        }
61
    }
62
    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63
64
} else {
65
    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
        /**
68
         * espresso_minimum_php_version_error
69
         *
70
         * @return void
71
         */
72
        function espresso_minimum_php_version_error()
73
        {
74
            ?>
75
            <div class="error">
76
                <p>
77
                    <?php
78
                    printf(
79
                        esc_html__(
80
                            '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.',
81
                            'event_espresso'
82
                        ),
83
                        EE_MIN_PHP_VER_REQUIRED,
84
                        PHP_VERSION,
85
                        '<br/>',
86
                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
                    );
88
                    ?>
89
                </p>
90
            </div>
91
            <?php
92
            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
        }
94
95
        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
    } else {
97
        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
        /**
99
         * espresso_version
100
         * Returns the plugin version
101
         *
102
         * @return string
103
         */
104
        function espresso_version()
105
        {
106
            return apply_filters('FHEE__espresso__espresso_version', '4.9.49.rc.001');
107
        }
108
109
        /**
110
         * espresso_plugin_activation
111
         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
         */
113
        function espresso_plugin_activation()
114
        {
115
            update_option('ee_espresso_activation', true);
116
        }
117
118
        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
        /**
120
         *    espresso_load_error_handling
121
         *    this function loads EE's class for handling exceptions and errors
122
         */
123
        function espresso_load_error_handling()
124
        {
125
            static $error_handling_loaded = false;
126
            if ($error_handling_loaded) {
127
                return;
128
            }
129
            // load debugging tools
130
            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
                \EEH_Debug_Tools::instance();
133
            }
134
            // load error handling
135
            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
                require_once EE_CORE . 'EE_Error.core.php';
137
            } else {
138
                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
            }
140
            $error_handling_loaded = true;
141
        }
142
143
        /**
144
         *    espresso_load_required
145
         *    given a class name and path, this function will load that file or throw an exception
146
         *
147
         * @param    string $classname
148
         * @param    string $full_path_to_file
149
         * @throws    EE_Error
150
         */
151
        function espresso_load_required($classname, $full_path_to_file)
152
        {
153
            if (is_readable($full_path_to_file)) {
154
                require_once $full_path_to_file;
155
            } else {
156
                throw new \EE_Error (
157
                    sprintf(
158
                        esc_html__(
159
                            'The %s class file could not be located or is not readable due to file permissions.',
160
                            'event_espresso'
161
                        ),
162
                        $classname
163
                    )
164
                );
165
            }
166
        }
167
168
        /**
169
         * @since 4.9.27
170
         * @throws \EE_Error
171
         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
         * @throws \OutOfBoundsException
179
         */
180
        function bootstrap_espresso()
181
        {
182
            require_once __DIR__ . '/core/espresso_definitions.php';
183
            try {
184
                espresso_load_error_handling();
185
                espresso_load_required(
186
                    'EEH_Base',
187
                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
                );
189
                espresso_load_required(
190
                    'EEH_File',
191
                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
                );
193
                espresso_load_required(
194
                    'EEH_File',
195
                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
                );
197
                espresso_load_required(
198
                    'EEH_Array',
199
                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
                );
201
                // instantiate and configure PSR4 autoloader
202
                espresso_load_required(
203
                    'Psr4Autoloader',
204
                    EE_CORE . 'Psr4Autoloader.php'
205
                );
206
                espresso_load_required(
207
                    'EE_Psr4AutoloaderInit',
208
                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
                );
210
                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
                $AutoloaderInit->initializeAutoloader();
212
                espresso_load_required(
213
                    'EE_Request',
214
                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
                );
216
                espresso_load_required(
217
                    'EE_Response',
218
                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
                );
220
                espresso_load_required(
221
                    'EE_Bootstrap',
222
                    EE_CORE . 'EE_Bootstrap.core.php'
223
                );
224
                // bootstrap EE and the request stack
225
                new EE_Bootstrap(
226
                    new EE_Request($_GET, $_POST, $_COOKIE),
227
                    new EE_Response()
228
                );
229
            } catch (Exception $e) {
230
                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
            }
233
        }
234
        bootstrap_espresso();
235
    }
236
}
237
if (! function_exists('espresso_deactivate_plugin')) {
238
    /**
239
     *    deactivate_plugin
240
     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
     *
242
     * @access public
243
     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
     * @return    void
245
     */
246
    function espresso_deactivate_plugin($plugin_basename = '')
247
    {
248
        if (! function_exists('deactivate_plugins')) {
249
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
        }
251
        unset($_GET['activate'], $_REQUEST['activate']);
252
        deactivate_plugins($plugin_basename);
253
    }
254
}
255