Completed
Branch FET-8385-datetime-ticket-selec... (7a6bc0)
by
unknown
44:51 queued 34:12
created
form_sections/strategies/display/EE_Select_Display_Strategy.strategy.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@
 block discarded – undo
38 38
 		if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) {
39 39
 			EEH_HTML::indent( 1, 'optgroup' );
40 40
 			foreach( $this->_input->options() as $opt_group_label => $opt_group ){
41
-			    if ( ! empty($opt_group_label)) {
42
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
43
-                }
41
+				if ( ! empty($opt_group_label)) {
42
+					$html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
43
+				}
44 44
 				EEH_HTML::indent( 1, 'option' );
45 45
 				$html .= $this->_display_options( $opt_group );
46 46
 				EEH_HTML::indent( -1, 'option' );
47
-                if ( ! empty($opt_group_label)) {
48
-                    $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
49
-			    }
47
+				if ( ! empty($opt_group_label)) {
48
+					$html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
49
+				}
50 50
 			}
51 51
 			EEH_HTML::indent( -1, 'optgroup' );
52 52
 		} else {
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,49 +11,49 @@  discard block
 block discarded – undo
11 11
  * @since 				$VID:$
12 12
  *
13 13
  */
14
-class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{
14
+class EE_Select_Display_Strategy extends EE_Display_Strategy_Base {
15 15
 
16 16
 	/**
17 17
 	 *
18 18
 	 * @throws EE_Error
19 19
 	 * @return string of html to display the field
20 20
 	 */
21
-	function display(){
22
-		if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){
23
-			throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' )));
21
+	function display() {
22
+		if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+			throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
24 24
 		}
25 25
 
26
-		$html = EEH_HTML::nl( 0, 'select' );
26
+		$html = EEH_HTML::nl(0, 'select');
27 27
 		$html .= '<select';
28
-		$html .= ' id="' . $this->_input->html_id() . '"';
29
-		$html .= ' name="' . $this->_input->html_name() . '"';
30
-		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
31
-		$html .= ' class="' . $class . '"';
28
+		$html .= ' id="'.$this->_input->html_id().'"';
29
+		$html .= ' name="'.$this->_input->html_name().'"';
30
+		$class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
31
+		$html .= ' class="'.$class.'"';
32 32
 		// add html5 required
33 33
 		$html .= $this->_input->required() ? ' required' : '';
34
-		$html .= ' style="' . $this->_input->html_style() . '"';
35
-		$html .= ' ' . $this->_input->other_html_attributes();
34
+		$html .= ' style="'.$this->_input->html_style().'"';
35
+		$html .= ' '.$this->_input->other_html_attributes();
36 36
 		$html .= '>';
37 37
 
38
-		if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) {
39
-			EEH_HTML::indent( 1, 'optgroup' );
40
-			foreach( $this->_input->options() as $opt_group_label => $opt_group ){
38
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
39
+			EEH_HTML::indent(1, 'optgroup');
40
+			foreach ($this->_input->options() as $opt_group_label => $opt_group) {
41 41
 			    if ( ! empty($opt_group_label)) {
42
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
42
+                    $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">';
43 43
                 }
44
-				EEH_HTML::indent( 1, 'option' );
45
-				$html .= $this->_display_options( $opt_group );
44
+				EEH_HTML::indent(1, 'option');
45
+				$html .= $this->_display_options($opt_group);
46 46
 				EEH_HTML::indent( -1, 'option' );
47 47
                 if ( ! empty($opt_group_label)) {
48
-                    $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
48
+                    $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>';
49 49
 			    }
50 50
 			}
51 51
 			EEH_HTML::indent( -1, 'optgroup' );
52 52
 		} else {
53
-			$html.=$this->_display_options( $this->_input->options() );
53
+			$html .= $this->_display_options($this->_input->options());
54 54
 		}
55 55
 
56
-		$html.= EEH_HTML::nl( 0, 'select' ) . '</select>';
56
+		$html .= EEH_HTML::nl(0, 'select').'</select>';
57 57
 		return $html;
58 58
 	}
59 59
 
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 	 * @param array $options
65 65
 	 * @return string
66 66
 	 */
67
-	protected function _display_options($options){
67
+	protected function _display_options($options) {
68 68
 		$html = '';
69
-		EEH_HTML::indent( 1, 'option' );
70
-		foreach( $options as $value => $display_text ){
71
-			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value );
72
-			$selected = $this->_check_if_option_selected( $unnormalized_value ) ? ' selected="selected"' : '';
73
-			$html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr( $unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>';
69
+		EEH_HTML::indent(1, 'option');
70
+		foreach ($options as $value => $display_text) {
71
+			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
72
+			$selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
73
+			$html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>';
74 74
 		}
75 75
 		EEH_HTML::indent( -1, 'option' );
76 76
 		return $html;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param string|int $value unnormalized value option (string)
84 84
 	 * @return string
85 85
 	 */
86
-	protected function _check_if_option_selected( $value ){
86
+	protected function _check_if_option_selected($value) {
87 87
 		return $this->_input->raw_value() == $value ? TRUE : FALSE;
88 88
 	}
89 89
 
Please login to merge, or discard this patch.
core/wordpress-shims.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -5,51 +5,51 @@
 block discarded – undo
5 5
  * it does not override any existing definition of the function in WP.
6 6
  */
7 7
 if ( ! function_exists( 'get_preview_post_link' ) ) {
8
-    /**
9
-     * Function was added in WordPress 4.4.0
10
-     * @param null   $post
11
-     * @param array  $query_args
12
-     * @param string $preview_link
13
-     * @return mixed
14
-     */
15
-    function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
16
-    {
17
-        $post = get_post($post);
18
-        if (! $post) {
19
-            return '';
20
-        }
8
+	/**
9
+	 * Function was added in WordPress 4.4.0
10
+	 * @param null   $post
11
+	 * @param array  $query_args
12
+	 * @param string $preview_link
13
+	 * @return mixed
14
+	 */
15
+	function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
16
+	{
17
+		$post = get_post($post);
18
+		if (! $post) {
19
+			return '';
20
+		}
21 21
 
22
-        $post_type_object = get_post_type_object($post->post_type);
23
-        if (is_post_type_viewable($post_type_object)) {
24
-            if (! $preview_link) {
25
-                $preview_link = set_url_scheme(get_permalink($post));
26
-            }
22
+		$post_type_object = get_post_type_object($post->post_type);
23
+		if (is_post_type_viewable($post_type_object)) {
24
+			if (! $preview_link) {
25
+				$preview_link = set_url_scheme(get_permalink($post));
26
+			}
27 27
 
28
-            $query_args['preview'] = 'true';
29
-            $preview_link          = add_query_arg($query_args, $preview_link);
30
-        }
28
+			$query_args['preview'] = 'true';
29
+			$preview_link          = add_query_arg($query_args, $preview_link);
30
+		}
31 31
 
32
-        /**
33
-         * Filters the URL used for a post preview.
34
-         *
35
-         * @since 2.0.5
36
-         * @since 4.0.0 Added the `$post` parameter.
37
-         * @param string  $preview_link URL used for the post preview.
38
-         * @param WP_Post $post         Post object.
39
-         */
40
-        return apply_filters('preview_post_link', $preview_link, $post);
41
-    }
32
+		/**
33
+		 * Filters the URL used for a post preview.
34
+		 *
35
+		 * @since 2.0.5
36
+		 * @since 4.0.0 Added the `$post` parameter.
37
+		 * @param string  $preview_link URL used for the post preview.
38
+		 * @param WP_Post $post         Post object.
39
+		 */
40
+		return apply_filters('preview_post_link', $preview_link, $post);
41
+	}
42 42
 }
43 43
 
44 44
 if ( ! function_exists( 'is_post_type_viewable' ) ) {
45
-    function is_post_type_viewable( $post_type ) {
46
-        if ( is_scalar( $post_type ) ) {
47
-            $post_type = get_post_type_object( $post_type );
48
-            if ( ! $post_type ) {
49
-                return false;
50
-            }
51
-        }
45
+	function is_post_type_viewable( $post_type ) {
46
+		if ( is_scalar( $post_type ) ) {
47
+			$post_type = get_post_type_object( $post_type );
48
+			if ( ! $post_type ) {
49
+				return false;
50
+			}
51
+		}
52 52
      
53
-        return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
54
-    }
53
+		return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
54
+	}
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Note: this file should only be required right before calling the function the shim is for.  This is to ensure that
5 5
  * it does not override any existing definition of the function in WP.
6 6
  */
7
-if ( ! function_exists( 'get_preview_post_link' ) ) {
7
+if ( ! function_exists('get_preview_post_link')) {
8 8
     /**
9 9
      * Function was added in WordPress 4.4.0
10 10
      * @param null   $post
@@ -15,13 +15,13 @@  discard block
 block discarded – undo
15 15
     function get_preview_post_link($post = null, $query_args = array(), $preview_link = '')
16 16
     {
17 17
         $post = get_post($post);
18
-        if (! $post) {
18
+        if ( ! $post) {
19 19
             return '';
20 20
         }
21 21
 
22 22
         $post_type_object = get_post_type_object($post->post_type);
23 23
         if (is_post_type_viewable($post_type_object)) {
24
-            if (! $preview_link) {
24
+            if ( ! $preview_link) {
25 25
                 $preview_link = set_url_scheme(get_permalink($post));
26 26
             }
27 27
 
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
     }
42 42
 }
43 43
 
44
-if ( ! function_exists( 'is_post_type_viewable' ) ) {
45
-    function is_post_type_viewable( $post_type ) {
46
-        if ( is_scalar( $post_type ) ) {
47
-            $post_type = get_post_type_object( $post_type );
48
-            if ( ! $post_type ) {
44
+if ( ! function_exists('is_post_type_viewable')) {
45
+    function is_post_type_viewable($post_type) {
46
+        if (is_scalar($post_type)) {
47
+            $post_type = get_post_type_object($post_type);
48
+            if ( ! $post_type) {
49 49
                 return false;
50 50
             }
51 51
         }
52 52
      
53
-        return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
53
+        return $post_type->publicly_queryable || ($post_type->_builtin && $post_type->public);
54 54
     }
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php 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
-                ); ?>
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 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    '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.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'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.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.004');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.004');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1388 added lines, -1388 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -24,445 +24,445 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * This gets set in _setup_cpt
29
-     * It will contain the object for the custom post type.
30
-     *
31
-     * @var object
32
-     */
33
-    protected $_cpt_object;
34
-
35
-
36
-
37
-    /**
38
-     * a boolean flag to set whether the current route is a cpt route or not.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $_cpt_route = false;
43
-
44
-
45
-
46
-    /**
47
-     * This property allows cpt classes to define multiple routes as cpt routes.
48
-     * //in this array we define what the custom post type for this route is.
49
-     * array(
50
-     * 'route_name' => 'custom_post_type_slug'
51
-     * )
52
-     *
53
-     * @var array
54
-     */
55
-    protected $_cpt_routes = array();
56
-
27
+	/**
28
+	 * This gets set in _setup_cpt
29
+	 * It will contain the object for the custom post type.
30
+	 *
31
+	 * @var object
32
+	 */
33
+	protected $_cpt_object;
34
+
35
+
36
+
37
+	/**
38
+	 * a boolean flag to set whether the current route is a cpt route or not.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $_cpt_route = false;
43
+
44
+
45
+
46
+	/**
47
+	 * This property allows cpt classes to define multiple routes as cpt routes.
48
+	 * //in this array we define what the custom post type for this route is.
49
+	 * array(
50
+	 * 'route_name' => 'custom_post_type_slug'
51
+	 * )
52
+	 *
53
+	 * @var array
54
+	 */
55
+	protected $_cpt_routes = array();
56
+
57 57
 
58 58
 
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-
90
-    /**
91
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
-     * Registration of containers should be done before load_page_dependencies() is run.
95
-     *
96
-     * @var array()
97
-     */
98
-    protected $_autosave_containers = array();
99
-    protected $_autosave_fields = array();
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map = null;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @access protected
119
-     * @abstract
120
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
-     * @param  object $post    The post object of the cpt that was saved.
122
-     * @return void
123
-     */
124
-    abstract protected function _insert_update_cpt_item($post_id, $post);
125
-
126
-
127
-
128
-    /**
129
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
-     *
131
-     * @abstract
132
-     * @access public
133
-     * @param  string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-
150
-    /**
151
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
-     * from the db
153
-     *
154
-     * @param  string $post_id the ID of the cpt that was deleted
155
-     * @return void
156
-     */
157
-    abstract public function delete_cpt_item($post_id);
158
-
159
-
160
-
161
-    /**
162
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
-     *
164
-     * @access protected
165
-     * @return void
166
-     */
167
-    protected function _before_page_setup()
168
-    {
169
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
-        $this->_cpt_routes = array_merge(array(
171
-            'create_new' => $this->page_slug,
172
-            'edit'       => $this->page_slug,
173
-            'trash'      => $this->page_slug,
174
-        ), $this->_cpt_routes);
175
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
-            : get_post_type_object($page);
179
-        //tweak pagenow for page loading.
180
-        if ( ! $this->_pagenow_map) {
181
-            $this->_pagenow_map = array(
182
-                'create_new' => 'post-new.php',
183
-                'edit'       => 'post.php',
184
-                'trash'      => 'post.php',
185
-            );
186
-        }
187
-        add_action('current_screen', array($this, 'modify_pagenow'));
188
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
-        //get current page from autosave
190
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
-            : null;
193
-        $this->_current_page = isset($this->_req_data['current_page'])
194
-            ? $this->_req_data['current_page']
195
-            : $current_page;
196
-        //autosave... make sure its only for the correct page
197
-        if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
-            //setup autosave ajax hook
199
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Simply ensure that we simulate the correct post route for cpt screens
207
-     *
208
-     * @param WP_Screen $current_screen
209
-     * @return void
210
-     */
211
-    public function modify_pagenow($current_screen)
212
-    {
213
-        global $pagenow, $hook_suffix;
214
-        //possibly reset pagenow.
215
-        if ( ! empty($this->_req_data['page'])
216
-             && $this->_req_data['page'] == $this->page_slug
217
-             && ! empty($this->_req_data['action'])
218
-             && isset($this->_pagenow_map[$this->_req_data['action']])
219
-        ) {
220
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
-            $hook_suffix = $pagenow;
222
-        }
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * This method is used to register additional autosave containers to the _autosave_containers property.
229
-     *
230
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
-     *       automatically register the id for the post metabox as a container.
232
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
-     *                    you would send along the id of a metabox container.
234
-     * @return void
235
-     */
236
-    protected function _register_autosave_containers($ids)
237
-    {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
-     */
247
-    protected function _set_autosave_containers()
248
-    {
249
-        global $wp_meta_boxes;
250
-        $containers = array();
251
-        if (empty($wp_meta_boxes)) {
252
-            return;
253
-        }
254
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
-        foreach ($current_metaboxes as $box_context) {
256
-            foreach ($box_context as $box_details) {
257
-                foreach ($box_details as $box) {
258
-                    if (is_array($box['callback'])
259
-                        && ($box['callback'][0] instanceof EE_Admin_Page
260
-                            || $box['callback'][0] instanceof EE_Admin_Hooks)
261
-                    ) {
262
-                        $containers[] = $box['id'];
263
-                    }
264
-                }
265
-            }
266
-        }
267
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
-        //add hidden inputs container
269
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
-    }
271
-
272
-
273
-
274
-    protected function _load_autosave_scripts_styles()
275
-    {
276
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+
90
+	/**
91
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
+	 * Registration of containers should be done before load_page_dependencies() is run.
95
+	 *
96
+	 * @var array()
97
+	 */
98
+	protected $_autosave_containers = array();
99
+	protected $_autosave_fields = array();
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map = null;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @access protected
119
+	 * @abstract
120
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
+	 * @param  object $post    The post object of the cpt that was saved.
122
+	 * @return void
123
+	 */
124
+	abstract protected function _insert_update_cpt_item($post_id, $post);
125
+
126
+
127
+
128
+	/**
129
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
+	 *
131
+	 * @abstract
132
+	 * @access public
133
+	 * @param  string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+
150
+	/**
151
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
+	 * from the db
153
+	 *
154
+	 * @param  string $post_id the ID of the cpt that was deleted
155
+	 * @return void
156
+	 */
157
+	abstract public function delete_cpt_item($post_id);
158
+
159
+
160
+
161
+	/**
162
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
+	 *
164
+	 * @access protected
165
+	 * @return void
166
+	 */
167
+	protected function _before_page_setup()
168
+	{
169
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
+		$this->_cpt_routes = array_merge(array(
171
+			'create_new' => $this->page_slug,
172
+			'edit'       => $this->page_slug,
173
+			'trash'      => $this->page_slug,
174
+		), $this->_cpt_routes);
175
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
+			: get_post_type_object($page);
179
+		//tweak pagenow for page loading.
180
+		if ( ! $this->_pagenow_map) {
181
+			$this->_pagenow_map = array(
182
+				'create_new' => 'post-new.php',
183
+				'edit'       => 'post.php',
184
+				'trash'      => 'post.php',
185
+			);
186
+		}
187
+		add_action('current_screen', array($this, 'modify_pagenow'));
188
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
+		//get current page from autosave
190
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
+			: null;
193
+		$this->_current_page = isset($this->_req_data['current_page'])
194
+			? $this->_req_data['current_page']
195
+			: $current_page;
196
+		//autosave... make sure its only for the correct page
197
+		if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
+			//setup autosave ajax hook
199
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Simply ensure that we simulate the correct post route for cpt screens
207
+	 *
208
+	 * @param WP_Screen $current_screen
209
+	 * @return void
210
+	 */
211
+	public function modify_pagenow($current_screen)
212
+	{
213
+		global $pagenow, $hook_suffix;
214
+		//possibly reset pagenow.
215
+		if ( ! empty($this->_req_data['page'])
216
+			 && $this->_req_data['page'] == $this->page_slug
217
+			 && ! empty($this->_req_data['action'])
218
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
219
+		) {
220
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
+			$hook_suffix = $pagenow;
222
+		}
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
229
+	 *
230
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
+	 *       automatically register the id for the post metabox as a container.
232
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
+	 *                    you would send along the id of a metabox container.
234
+	 * @return void
235
+	 */
236
+	protected function _register_autosave_containers($ids)
237
+	{
238
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
+	 */
247
+	protected function _set_autosave_containers()
248
+	{
249
+		global $wp_meta_boxes;
250
+		$containers = array();
251
+		if (empty($wp_meta_boxes)) {
252
+			return;
253
+		}
254
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
+		foreach ($current_metaboxes as $box_context) {
256
+			foreach ($box_context as $box_details) {
257
+				foreach ($box_details as $box) {
258
+					if (is_array($box['callback'])
259
+						&& ($box['callback'][0] instanceof EE_Admin_Page
260
+							|| $box['callback'][0] instanceof EE_Admin_Hooks)
261
+					) {
262
+						$containers[] = $box['id'];
263
+					}
264
+				}
265
+			}
266
+		}
267
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
+		//add hidden inputs container
269
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
+	}
271
+
272
+
273
+
274
+	protected function _load_autosave_scripts_styles()
275
+	{
276
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
277 277
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
278 278
 
279
-        //filter _autosave_containers
280
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
-            $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
-            $containers, $this);
284
-
285
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
-
288
-        $unsaved_data_msg = array(
289
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
291
-            'inputChanged' => 0,
292
-        );
293
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
-    }
295
-
296
-
297
-
298
-    public function load_page_dependencies()
299
-    {
300
-        try {
301
-            $this->_load_page_dependencies();
302
-        } catch (EE_Error $e) {
303
-            $e->get_error();
304
-        }
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
-     *
312
-     * @access protected
313
-     * @return void
314
-     */
315
-    protected function _load_page_dependencies()
316
-    {
317
-        //we only add stuff if this is a cpt_route!
318
-        if ( ! $this->_cpt_route) {
319
-            parent::_load_page_dependencies();
320
-            return;
321
-        }
322
-        //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
-        //the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
-        //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
-        //inject our Admin page nav tabs...
327
-        //let's make sure the nav tabs are set if they aren't already
328
-        //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
-        //modify the post_updated messages array
331
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
-        //add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
-        //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
-        if ( ! empty($this->_labels['publishbox'])) {
336
-            $box_label = is_array($this->_labels['publishbox'])
337
-                         && isset($this->_labels['publishbox'][$this->_req_action])
338
-                ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
-            remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
-                'side', 'core');
341
-            add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
-                'side', 'core');
343
-        }
344
-        //let's add page_templates metabox if this cpt added support for it.
345
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
-            add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
-                array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
-        }
349
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
351
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
-        }
353
-        //add preview button
354
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
-        //insert our own post_stati dropdown
356
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
358
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
-        }
361
-        //This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
-        if (method_exists($this, 'edit_form_after_title')) {
363
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
-        }
365
-        /**
366
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
-         */
368
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
-        parent::_load_page_dependencies();
370
-        //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
-        global $pagenow;
372
-        do_action('load-' . $pagenow);
373
-        $this->modify_current_screen();
374
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
-        //we route REALLY early.
376
-        try {
377
-            $this->_route_admin_request();
378
-        } catch (EE_Error $e) {
379
-            $e->get_error();
380
-        }
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
-     * route instead.
389
-     *
390
-     * @param string $good_protocol_url The escaped url.
391
-     * @param string $original_url      The original url.
392
-     * @param string $_context          The context sendt to the esc_url method.
393
-     * @return string possibly a new url for our route.
394
-     */
395
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
-    {
397
-        $routes_to_match = array(
398
-            0 => array(
399
-                'edit.php?post_type=espresso_attendees',
400
-                'admin.php?page=espresso_registrations&action=contact_list',
401
-            ),
402
-            1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
405
-            ),
406
-        );
407
-        foreach ($routes_to_match as $route_matches) {
408
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
-            }
411
-        }
412
-        return $good_protocol_url;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Determine whether the current cpt supports page templates or not.
419
-     *
420
-     * @since %VER%
421
-     * @param string $cpt_name The cpt slug we're checking on.
422
-     * @return bool True supported, false not.
423
-     */
424
-    private function _supports_page_templates($cpt_name)
425
-    {
426
-
427
-        $cpt_args = EE_Register_CPTs::get_CPTs();
428
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
430
-
431
-        //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
-            $post_templates = wp_get_theme()->get_post_templates();
434
-            //if there are $post_templates for this cpt, then we return false for this method because
435
-            //that means we aren't going to load our page template manager and leave that up to the native
436
-            //cpt template manager.
437
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
-        }
439
-
440
-        return $cpt_has_support;
441
-    }
442
-
443
-
444
-    /**
445
-     * Callback for the page_templates metabox selector.
446
-     *
447
-     * @since %VER%
448
-     * @return string html
449
-     */
450
-    public function page_template_meta_box()
451
-    {
452
-        global $post;
453
-        $template = '';
454
-
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
-            $page_template_count = count(get_page_templates());
457
-        } else {
458
-            $page_template_count = count(get_page_templates($post));
459
-        };
460
-
461
-        if ($page_template_count) {
462
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
-            $template      = ! empty($page_template) ? $page_template : '';
464
-        }
465
-        ?>
279
+		//filter _autosave_containers
280
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
+			$this->_autosave_containers, $this);
282
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
+			$containers, $this);
284
+
285
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
+
288
+		$unsaved_data_msg = array(
289
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
291
+			'inputChanged' => 0,
292
+		);
293
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
+	}
295
+
296
+
297
+
298
+	public function load_page_dependencies()
299
+	{
300
+		try {
301
+			$this->_load_page_dependencies();
302
+		} catch (EE_Error $e) {
303
+			$e->get_error();
304
+		}
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
+	 *
312
+	 * @access protected
313
+	 * @return void
314
+	 */
315
+	protected function _load_page_dependencies()
316
+	{
317
+		//we only add stuff if this is a cpt_route!
318
+		if ( ! $this->_cpt_route) {
319
+			parent::_load_page_dependencies();
320
+			return;
321
+		}
322
+		//now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
+		//the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
+		//let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
+		//inject our Admin page nav tabs...
327
+		//let's make sure the nav tabs are set if they aren't already
328
+		//if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
+		//modify the post_updated messages array
331
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
+		//add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
+		//This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
+		if ( ! empty($this->_labels['publishbox'])) {
336
+			$box_label = is_array($this->_labels['publishbox'])
337
+						 && isset($this->_labels['publishbox'][$this->_req_action])
338
+				? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
+			remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
+				'side', 'core');
341
+			add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
+				'side', 'core');
343
+		}
344
+		//let's add page_templates metabox if this cpt added support for it.
345
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
+			add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
+				array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
+		}
349
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
351
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
+		}
353
+		//add preview button
354
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
+		//insert our own post_stati dropdown
356
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
358
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
+		}
361
+		//This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
+		if (method_exists($this, 'edit_form_after_title')) {
363
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
+		}
365
+		/**
366
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
+		 */
368
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
+		parent::_load_page_dependencies();
370
+		//notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
+		global $pagenow;
372
+		do_action('load-' . $pagenow);
373
+		$this->modify_current_screen();
374
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
+		//we route REALLY early.
376
+		try {
377
+			$this->_route_admin_request();
378
+		} catch (EE_Error $e) {
379
+			$e->get_error();
380
+		}
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
+	 * route instead.
389
+	 *
390
+	 * @param string $good_protocol_url The escaped url.
391
+	 * @param string $original_url      The original url.
392
+	 * @param string $_context          The context sendt to the esc_url method.
393
+	 * @return string possibly a new url for our route.
394
+	 */
395
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
+	{
397
+		$routes_to_match = array(
398
+			0 => array(
399
+				'edit.php?post_type=espresso_attendees',
400
+				'admin.php?page=espresso_registrations&action=contact_list',
401
+			),
402
+			1 => array(
403
+				'edit.php?post_type=' . $this->_cpt_object->name,
404
+				'admin.php?page=' . $this->_cpt_object->name,
405
+			),
406
+		);
407
+		foreach ($routes_to_match as $route_matches) {
408
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
+			}
411
+		}
412
+		return $good_protocol_url;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Determine whether the current cpt supports page templates or not.
419
+	 *
420
+	 * @since %VER%
421
+	 * @param string $cpt_name The cpt slug we're checking on.
422
+	 * @return bool True supported, false not.
423
+	 */
424
+	private function _supports_page_templates($cpt_name)
425
+	{
426
+
427
+		$cpt_args = EE_Register_CPTs::get_CPTs();
428
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
430
+
431
+		//if the installed version of WP is > 4.7 we do some additional checks.
432
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
+			$post_templates = wp_get_theme()->get_post_templates();
434
+			//if there are $post_templates for this cpt, then we return false for this method because
435
+			//that means we aren't going to load our page template manager and leave that up to the native
436
+			//cpt template manager.
437
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
+		}
439
+
440
+		return $cpt_has_support;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Callback for the page_templates metabox selector.
446
+	 *
447
+	 * @since %VER%
448
+	 * @return string html
449
+	 */
450
+	public function page_template_meta_box()
451
+	{
452
+		global $post;
453
+		$template = '';
454
+
455
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
+			$page_template_count = count(get_page_templates());
457
+		} else {
458
+			$page_template_count = count(get_page_templates($post));
459
+		};
460
+
461
+		if ($page_template_count) {
462
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
+			$template      = ! empty($page_template) ? $page_template : '';
464
+		}
465
+		?>
466 466
         <p><strong><?php _e('Template') ?></strong></p>
467 467
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
468 468
             name="page_template" id="page_template">
@@ -470,437 +470,437 @@  discard block
 block discarded – undo
470 470
         <?php page_template_dropdown($template); ?>
471 471
     </select>
472 472
         <?php
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
479
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
-     *
481
-     * @param  string $return    the current html
482
-     * @param  int    $id        the post id for the page
483
-     * @param  string $new_title What the title is
484
-     * @param  string $new_slug  what the slug is
485
-     * @return string            The new html string for the permalink area
486
-     */
487
-    public function preview_button_html($return, $id, $new_title, $new_slug)
488
-    {
489
-        $post = get_post($id);
490
-        if ('publish' != get_post_status($post)) {
491
-            //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
493
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
-                       . get_preview_post_link($id)
495
-                       . '" class="button button-small">'
496
-                       . __('Preview', 'event_espresso')
497
-                       . '</a></span>'
498
-                       . "\n";
499
-        }
500
-        return $return;
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * add our custom post stati dropdown on the wp post page for this cpt
507
-     *
508
-     * @return string html for dropdown
509
-     */
510
-    public function custom_post_stati_dropdown()
511
-    {
512
-
513
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
-            ? $statuses[$this->_cpt_model_obj->status()]
516
-            : '';
517
-        $template_args    = array(
518
-            'cur_status'            => $this->_cpt_model_obj->status(),
519
-            'statuses'              => $statuses,
520
-            'cur_status_label'      => $cur_status_label,
521
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
-        );
523
-        //we'll add a trash post status (WP doesn't add one for some reason)
524
-        if ($this->_cpt_model_obj->status() == 'trash') {
525
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
527
-            $template_args['statuses']         = $statuses;
528
-        }
529
-
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
-        EEH_Template::display_template($template, $template_args);
532
-    }
533
-
534
-
535
-
536
-    public function setup_autosave_hooks()
537
-    {
538
-        $this->_set_autosave_containers();
539
-        $this->_load_autosave_scripts_styles();
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
-     * for the nonce in here, but then this method looks for two things:
548
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
-     * template args.
553
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
-     *    $this->_template_args['data']['items'] = array(
557
-     *        'event-datetime-ids' => '1,2,3';
558
-     *    );
559
-     *    Keep in mind the following things:
560
-     *    - "where" index is for the input with the id as that string.
561
-     *    - "what" index is what will be used for the value of that input.
562
-     *
563
-     * @return void
564
-     */
565
-    public function do_extra_autosave_stuff()
566
-    {
567
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
568
-        $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
-        $this->_verify_nonce($nonce, 'autosave');
570
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
-        if ( ! defined('DOING_AUTOSAVE')) {
572
-            define('DOING_AUTOSAVE', true);
573
-        }
574
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
-        } else {
578
-            $this->_template_args['success'] = true;
579
-        }
580
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
-        //now let's return json
583
-        $this->_return_json();
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
-     *
593
-     * @access protected
594
-     * @throws EE_Error
595
-     * @return void
596
-     */
597
-    protected function _extend_page_config_for_cpt()
598
-    {
599
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
-        if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
-            return;
602
-        }
603
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
-        if ( ! empty($this->_cpt_object)) {
605
-            $this->_page_routes = array_merge(array(
606
-                'create_new' => '_create_new_cpt_item',
607
-                'edit'       => '_edit_cpt_item',
608
-            ), $this->_page_routes);
609
-            $this->_page_config = array_merge(array(
610
-                'create_new' => array(
611
-                    'nav'           => array(
612
-                        'label' => $this->_cpt_object->labels->add_new_item,
613
-                        'order' => 5,
614
-                    ),
615
-                    'require_nonce' => false,
616
-                ),
617
-                'edit'       => array(
618
-                    'nav'           => array(
619
-                        'label'      => $this->_cpt_object->labels->edit_item,
620
-                        'order'      => 5,
621
-                        'persistent' => false,
622
-                        'url'        => '',
623
-                    ),
624
-                    'require_nonce' => false,
625
-                ),
626
-            ),
627
-                $this->_page_config
628
-            );
629
-        }
630
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
631
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
-            return;
633
-        }
634
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
-        if (empty($this->_cpt_object)) {
637
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
-                $this->page_slug, $this->_req_action, get_class($this));
639
-            throw new EE_Error($msg);
640
-        }
641
-        if ($this->_cpt_route) {
642
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
-            $this->_set_model_object($id);
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
-     *
652
-     * @access protected
653
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
-     * @param bool $ignore_route_check
655
-     */
656
-    protected function _set_model_object($id = null, $ignore_route_check = false)
657
-    {
658
-        $model = null;
659
-        if (
660
-            empty($this->_cpt_model_names)
661
-            || (
662
-                ! $ignore_route_check
663
-                && ! isset($this->_cpt_routes[$this->_req_action])
664
-            ) || (
665
-                $this->_cpt_model_obj instanceof EE_CPT_Base
666
-                && $this->_cpt_model_obj->ID() === $id
667
-            )
668
-        ) {
669
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
-            return;
671
-        }
672
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
-        if ($ignore_route_check) {
674
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
675
-            $post_type   = get_post_type($id);
676
-            if (isset($model_names[$post_type])) {
677
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
-            }
679
-        } else {
680
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
-        }
682
-        if ($model instanceof EEM_Base) {
683
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
-        }
685
-        do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * admin_init_global
692
-     * This runs all the code that we want executed within the WP admin_init hook.
693
-     * This method executes for ALL EE Admin pages.
694
-     *
695
-     * @access public
696
-     * @return void
697
-     */
698
-    public function admin_init_global()
699
-    {
700
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
-        //its possible this is a new save so let's catch that instead
702
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
-        $post_type = $post ? $post->post_type : false;
704
-        $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
-            : 'shouldneverwork';
706
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
-            : '';
708
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
-        if ($post_type === $route_to_check) {
711
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
-            //catch trashed wp redirect
713
-            add_filter('wp_redirect', array($this, 'cpt_trash_post_location_redirect'), 10, 2);
714
-        }
715
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
716
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
717
-        if ( ! empty($revision)) {
718
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
719
-            //doing a restore?
720
-            if ( ! empty($action) && $action == 'restore') {
721
-                //get post for revision
722
-                $rev_post = get_post($revision);
723
-                $rev_parent = get_post($rev_post->post_parent);
724
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
725
-                if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
726
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
727
-                    //restores of revisions
728
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
729
-                }
730
-            }
731
-        }
732
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
733
-        if ($post_type && $post_type === $route_to_check) {
734
-            //$post_id, $post
735
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
736
-            //$post_id
737
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
738
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
739
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
740
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
741
-        }
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * Callback for the WordPress trashed_post hook.
748
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
749
-     *
750
-     * @param int $post_id
751
-     */
752
-    public function before_trash_cpt_item($post_id)
753
-    {
754
-        $this->_set_model_object($post_id, true);
755
-        //if our cpt object isn't existent then get out immediately.
756
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
757
-            return;
758
-        }
759
-        $this->trash_cpt_item($post_id);
760
-    }
761
-
762
-
763
-
764
-    /**
765
-     * Callback for the WordPress untrashed_post hook.
766
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
767
-     *
768
-     * @param $post_id
769
-     */
770
-    public function before_restore_cpt_item($post_id)
771
-    {
772
-        $this->_set_model_object($post_id, true);
773
-        //if our cpt object isn't existent then get out immediately.
774
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
775
-            return;
776
-        }
777
-        $this->restore_cpt_item($post_id);
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     * Callback for the WordPress after_delete_post hook.
784
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
785
-     *
786
-     * @param $post_id
787
-     */
788
-    public function before_delete_cpt_item($post_id)
789
-    {
790
-        $this->_set_model_object($post_id, true);
791
-        //if our cpt object isn't existent then get out immediately.
792
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
793
-            return;
794
-        }
795
-        $this->delete_cpt_item($post_id);
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
802
-     * accordingly.
803
-     *
804
-     * @access public
805
-     * @throws EE_Error
806
-     * @return void
807
-     */
808
-    public function verify_cpt_object()
809
-    {
810
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
811
-        // verify event object
812
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
813
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
814
-                'event_espresso'), $label));
815
-        }
816
-        //if auto-draft then throw an error
817
-        if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
818
-            EE_Error::overwrite_errors();
819
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
820
-                $label), __FILE__, __FUNCTION__, __LINE__);
821
-        }
822
-    }
823
-
824
-
825
-
826
-    /**
827
-     * admin_footer_scripts_global
828
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
829
-     * will apply on ALL EE_Admin pages.
830
-     *
831
-     * @access public
832
-     * @return void
833
-     */
834
-    public function admin_footer_scripts_global()
835
-    {
836
-        $this->_add_admin_page_ajax_loading_img();
837
-        $this->_add_admin_page_overlay();
838
-    }
839
-
840
-
841
-
842
-    /**
843
-     * add in any global scripts for cpt routes
844
-     *
845
-     * @return void
846
-     */
847
-    public function load_global_scripts_styles()
848
-    {
849
-        parent::load_global_scripts_styles();
850
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
851
-            //setup custom post status object for localize script but only if we've got a cpt object
852
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
853
-            if ( ! empty($statuses)) {
854
-                //get ALL statuses!
855
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
856
-                //setup object
857
-                $ee_cpt_statuses = array();
858
-                foreach ($statuses as $status => $label) {
859
-                    $ee_cpt_statuses[$status] = array(
860
-                        'label'      => $label,
861
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
862
-                    );
863
-                }
864
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
865
-            }
866
-        }
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
873
-     * insert/updates
874
-     *
875
-     * @param  int     $post_id ID of post being updated
876
-     * @param  WP_Post $post    Post object from WP
877
-     * @param  bool    $update  Whether this is an update or a new save.
878
-     * @return void
879
-     */
880
-    public function insert_update($post_id, $post, $update)
881
-    {
882
-        //make sure that if this is a revision OR trash action that we don't do any updates!
883
-        if (
884
-            isset($this->_req_data['action'])
885
-            && (
886
-                $this->_req_data['action'] == 'restore'
887
-                || $this->_req_data['action'] == 'trash'
888
-            )
889
-        ) {
890
-            return;
891
-        }
892
-        $this->_set_model_object($post_id, true);
893
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
894
-        if ($update
895
-            && (
896
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
897
-                || $this->_cpt_model_obj->ID() !== $post_id
898
-            )
899
-        ) {
900
-            return;
901
-        }
902
-        //check for autosave and update our req_data property accordingly.
903
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
479
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
+	 *
481
+	 * @param  string $return    the current html
482
+	 * @param  int    $id        the post id for the page
483
+	 * @param  string $new_title What the title is
484
+	 * @param  string $new_slug  what the slug is
485
+	 * @return string            The new html string for the permalink area
486
+	 */
487
+	public function preview_button_html($return, $id, $new_title, $new_slug)
488
+	{
489
+		$post = get_post($id);
490
+		if ('publish' != get_post_status($post)) {
491
+			//include shims for the `get_preview_post_link` function
492
+			require_once( EE_CORE . 'wordpress-shims.php' );
493
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
+					   . get_preview_post_link($id)
495
+					   . '" class="button button-small">'
496
+					   . __('Preview', 'event_espresso')
497
+					   . '</a></span>'
498
+					   . "\n";
499
+		}
500
+		return $return;
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * add our custom post stati dropdown on the wp post page for this cpt
507
+	 *
508
+	 * @return string html for dropdown
509
+	 */
510
+	public function custom_post_stati_dropdown()
511
+	{
512
+
513
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
+			? $statuses[$this->_cpt_model_obj->status()]
516
+			: '';
517
+		$template_args    = array(
518
+			'cur_status'            => $this->_cpt_model_obj->status(),
519
+			'statuses'              => $statuses,
520
+			'cur_status_label'      => $cur_status_label,
521
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
+		);
523
+		//we'll add a trash post status (WP doesn't add one for some reason)
524
+		if ($this->_cpt_model_obj->status() == 'trash') {
525
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
527
+			$template_args['statuses']         = $statuses;
528
+		}
529
+
530
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
+		EEH_Template::display_template($template, $template_args);
532
+	}
533
+
534
+
535
+
536
+	public function setup_autosave_hooks()
537
+	{
538
+		$this->_set_autosave_containers();
539
+		$this->_load_autosave_scripts_styles();
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
+	 * for the nonce in here, but then this method looks for two things:
548
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
+	 * template args.
553
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
+	 *    $this->_template_args['data']['items'] = array(
557
+	 *        'event-datetime-ids' => '1,2,3';
558
+	 *    );
559
+	 *    Keep in mind the following things:
560
+	 *    - "where" index is for the input with the id as that string.
561
+	 *    - "what" index is what will be used for the value of that input.
562
+	 *
563
+	 * @return void
564
+	 */
565
+	public function do_extra_autosave_stuff()
566
+	{
567
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
568
+		$nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
+		$this->_verify_nonce($nonce, 'autosave');
570
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
+		if ( ! defined('DOING_AUTOSAVE')) {
572
+			define('DOING_AUTOSAVE', true);
573
+		}
574
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
575
+		if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
+			call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
+		} else {
578
+			$this->_template_args['success'] = true;
579
+		}
580
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
+		//now let's return json
583
+		$this->_return_json();
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
+	 *
593
+	 * @access protected
594
+	 * @throws EE_Error
595
+	 * @return void
596
+	 */
597
+	protected function _extend_page_config_for_cpt()
598
+	{
599
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
+		if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
+			return;
602
+		}
603
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
+		if ( ! empty($this->_cpt_object)) {
605
+			$this->_page_routes = array_merge(array(
606
+				'create_new' => '_create_new_cpt_item',
607
+				'edit'       => '_edit_cpt_item',
608
+			), $this->_page_routes);
609
+			$this->_page_config = array_merge(array(
610
+				'create_new' => array(
611
+					'nav'           => array(
612
+						'label' => $this->_cpt_object->labels->add_new_item,
613
+						'order' => 5,
614
+					),
615
+					'require_nonce' => false,
616
+				),
617
+				'edit'       => array(
618
+					'nav'           => array(
619
+						'label'      => $this->_cpt_object->labels->edit_item,
620
+						'order'      => 5,
621
+						'persistent' => false,
622
+						'url'        => '',
623
+					),
624
+					'require_nonce' => false,
625
+				),
626
+			),
627
+				$this->_page_config
628
+			);
629
+		}
630
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
631
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
+			return;
633
+		}
634
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
+		if (empty($this->_cpt_object)) {
637
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
+				$this->page_slug, $this->_req_action, get_class($this));
639
+			throw new EE_Error($msg);
640
+		}
641
+		if ($this->_cpt_route) {
642
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
+			$this->_set_model_object($id);
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
+	 *
652
+	 * @access protected
653
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
+	 * @param bool $ignore_route_check
655
+	 */
656
+	protected function _set_model_object($id = null, $ignore_route_check = false)
657
+	{
658
+		$model = null;
659
+		if (
660
+			empty($this->_cpt_model_names)
661
+			|| (
662
+				! $ignore_route_check
663
+				&& ! isset($this->_cpt_routes[$this->_req_action])
664
+			) || (
665
+				$this->_cpt_model_obj instanceof EE_CPT_Base
666
+				&& $this->_cpt_model_obj->ID() === $id
667
+			)
668
+		) {
669
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
+			return;
671
+		}
672
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
+		if ($ignore_route_check) {
674
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
675
+			$post_type   = get_post_type($id);
676
+			if (isset($model_names[$post_type])) {
677
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
+			}
679
+		} else {
680
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
+		}
682
+		if ($model instanceof EEM_Base) {
683
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
+		}
685
+		do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * admin_init_global
692
+	 * This runs all the code that we want executed within the WP admin_init hook.
693
+	 * This method executes for ALL EE Admin pages.
694
+	 *
695
+	 * @access public
696
+	 * @return void
697
+	 */
698
+	public function admin_init_global()
699
+	{
700
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
+		//its possible this is a new save so let's catch that instead
702
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
+		$post_type = $post ? $post->post_type : false;
704
+		$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
+			: 'shouldneverwork';
706
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
+			: '';
708
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
+		if ($post_type === $route_to_check) {
711
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
+			//catch trashed wp redirect
713
+			add_filter('wp_redirect', array($this, 'cpt_trash_post_location_redirect'), 10, 2);
714
+		}
715
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
716
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
717
+		if ( ! empty($revision)) {
718
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
719
+			//doing a restore?
720
+			if ( ! empty($action) && $action == 'restore') {
721
+				//get post for revision
722
+				$rev_post = get_post($revision);
723
+				$rev_parent = get_post($rev_post->post_parent);
724
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
725
+				if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
726
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
727
+					//restores of revisions
728
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
729
+				}
730
+			}
731
+		}
732
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
733
+		if ($post_type && $post_type === $route_to_check) {
734
+			//$post_id, $post
735
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
736
+			//$post_id
737
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
738
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
739
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
740
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
741
+		}
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * Callback for the WordPress trashed_post hook.
748
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
749
+	 *
750
+	 * @param int $post_id
751
+	 */
752
+	public function before_trash_cpt_item($post_id)
753
+	{
754
+		$this->_set_model_object($post_id, true);
755
+		//if our cpt object isn't existent then get out immediately.
756
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
757
+			return;
758
+		}
759
+		$this->trash_cpt_item($post_id);
760
+	}
761
+
762
+
763
+
764
+	/**
765
+	 * Callback for the WordPress untrashed_post hook.
766
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
767
+	 *
768
+	 * @param $post_id
769
+	 */
770
+	public function before_restore_cpt_item($post_id)
771
+	{
772
+		$this->_set_model_object($post_id, true);
773
+		//if our cpt object isn't existent then get out immediately.
774
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
775
+			return;
776
+		}
777
+		$this->restore_cpt_item($post_id);
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 * Callback for the WordPress after_delete_post hook.
784
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
785
+	 *
786
+	 * @param $post_id
787
+	 */
788
+	public function before_delete_cpt_item($post_id)
789
+	{
790
+		$this->_set_model_object($post_id, true);
791
+		//if our cpt object isn't existent then get out immediately.
792
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
793
+			return;
794
+		}
795
+		$this->delete_cpt_item($post_id);
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
802
+	 * accordingly.
803
+	 *
804
+	 * @access public
805
+	 * @throws EE_Error
806
+	 * @return void
807
+	 */
808
+	public function verify_cpt_object()
809
+	{
810
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
811
+		// verify event object
812
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
813
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
814
+				'event_espresso'), $label));
815
+		}
816
+		//if auto-draft then throw an error
817
+		if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
818
+			EE_Error::overwrite_errors();
819
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
820
+				$label), __FILE__, __FUNCTION__, __LINE__);
821
+		}
822
+	}
823
+
824
+
825
+
826
+	/**
827
+	 * admin_footer_scripts_global
828
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
829
+	 * will apply on ALL EE_Admin pages.
830
+	 *
831
+	 * @access public
832
+	 * @return void
833
+	 */
834
+	public function admin_footer_scripts_global()
835
+	{
836
+		$this->_add_admin_page_ajax_loading_img();
837
+		$this->_add_admin_page_overlay();
838
+	}
839
+
840
+
841
+
842
+	/**
843
+	 * add in any global scripts for cpt routes
844
+	 *
845
+	 * @return void
846
+	 */
847
+	public function load_global_scripts_styles()
848
+	{
849
+		parent::load_global_scripts_styles();
850
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
851
+			//setup custom post status object for localize script but only if we've got a cpt object
852
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
853
+			if ( ! empty($statuses)) {
854
+				//get ALL statuses!
855
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
856
+				//setup object
857
+				$ee_cpt_statuses = array();
858
+				foreach ($statuses as $status => $label) {
859
+					$ee_cpt_statuses[$status] = array(
860
+						'label'      => $label,
861
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
862
+					);
863
+				}
864
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
865
+			}
866
+		}
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
873
+	 * insert/updates
874
+	 *
875
+	 * @param  int     $post_id ID of post being updated
876
+	 * @param  WP_Post $post    Post object from WP
877
+	 * @param  bool    $update  Whether this is an update or a new save.
878
+	 * @return void
879
+	 */
880
+	public function insert_update($post_id, $post, $update)
881
+	{
882
+		//make sure that if this is a revision OR trash action that we don't do any updates!
883
+		if (
884
+			isset($this->_req_data['action'])
885
+			&& (
886
+				$this->_req_data['action'] == 'restore'
887
+				|| $this->_req_data['action'] == 'trash'
888
+			)
889
+		) {
890
+			return;
891
+		}
892
+		$this->_set_model_object($post_id, true);
893
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
894
+		if ($update
895
+			&& (
896
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
897
+				|| $this->_cpt_model_obj->ID() !== $post_id
898
+			)
899
+		) {
900
+			return;
901
+		}
902
+		//check for autosave and update our req_data property accordingly.
903
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
904 904
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
905 905
 
906 906
                 foreach ( (array) $values as $key => $value ) {
@@ -910,536 +910,536 @@  discard block
 block discarded – undo
910 910
 
911 911
         }/**/ //TODO reactivate after autosave is implemented in 4.2
912 912
 
913
-        //take care of updating any selected page_template IF this cpt supports it.
914
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
915
-            //wp version aware.
916
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
917
-                $page_templates = wp_get_theme()->get_page_templates();
918
-            } else {
919
-                $post->page_template = $this->_req_data['page_template'];
920
-                $page_templates      = wp_get_theme()->get_page_templates($post);
921
-            }
922
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
923
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
924
-            } else {
925
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
926
-            }
927
-        }
928
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
929
-            return;
930
-        } //TODO we'll remove this after reimplementing autosave in 4.2
931
-        $this->_insert_update_cpt_item($post_id, $post);
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
938
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
939
-     * so we don't have to check for our CPT.
940
-     *
941
-     * @param  int $post_id ID of the post
942
-     * @return void
943
-     */
944
-    public function dont_permanently_delete_ee_cpts($post_id)
945
-    {
946
-        //only do this if we're actually processing one of our CPTs
947
-        //if our cpt object isn't existent then get out immediately.
948
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
949
-            return;
950
-        }
951
-        delete_post_meta($post_id, '_wp_trash_meta_status');
952
-        delete_post_meta($post_id, '_wp_trash_meta_time');
953
-        //our cpts may have comments so let's take care of that too
954
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
955
-    }
956
-
957
-
958
-
959
-    /**
960
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
961
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
962
-     * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
963
-     *
964
-     * @param  int $post_id     ID of cpt item
965
-     * @param  int $revision_id ID of revision being restored
966
-     * @return void
967
-     */
968
-    public function restore_revision($post_id, $revision_id)
969
-    {
970
-        $this->_restore_cpt_item($post_id, $revision_id);
971
-        //global action
972
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
973
-        //class specific action so you can limit hooking into a specific page.
974
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     * @see restore_revision() for details
981
-     * @param  int $post_id     ID of cpt item
982
-     * @param  int $revision_id ID of revision for item
983
-     * @return void
984
-     */
985
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
986
-
987
-
988
-
989
-    /**
990
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
991
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
992
-     * To fix we have to reset the current_screen using the page_slug
993
-     * (which is identical - or should be - to our registered_post_type id.)
994
-     * Also, since the core WP file loads the admin_header.php for WP
995
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
996
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
997
-     *
998
-     * @return void
999
-     */
1000
-    public function modify_current_screen()
1001
-    {
1002
-        //ONLY do this if the current page_route IS a cpt route
1003
-        if ( ! $this->_cpt_route) {
1004
-            return;
1005
-        }
1006
-        //routing things REALLY early b/c this is a cpt admin page
1007
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1008
-        $this->_current_screen       = get_current_screen();
1009
-        $this->_current_screen->base = 'event-espresso';
1010
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1011
-        /*try {
913
+		//take care of updating any selected page_template IF this cpt supports it.
914
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
915
+			//wp version aware.
916
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
917
+				$page_templates = wp_get_theme()->get_page_templates();
918
+			} else {
919
+				$post->page_template = $this->_req_data['page_template'];
920
+				$page_templates      = wp_get_theme()->get_page_templates($post);
921
+			}
922
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
923
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
924
+			} else {
925
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
926
+			}
927
+		}
928
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
929
+			return;
930
+		} //TODO we'll remove this after reimplementing autosave in 4.2
931
+		$this->_insert_update_cpt_item($post_id, $post);
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
938
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
939
+	 * so we don't have to check for our CPT.
940
+	 *
941
+	 * @param  int $post_id ID of the post
942
+	 * @return void
943
+	 */
944
+	public function dont_permanently_delete_ee_cpts($post_id)
945
+	{
946
+		//only do this if we're actually processing one of our CPTs
947
+		//if our cpt object isn't existent then get out immediately.
948
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
949
+			return;
950
+		}
951
+		delete_post_meta($post_id, '_wp_trash_meta_status');
952
+		delete_post_meta($post_id, '_wp_trash_meta_time');
953
+		//our cpts may have comments so let's take care of that too
954
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
955
+	}
956
+
957
+
958
+
959
+	/**
960
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
961
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
962
+	 * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
963
+	 *
964
+	 * @param  int $post_id     ID of cpt item
965
+	 * @param  int $revision_id ID of revision being restored
966
+	 * @return void
967
+	 */
968
+	public function restore_revision($post_id, $revision_id)
969
+	{
970
+		$this->_restore_cpt_item($post_id, $revision_id);
971
+		//global action
972
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
973
+		//class specific action so you can limit hooking into a specific page.
974
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 * @see restore_revision() for details
981
+	 * @param  int $post_id     ID of cpt item
982
+	 * @param  int $revision_id ID of revision for item
983
+	 * @return void
984
+	 */
985
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
986
+
987
+
988
+
989
+	/**
990
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
991
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
992
+	 * To fix we have to reset the current_screen using the page_slug
993
+	 * (which is identical - or should be - to our registered_post_type id.)
994
+	 * Also, since the core WP file loads the admin_header.php for WP
995
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
996
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
997
+	 *
998
+	 * @return void
999
+	 */
1000
+	public function modify_current_screen()
1001
+	{
1002
+		//ONLY do this if the current page_route IS a cpt route
1003
+		if ( ! $this->_cpt_route) {
1004
+			return;
1005
+		}
1006
+		//routing things REALLY early b/c this is a cpt admin page
1007
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1008
+		$this->_current_screen       = get_current_screen();
1009
+		$this->_current_screen->base = 'event-espresso';
1010
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1011
+		/*try {
1012 1012
             $this->_route_admin_request();
1013 1013
         } catch ( EE_Error $e ) {
1014 1014
             $e->get_error();
1015 1015
         }/**/
1016
-    }
1017
-
1018
-
1019
-
1020
-    /**
1021
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1022
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1023
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1024
-     * default to be.
1025
-     *
1026
-     * @param string $title The new title (or existing if there is no editor_title defined)
1027
-     * @return string
1028
-     */
1029
-    public function add_custom_editor_default_title($title)
1030
-    {
1031
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1032
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1033
-            : $title;
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1040
-     *
1041
-     * @param string $shortlink   The already generated shortlink
1042
-     * @param int    $id          Post ID for this item
1043
-     * @param string $context     The context for the link
1044
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1045
-     * @return string
1046
-     */
1047
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1048
-    {
1049
-        if ( ! empty($id) && '' != get_option('permalink_structure')) {
1050
-            $post = get_post($id);
1051
-            if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1052
-                $shortlink = home_url('?p=' . $post->ID);
1053
-            }
1054
-        }
1055
-        return $shortlink;
1056
-    }
1057
-
1058
-
1059
-
1060
-    /**
1061
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1062
-     * already run in modify_current_screen())
1063
-     *
1064
-     * @return void
1065
-     */
1066
-    public function route_admin_request()
1067
-    {
1068
-        if ($this->_cpt_route) {
1069
-            return;
1070
-        }
1071
-        try {
1072
-            $this->_route_admin_request();
1073
-        } catch (EE_Error $e) {
1074
-            $e->get_error();
1075
-        }
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1082
-     *
1083
-     * @return string html
1084
-     */
1085
-    public function cpt_post_form_hidden_input()
1086
-    {
1087
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1088
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1089
-        echo '<div id="ee-cpt-hidden-inputs">';
1090
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1091
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1092
-        echo '</div>';
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1099
-     *
1100
-     * @param  string $location Original location url
1101
-     * @param  int    $status   Status for http header
1102
-     * @return string           new (or original) url to redirect to.
1103
-     */
1104
-    public function revision_redirect($location, $status)
1105
-    {
1106
-        //get revision
1107
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1108
-        //can't do anything without revision so let's get out if not present
1109
-        if (empty($rev_id)) {
1110
-            return $location;
1111
-        }
1112
-        //get rev_post_data
1113
-        $rev = get_post($rev_id);
1114
-        $admin_url = $this->_admin_base_url;
1115
-        $query_args = array(
1116
-            'action'   => 'edit',
1117
-            'post'     => $rev->post_parent,
1118
-            'revision' => $rev_id,
1119
-            'message'  => 5,
1120
-        );
1121
-        $this->_process_notices($query_args, true);
1122
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1129
-     *
1130
-     * @param  string $link    the original generated link
1131
-     * @param  int    $id      post id
1132
-     * @param  string $context optional, defaults to display.  How to write the '&'
1133
-     * @return string          the link
1134
-     */
1135
-    public function modify_edit_post_link($link, $id, $context)
1136
-    {
1137
-        $post = get_post($id);
1138
-        if ( ! isset($this->_req_data['action'])
1139
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1140
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1141
-        ) {
1142
-            return $link;
1143
-        }
1144
-        $query_args = array(
1145
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1146
-                ? $this->_cpt_edit_routes[$post->post_type]
1147
-                : 'edit',
1148
-            'post'   => $id,
1149
-        );
1150
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1151
-    }
1152
-
1153
-
1154
-
1155
-    /**
1156
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1157
-     * our routes.
1158
-     *
1159
-     * @param  string $delete_link  original delete link
1160
-     * @param  int    $post_id      id of cpt object
1161
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1162
-     * @return string               new delete link
1163
-     */
1164
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1165
-    {
1166
-        $post = get_post($post_id);
1167
-        if ( ! isset($this->_req_data['action'])
1168
-             || (isset($this->_cpt_routes[$this->_req_data['action']])
1169
-                 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1170
-        ) {
1171
-            return $delete_link;
1172
-        }
1173
-        return add_query_arg(array('current_route' => 'trash'), $delete_link);
1174
-    }
1175
-
1176
-
1177
-
1178
-    /**
1179
-     * This hooks into the wp_redirect filter and if trashed is detected, then we'll redirect to the appropriate EE
1180
-     * route
1181
-     *
1182
-     * @param  string $location url
1183
-     * @param  string $status   status
1184
-     * @return string           url to redirect to
1185
-     */
1186
-    public function cpt_trash_post_location_redirect($location, $status)
1187
-    {
1188
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] !== 'trash' && empty($this->_req_data['post'])) {
1189
-            return $location;
1190
-        }
1191
-
1192
-        $post              = get_post($this->_req_data['post']);
1193
-        $query_args        = array('action' => 'default');
1194
-        $this->_cpt_object = get_post_type_object($post->post_type);
1195
-        EE_Error::add_success(sprintf(__('%s trashed.', 'event_espresso'), $this->_cpt_object->labels->singular_name));
1196
-        $this->_process_notices($query_args, true);
1197
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1198
-    }
1199
-
1200
-
1201
-
1202
-    /**
1203
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1204
-     * so that we can hijack the default redirect locations for wp custom post types
1205
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1206
-     *
1207
-     * @param  string $location This is the incoming currently set redirect location
1208
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1209
-     * @return string           the new location to redirect to
1210
-     */
1211
-    public function cpt_post_location_redirect($location, $post_id)
1212
-    {
1213
-        //we DO have a match so let's setup the url
1214
-        //we have to get the post to determine our route
1215
-        $post       = get_post($post_id);
1216
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1217
-        //shared query_args
1218
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1219
-        $admin_url  = $this->_admin_base_url;
1220
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1221
-            $status = get_post_status($post_id);
1222
-            if (isset($this->_req_data['publish'])) {
1223
-                switch ($status) {
1224
-                    case 'pending':
1225
-                        $message = 8;
1226
-                        break;
1227
-                    case 'future':
1228
-                        $message = 9;
1229
-                        break;
1230
-                    default:
1231
-                        $message = 6;
1232
-                }
1233
-            } else {
1234
-                $message = 'draft' == $status ? 10 : 1;
1235
-            }
1236
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1237
-            $message = 2;
1238
-            //			$append = '#postcustom';
1239
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1240
-            $message = 3;
1241
-            //			$append = '#postcustom';
1242
-        } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1243
-            $message = 7;
1244
-        } else {
1245
-            $message = 4;
1246
-        }
1247
-        //change the message if the post type is not viewable on the frontend
1248
-        $this->_cpt_object = get_post_type_object($post->post_type);
1249
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1250
-        $query_args = array_merge(array('message' => $message), $query_args);
1251
-        $this->_process_notices($query_args, true);
1252
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1253
-    }
1254
-
1255
-
1256
-
1257
-    /**
1258
-     * This method is called to inject nav tabs on core WP cpt pages
1259
-     *
1260
-     * @access public
1261
-     * @return string html
1262
-     */
1263
-    public function inject_nav_tabs()
1264
-    {
1265
-        //can we hijack and insert the nav_tabs?
1266
-        $nav_tabs = $this->_get_main_nav_tabs();
1267
-        //first close off existing form tag
1268
-        $html = '>';
1269
-        $html .= $nav_tabs;
1270
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1271
-        $html .= '<span></span';
1272
-        echo $html;
1273
-    }
1274
-
1275
-
1276
-
1277
-    /**
1278
-     * This just sets up the post update messages when an update form is loaded
1279
-     *
1280
-     * @access public
1281
-     * @param  array $messages the original messages array
1282
-     * @return array           the new messages array
1283
-     */
1284
-    public function post_update_messages($messages)
1285
-    {
1286
-        global $post;
1287
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1288
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1289
-        //		$post_type = $post ? $post->post_type : false;
1290
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1016
+	}
1017
+
1018
+
1019
+
1020
+	/**
1021
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1022
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1023
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1024
+	 * default to be.
1025
+	 *
1026
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1027
+	 * @return string
1028
+	 */
1029
+	public function add_custom_editor_default_title($title)
1030
+	{
1031
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1032
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1033
+			: $title;
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1040
+	 *
1041
+	 * @param string $shortlink   The already generated shortlink
1042
+	 * @param int    $id          Post ID for this item
1043
+	 * @param string $context     The context for the link
1044
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1045
+	 * @return string
1046
+	 */
1047
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1048
+	{
1049
+		if ( ! empty($id) && '' != get_option('permalink_structure')) {
1050
+			$post = get_post($id);
1051
+			if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1052
+				$shortlink = home_url('?p=' . $post->ID);
1053
+			}
1054
+		}
1055
+		return $shortlink;
1056
+	}
1057
+
1058
+
1059
+
1060
+	/**
1061
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1062
+	 * already run in modify_current_screen())
1063
+	 *
1064
+	 * @return void
1065
+	 */
1066
+	public function route_admin_request()
1067
+	{
1068
+		if ($this->_cpt_route) {
1069
+			return;
1070
+		}
1071
+		try {
1072
+			$this->_route_admin_request();
1073
+		} catch (EE_Error $e) {
1074
+			$e->get_error();
1075
+		}
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1082
+	 *
1083
+	 * @return string html
1084
+	 */
1085
+	public function cpt_post_form_hidden_input()
1086
+	{
1087
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1088
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1089
+		echo '<div id="ee-cpt-hidden-inputs">';
1090
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1091
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1092
+		echo '</div>';
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1099
+	 *
1100
+	 * @param  string $location Original location url
1101
+	 * @param  int    $status   Status for http header
1102
+	 * @return string           new (or original) url to redirect to.
1103
+	 */
1104
+	public function revision_redirect($location, $status)
1105
+	{
1106
+		//get revision
1107
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1108
+		//can't do anything without revision so let's get out if not present
1109
+		if (empty($rev_id)) {
1110
+			return $location;
1111
+		}
1112
+		//get rev_post_data
1113
+		$rev = get_post($rev_id);
1114
+		$admin_url = $this->_admin_base_url;
1115
+		$query_args = array(
1116
+			'action'   => 'edit',
1117
+			'post'     => $rev->post_parent,
1118
+			'revision' => $rev_id,
1119
+			'message'  => 5,
1120
+		);
1121
+		$this->_process_notices($query_args, true);
1122
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1129
+	 *
1130
+	 * @param  string $link    the original generated link
1131
+	 * @param  int    $id      post id
1132
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1133
+	 * @return string          the link
1134
+	 */
1135
+	public function modify_edit_post_link($link, $id, $context)
1136
+	{
1137
+		$post = get_post($id);
1138
+		if ( ! isset($this->_req_data['action'])
1139
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1140
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1141
+		) {
1142
+			return $link;
1143
+		}
1144
+		$query_args = array(
1145
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1146
+				? $this->_cpt_edit_routes[$post->post_type]
1147
+				: 'edit',
1148
+			'post'   => $id,
1149
+		);
1150
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1151
+	}
1152
+
1153
+
1154
+
1155
+	/**
1156
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1157
+	 * our routes.
1158
+	 *
1159
+	 * @param  string $delete_link  original delete link
1160
+	 * @param  int    $post_id      id of cpt object
1161
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1162
+	 * @return string               new delete link
1163
+	 */
1164
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1165
+	{
1166
+		$post = get_post($post_id);
1167
+		if ( ! isset($this->_req_data['action'])
1168
+			 || (isset($this->_cpt_routes[$this->_req_data['action']])
1169
+				 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1170
+		) {
1171
+			return $delete_link;
1172
+		}
1173
+		return add_query_arg(array('current_route' => 'trash'), $delete_link);
1174
+	}
1175
+
1176
+
1177
+
1178
+	/**
1179
+	 * This hooks into the wp_redirect filter and if trashed is detected, then we'll redirect to the appropriate EE
1180
+	 * route
1181
+	 *
1182
+	 * @param  string $location url
1183
+	 * @param  string $status   status
1184
+	 * @return string           url to redirect to
1185
+	 */
1186
+	public function cpt_trash_post_location_redirect($location, $status)
1187
+	{
1188
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] !== 'trash' && empty($this->_req_data['post'])) {
1189
+			return $location;
1190
+		}
1191
+
1192
+		$post              = get_post($this->_req_data['post']);
1193
+		$query_args        = array('action' => 'default');
1194
+		$this->_cpt_object = get_post_type_object($post->post_type);
1195
+		EE_Error::add_success(sprintf(__('%s trashed.', 'event_espresso'), $this->_cpt_object->labels->singular_name));
1196
+		$this->_process_notices($query_args, true);
1197
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1198
+	}
1199
+
1200
+
1201
+
1202
+	/**
1203
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1204
+	 * so that we can hijack the default redirect locations for wp custom post types
1205
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1206
+	 *
1207
+	 * @param  string $location This is the incoming currently set redirect location
1208
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1209
+	 * @return string           the new location to redirect to
1210
+	 */
1211
+	public function cpt_post_location_redirect($location, $post_id)
1212
+	{
1213
+		//we DO have a match so let's setup the url
1214
+		//we have to get the post to determine our route
1215
+		$post       = get_post($post_id);
1216
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1217
+		//shared query_args
1218
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1219
+		$admin_url  = $this->_admin_base_url;
1220
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1221
+			$status = get_post_status($post_id);
1222
+			if (isset($this->_req_data['publish'])) {
1223
+				switch ($status) {
1224
+					case 'pending':
1225
+						$message = 8;
1226
+						break;
1227
+					case 'future':
1228
+						$message = 9;
1229
+						break;
1230
+					default:
1231
+						$message = 6;
1232
+				}
1233
+			} else {
1234
+				$message = 'draft' == $status ? 10 : 1;
1235
+			}
1236
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1237
+			$message = 2;
1238
+			//			$append = '#postcustom';
1239
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1240
+			$message = 3;
1241
+			//			$append = '#postcustom';
1242
+		} elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1243
+			$message = 7;
1244
+		} else {
1245
+			$message = 4;
1246
+		}
1247
+		//change the message if the post type is not viewable on the frontend
1248
+		$this->_cpt_object = get_post_type_object($post->post_type);
1249
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1250
+		$query_args = array_merge(array('message' => $message), $query_args);
1251
+		$this->_process_notices($query_args, true);
1252
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1253
+	}
1254
+
1255
+
1256
+
1257
+	/**
1258
+	 * This method is called to inject nav tabs on core WP cpt pages
1259
+	 *
1260
+	 * @access public
1261
+	 * @return string html
1262
+	 */
1263
+	public function inject_nav_tabs()
1264
+	{
1265
+		//can we hijack and insert the nav_tabs?
1266
+		$nav_tabs = $this->_get_main_nav_tabs();
1267
+		//first close off existing form tag
1268
+		$html = '>';
1269
+		$html .= $nav_tabs;
1270
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1271
+		$html .= '<span></span';
1272
+		echo $html;
1273
+	}
1274
+
1275
+
1276
+
1277
+	/**
1278
+	 * This just sets up the post update messages when an update form is loaded
1279
+	 *
1280
+	 * @access public
1281
+	 * @param  array $messages the original messages array
1282
+	 * @return array           the new messages array
1283
+	 */
1284
+	public function post_update_messages($messages)
1285
+	{
1286
+		global $post;
1287
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1288
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1289
+		//		$post_type = $post ? $post->post_type : false;
1290
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1291 1291
 
1292 1292
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1293
-        $messages[$post->post_type] = array(
1294
-            0 => '', //Unused. Messages start at index 1.
1295
-            1 => sprintf(
1296
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1297
-                $this->_cpt_object->labels->singular_name,
1298
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1299
-                '</a>'
1300
-            ),
1301
-            2 => __('Custom field updated'),
1302
-            3 => __('Custom field deleted.'),
1303
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1304
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1305
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1306
-                : false,
1307
-            6 => sprintf(
1308
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1309
-                $this->_cpt_object->labels->singular_name,
1310
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1311
-                '</a>'
1312
-            ),
1313
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1314
-            8 => sprintf(
1315
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1316
-                $this->_cpt_object->labels->singular_name,
1317
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1318
-                '</a>'
1319
-            ),
1320
-            9 => sprintf(
1321
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1322
-                $this->_cpt_object->labels->singular_name,
1323
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1324
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1325
-                '</a>'
1326
-            ),
1327
-            10 => sprintf(
1328
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1329
-                $this->_cpt_object->labels->singular_name,
1330
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1331
-                '</a>'
1332
-            ),
1333
-        );
1334
-        return $messages;
1335
-    }
1336
-
1337
-
1338
-
1339
-    /**
1340
-     * default method for the 'create_new' route for cpt admin pages.
1341
-     * For reference what to include in here, see wp-admin/post-new.php
1342
-     *
1343
-     * @access  protected
1344
-     * @return string template for add new cpt form
1345
-     */
1346
-    protected function _create_new_cpt_item()
1347
-    {
1348
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1349
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1350
-        $post_type_object = $this->_cpt_object;
1351
-        $title            = $post_type_object->labels->add_new_item;
1352
-        $editing          = true;
1353
-        wp_enqueue_script('autosave');
1354
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1355
-        $post_ID = $post->ID;
1356
-        $is_IE   = $is_IE;
1357
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1358
-        //modify the default editor title field with default title.
1359
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1360
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1361
-    }
1362
-
1363
-
1364
-
1365
-    public function add_new_admin_page_global()
1366
-    {
1367
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1368
-        ?>
1293
+		$messages[$post->post_type] = array(
1294
+			0 => '', //Unused. Messages start at index 1.
1295
+			1 => sprintf(
1296
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1297
+				$this->_cpt_object->labels->singular_name,
1298
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1299
+				'</a>'
1300
+			),
1301
+			2 => __('Custom field updated'),
1302
+			3 => __('Custom field deleted.'),
1303
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1304
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1305
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1306
+				: false,
1307
+			6 => sprintf(
1308
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1309
+				$this->_cpt_object->labels->singular_name,
1310
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1311
+				'</a>'
1312
+			),
1313
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1314
+			8 => sprintf(
1315
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1316
+				$this->_cpt_object->labels->singular_name,
1317
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1318
+				'</a>'
1319
+			),
1320
+			9 => sprintf(
1321
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1322
+				$this->_cpt_object->labels->singular_name,
1323
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1324
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1325
+				'</a>'
1326
+			),
1327
+			10 => sprintf(
1328
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1329
+				$this->_cpt_object->labels->singular_name,
1330
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1331
+				'</a>'
1332
+			),
1333
+		);
1334
+		return $messages;
1335
+	}
1336
+
1337
+
1338
+
1339
+	/**
1340
+	 * default method for the 'create_new' route for cpt admin pages.
1341
+	 * For reference what to include in here, see wp-admin/post-new.php
1342
+	 *
1343
+	 * @access  protected
1344
+	 * @return string template for add new cpt form
1345
+	 */
1346
+	protected function _create_new_cpt_item()
1347
+	{
1348
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1349
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1350
+		$post_type_object = $this->_cpt_object;
1351
+		$title            = $post_type_object->labels->add_new_item;
1352
+		$editing          = true;
1353
+		wp_enqueue_script('autosave');
1354
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1355
+		$post_ID = $post->ID;
1356
+		$is_IE   = $is_IE;
1357
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1358
+		//modify the default editor title field with default title.
1359
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1360
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1361
+	}
1362
+
1363
+
1364
+
1365
+	public function add_new_admin_page_global()
1366
+	{
1367
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1368
+		?>
1369 1369
         <script type="text/javascript">
1370 1370
             adminpage = '<?php echo $admin_page; ?>';
1371 1371
         </script>
1372 1372
         <?php
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     * default method for the 'edit' route for cpt admin pages
1379
-     * For reference on what to put in here, refer to wp-admin/post.php
1380
-     *
1381
-     * @access protected
1382
-     * @return string   template for edit cpt form
1383
-     */
1384
-    protected function _edit_cpt_item()
1385
-    {
1386
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1387
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1388
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1389
-        if (empty ($post)) {
1390
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1391
-        }
1392
-        if ( ! empty($_GET['get-post-lock'])) {
1393
-            wp_set_post_lock($post_id);
1394
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1395
-            exit();
1396
-        }
1397
-
1398
-        // template vars
1399
-        $editing          = true;
1400
-        $post_ID          = $post_id;
1401
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1402
-        $post_type_object = $this->_cpt_object;
1403
-
1404
-        if ( ! wp_check_post_lock($post->ID)) {
1405
-            $active_post_lock = wp_set_post_lock($post->ID);
1406
-            //wp_enqueue_script('autosave');
1407
-        }
1408
-        $title = $this->_cpt_object->labels->edit_item;
1409
-        add_action('admin_footer', '_admin_notice_post_locked');
1410
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1411
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1412
-        ) {
1413
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1414
-                'create_new', $this);
1415
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1416
-                'action' => $create_new_action,
1417
-                'page'   => $this->page_slug,
1418
-            ), 'admin.php');
1419
-        }
1420
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1421
-            wp_enqueue_script('admin-comments');
1422
-            enqueue_comment_hotkeys_js();
1423
-        }
1424
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1425
-        //modify the default editor title field with default title.
1426
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1427
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1428
-    }
1429
-
1430
-
1431
-
1432
-    /**
1433
-     * some getters
1434
-     */
1435
-    /**
1436
-     * This returns the protected _cpt_model_obj property
1437
-     *
1438
-     * @return EE_CPT_Base
1439
-     */
1440
-    public function get_cpt_model_obj()
1441
-    {
1442
-        return $this->_cpt_model_obj;
1443
-    }
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 * default method for the 'edit' route for cpt admin pages
1379
+	 * For reference on what to put in here, refer to wp-admin/post.php
1380
+	 *
1381
+	 * @access protected
1382
+	 * @return string   template for edit cpt form
1383
+	 */
1384
+	protected function _edit_cpt_item()
1385
+	{
1386
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1387
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1388
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1389
+		if (empty ($post)) {
1390
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1391
+		}
1392
+		if ( ! empty($_GET['get-post-lock'])) {
1393
+			wp_set_post_lock($post_id);
1394
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1395
+			exit();
1396
+		}
1397
+
1398
+		// template vars
1399
+		$editing          = true;
1400
+		$post_ID          = $post_id;
1401
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1402
+		$post_type_object = $this->_cpt_object;
1403
+
1404
+		if ( ! wp_check_post_lock($post->ID)) {
1405
+			$active_post_lock = wp_set_post_lock($post->ID);
1406
+			//wp_enqueue_script('autosave');
1407
+		}
1408
+		$title = $this->_cpt_object->labels->edit_item;
1409
+		add_action('admin_footer', '_admin_notice_post_locked');
1410
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1411
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1412
+		) {
1413
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1414
+				'create_new', $this);
1415
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1416
+				'action' => $create_new_action,
1417
+				'page'   => $this->page_slug,
1418
+			), 'admin.php');
1419
+		}
1420
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1421
+			wp_enqueue_script('admin-comments');
1422
+			enqueue_comment_hotkeys_js();
1423
+		}
1424
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1425
+		//modify the default editor title field with default title.
1426
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1427
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1428
+	}
1429
+
1430
+
1431
+
1432
+	/**
1433
+	 * some getters
1434
+	 */
1435
+	/**
1436
+	 * This returns the protected _cpt_model_obj property
1437
+	 *
1438
+	 * @return EE_CPT_Base
1439
+	 */
1440
+	public function get_cpt_model_obj()
1441
+	{
1442
+		return $this->_cpt_model_obj;
1443
+	}
1444 1444
 
