Changeset 6862
- Timestamp:
- 09/05/2018 06:55:06 PM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
-
includes/core/template-functions.php (modified) (3 diffs)
-
templates/default/bbpress-functions.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/template-functions.php
r6795 r6862 105 105 106 106 return $located; 107 } 108 109 /** 110 * Locate an enqueueable file on the server. Used before being enqueued. 111 * 112 * If SCRIPT_DEBUG is set and the file includes a .min suffix, this function 113 * will automatically attempt to locate a non-minified version of that file. 114 * 115 * If SCRIPT_DEBUG is not set and the file exclude a .min suffix, this function 116 * will automatically attempt to locate a minified version of that file. 117 * 118 * See: https://bbpress.trac.wordpress.org/ticket/3218 119 * 120 * @since 2.6.0 121 * 122 * @param string $file 123 * 124 * @return boolean 125 */ 126 function bbp_locate_enqueueable( $file = '' ) { 127 128 // Bail if no file to locate 129 if ( empty( $file ) ) { 130 return false; 131 } 132 133 // Add file to files array 134 $files = array( $file ); 135 136 // Get the file variant (minified or not, but opposite of $file) 137 $file_is_min = ( false !== strpos( $file, '.min' ) ); 138 $file_variant = ( false === $file_is_min ) 139 ? str_replace( array( '.css', '.js' ), array( '.min.css', '.min.js' ), $file ) 140 : str_replace( '.min', '', $file ); 141 142 // Are we debugging? 143 $script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; 144 145 // Debugging, so prefer unminified files 146 if ( true === $script_debug ) { 147 if ( true === $file_is_min ) { 148 array_unshift( $files, $file_variant ); 149 } else { 150 array_push( $files, $file_variant ); 151 } 152 153 // Not debugging, so prefer minified files 154 } elseif ( false === $script_debug ) { 155 if ( true === $file_is_min ) { 156 array_push( $files, $file_variant ); 157 } else { 158 array_unshift( $files, $file_variant ); 159 } 160 } 161 162 // Return first found file location in the stack 163 return bbp_locate_template( $files, false, false ); 164 } 165 166 /** 167 * Convert an enqueueable file path to a URL 168 * 169 * @since 2.6.0 170 * @param string $file 171 * 172 * @return string 173 */ 174 function bbp_urlize_enqueueable( $file = '' ) { 175 176 // Get DIR and URL 177 $content_dir = constant( 'WP_CONTENT_DIR' ); 178 $content_url = content_url(); 179 180 // IIS (Windows) here 181 // Replace back slashes with forward slash 182 if ( false !== strpos( $file, '\\' ) ) { 183 $file = str_replace( '\\', '/', $file ); 184 $content_dir = str_replace( '\\', '/', $content_dir ); 185 } 186 187 // Return path to file relative to site URL 188 return str_replace( $content_dir, $content_url, $file ); 107 189 } 108 190 … … 124 206 * 'screen', 'tty', or 'tv'. 125 207 * 126 * @return string The style filename if one is located.208 * @return mixed The style filename if one is located. False if not. 127 209 */ 128 210 function bbp_enqueue_style( $handle = '', $file = '', $deps = array(), $ver = false, $media = 'all' ) { 129 211 130 // No file found yet 131 $located = false; 132 133 // Trim off any slashes from the template name 134 $file = ltrim( $file, '/' ); 135 136 // Make sure there is always a version 137 if ( empty( $ver ) ) { 138 $ver = bbp_get_version(); 139 } 140 141 // Loop through template stack 142 foreach ( (array) bbp_get_template_stack() as $template_location ) { 143 144 // Continue if $template_location is empty 145 if ( empty( $template_location ) ) { 146 continue; 147 } 148 149 // Check child theme first 150 if ( file_exists( trailingslashit( $template_location ) . $file ) ) { 151 $located = trailingslashit( $template_location ) . $file; 152 break; 153 } 154 } 212 // Attempt to locate an enqueueable 213 $located = bbp_locate_enqueueable( $file ); 155 214 156 215 // Enqueue if located 157 216 if ( ! empty( $located ) ) { 158 217 159 $content_dir = constant( 'WP_CONTENT_DIR' ); 160 161 // IIS (Windows) here 162 // Replace back slashes with forward slash 163 if ( strpos( $located, '\\' ) !== false ) { 164 $located = str_replace( '\\', '/', $located ); 165 $content_dir = str_replace( '\\', '/', $content_dir ); 166 } 167 168 // Make path to file relative to site URL 169 $located = str_replace( $content_dir, content_url(), $located ); 218 // Make sure there is always a version 219 if ( empty( $ver ) ) { 220 $ver = bbp_get_version(); 221 } 222 223 // Make path to file relative to site URL 224 $located = bbp_urlize_enqueueable( $located ); 170 225 171 226 // Register the style … … 195 250 * Default 'false'. Accepts 'false' or 'true'. 196 251 * 197 * @return string The script filename if one is located.252 * @return mixed The script filename if one is located. False if not. 198 253 */ 199 254 function bbp_enqueue_script( $handle = '', $file = '', $deps = array(), $ver = false, $in_footer = false ) { 200 255 201 // No file found yet 202 $located = false; 203 204 // Trim off any slashes from the template name 205 $file = ltrim( $file, '/' ); 206 207 // Make sure there is always a version 208 if ( empty( $ver ) ) { 209 $ver = bbp_get_version(); 210 } 211 212 // Loop through template stack 213 foreach ( (array) bbp_get_template_stack() as $template_location ) { 214 215 // Continue if $template_location is empty 216 if ( empty( $template_location ) ) { 217 continue; 218 } 219 220 // Check child theme first 221 if ( file_exists( trailingslashit( $template_location ) . $file ) ) { 222 $located = trailingslashit( $template_location ) . $file; 223 break; 224 } 225 } 256 // Attempt to locate an enqueueable 257 $located = bbp_locate_enqueueable( $file ); 226 258 227 259 // Enqueue if located 228 260 if ( ! empty( $located ) ) { 229 261 230 $content_dir = constant( 'WP_CONTENT_DIR' ); 231 232 // IIS (Windows) here 233 // Replace back slashes with forward slash 234 if ( strpos( $located, '\\' ) !== false ) { 235 $located = str_replace( '\\', '/', $located ); 236 $content_dir = str_replace( '\\', '/', $content_dir ); 237 } 238 239 // Make path to file relative to site URL 240 $located = str_replace( $content_dir, content_url(), $located ); 262 // Make sure there is always a version 263 if ( empty( $ver ) ) { 264 $ver = bbp_get_version(); 265 } 266 267 // Make path to file relative to site URL 268 $located = bbp_urlize_enqueueable( $located ); 241 269 242 270 // Register the style -
trunk/src/templates/default/bbpress-functions.php
r6795 r6862 41 41 * 42 42 * @since 2.1.0 bbPress (r3732) 43 *44 43 */ 45 44 public function __construct( $properties = array() ) { … … 62 61 * 63 62 * @access private 64 *65 63 */ 66 64 private function setup_actions() { … … 118 116 * 119 117 * @since 2.1.0 bbPress (r3732) 120 *121 118 */ 122 119 public function enqueue_styles() { … … 124 121 // RTL and/or minified 125 122 $suffix = is_rtl() ? '-rtl' : ''; 126 $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';127 123 128 124 // Get and filter the bbp-default style 129 125 $styles = apply_filters( 'bbp_default_styles', array( 130 126 'bbp-default' => array( 131 'file' => 'css/bbpress ' . $suffix . '.css',127 'file' => 'css/bbpress.css', 132 128 'dependencies' => array() 133 129 ) … … 144 140 * 145 141 * @since 2.1.0 bbPress (r3732) 146 *147 142 */ 148 143 public function enqueue_scripts() { … … 150 145 // Setup scripts array 151 146 $scripts = array(); 152 153 // Minified154 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';155 147 156 148 // Editor scripts … … 158 150 if ( bbp_use_wp_editor() && is_bbpress() ) { 159 151 $scripts['bbpress-editor'] = array( 160 'file' => 'js/editor ' . $suffix . '.js',152 'file' => 'js/editor.js', 161 153 'dependencies' => array( 'jquery' ) 162 154 ); … … 166 158 if ( bbp_is_single_forum() ) { 167 159 $scripts['bbpress-engagements'] = array( 168 'file' => 'js/engagements ' . $suffix . '.js',160 'file' => 'js/engagements.js', 169 161 'dependencies' => array( 'jquery' ) 170 162 ); … … 176 168 // Engagements 177 169 $scripts['bbpress-engagements'] = array( 178 'file' => 'js/engagements ' . $suffix . '.js',170 'file' => 'js/engagements.js', 179 171 'dependencies' => array( 'jquery' ) 180 172 ); … … 183 175 if ( bbp_thread_replies() ) { 184 176 $scripts['bbpress-reply'] = array( 185 'file' => 'js/reply ' . $suffix . '.js',177 'file' => 'js/reply.js', 186 178 'dependencies' => array( 'jquery' ) 187 179 ); … … 209 201 * 210 202 * @since 2.1.0 bbPress (r3732) 211 *212 203 */ 213 204 public function localize_topic_script() { … … 227 218 * 228 219 * @since 2.1.0 bbPress (r3732) 229 *230 220 */ 231 221 public function ajax_favorite() { … … 291 281 * 292 282 * @since 2.1.0 bbPress (r3732) 293 *294 283 */ 295 284 public function ajax_subscription() {
Note: See TracChangeset
for help on using the changeset viewer.