Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: media.php
return $image;
[2000] Fix | Delete
}
[2001] Fix | Delete
[2002] Fix | Delete
if ( empty( $decoding_val ) ) {
[2003] Fix | Delete
/**
[2004] Fix | Delete
* Filters the `decoding` attribute value to add to an image. Default `async`.
[2005] Fix | Delete
*
[2006] Fix | Delete
* Returning a falsey value will omit the attribute.
[2007] Fix | Delete
*
[2008] Fix | Delete
* @since 6.1.0
[2009] Fix | Delete
*
[2010] Fix | Delete
* @param string|false|null $value The `decoding` attribute value. Returning a falsey value
[2011] Fix | Delete
* will result in the attribute being omitted for the image.
[2012] Fix | Delete
* Otherwise, it may be: 'async', 'sync', or 'auto'. Defaults to false.
[2013] Fix | Delete
* @param string $image The HTML `img` tag to be filtered.
[2014] Fix | Delete
* @param string $context Additional context about how the function was called
[2015] Fix | Delete
* or where the img tag is.
[2016] Fix | Delete
*/
[2017] Fix | Delete
$filtered_decoding_attr = apply_filters(
[2018] Fix | Delete
'wp_img_tag_add_decoding_attr',
[2019] Fix | Delete
isset( $optimization_attrs['decoding'] ) ? $optimization_attrs['decoding'] : false,
[2020] Fix | Delete
$image,
[2021] Fix | Delete
$context
[2022] Fix | Delete
);
[2023] Fix | Delete
[2024] Fix | Delete
// Validate the values after filtering.
[2025] Fix | Delete
if ( isset( $optimization_attrs['decoding'] ) && ! $filtered_decoding_attr ) {
[2026] Fix | Delete
// Unset `decoding` attribute if `$filtered_decoding_attr` is set to `false`.
[2027] Fix | Delete
unset( $optimization_attrs['decoding'] );
[2028] Fix | Delete
} elseif ( in_array( $filtered_decoding_attr, array( 'async', 'sync', 'auto' ), true ) ) {
[2029] Fix | Delete
$optimization_attrs['decoding'] = $filtered_decoding_attr;
[2030] Fix | Delete
}
[2031] Fix | Delete
[2032] Fix | Delete
if ( ! empty( $optimization_attrs['decoding'] ) ) {
[2033] Fix | Delete
$image = str_replace( '<img', '<img decoding="' . esc_attr( $optimization_attrs['decoding'] ) . '"', $image );
[2034] Fix | Delete
}
[2035] Fix | Delete
}
[2036] Fix | Delete
[2037] Fix | Delete
// Images should have dimension attributes for the 'loading' and 'fetchpriority' attributes to be added.
[2038] Fix | Delete
if ( ! str_contains( $image, ' width="' ) || ! str_contains( $image, ' height="' ) ) {
[2039] Fix | Delete
return $image;
[2040] Fix | Delete
}
[2041] Fix | Delete
[2042] Fix | Delete
// Retained for backward compatibility.
[2043] Fix | Delete
$loading_attrs_enabled = wp_lazy_loading_enabled( 'img', $context );
[2044] Fix | Delete
[2045] Fix | Delete
if ( empty( $loading_val ) && $loading_attrs_enabled ) {
[2046] Fix | Delete
/**
[2047] Fix | Delete
* Filters the `loading` attribute value to add to an image. Default `lazy`.
[2048] Fix | Delete
*
[2049] Fix | Delete
* Returning `false` or an empty string will not add the attribute.
[2050] Fix | Delete
* Returning `true` will add the default value.
[2051] Fix | Delete
*
[2052] Fix | Delete
* @since 5.5.0
[2053] Fix | Delete
*
[2054] Fix | Delete
* @param string|bool $value The `loading` attribute value. Returning a falsey value will result in
[2055] Fix | Delete
* the attribute being omitted for the image.
[2056] Fix | Delete
* @param string $image The HTML `img` tag to be filtered.
[2057] Fix | Delete
* @param string $context Additional context about how the function was called or where the img tag is.
[2058] Fix | Delete
*/
[2059] Fix | Delete
$filtered_loading_attr = apply_filters(
[2060] Fix | Delete
'wp_img_tag_add_loading_attr',
[2061] Fix | Delete
isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false,
[2062] Fix | Delete
$image,
[2063] Fix | Delete
$context
[2064] Fix | Delete
);
[2065] Fix | Delete
[2066] Fix | Delete
// Validate the values after filtering.
[2067] Fix | Delete
if ( isset( $optimization_attrs['loading'] ) && ! $filtered_loading_attr ) {
[2068] Fix | Delete
// Unset `loading` attributes if `$filtered_loading_attr` is set to `false`.
[2069] Fix | Delete
unset( $optimization_attrs['loading'] );
[2070] Fix | Delete
} elseif ( in_array( $filtered_loading_attr, array( 'lazy', 'eager' ), true ) ) {
[2071] Fix | Delete
/*
[2072] Fix | Delete
* If the filter changed the loading attribute to "lazy" when a fetchpriority attribute
[2073] Fix | Delete
* with value "high" is already present, trigger a warning since those two attribute
[2074] Fix | Delete
* values should be mutually exclusive.
[2075] Fix | Delete
*
[2076] Fix | Delete
* The same warning is present in `wp_get_loading_optimization_attributes()`, and here it
[2077] Fix | Delete
* is only intended for the specific scenario where the above filtered caused the problem.
[2078] Fix | Delete
*/
[2079] Fix | Delete
if ( isset( $optimization_attrs['fetchpriority'] ) && 'high' === $optimization_attrs['fetchpriority'] &&
[2080] Fix | Delete
( isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false ) !== $filtered_loading_attr &&
[2081] Fix | Delete
'lazy' === $filtered_loading_attr
[2082] Fix | Delete
) {
[2083] Fix | Delete
_doing_it_wrong(
[2084] Fix | Delete
__FUNCTION__,
[2085] Fix | Delete
__( 'An image should not be lazy-loaded and marked as high priority at the same time.' ),
[2086] Fix | Delete
'6.3.0'
[2087] Fix | Delete
);
[2088] Fix | Delete
}
[2089] Fix | Delete
[2090] Fix | Delete
// The filtered value will still be respected.
[2091] Fix | Delete
$optimization_attrs['loading'] = $filtered_loading_attr;
[2092] Fix | Delete
}
[2093] Fix | Delete
[2094] Fix | Delete
if ( ! empty( $optimization_attrs['loading'] ) ) {
[2095] Fix | Delete
$image = str_replace( '<img', '<img loading="' . esc_attr( $optimization_attrs['loading'] ) . '"', $image );
[2096] Fix | Delete
}
[2097] Fix | Delete
}
[2098] Fix | Delete
[2099] Fix | Delete
if ( empty( $fetchpriority_val ) && ! empty( $optimization_attrs['fetchpriority'] ) ) {
[2100] Fix | Delete
$image = str_replace( '<img', '<img fetchpriority="' . esc_attr( $optimization_attrs['fetchpriority'] ) . '"', $image );
[2101] Fix | Delete
}
[2102] Fix | Delete
[2103] Fix | Delete
return $image;
[2104] Fix | Delete
}
[2105] Fix | Delete
[2106] Fix | Delete
/**
[2107] Fix | Delete
* Adds `width` and `height` attributes to an `img` HTML tag.
[2108] Fix | Delete
*
[2109] Fix | Delete
* @since 5.5.0
[2110] Fix | Delete
*
[2111] Fix | Delete
* @param string $image The HTML `img` tag where the attribute should be added.
[2112] Fix | Delete
* @param string $context Additional context to pass to the filters.
[2113] Fix | Delete
* @param int $attachment_id Image attachment ID.
[2114] Fix | Delete
* @return string Converted 'img' element with 'width' and 'height' attributes added.
[2115] Fix | Delete
*/
[2116] Fix | Delete
function wp_img_tag_add_width_and_height_attr( $image, $context, $attachment_id ) {
[2117] Fix | Delete
$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';
[2118] Fix | Delete
list( $image_src ) = explode( '?', $image_src );
[2119] Fix | Delete
[2120] Fix | Delete
// Return early if we couldn't get the image source.
[2121] Fix | Delete
if ( ! $image_src ) {
[2122] Fix | Delete
return $image;
[2123] Fix | Delete
}
[2124] Fix | Delete
[2125] Fix | Delete
/**
[2126] Fix | Delete
* Filters whether to add the missing `width` and `height` HTML attributes to the img tag. Default `true`.
[2127] Fix | Delete
*
[2128] Fix | Delete
* Returning anything else than `true` will not add the attributes.
[2129] Fix | Delete
*
[2130] Fix | Delete
* @since 5.5.0
[2131] Fix | Delete
*
[2132] Fix | Delete
* @param bool $value The filtered value, defaults to `true`.
[2133] Fix | Delete
* @param string $image The HTML `img` tag where the attribute should be added.
[2134] Fix | Delete
* @param string $context Additional context about how the function was called or where the img tag is.
[2135] Fix | Delete
* @param int $attachment_id The image attachment ID.
[2136] Fix | Delete
*/
[2137] Fix | Delete
$add = apply_filters( 'wp_img_tag_add_width_and_height_attr', true, $image, $context, $attachment_id );
[2138] Fix | Delete
[2139] Fix | Delete
if ( true === $add ) {
[2140] Fix | Delete
$image_meta = wp_get_attachment_metadata( $attachment_id );
[2141] Fix | Delete
$size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
[2142] Fix | Delete
[2143] Fix | Delete
if ( $size_array && $size_array[0] && $size_array[1] ) {
[2144] Fix | Delete
// If the width is enforced through style (e.g. in an inline image), calculate the dimension attributes.
[2145] Fix | Delete
$style_width = preg_match( '/style="width:\s*(\d+)px;"/', $image, $match_width ) ? (int) $match_width[1] : 0;
[2146] Fix | Delete
if ( $style_width ) {
[2147] Fix | Delete
$size_array[1] = (int) round( $size_array[1] * $style_width / $size_array[0] );
[2148] Fix | Delete
$size_array[0] = $style_width;
[2149] Fix | Delete
}
[2150] Fix | Delete
[2151] Fix | Delete
$hw = trim( image_hwstring( $size_array[0], $size_array[1] ) );
[2152] Fix | Delete
return str_replace( '<img', "<img {$hw}", $image );
[2153] Fix | Delete
}
[2154] Fix | Delete
}
[2155] Fix | Delete
[2156] Fix | Delete
return $image;
[2157] Fix | Delete
}
[2158] Fix | Delete
[2159] Fix | Delete
/**
[2160] Fix | Delete
* Adds `srcset` and `sizes` attributes to an existing `img` HTML tag.
[2161] Fix | Delete
*
[2162] Fix | Delete
* @since 5.5.0
[2163] Fix | Delete
*
[2164] Fix | Delete
* @param string $image The HTML `img` tag where the attribute should be added.
[2165] Fix | Delete
* @param string $context Additional context to pass to the filters.
[2166] Fix | Delete
* @param int $attachment_id Image attachment ID.
[2167] Fix | Delete
* @return string Converted 'img' element with 'loading' attribute added.
[2168] Fix | Delete
*/
[2169] Fix | Delete
function wp_img_tag_add_srcset_and_sizes_attr( $image, $context, $attachment_id ) {
[2170] Fix | Delete
/**
[2171] Fix | Delete
* Filters whether to add the `srcset` and `sizes` HTML attributes to the img tag. Default `true`.
[2172] Fix | Delete
*
[2173] Fix | Delete
* Returning anything else than `true` will not add the attributes.
[2174] Fix | Delete
*
[2175] Fix | Delete
* @since 5.5.0
[2176] Fix | Delete
*
[2177] Fix | Delete
* @param bool $value The filtered value, defaults to `true`.
[2178] Fix | Delete
* @param string $image The HTML `img` tag where the attribute should be added.
[2179] Fix | Delete
* @param string $context Additional context about how the function was called or where the img tag is.
[2180] Fix | Delete
* @param int $attachment_id The image attachment ID.
[2181] Fix | Delete
*/
[2182] Fix | Delete
$add = apply_filters( 'wp_img_tag_add_srcset_and_sizes_attr', true, $image, $context, $attachment_id );
[2183] Fix | Delete
[2184] Fix | Delete
if ( true === $add ) {
[2185] Fix | Delete
$image_meta = wp_get_attachment_metadata( $attachment_id );
[2186] Fix | Delete
return wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id );
[2187] Fix | Delete
}
[2188] Fix | Delete
[2189] Fix | Delete
return $image;
[2190] Fix | Delete
}
[2191] Fix | Delete
[2192] Fix | Delete
/**
[2193] Fix | Delete
* Adds `loading` attribute to an `iframe` HTML tag.
[2194] Fix | Delete
*
[2195] Fix | Delete
* @since 5.7.0
[2196] Fix | Delete
*
[2197] Fix | Delete
* @param string $iframe The HTML `iframe` tag where the attribute should be added.
[2198] Fix | Delete
* @param string $context Additional context to pass to the filters.
[2199] Fix | Delete
* @return string Converted `iframe` tag with `loading` attribute added.
[2200] Fix | Delete
*/
[2201] Fix | Delete
function wp_iframe_tag_add_loading_attr( $iframe, $context ) {
[2202] Fix | Delete
/*
[2203] Fix | Delete
* Get loading attribute value to use. This must occur before the conditional check below so that even iframes that
[2204] Fix | Delete
* are ineligible for being lazy-loaded are considered.
[2205] Fix | Delete
*/
[2206] Fix | Delete
$optimization_attrs = wp_get_loading_optimization_attributes(
[2207] Fix | Delete
'iframe',
[2208] Fix | Delete
array(
[2209] Fix | Delete
/*
[2210] Fix | Delete
* The concrete values for width and height are not important here for now
[2211] Fix | Delete
* since fetchpriority is not yet supported for iframes.
[2212] Fix | Delete
* TODO: Use WP_HTML_Tag_Processor to extract actual values once support is
[2213] Fix | Delete
* added.
[2214] Fix | Delete
*/
[2215] Fix | Delete
'width' => str_contains( $iframe, ' width="' ) ? 100 : null,
[2216] Fix | Delete
'height' => str_contains( $iframe, ' height="' ) ? 100 : null,
[2217] Fix | Delete
// This function is never called when a 'loading' attribute is already present.
[2218] Fix | Delete
'loading' => null,
[2219] Fix | Delete
),
[2220] Fix | Delete
$context
[2221] Fix | Delete
);
[2222] Fix | Delete
[2223] Fix | Delete
// Iframes should have source and dimension attributes for the `loading` attribute to be added.
[2224] Fix | Delete
if ( ! str_contains( $iframe, ' src="' ) || ! str_contains( $iframe, ' width="' ) || ! str_contains( $iframe, ' height="' ) ) {
[2225] Fix | Delete
return $iframe;
[2226] Fix | Delete
}
[2227] Fix | Delete
[2228] Fix | Delete
$value = isset( $optimization_attrs['loading'] ) ? $optimization_attrs['loading'] : false;
[2229] Fix | Delete
[2230] Fix | Delete
/**
[2231] Fix | Delete
* Filters the `loading` attribute value to add to an iframe. Default `lazy`.
[2232] Fix | Delete
*
[2233] Fix | Delete
* Returning `false` or an empty string will not add the attribute.
[2234] Fix | Delete
* Returning `true` will add the default value.
[2235] Fix | Delete
*
[2236] Fix | Delete
* @since 5.7.0
[2237] Fix | Delete
*
[2238] Fix | Delete
* @param string|bool $value The `loading` attribute value. Returning a falsey value will result in
[2239] Fix | Delete
* the attribute being omitted for the iframe.
[2240] Fix | Delete
* @param string $iframe The HTML `iframe` tag to be filtered.
[2241] Fix | Delete
* @param string $context Additional context about how the function was called or where the iframe tag is.
[2242] Fix | Delete
*/
[2243] Fix | Delete
$value = apply_filters( 'wp_iframe_tag_add_loading_attr', $value, $iframe, $context );
[2244] Fix | Delete
[2245] Fix | Delete
if ( $value ) {
[2246] Fix | Delete
if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) {
[2247] Fix | Delete
$value = 'lazy';
[2248] Fix | Delete
}
[2249] Fix | Delete
[2250] Fix | Delete
return str_replace( '<iframe', '<iframe loading="' . esc_attr( $value ) . '"', $iframe );
[2251] Fix | Delete
}
[2252] Fix | Delete
[2253] Fix | Delete
return $iframe;
[2254] Fix | Delete
}
[2255] Fix | Delete
[2256] Fix | Delete
/**
[2257] Fix | Delete
* Adds a 'wp-post-image' class to post thumbnails. Internal use only.
[2258] Fix | Delete
*
[2259] Fix | Delete
* Uses the {@see 'begin_fetch_post_thumbnail_html'} and {@see 'end_fetch_post_thumbnail_html'}
[2260] Fix | Delete
* action hooks to dynamically add/remove itself so as to only filter post thumbnails.
[2261] Fix | Delete
*
[2262] Fix | Delete
* @ignore
[2263] Fix | Delete
* @since 2.9.0
[2264] Fix | Delete
*
[2265] Fix | Delete
* @param string[] $attr Array of thumbnail attributes including src, class, alt, title, keyed by attribute name.
[2266] Fix | Delete
* @return string[] Modified array of attributes including the new 'wp-post-image' class.
[2267] Fix | Delete
*/
[2268] Fix | Delete
function _wp_post_thumbnail_class_filter( $attr ) {
[2269] Fix | Delete
$attr['class'] .= ' wp-post-image';
[2270] Fix | Delete
return $attr;
[2271] Fix | Delete
}
[2272] Fix | Delete
[2273] Fix | Delete
/**
[2274] Fix | Delete
* Adds '_wp_post_thumbnail_class_filter' callback to the 'wp_get_attachment_image_attributes'
[2275] Fix | Delete
* filter hook. Internal use only.
[2276] Fix | Delete
*
[2277] Fix | Delete
* @ignore
[2278] Fix | Delete
* @since 2.9.0
[2279] Fix | Delete
*
[2280] Fix | Delete
* @param string[] $attr Array of thumbnail attributes including src, class, alt, title, keyed by attribute name.
[2281] Fix | Delete
*/
[2282] Fix | Delete
function _wp_post_thumbnail_class_filter_add( $attr ) {
[2283] Fix | Delete
add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
[2284] Fix | Delete
}
[2285] Fix | Delete
[2286] Fix | Delete
/**
[2287] Fix | Delete
* Removes the '_wp_post_thumbnail_class_filter' callback from the 'wp_get_attachment_image_attributes'
[2288] Fix | Delete
* filter hook. Internal use only.
[2289] Fix | Delete
*
[2290] Fix | Delete
* @ignore
[2291] Fix | Delete
* @since 2.9.0
[2292] Fix | Delete
*
[2293] Fix | Delete
* @param string[] $attr Array of thumbnail attributes including src, class, alt, title, keyed by attribute name.
[2294] Fix | Delete
*/
[2295] Fix | Delete
function _wp_post_thumbnail_class_filter_remove( $attr ) {
[2296] Fix | Delete
remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
[2297] Fix | Delete
}
[2298] Fix | Delete
[2299] Fix | Delete
/**
[2300] Fix | Delete
* Overrides the context used in {@see wp_get_attachment_image()}. Internal use only.
[2301] Fix | Delete
*
[2302] Fix | Delete
* Uses the {@see 'begin_fetch_post_thumbnail_html'} and {@see 'end_fetch_post_thumbnail_html'}
[2303] Fix | Delete
* action hooks to dynamically add/remove itself so as to only filter post thumbnails.
[2304] Fix | Delete
*
[2305] Fix | Delete
* @ignore
[2306] Fix | Delete
* @since 6.3.0
[2307] Fix | Delete
* @access private
[2308] Fix | Delete
*
[2309] Fix | Delete
* @param string $context The context for rendering an attachment image.
[2310] Fix | Delete
* @return string Modified context set to 'the_post_thumbnail'.
[2311] Fix | Delete
*/
[2312] Fix | Delete
function _wp_post_thumbnail_context_filter( $context ) {
[2313] Fix | Delete
return 'the_post_thumbnail';
[2314] Fix | Delete
}
[2315] Fix | Delete
[2316] Fix | Delete
/**
[2317] Fix | Delete
* Adds the '_wp_post_thumbnail_context_filter' callback to the 'wp_get_attachment_image_context'
[2318] Fix | Delete
* filter hook. Internal use only.
[2319] Fix | Delete
*
[2320] Fix | Delete
* @ignore
[2321] Fix | Delete
* @since 6.3.0
[2322] Fix | Delete
* @access private
[2323] Fix | Delete
*/
[2324] Fix | Delete
function _wp_post_thumbnail_context_filter_add() {
[2325] Fix | Delete
add_filter( 'wp_get_attachment_image_context', '_wp_post_thumbnail_context_filter' );
[2326] Fix | Delete
}
[2327] Fix | Delete
[2328] Fix | Delete
/**
[2329] Fix | Delete
* Removes the '_wp_post_thumbnail_context_filter' callback from the 'wp_get_attachment_image_context'
[2330] Fix | Delete
* filter hook. Internal use only.
[2331] Fix | Delete
*
[2332] Fix | Delete
* @ignore
[2333] Fix | Delete
* @since 6.3.0
[2334] Fix | Delete
* @access private
[2335] Fix | Delete
*/
[2336] Fix | Delete
function _wp_post_thumbnail_context_filter_remove() {
[2337] Fix | Delete
remove_filter( 'wp_get_attachment_image_context', '_wp_post_thumbnail_context_filter' );
[2338] Fix | Delete
}
[2339] Fix | Delete
[2340] Fix | Delete
add_shortcode( 'wp_caption', 'img_caption_shortcode' );
[2341] Fix | Delete
add_shortcode( 'caption', 'img_caption_shortcode' );
[2342] Fix | Delete
[2343] Fix | Delete
/**
[2344] Fix | Delete
* Builds the Caption shortcode output.
[2345] Fix | Delete
*
[2346] Fix | Delete
* Allows a plugin to replace the content that would otherwise be returned. The
[2347] Fix | Delete
* filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr
[2348] Fix | Delete
* parameter and the content parameter values.
[2349] Fix | Delete
*
[2350] Fix | Delete
* The supported attributes for the shortcode are 'id', 'caption_id', 'align',
[2351] Fix | Delete
* 'width', 'caption', and 'class'.
[2352] Fix | Delete
*
[2353] Fix | Delete
* @since 2.6.0
[2354] Fix | Delete
* @since 3.9.0 The `class` attribute was added.
[2355] Fix | Delete
* @since 5.1.0 The `caption_id` attribute was added.
[2356] Fix | Delete
* @since 5.9.0 The `$content` parameter default value changed from `null` to `''`.
[2357] Fix | Delete
*
[2358] Fix | Delete
* @param array $attr {
[2359] Fix | Delete
* Attributes of the caption shortcode.
[2360] Fix | Delete
*
[2361] Fix | Delete
* @type string $id ID of the image and caption container element, i.e. `<figure>` or `<div>`.
[2362] Fix | Delete
* @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
[2363] Fix | Delete
* @type string $align Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft',
[2364] Fix | Delete
* 'aligncenter', alignright', 'alignnone'.
[2365] Fix | Delete
* @type int $width The width of the caption, in pixels.
[2366] Fix | Delete
* @type string $caption The caption text.
[2367] Fix | Delete
* @type string $class Additional class name(s) added to the caption container.
[2368] Fix | Delete
* }
[2369] Fix | Delete
* @param string $content Optional. Shortcode content. Default empty string.
[2370] Fix | Delete
* @return string HTML content to display the caption.
[2371] Fix | Delete
*/
[2372] Fix | Delete
function img_caption_shortcode( $attr, $content = '' ) {
[2373] Fix | Delete
// New-style shortcode with the caption inside the shortcode with the link and image tags.
[2374] Fix | Delete
if ( ! isset( $attr['caption'] ) ) {
[2375] Fix | Delete
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
[2376] Fix | Delete
$content = $matches[1];
[2377] Fix | Delete
$attr['caption'] = trim( $matches[2] );
[2378] Fix | Delete
}
[2379] Fix | Delete
} elseif ( str_contains( $attr['caption'], '<' ) ) {
[2380] Fix | Delete
$attr['caption'] = wp_kses( $attr['caption'], 'post' );
[2381] Fix | Delete
}
[2382] Fix | Delete
[2383] Fix | Delete
/**
[2384] Fix | Delete
* Filters the default caption shortcode output.
[2385] Fix | Delete
*
[2386] Fix | Delete
* If the filtered output isn't empty, it will be used instead of generating
[2387] Fix | Delete
* the default caption template.
[2388] Fix | Delete
*
[2389] Fix | Delete
* @since 2.6.0
[2390] Fix | Delete
*
[2391] Fix | Delete
* @see img_caption_shortcode()
[2392] Fix | Delete
*
[2393] Fix | Delete
* @param string $output The caption output. Default empty.
[2394] Fix | Delete
* @param array $attr Attributes of the caption shortcode.
[2395] Fix | Delete
* @param string $content The image element, possibly wrapped in a hyperlink.
[2396] Fix | Delete
*/
[2397] Fix | Delete
$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
[2398] Fix | Delete
[2399] Fix | Delete
if ( ! empty( $output ) ) {
[2400] Fix | Delete
return $output;
[2401] Fix | Delete
}
[2402] Fix | Delete
[2403] Fix | Delete
$atts = shortcode_atts(
[2404] Fix | Delete
array(
[2405] Fix | Delete
'id' => '',
[2406] Fix | Delete
'caption_id' => '',
[2407] Fix | Delete
'align' => 'alignnone',
[2408] Fix | Delete
'width' => '',
[2409] Fix | Delete
'caption' => '',
[2410] Fix | Delete
'class' => '',
[2411] Fix | Delete
),
[2412] Fix | Delete
$attr,
[2413] Fix | Delete
'caption'
[2414] Fix | Delete
);
[2415] Fix | Delete
[2416] Fix | Delete
$atts['width'] = (int) $atts['width'];
[2417] Fix | Delete
[2418] Fix | Delete
if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) {
[2419] Fix | Delete
return $content;
[2420] Fix | Delete
}
[2421] Fix | Delete
[2422] Fix | Delete
$id = '';
[2423] Fix | Delete
$caption_id = '';
[2424] Fix | Delete
$describedby = '';
[2425] Fix | Delete
[2426] Fix | Delete
if ( $atts['id'] ) {
[2427] Fix | Delete
$atts['id'] = sanitize_html_class( $atts['id'] );
[2428] Fix | Delete
$id = 'id="' . esc_attr( $atts['id'] ) . '" ';
[2429] Fix | Delete
}
[2430] Fix | Delete
[2431] Fix | Delete
if ( $atts['caption_id'] ) {
[2432] Fix | Delete
$atts['caption_id'] = sanitize_html_class( $atts['caption_id'] );
[2433] Fix | Delete
} elseif ( $atts['id'] ) {
[2434] Fix | Delete
$atts['caption_id'] = 'caption-' . str_replace( '_', '-', $atts['id'] );
[2435] Fix | Delete
}
[2436] Fix | Delete
[2437] Fix | Delete
if ( $atts['caption_id'] ) {
[2438] Fix | Delete
$caption_id = 'id="' . esc_attr( $atts['caption_id'] ) . '" ';
[2439] Fix | Delete
$describedby = 'aria-describedby="' . esc_attr( $atts['caption_id'] ) . '" ';
[2440] Fix | Delete
}
[2441] Fix | Delete
[2442] Fix | Delete
$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
[2443] Fix | Delete
[2444] Fix | Delete
$html5 = current_theme_supports( 'html5', 'caption' );
[2445] Fix | Delete
// HTML5 captions never added the extra 10px to the image width.
[2446] Fix | Delete
$width = $html5 ? $atts['width'] : ( 10 + $atts['width'] );
[2447] Fix | Delete
[2448] Fix | Delete
/**
[2449] Fix | Delete
* Filters the width of an image's caption.
[2450] Fix | Delete
*
[2451] Fix | Delete
* By default, the caption is 10 pixels greater than the width of the image,
[2452] Fix | Delete
* to prevent post content from running up against a floated image.
[2453] Fix | Delete
*
[2454] Fix | Delete
* @since 3.7.0
[2455] Fix | Delete
*
[2456] Fix | Delete
* @see img_caption_shortcode()
[2457] Fix | Delete
*
[2458] Fix | Delete
* @param int $width Width of the caption in pixels. To remove this inline style,
[2459] Fix | Delete
* return zero.
[2460] Fix | Delete
* @param array $atts Attributes of the caption shortcode.
[2461] Fix | Delete
* @param string $content The image element, possibly wrapped in a hyperlink.
[2462] Fix | Delete
*/
[2463] Fix | Delete
$caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );
[2464] Fix | Delete
[2465] Fix | Delete
$style = '';
[2466] Fix | Delete
[2467] Fix | Delete
if ( $caption_width ) {
[2468] Fix | Delete
$style = 'style="width: ' . (int) $caption_width . 'px" ';
[2469] Fix | Delete
}
[2470] Fix | Delete
[2471] Fix | Delete
if ( $html5 ) {
[2472] Fix | Delete
$html = sprintf(
[2473] Fix | Delete
'<figure %s%s%sclass="%s">%s%s</figure>',
[2474] Fix | Delete
$id,
[2475] Fix | Delete
$describedby,
[2476] Fix | Delete
$style,
[2477] Fix | Delete
esc_attr( $class ),
[2478] Fix | Delete
do_shortcode( $content ),
[2479] Fix | Delete
sprintf(
[2480] Fix | Delete
'<figcaption %sclass="wp-caption-text">%s</figcaption>',
[2481] Fix | Delete
$caption_id,
[2482] Fix | Delete
$atts['caption']
[2483] Fix | Delete
)
[2484] Fix | Delete
);
[2485] Fix | Delete
} else {
[2486] Fix | Delete
$html = sprintf(
[2487] Fix | Delete
'<div %s%sclass="%s">%s%s</div>',
[2488] Fix | Delete
$id,
[2489] Fix | Delete
$style,
[2490] Fix | Delete
esc_attr( $class ),
[2491] Fix | Delete
str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
[2492] Fix | Delete
sprintf(
[2493] Fix | Delete
'<p %sclass="wp-caption-text">%s</p>',
[2494] Fix | Delete
$caption_id,
[2495] Fix | Delete
$atts['caption']
[2496] Fix | Delete
)
[2497] Fix | Delete
);
[2498] Fix | Delete
}
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function