1445 1445
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     protected function _register_autosave_containers($ids)
237 237
     {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
238
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
239 239
     }
240 240
 
241 241
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         //filter _autosave_containers
280 280
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281 281
             $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
282
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
283 283
             $containers, $this);
284 284
 
285 285
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         parent::_load_page_dependencies();
370 370
         //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371 371
         global $pagenow;
372
-        do_action('load-' . $pagenow);
372
+        do_action('load-'.$pagenow);
373 373
         $this->modify_current_screen();
374 374
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375 375
         //we route REALLY early.
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
                 'admin.php?page=espresso_registrations&action=contact_list',
401 401
             ),
402 402
             1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
403
+                'edit.php?post_type='.$this->_cpt_object->name,
404
+                'admin.php?page='.$this->_cpt_object->name,
405 405
             ),
406 406
         );
407 407
         foreach ($routes_to_match as $route_matches) {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $cpt_has_support = ! empty($cpt_args['page_templates']);
430 430
 
431 431
         //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
432
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
433 433
             $post_templates = wp_get_theme()->get_post_templates();
434 434
             //if there are $post_templates for this cpt, then we return false for this method because
435 435
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         global $post;
453 453
         $template = '';
454 454
 
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
455
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
456 456
             $page_template_count = count(get_page_templates());
457 457
         } else {
458 458
             $page_template_count = count(get_page_templates($post));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $post = get_post($id);
490 490
         if ('publish' != get_post_status($post)) {
491 491
             //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
492
+            require_once(EE_CORE.'wordpress-shims.php');
493 493
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494 494
                        . get_preview_post_link($id)
495 495
                        . '" class="button button-small">'
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             $template_args['statuses']         = $statuses;
528 528
         }
529 529
 
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
530
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
531 531
         EEH_Template::display_template($template, $template_args);
532 532
     }
