Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/page-templates.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + /**
4 + * Get the template path that should be loaded for a given page.
5 + *
6 + * @since 2.11
7 + *
8 + * @param null $page_name - Name of the page/template
9 + * @param string $where - `local` or `url` (whether to load from FS or over http)
10 + * @param string $type - Type of template (valid: 'email' or 'pages', 'adminpages', 'preheader')
11 + * @param string $ext - File extension ('php', 'html', 'htm', etc)
12 + * @return string|null - The HTML for the template or null if not found.
13 + */
14 + function pmpro_get_template_path_to_load( $page_name = null, $where = 'local', $type = 'pages', $ext = 'php' ) {
15 + // called from page handler shortcode
16 + if ( is_null( $page_name ) ) {
17 + global $pmpro_page_name;
18 + $page_name = $pmpro_page_name;
19 + }
20 + if ( $where == 'local' ) {
21 + // template paths in order of priority (array gets reversed)
22 + $default_templates = array(
23 + PMPRO_DIR . "/{$type}/{$page_name}.{$ext}", // default plugin path
24 + get_template_directory() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // parent theme
25 + get_stylesheet_directory() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // child / active theme
26 + );
27 + } elseif ( $where == 'url' ) {
28 + // template paths in order of priority (array gets reversed)
29 + $default_templates = array(
30 + PMPRO_URL . "/{$type}/{$page_name}.{$ext}", // default plugin path
31 + get_template_directory_uri() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // parent theme
32 + get_stylesheet_directory_uri() . "/paid-memberships-pro/{$type}/{$page_name}.{$ext}", // child / active theme
33 + );
34 + }
35 + // Valid types: 'email', 'pages'
36 + $templates = apply_filters( "pmpro_{$type}_custom_template_path", $default_templates, $page_name, $type, $where, $ext );
37 + $user_templates = array_diff( $templates, $default_templates );
38 + $allowed_default_templates = array_intersect( $templates, $default_templates );
39 + // user specified a custom template path, so it has priority.
40 + if ( ! empty( $user_templates ) ) {
41 + $templates = array_merge($allowed_default_templates, $user_templates);
42 + }
43 + // last element included in the array is the most first one we try to load
44 + $templates = array_reverse( $templates );
45 +
46 + // look for template file to include
47 + foreach ( $templates as $template_path ) {
48 + // If loading a local file, check if it exists first
49 + if ( $where == 'url' || file_exists( $template_path ) ) {
50 + return $template_path;
51 + }
52 + }
53 +
54 + return null;
55 + }
56 +
57 + /**
58 + * Loads a template from one of the default paths (PMPro plugin or theme), or from filtered path
59 + *
60 + * @param null $page_name - Name of the page/template
61 + * @param string $where - `local` or `url` (whether to load from FS or over http)
62 + * @param string $type - Type of template (valid: 'email' or 'pages', 'adminpages', 'preheader')
63 + * @param string $ext - File extension ('php', 'html', 'htm', etc)
64 + * @return string - The HTML for the template.
65 + *
66 + * TODO - Allow localized template files to be loaded?
67 + *
68 + * @since 1.8.9
69 + */
70 + function pmpro_loadTemplate( $page_name = null, $where = 'local', $type = 'pages', $ext = 'php' ) {
71 + // Get the path of the template to load.
72 + $path = pmpro_get_template_path_to_load( $page_name, $where, $type, $ext );
73 +
74 + // Get the default plugin path.
75 + $default_path = PMPRO_DIR . "/{$type}/{$page_name}.{$ext}";
76 +
77 + // If this is a custom page template, check if we should load it.
78 + if ( $type = 'pages' && $path !== $default_path ) {
79 + $use_custom_page_template = get_option( 'pmpro_use_custom_page_template_' . $page_name );
80 + switch( $use_custom_page_template ) {
81 + case 'yes':
82 + break;
83 + case 'no':
84 + $path = $default_path;
85 + break;
86 + default:
87 + // Check if the custom template is newer than the default template.
88 + $default_version = pmpro_get_version_for_page_template_at_path( $default_path );
89 + $custom_version = pmpro_get_version_for_page_template_at_path( $path );
90 + if ( $default_version != $custom_version ) {
91 + $path = $default_path;
92 + }
93 + break;
94 + }
95 + }
96 +
97 + // If the template exists, load it.
98 + ob_start();
99 + if ( ! empty( $path ) && file_exists( $path ) ) {
100 + include $path;
101 + }
102 + $template = ob_get_clean();
103 +
104 + // Return template content.
105 + return $template;
106 + }
107 +
108 + /**
109 + * Get the version of a page template at a given path.
110 + *
111 + * @since 2.11
112 + *
113 + * @param string $path Path to the page template.
114 + * @return string|null Version of the page template, or null if not found.
115 + */
116 + function pmpro_get_version_for_page_template_at_path( $path ) {
117 + if ( ! file_exists( $path ) ) {
118 + return null;
119 + }
120 +
121 + $file_header_data = get_file_data( $path, array( 'version' => 'version' ) );
122 + return empty( $file_header_data['version'] ) ? null : $file_header_data['version'];
123 + }
124 +
125 + /**
126 + * List all outdated page templates being used.
127 + *
128 + * @since 2.11
129 + *
130 + * @return array List of outdated page templates.
131 + */
132 + function pmpro_get_outdated_page_templates() {
133 + // Create a $template => $path array of all default page templates.
134 + $default_templates = array(
135 + 'account' => PMPRO_DIR . '/pages/account.php',
136 + 'billing' => PMPRO_DIR . '/pages/billing.php',
137 + 'cancel' => PMPRO_DIR . '/pages/cancel.php',
138 + 'checkout' => PMPRO_DIR . '/pages/checkout.php',
139 + 'confirmation' => PMPRO_DIR . '/pages/confirmation.php',
140 + 'invoice' => PMPRO_DIR . '/pages/invoice.php',
141 + 'levels' => PMPRO_DIR . '/pages/levels.php',
142 + 'login' => PMPRO_DIR . '/pages/login.php',
143 + 'member_profile_edit' => PMPRO_DIR . '/pages/member_profile_edit.php',
144 + );
145 +
146 + // Filter $default_templates so that Add Ons can add their own templates.
147 + $default_templates = apply_filters( 'pmpro_default_page_templates', $default_templates );
148 +
149 + // Loop through each template. For each, get the version for the default template and
150 + // compare it to the version for the template that is actually being loaded. If the
151 + // version for the template that is actually being loaded is older, add it to an
152 + // $outdated_templates array.
153 + $outdated_templates = array(); // Array of $template => array( 'default_version' => $default_version, 'loaded_version' => $loaded_version, 'loaded_path' => $loaded_path ).
154 + foreach ( $default_templates as $template => $path ) {
155 + // Check if the custom page template would actually be loaded.
156 + if ( 'yes' !== get_option( 'pmpro_use_custom_page_template_' . $template ) ) {
157 + continue;
158 + }
159 +
160 + // Get the version for the default template.
161 + $default_version = pmpro_get_version_for_page_template_at_path( $path );
162 +
163 + // All templates started at 2.0. If the core version is still outdated, let's not call the custom template outdated.
164 + if ( '2.0' === $default_version ) {
165 + continue;
166 + }
167 +
168 + // Get the version for the template that is actually being loaded.
169 + $loaded_path = pmpro_get_template_path_to_load( $template );
170 + $loaded_version = pmpro_get_version_for_page_template_at_path( $loaded_path );
171 +
172 + // If either version is null or the loaded version is older than the default version, add it to the $outdated_templates array.
173 + if ( $default_version !== $loaded_version ) {
174 + $outdated_templates[ $template ] = array(
175 + 'default_version' => $default_version,
176 + 'loaded_version' => $loaded_version,
177 + 'loaded_path' => $loaded_path,
178 + );
179 + }
180 + }
181 + return $outdated_templates;
182 + }
183 +
184 + /**
185 + * Displays a warning notice regarding outdated templates
186 + *
187 + * @since 2.11
188 + *
189 + * @return mixed|string - Empty, or the HTML containing the notice
190 + */
191 + function pmpro_page_template_notices() {
192 +
193 + //Only show this notice on PMPro admin pages
194 + if ( ! isset( $_REQUEST['page'] ) || strpos( $_REQUEST['page'], 'pmpro' ) === false || $_REQUEST['page'] === 'pmpro-pagesettings' ) {
195 + return;
196 + }
197 +
198 + /**
199 + * Permanently disable any template version notices
200 + *
201 + * @param bool To permanently hide template version notices
202 + *
203 + * @since 2.11
204 + *
205 + */
206 + $hide_template_notices = apply_filters( 'pmpro_hide_template_version_notices', (bool) get_option( 'pmpro_disable_outdated_template_warning' ) );
207 +
208 + if( $hide_template_notices ) {
209 + return;
210 + }
211 +
212 + $outdated_templates = pmpro_get_outdated_page_templates();
213 +
214 + if( ! empty( $outdated_templates ) ) {
215 + // Build a string listing the outdated template names and paths.
216 + $outdated_templates_string = '';
217 + foreach ( $outdated_templates as $template_name => $template_data ) {
218 + $outdated_templates_string .= '<li><strong>' . esc_html( $template_name ) . '</strong> - ' . esc_html( $template_data['loaded_path'] ) . '</li>';
219 + }
220 + ?>
221 + <div class="notice notice-error pmpro_notification pmpro_notification-error">
222 + <div class="pmpro_notification-icon">
223 + <span class="dashicons dashicons-warning"></span>
224 + </div>
225 + <div class="pmpro_notification-content">
226 + <h3><?php esc_html_e( 'Outdated Page Templates Detected', 'paid-memberships-pro' ); ?></h3>
227 + <p>
228 + <?php
229 + esc_html_e( 'Paid Memberships Pro has detected that your site is using outdated frontend page templates. If you are experiencing an issue on the frontend of your site, use the Settings > Pages screen to change which custom template is being loaded for your frontend pages.', 'paid-memberships-pro' );
230 + ?>
231 + </p>
232 + <p>
233 + <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'pmpro-pagesettings#pmpro-custom-page-template-settings' ), admin_url( 'admin.php' ) ) ); ?>" class="button"><?php esc_html_e( 'View outdated page templates', 'paid-memberships-pro' ); ?></a>
234 + </p>
235 + </div>
236 + </div>
237 + <?php
238 + }
239 +
240 + }
241 + add_action( 'admin_notices', 'pmpro_page_template_notices' );