533 533
 
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
             define('DOING_AUTOSAVE', true);
573 573
         }
574 574
         //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
575
+        if (method_exists($this, '_ee_autosave_'.$this->_current_view)) {
576
+            call_user_func(array($this, '_ee_autosave_'.$this->_current_view));
577 577
         } else {
578 578
             $this->_template_args['success'] = true;
579 579
         }
580 580
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
581
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
582 582
         //now let's return json
583 583
         $this->_return_json();
584 584
     }
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
         //global action
972 972
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
973 973
         //class specific action so you can limit hooking into a specific page.
974
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
974
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
975 975
     }
976 976
 
977 977
 
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
         if ( ! empty($id) && '' != get_option('permalink_structure')) {
1050 1050
             $post = get_post($id);
1051 1051
             if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1052
-                $shortlink = home_url('?p=' . $post->ID);
1052
+                $shortlink = home_url('?p='.$post->ID);
1053 1053
             }
1054 1054
         }
1055 1055
         return $shortlink;
@@ -1084,11 +1084,11 @@  discard block
 block discarded – undo
1084 1084
      */
1085 1085
     public function cpt_post_form_hidden_input()
1086 1086
     {
1087
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1087
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1088 1088
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1089 1089
         echo '<div id="ee-cpt-hidden-inputs">';
1090
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1091
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1091
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1092 1092
         echo '</div>';
1093 1093
     }
1094 1094
 
@@ -1295,39 +1295,39 @@  discard block
 block discarded – undo
1295 1295
             1 => sprintf(
1296 1296
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1297 1297
                 $this->_cpt_object->labels->singular_name,
1298
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1298
+                '<a href="'.esc_url(get_permalink($id)).'">',
1299 1299
                 '</a>'
1300 1300
             ),
1301 1301
             2 => __('Custom field updated'),
1302 1302
             3 => __('Custom field deleted.'),
1303 1303
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1304 1304
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1305
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1305
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1306 1306
                 : false,
1307 1307
             6 => sprintf(
1308 1308
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1309 1309
                 $this->_cpt_object->labels->singular_name,
1310
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1310
+                '<a href="'.esc_url(get_permalink($id)).'">',
1311 1311
                 '</a>'
1312 1312
             ),
1313 1313
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1314 1314
             8 => sprintf(
1315 1315
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1316 1316
                 $this->_cpt_object->labels->singular_name,
1317
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1317
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1318 1318
                 '</a>'
1319 1319
             ),
1320 1320
             9 => sprintf(
1321 1321
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1322 1322
                 $this->_cpt_object->labels->singular_name,
1323
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1324
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1323
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1324
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1325 1325
                 '</a>'
1326 1326
             ),
1327 1327
             10 => sprintf(
1328 1328
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1329 1329
                 $this->_cpt_object->labels->singular_name,
1330
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1330
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1331 1331
                 '</a>'
1332 1332
             ),
1333 1333
         );
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1358 1358
         //modify the default editor title field with default title.
1359 1359
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1360
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1360
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1361 1361
     }
1362 1362
 
1363 1363
 
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1425 1425
         //modify the default editor title field with default title.
1426 1426
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1427
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1427
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1428 1428
     }
1429 1429
 
1430 1430
 
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 1 patch
Indentation   +579 added lines, -579 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Class Datetime Model
@@ -11,584 +11,584 @@  discard block
 block discarded – undo
11 11
 class EEM_Datetime extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @var EEM_Datetime $_instance
16
-     */
17
-    protected static $_instance;
18
-
19
-
20
-
21
-    /**
22
-     *        private constructor to prevent direct creation
23
-     *
24
-     * @Constructor
25
-     * @access private
26
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
-     *                         timezone in the 'timezone_string' wp option)
30
-     * @throws \EE_Error
31
-     */
32
-    protected function __construct($timezone)
33
-    {
34
-        $this->singular_item = __('Datetime', 'event_espresso');
35
-        $this->plural_item = __('Datetimes', 'event_espresso');
36
-        $this->_tables = array(
37
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
-        );
39
-        $this->_fields = array(
40
-            'Datetime' => array(
41
-                'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
-                    'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
-                ),
45
-                'DTT_name'        => new EE_Plain_Text_Field(
46
-                    'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
-                ),
48
-                'DTT_description' => new EE_Post_Content_Field(
49
-                    'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
-                ),
51
-                'DTT_EVT_start'   => new EE_Datetime_Field(
52
-                    'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
-                    $timezone
54
-                ),
55
-                'DTT_EVT_end'     => new EE_Datetime_Field(
56
-                    'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
-                    $timezone
58
-                ),
59
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
-                    'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
-                'DTT_sold'        => new EE_Integer_Field(
62
-                    'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
-                ),
64
-                'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
-                    __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
-                ),
67
-                'DTT_is_primary'  => new EE_Boolean_Field(
68
-                    'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
-                    false, false
70
-                ),
71
-                'DTT_order'       => new EE_Integer_Field(
72
-                    'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
-                ),
74
-                'DTT_parent'      => new EE_Integer_Field(
75
-                    'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
-                ),
77
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
-                    'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
-                ),
80
-            ),
81
-        );
82
-        $this->_model_relations = array(
83
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
-            'Event'   => new EE_Belongs_To_Relation(),
85
-            'Checkin' => new EE_Has_Many_Relation(),
86
-        );
87
-        $this->_model_chain_to_wp_user = 'Event';
88
-        //this model is generally available for reading
89
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
-            EEM_Base::caps_edit);
94
-        parent::__construct($timezone);
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * create new blank datetime
101
-     *
102
-     * @access public
103
-     * @return EE_Datetime[] array on success, FALSE on fail
104
-     * @throws \EE_Error
105
-     */
106
-    public function create_new_blank_datetime()
107
-    {
108
-        $blank_datetime = EE_Datetime::new_instance(
109
-            array(
110
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
111
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
112
-                'DTT_order'     => 1,
113
-                'DTT_reg_limit' => EE_INF,
114
-            ),
115
-            $this->_timezone
116
-        );
117
-        $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
118
-            $this->_timezone));
119
-        $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone));
120
-        return array($blank_datetime);
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * get event start date from db
127
-     *
128
-     * @access public
129
-     * @param  int $EVT_ID
130
-     * @return EE_Datetime[] array on success, FALSE on fail
131
-     * @throws \EE_Error
132
-     */
133
-    public function get_all_event_dates($EVT_ID = 0)
134
-    {
135
-        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
136
-            return $this->create_new_blank_datetime();
137
-        }
138
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
139
-        if (empty($results)) {
140
-            return $this->create_new_blank_datetime();
141
-        }
142
-        return $results;
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * get all datetimes attached to an event ordered by the DTT_order field
149
-     *
150
-     * @public
151
-     * @param  int    $EVT_ID     event id
152
-     * @param boolean $include_expired
153
-     * @param boolean $include_deleted
154
-     * @param  int    $limit      If included then limit the count of results by
155
-     *                            the given number
156
-     * @return EE_Datetime[]
157
-     * @throws \EE_Error
158
-     */
159
-    public function get_datetimes_for_event_ordered_by_DTT_order(
160
-        $EVT_ID,
161
-        $include_expired = true,
162
-        $include_deleted = true,
163
-        $limit = null
164
-    ) {
165
-        //sanitize EVT_ID
166
-        $EVT_ID = absint($EVT_ID);
167
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
168
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
169
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
170
-        $query_params = ! empty($limit)
171
-            ? array(
172
-                $where_params,
173
-                'limit'                    => $limit,
174
-                'order_by'                 => array('DTT_order' => 'ASC'),
175
-                'default_where_conditions' => 'none',
176
-            )
177
-            : array(
178
-                $where_params,
179
-                'order_by'                 => array('DTT_order' => 'ASC'),
180
-                'default_where_conditions' => 'none',
181
-            );
182
-        if ( ! $include_expired) {
183
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
184
-        }
185
-        if ($include_deleted) {
186
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
187
-        }
188
-        /** @var EE_Datetime[] $result */
189
-        $result = $this->get_all($query_params);
190
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
191
-        return $result;
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
198
-     * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
199
-     * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
200
-     *
201
-     * @param int $EVT_ID
202
-     * @param int $limit
203
-     * @return EE_Datetime[]|EE_Base_Class[]
204
-     * @throws \EE_Error
205
-     */
206
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
207
-    {
208
-        return $this->get_all(
209
-            array(
210
-                array('Event.EVT_ID' => $EVT_ID),
211
-                'limit'                    => $limit,
212
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
213
-                'default_where_conditions' => 'none',
214
-            )
215
-        );
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * @param int     $EVT_ID
222
-     * @param boolean $include_expired
223
-     * @param boolean $include_deleted
224
-     * @return EE_Datetime
225
-     * @throws \EE_Error
226
-     */
227
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
228
-    {
229
-        $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
230
-        if ($results) {
231
-            return array_shift($results);
232
-        } else {
233
-            return null;
234
-        }
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets the 'primary' datetime for an event.
241
-     *
242
-     * @param int  $EVT_ID
243
-     * @param bool $try_to_exclude_expired
244
-     * @param bool $try_to_exclude_deleted
245
-     * @return \EE_Datetime
246
-     * @throws \EE_Error
247
-     */
248
-    public function get_primary_datetime_for_event(
249
-        $EVT_ID,
250
-        $try_to_exclude_expired = true,
251
-        $try_to_exclude_deleted = true
252
-    ) {
253
-        if ($try_to_exclude_expired) {
254
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
255
-            if ($non_expired) {
256
-                return $non_expired;
257
-            }
258
-        }
259
-        if ($try_to_exclude_deleted) {
260
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
261
-            if ($expired_even) {
262
-                return $expired_even;
263
-            }
264
-        }
265
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
272
-     * only by start date
273
-     *
274
-     * @param int     $EVT_ID
275
-     * @param boolean $include_expired
276
-     * @param boolean $include_deleted
277
-     * @param int     $limit
278
-     * @return EE_Datetime[]
279
-     * @throws \EE_Error
280
-     */
281
-    public function get_datetimes_for_event_ordered_by_start_time(
282
-        $EVT_ID,
283
-        $include_expired = true,
284
-        $include_deleted = true,
285
-        $limit = null
286
-    ) {
287
-        //sanitize EVT_ID
288
-        $EVT_ID = absint($EVT_ID);
289
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
290
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
291
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
292
-        if ( ! $include_expired) {
293
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
294
-        }
295
-        if ($include_deleted) {
296
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
297
-        }
298
-        if ($limit) {
299
-            $query_params['limit'] = $limit;
300
-        }
301
-        /** @var EE_Datetime[] $result */
302
-        $result = $this->get_all($query_params);
303
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
304
-        return $result;
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
311
-     * only by start date
312
-     *
313
-     * @param int     $TKT_ID
314
-     * @param boolean $include_expired
315
-     * @param boolean $include_deleted
316
-     * @param int     $limit
317
-     * @return EE_Datetime[]
318
-     * @throws \EE_Error
319
-     */
320
-    public function get_datetimes_for_ticket_ordered_by_start_time(
321
-        $TKT_ID,
322
-        $include_expired = true,
323
-        $include_deleted = true,
324
-        $limit = null
325
-    ) {
326
-        //sanitize TKT_ID
327
-        $TKT_ID = absint($TKT_ID);
328
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
329
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
330
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
331
-        if ( ! $include_expired) {
332
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
333
-        }
334
-        if ($include_deleted) {
335
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
336
-        }
337
-        if ($limit) {
338
-            $query_params['limit'] = $limit;
339
-        }
340
-        /** @var EE_Datetime[] $result */
341
-        $result = $this->get_all($query_params);
342
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
343
-        return $result;
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
350
-     * datetimes.
351
-     *
352
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
353
-     * @param  boolean  $include_expired whether to include expired datetimes or not
354
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
355
-     * @param  int|null $limit           if null, no limit, if int then limit results by
356
-     *                                   that number
357
-     * @return EE_Datetime[]
358
-     * @throws \EE_Error
359
-     */
360
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
361
-        $TKT_ID,
362
-        $include_expired = true,
363
-        $include_deleted = true,
364
-        $limit = null
365
-    ) {
366
-        //sanitize id.
367
-        $TKT_ID = absint($TKT_ID);
368
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
369
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
370
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
371
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
372
-        if ( ! $include_expired) {
373
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
374
-        }
375
-        if ($include_deleted) {
376
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
377
-        }
378
-        if ($limit) {
379
-            $query_params['limit'] = $limit;
380
-        }
381
-        /** @var EE_Datetime[] $result */
382
-        $result = $this->get_all($query_params);
383
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
384
-        return $result;
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
391
-     * reason it doesn't exist, we consider the earliest event the most important)
392
-     *
393
-     * @param int $EVT_ID
394
-     * @return EE_Datetime
395
-     * @throws \EE_Error
396
-     */
397
-    public function get_most_important_datetime_for_event($EVT_ID)
398
-    {
399
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
400
-        if ($results) {
401
-            return array_shift($results);
402
-        } else {
403
-            return null;
404
-        }
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
411
-     * grouped by month and year.
412
-     *
413
-     * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
414
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
415
-     *                                   Can be:
416
-     *                                   - '' = no filter
417
-     *                                   - upcoming = Published events with at least one upcoming datetime.
418
-     *                                   - expired = Events with all datetimes expired.
419
-     *                                   - active = Events that are published and have at least one datetime that
420
-     *                                   starts before now and ends after now.
421
-     *                                   - inactive = Events that are either not published.
422
-     * @return EE_Base_Class[]
423
-     * @throws \EE_Error
424
-     */
425
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
426
-    {
427
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
428
-        $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
429
-        switch ($evt_active_status) {
430
-            case 'upcoming' :
431
-                $where_params['Event.status'] = 'publish';
432
-                //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
433
-                if (isset($where_params['DTT_EVT_start'])) {
434
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
435
-                }
436
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
437
-                break;
438
-            case 'expired' :
439
-                if (isset($where_params['Event.status'])) {
440
-                    unset($where_params['Event.status']);
441
-                }
442
-                //get events to exclude
443
-                $exclude_query[0] = array_merge($where_params,
444
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
445
-                //first get all events that have datetimes where its not expired.
446
-                $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
447
-                $event_ids = array_keys($event_ids);
448
-                if (isset($where_params['DTT_EVT_end'])) {
449
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
450
-                }
451
-                $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
452
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
453
-                break;
454
-            case 'active' :
455
-                $where_params['Event.status'] = 'publish';
456
-                if (isset($where_params['DTT_EVT_start'])) {
457
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
458
-                }
459
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
460
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
461
-                }
462
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
463
-                $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
464
-                break;
465
-            case 'inactive' :
466
-                if (isset($where_params['Event.status'])) {
467
-                    unset($where_params['Event.status']);
468
-                }
469
-                if (isset($where_params['OR'])) {
470
-                    $where_params['AND']['OR'] = $where_params['OR'];
471
-                }
472
-                if (isset($where_params['DTT_EVT_end'])) {
473
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
474
-                    unset($where_params['DTT_EVT_end']);
475
-                }
476
-                if (isset($where_params['DTT_EVT_start'])) {
477
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
478
-                    unset($where_params['DTT_EVT_start']);
479
-                }
480
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
481
-                break;
482
-        }
483
-        $query_params[0] = $where_params;
484
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
485
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
486
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
487
-        $columns_to_select = array(
488
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
489
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
490
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
491
-        );
492
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
493
-    }
494
-
495
-
496
-
497
-    /**
498
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
499
-     * for the tickets for each datetime)
500
-     *
501
-     * @param EE_Datetime[] $datetimes
502
-     */
503
-    public function update_sold($datetimes)
504
-    {
505
-        foreach ($datetimes as $datetime) {
506
-            $datetime->update_sold();
507
-        }
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     *    Gets the total number of tickets available at a particular datetime
514
-     *    (does NOT take into account the datetime's spaces available)
515
-     *
516
-     * @param int   $DTT_ID
517
-     * @param array $query_params
518
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
519
-     *             tickets attached to datetime then FALSE is returned.
520
-     */
521
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
522
-    {
523
-        $datetime = $this->get_one_by_ID($DTT_ID);
524
-        if ($datetime instanceof EE_Datetime) {
525
-            return $datetime->tickets_remaining($query_params);
526
-        }
527
-        return 0;
528
-    }
529
-
530
-
531
-
532
-    /**
533
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
534
-     *
535
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
536
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
537
-     *                                 for all valid stati.
538
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
539
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
540
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
541
-     * @throws \EE_Error
542
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
543
-     */
544
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
545
-    {
546
-        //only accept where conditions for this query.
547
-        $_where = isset($query_params[0]) ? $query_params[0] : array();
548
-        $status_query_args = array(
549
-            EE_Datetime::active   => array_merge(
550
-                $_where,
551
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
552
-            ),
553
-            EE_Datetime::upcoming => array_merge(
554
-                $_where,
555
-                array('DTT_EVT_start' => array('>', time()))
556
-            ),
557
-            EE_Datetime::expired  => array_merge(
558
-                $_where,
559
-                array('DTT_EVT_end' => array('<', time()))
560
-            ),
561
-        );
562
-        if ( ! empty($stati_to_include)) {
563
-            foreach (array_keys($status_query_args) as $status) {
564
-                if ( ! in_array($status, $stati_to_include, true)) {
565
-                    unset($status_query_args[$status]);
566
-                }
567
-            }
568
-        }
569
-        //loop through and query counts for each stati.
570
-        $status_query_results = array();
571
-        foreach ($status_query_args as $status => $status_where_conditions) {
572
-            $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
573
-        }
574
-        return $status_query_results;
575
-    }
576
-
577
-
578
-
579
-    /**
580
-     * Returns the specific count for a given Datetime status matching any given query_params.
581
-     *
582
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
583
-     * @param array  $query_params
584
-     * @return int
585
-     * @throws \EE_Error
586
-     */
587
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
588
-    {
589
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
590
-        return ! empty($count[$status]) ? $count[$status] : 0;
591
-    }
14
+	/**
15
+	 * @var EEM_Datetime $_instance
16
+	 */
17
+	protected static $_instance;
18
+
19
+
20
+
21
+	/**
22
+	 *        private constructor to prevent direct creation
23
+	 *
24
+	 * @Constructor
25
+	 * @access private
26
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
27
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
28
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
29
+	 *                         timezone in the 'timezone_string' wp option)
30
+	 * @throws \EE_Error
31
+	 */
32
+	protected function __construct($timezone)
33
+	{
34
+		$this->singular_item = __('Datetime', 'event_espresso');
35
+		$this->plural_item = __('Datetimes', 'event_espresso');
36
+		$this->_tables = array(
37
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
38
+		);
39
+		$this->_fields = array(
40
+			'Datetime' => array(
41
+				'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
42
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
43
+					'EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'
44
+				),
45
+				'DTT_name'        => new EE_Plain_Text_Field(
46
+					'DTT_name', __('Datetime Name', 'event_espresso'), false, ''
47
+				),
48
+				'DTT_description' => new EE_Post_Content_Field(
49
+					'DTT_description', __('Description for Datetime', 'event_espresso'), false, ''
50
+				),
51
+				'DTT_EVT_start'   => new EE_Datetime_Field(
52
+					'DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
53
+					$timezone
54
+				),
55
+				'DTT_EVT_end'     => new EE_Datetime_Field(
56
+					'DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now,
57
+					$timezone
58
+				),
59
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
60
+					'DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
61
+				'DTT_sold'        => new EE_Integer_Field(
62
+					'DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0
63
+				),
64
+				'DTT_reserved' => new EE_Integer_Field('DTT_reserved',
65
+					__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), false, 0
66
+				),
67
+				'DTT_is_primary'  => new EE_Boolean_Field(
68
+					'DTT_is_primary', __('Flag indicating datetime is primary one for event', 'event_espresso'),
69
+					false, false
70
+				),
71
+				'DTT_order'       => new EE_Integer_Field(
72
+					'DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0
73
+				),
74
+				'DTT_parent'      => new EE_Integer_Field(
75
+					'DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0
76
+				),
77
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
78
+					'DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false
79
+				),
80
+			),
81
+		);
82
+		$this->_model_relations = array(
83
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
84
+			'Event'   => new EE_Belongs_To_Relation(),
85
+			'Checkin' => new EE_Has_Many_Relation(),
86
+		);
87
+		$this->_model_chain_to_wp_user = 'Event';
88
+		//this model is generally available for reading
89
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
90
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
91
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
92
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
93
+			EEM_Base::caps_edit);
94
+		parent::__construct($timezone);
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * create new blank datetime
101
+	 *
102
+	 * @access public
103
+	 * @return EE_Datetime[] array on success, FALSE on fail
104
+	 * @throws \EE_Error
105
+	 */
106
+	public function create_new_blank_datetime()
107
+	{
108
+		$blank_datetime = EE_Datetime::new_instance(
109
+			array(
110
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS,
111
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS,
112
+				'DTT_order'     => 1,
113
+				'DTT_reg_limit' => EE_INF,
114
+			),
115
+			$this->_timezone
116
+		);
117
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
118
+			$this->_timezone));
119
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone));
120
+		return array($blank_datetime);
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * get event start date from db
127
+	 *
128
+	 * @access public
129
+	 * @param  int $EVT_ID
130
+	 * @return EE_Datetime[] array on success, FALSE on fail
131
+	 * @throws \EE_Error
132
+	 */
133
+	public function get_all_event_dates($EVT_ID = 0)
134
+	{
135
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
136
+			return $this->create_new_blank_datetime();
137
+		}
138
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
139
+		if (empty($results)) {
140
+			return $this->create_new_blank_datetime();
141
+		}
142
+		return $results;
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * get all datetimes attached to an event ordered by the DTT_order field
149
+	 *
150
+	 * @public
151
+	 * @param  int    $EVT_ID     event id
152
+	 * @param boolean $include_expired
153
+	 * @param boolean $include_deleted
154
+	 * @param  int    $limit      If included then limit the count of results by
155
+	 *                            the given number
156
+	 * @return EE_Datetime[]
157
+	 * @throws \EE_Error
158
+	 */
159
+	public function get_datetimes_for_event_ordered_by_DTT_order(
160
+		$EVT_ID,
161
+		$include_expired = true,
162
+		$include_deleted = true,
163
+		$limit = null
164
+	) {
165
+		//sanitize EVT_ID
166
+		$EVT_ID = absint($EVT_ID);
167
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
168
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
169
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
170
+		$query_params = ! empty($limit)
171
+			? array(
172
+				$where_params,
173
+				'limit'                    => $limit,
174
+				'order_by'                 => array('DTT_order' => 'ASC'),
175
+				'default_where_conditions' => 'none',
176
+			)
177
+			: array(
178
+				$where_params,
179
+				'order_by'                 => array('DTT_order' => 'ASC'),
180
+				'default_where_conditions' => 'none',
181
+			);
182
+		if ( ! $include_expired) {
183
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
184
+		}
185
+		if ($include_deleted) {
186
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
187
+		}
188
+		/** @var EE_Datetime[] $result */
189
+		$result = $this->get_all($query_params);
190
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
191
+		return $result;
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
198
+	 * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
199
+	 * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
200
+	 *
201
+	 * @param int $EVT_ID
202
+	 * @param int $limit
203
+	 * @return EE_Datetime[]|EE_Base_Class[]
204
+	 * @throws \EE_Error
205
+	 */
206
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
207
+	{
208
+		return $this->get_all(
209
+			array(
210
+				array('Event.EVT_ID' => $EVT_ID),
211
+				'limit'                    => $limit,
212
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
213
+				'default_where_conditions' => 'none',
214
+			)
215
+		);
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * @param int     $EVT_ID
222
+	 * @param boolean $include_expired
223
+	 * @param boolean $include_deleted
224
+	 * @return EE_Datetime
225
+	 * @throws \EE_Error
226
+	 */
227
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
228
+	{
229
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
230
+		if ($results) {
231
+			return array_shift($results);
232
+		} else {
233
+			return null;
234
+		}
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets the 'primary' datetime for an event.
241
+	 *
242
+	 * @param int  $EVT_ID
243
+	 * @param bool $try_to_exclude_expired
244
+	 * @param bool $try_to_exclude_deleted
245
+	 * @return \EE_Datetime
246
+	 * @throws \EE_Error
247
+	 */
248
+	public function get_primary_datetime_for_event(
249
+		$EVT_ID,
250
+		$try_to_exclude_expired = true,
251
+		$try_to_exclude_deleted = true
252
+	) {
253
+		if ($try_to_exclude_expired) {
254
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
255
+			if ($non_expired) {
256
+				return $non_expired;
257
+			}
258
+		}
259
+		if ($try_to_exclude_deleted) {
260
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
261
+			if ($expired_even) {
262
+				return $expired_even;
263
+			}
264
+		}
265
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
272
+	 * only by start date
273
+	 *
274
+	 * @param int     $EVT_ID
275
+	 * @param boolean $include_expired
276
+	 * @param boolean $include_deleted
277
+	 * @param int     $limit
278
+	 * @return EE_Datetime[]
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function get_datetimes_for_event_ordered_by_start_time(
282
+		$EVT_ID,
283
+		$include_expired = true,
284
+		$include_deleted = true,
285
+		$limit = null
286
+	) {
287
+		//sanitize EVT_ID
288
+		$EVT_ID = absint($EVT_ID);
289
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
290
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
291
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
292
+		if ( ! $include_expired) {
293
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
294
+		}
295
+		if ($include_deleted) {
296
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
297
+		}
298
+		if ($limit) {
299
+			$query_params['limit'] = $limit;
300
+		}
301
+		/** @var EE_Datetime[] $result */
302
+		$result = $this->get_all($query_params);
303
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
304
+		return $result;
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
311
+	 * only by start date
312
+	 *
313
+	 * @param int     $TKT_ID
314
+	 * @param boolean $include_expired
315
+	 * @param boolean $include_deleted
316
+	 * @param int     $limit
317
+	 * @return EE_Datetime[]
318
+	 * @throws \EE_Error
319
+	 */
320
+	public function get_datetimes_for_ticket_ordered_by_start_time(
321
+		$TKT_ID,
322
+		$include_expired = true,
323
+		$include_deleted = true,
324
+		$limit = null
325
+	) {
326
+		//sanitize TKT_ID
327
+		$TKT_ID = absint($TKT_ID);
328
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
329
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
330
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
331
+		if ( ! $include_expired) {
332
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
333
+		}
334
+		if ($include_deleted) {
335
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
336
+		}
337
+		if ($limit) {
338
+			$query_params['limit'] = $limit;
339
+		}
340
+		/** @var EE_Datetime[] $result */
341
+		$result = $this->get_all($query_params);
342
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
343
+		return $result;
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
350
+	 * datetimes.
351
+	 *
352
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
353
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
354
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
355
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
356
+	 *                                   that number
357
+	 * @return EE_Datetime[]
358
+	 * @throws \EE_Error
359
+	 */
360
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
361
+		$TKT_ID,
362
+		$include_expired = true,
363
+		$include_deleted = true,
364
+		$limit = null
365
+	) {
366
+		//sanitize id.
367
+		$TKT_ID = absint($TKT_ID);
368
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
369
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
370
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
371
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
372
+		if ( ! $include_expired) {
373
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
374
+		}
375
+		if ($include_deleted) {
376
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
377
+		}
378
+		if ($limit) {
379
+			$query_params['limit'] = $limit;
380
+		}
381
+		/** @var EE_Datetime[] $result */
382
+		$result = $this->get_all($query_params);
383
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
384
+		return $result;
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
391
+	 * reason it doesn't exist, we consider the earliest event the most important)
392
+	 *
393
+	 * @param int $EVT_ID
394
+	 * @return EE_Datetime
395
+	 * @throws \EE_Error
396
+	 */
397
+	public function get_most_important_datetime_for_event($EVT_ID)
398
+	{
399
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
400
+		if ($results) {
401
+			return array_shift($results);
402
+		} else {
403
+			return null;
404
+		}
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
411
+	 * grouped by month and year.
412
+	 *
413
+	 * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
414
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
415
+	 *                                   Can be:
416
+	 *                                   - '' = no filter
417
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
418
+	 *                                   - expired = Events with all datetimes expired.
419
+	 *                                   - active = Events that are published and have at least one datetime that
420
+	 *                                   starts before now and ends after now.
421
+	 *                                   - inactive = Events that are either not published.
422
+	 * @return EE_Base_Class[]
423
+	 * @throws \EE_Error
424
+	 */
425
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
426
+	{
427
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
428
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
429
+		switch ($evt_active_status) {
430
+			case 'upcoming' :
431
+				$where_params['Event.status'] = 'publish';
432
+				//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
433
+				if (isset($where_params['DTT_EVT_start'])) {
434
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
435
+				}
436
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
437
+				break;
438
+			case 'expired' :
439
+				if (isset($where_params['Event.status'])) {
440
+					unset($where_params['Event.status']);
441
+				}
442
+				//get events to exclude
443
+				$exclude_query[0] = array_merge($where_params,
444
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
445
+				//first get all events that have datetimes where its not expired.
446
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
447
+				$event_ids = array_keys($event_ids);
448
+				if (isset($where_params['DTT_EVT_end'])) {
449
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
450
+				}
451
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
452
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
453
+				break;
454
+			case 'active' :
455
+				$where_params['Event.status'] = 'publish';
456
+				if (isset($where_params['DTT_EVT_start'])) {
457
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
458
+				}
459
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
460
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
461
+				}
462
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
463
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
464
+				break;
465
+			case 'inactive' :
466
+				if (isset($where_params['Event.status'])) {
467
+					unset($where_params['Event.status']);
468
+				}
469
+				if (isset($where_params['OR'])) {
470
+					$where_params['AND']['OR'] = $where_params['OR'];
471
+				}
472
+				if (isset($where_params['DTT_EVT_end'])) {
473
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
474
+					unset($where_params['DTT_EVT_end']);
475
+				}
476
+				if (isset($where_params['DTT_EVT_start'])) {
477
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
478
+					unset($where_params['DTT_EVT_start']);
479
+				}
480
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
481
+				break;
482
+		}
483
+		$query_params[0] = $where_params;
484
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
485
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
486
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
487
+		$columns_to_select = array(
488
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
489
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
490
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
491
+		);
492
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
493
+	}
494
+
495
+
496
+
497
+	/**
498
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
499
+	 * for the tickets for each datetime)
500
+	 *
501
+	 * @param EE_Datetime[] $datetimes
502
+	 */
503
+	public function update_sold($datetimes)
504
+	{
505
+		foreach ($datetimes as $datetime) {
506
+			$datetime->update_sold();
507
+		}
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 *    Gets the total number of tickets available at a particular datetime
514
+	 *    (does NOT take into account the datetime's spaces available)
515
+	 *
516
+	 * @param int   $DTT_ID
517
+	 * @param array $query_params
518
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
519
+	 *             tickets attached to datetime then FALSE is returned.
520
+	 */
521
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
522
+	{
523
+		$datetime = $this->get_one_by_ID($DTT_ID);
524
+		if ($datetime instanceof EE_Datetime) {
525
+			return $datetime->tickets_remaining($query_params);
526
+		}
527
+		return 0;
528
+	}
529
+
530
+
531
+
532
+	/**
533
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
534
+	 *
535
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
536
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
537
+	 *                                 for all valid stati.
538
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
539
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
540
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
541
+	 * @throws \EE_Error
542
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
543
+	 */
544
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
545
+	{
546
+		//only accept where conditions for this query.
547
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
548
+		$status_query_args = array(
549
+			EE_Datetime::active   => array_merge(
550
+				$_where,
551
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
552
+			),
553
+			EE_Datetime::upcoming => array_merge(
554
+				$_where,
555
+				array('DTT_EVT_start' => array('>', time()))
556
+			),
557
+			EE_Datetime::expired  => array_merge(
558
+				$_where,
559
+				array('DTT_EVT_end' => array('<', time()))
560
+			),
561
+		);
562
+		if ( ! empty($stati_to_include)) {
563
+			foreach (array_keys($status_query_args) as $status) {
564
+				if ( ! in_array($status, $stati_to_include, true)) {
565
+					unset($status_query_args[$status]);
566
+				}
567
+			}
568
+		}
569
+		//loop through and query counts for each stati.
570
+		$status_query_results = array();
571
+		foreach ($status_query_args as $status => $status_where_conditions) {
572
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
573
+		}
574
+		return $status_query_results;
575
+	}
576
+
577
+
578
+
579
+	/**
580
+	 * Returns the specific count for a given Datetime status matching any given query_params.
581
+	 *
582
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
583
+	 * @param array  $query_params
584
+	 * @return int
585
+	 * @throws \EE_Error
586
+	 */
587
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
588
+	{
589
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
590
+		return ! empty($count[$status]) ? $count[$status] : 0;
591
+	}
592 592
 
593 593
 
594 594
 
Please login to merge, or discard this patch.