wp/wp-includes/media.php
author ymh <ymh.work@gmail.com>
Wed, 21 Sep 2022 18:19:35 +0200
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
permissions -rw-r--r--
Site enmi version 09/2022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress API for media display.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Media
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    10
 * Retrieve additional image sizes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    12
 * @since 4.7.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    13
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
 * @global array $_wp_additional_image_sizes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
 * @return array Additional images size data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
function wp_get_additional_image_sizes() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
	global $_wp_additional_image_sizes;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    20
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
	if ( ! $_wp_additional_image_sizes ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    22
		$_wp_additional_image_sizes = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    23
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    24
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
	return $_wp_additional_image_sizes;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    26
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    27
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    28
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 * Scale down the default size of an image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
 * This is so that the image is a better fit for the editor and theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
 * The `$size` parameter accepts either an array or a string. The supported string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 * values are 'thumb' or 'thumbnail' for the given thumbnail size or defaults at
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 * 128 width and 96 height in pixels. Also supported for the string value is
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    36
 * 'medium', 'medium_large' and 'full'. The 'full' isn't actually supported, but any value other
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
 * than the supported will result in the content_width size or 500 if that is
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 * not set.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
 * Finally, there is a filter named {@see 'editor_max_image_size'}, that will be
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    41
 * called on the calculated array for width and height, respectively.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    45
 * @global int $content_width
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    46
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
 * @param int          $width   Width of the image in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
 * @param int          $height  Height of the image in pixels.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    49
 * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    50
 *                              of width and height values in pixels (in that order). Default 'medium'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
 * @param string       $context Optional. Could be 'display' (like in a theme) or 'edit'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
 *                              (like inserting into an editor). Default null.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    53
 * @return int[] {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    54
 *     An array of width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    55
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    56
 *     @type int $0 The maximum width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    57
 *     @type int $1 The maximum height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    58
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    61
	global $content_width;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    62
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    63
	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    65
	if ( ! $context ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		$context = is_admin() ? 'edit' : 'display';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    68
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    69
	if ( is_array( $size ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    70
		$max_width  = $size[0];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    71
		$max_height = $size[1];
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    72
	} elseif ( 'thumb' === $size || 'thumbnail' === $size ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    73
		$max_width  = (int) get_option( 'thumbnail_size_w' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    74
		$max_height = (int) get_option( 'thumbnail_size_h' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    75
		// Last chance thumbnail size defaults.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    76
		if ( ! $max_width && ! $max_height ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    77
			$max_width  = 128;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			$max_height = 96;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    80
	} elseif ( 'medium' === $size ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    81
		$max_width  = (int) get_option( 'medium_size_w' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    82
		$max_height = (int) get_option( 'medium_size_h' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    83
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    84
	} elseif ( 'medium_large' === $size ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    85
		$max_width  = (int) get_option( 'medium_large_size_w' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    86
		$max_height = (int) get_option( 'medium_large_size_h' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    87
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    88
		if ( (int) $content_width > 0 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    89
			$max_width = min( (int) $content_width, $max_width );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    91
	} elseif ( 'large' === $size ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
		 * We're inserting a large size image into the editor. If it's a really
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		 * big image we'll scale it down to fit reasonably within the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
		 * itself, and within the theme's content width if it's known. The user
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		 * can resize it in the editor if they wish.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
		 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    98
		$max_width  = (int) get_option( 'large_size_w' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    99
		$max_height = (int) get_option( 'large_size_h' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   100
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   101
		if ( (int) $content_width > 0 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   102
			$max_width = min( (int) $content_width, $max_width );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   104
	} elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ), true ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   105
		$max_width  = (int) $_wp_additional_image_sizes[ $size ]['width'];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   106
		$max_height = (int) $_wp_additional_image_sizes[ $size ]['height'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
		// Only in admin. Assume that theme authors know what they're doing.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   108
		if ( (int) $content_width > 0 && 'edit' === $context ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   109
			$max_width = min( (int) $content_width, $max_width );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   110
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   111
	} else { // $size === 'full' has no constraint.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   112
		$max_width  = $width;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		$max_height = $height;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   117
	 * Filters the maximum image size dimensions for the editor.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   121
	 * @param int[]        $max_image_size {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   122
	 *     An array of width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   123
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   124
	 *     @type int $0 The maximum width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   125
	 *     @type int $1 The maximum height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   126
	 * }
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   127
	 * @param string|int[] $size     Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   128
	 *                               an array of width and height values in pixels (in that order).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   129
	 * @param string       $context  The context the image is being resized for.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   130
	 *                               Possible values are 'display' (like in a theme)
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   131
	 *                               or 'edit' (like inserting into an editor).
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
	return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
 * Retrieve width and height attributes using given width and height values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 * Both attributes are required in the sense that both parameters must have a
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
 * value, but are optional in that if you set them to false or null, then they
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
 * will not be added to the returned string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
 * You can set the value using a string, but it will only take numeric values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
 * If you wish to put 'px' after the numbers, then it will be stripped out of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
 * the return.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
 * @param int|string $width  Image width in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
 * @param int|string $height Image height in pixels.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 * @return string HTML attributes for width and, or height.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
function image_hwstring( $width, $height ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
	$out = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   157
	if ( $width ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   158
		$out .= 'width="' . (int) $width . '" ';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   159
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   160
	if ( $height ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   161
		$out .= 'height="' . (int) $height . '" ';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   162
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	return $out;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 * Scale an image to fit a particular size (such as 'thumb' or 'medium').
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
 * The URL might be the original image, or it might be a resized version. This
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 * function won't create a new resized copy, it will just return an already
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 * resized one if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   173
 * A plugin may use the {@see 'image_downsize'} filter to hook into and offer image
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
 * resizing services for images. The hook must return an array with the same
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   175
 * elements that are normally returned from the function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
 * @param int          $id   Attachment ID for image.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   180
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   181
 *                           of width and height values in pixels (in that order). Default 'medium'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   182
 * @return array|false {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   183
 *     Array of image data, or boolean false if no image is available.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   184
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   185
 *     @type string $0 Image source URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   186
 *     @type int    $1 Image width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   187
 *     @type int    $2 Image height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   188
 *     @type bool   $3 Whether the image is a resized image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   189
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
function image_downsize( $id, $size = 'medium' ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   192
	$is_image = wp_attachment_is_image( $id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
	 * Filters whether to preempt the output of image_downsize().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   197
	 * Returning a truthy value from the filter will effectively short-circuit
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   198
	 * down-sizing the image, returning that value instead.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   202
	 * @param bool|array   $downsize Whether to short-circuit the image downsize.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
	 * @param int          $id       Attachment ID for image.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   204
	 * @param string|int[] $size     Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   205
	 *                               an array of width and height values in pixels (in that order).
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   207
	$out = apply_filters( 'image_downsize', false, $id, $size );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   208
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   209
	if ( $out ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		return $out;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   213
	$img_url          = wp_get_attachment_url( $id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   214
	$meta             = wp_get_attachment_metadata( $id );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   215
	$width            = 0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   216
	$height           = 0;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   217
	$is_intermediate  = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   218
	$img_url_basename = wp_basename( $img_url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   220
	// If the file isn't an image, attempt to replace its URL with a rendered image from its meta.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   221
	// Otherwise, a non-image type could be returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   222
	if ( ! $is_image ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   223
		if ( ! empty( $meta['sizes']['full'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   224
			$img_url          = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
			$img_url_basename = $meta['sizes']['full']['file'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   226
			$width            = $meta['sizes']['full']['width'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   227
			$height           = $meta['sizes']['full']['height'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   230
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   231
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   233
	// Try for a new style intermediate size.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   234
	$intermediate = image_get_intermediate_size( $id, $size );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   235
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   236
	if ( $intermediate ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   237
		$img_url         = str_replace( $img_url_basename, $intermediate['file'], $img_url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   238
		$width           = $intermediate['width'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   239
		$height          = $intermediate['height'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		$is_intermediate = true;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   241
	} elseif ( 'thumbnail' === $size ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   242
		// Fall back to the old thumbnail.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   243
		$thumb_file = wp_get_attachment_thumb_file( $id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   244
		$info       = null;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   245
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   246
		if ( $thumb_file ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   247
			$info = wp_getimagesize( $thumb_file );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   248
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   249
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   250
		if ( $thumb_file && $info ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   251
			$img_url         = str_replace( $img_url_basename, wp_basename( $thumb_file ), $img_url );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   252
			$width           = $info[0];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   253
			$height          = $info[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
			$is_intermediate = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   257
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   258
	if ( ! $width && ! $height && isset( $meta['width'], $meta['height'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   259
		// Any other type: use the real image.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   260
		$width  = $meta['width'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		$height = $meta['height'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   264
	if ( $img_url ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   265
		// We have the actual image size, but might need to further constrain it if content_width is narrower.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
		list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
		return array( $img_url, $width, $height, $is_intermediate );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   270
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
 * Register a new image size.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
 * @global array $_wp_additional_image_sizes Associative array of additional image sizes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
 * @param string     $name   Image size identifier.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   282
 * @param int        $width  Optional. Image width in pixels. Default 0.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   283
 * @param int        $height Optional. Image height in pixels. Default 0.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   284
 * @param bool|array $crop   Optional. Image cropping behavior. If false, the image will be scaled (default),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   285
 *                           If true, image will be cropped to the specified dimensions using center positions.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   286
 *                           If an array, the image will be cropped using the array to specify the crop location.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   287
 *                           Array values must be in the format: array( x_crop_position, y_crop_position ) where:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   288
 *                               - x_crop_position accepts: 'left', 'center', or 'right'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   289
 *                               - y_crop_position accepts: 'top', 'center', or 'bottom'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	global $_wp_additional_image_sizes;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	$_wp_additional_image_sizes[ $name ] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
		'width'  => absint( $width ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
		'height' => absint( $height ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
		'crop'   => $crop,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
 * Check if an image size exists.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
 * @param string $name The image size to check.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
 * @return bool True if the image size exists, false if not.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
function has_image_size( $name ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   310
	$sizes = wp_get_additional_image_sizes();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   311
	return isset( $sizes[ $name ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
 * Remove a new image size.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   319
 * @global array $_wp_additional_image_sizes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   320
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
 * @param string $name The image size to remove.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
 * @return bool True if the image size was successfully removed, false on failure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
function remove_image_size( $name ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
	global $_wp_additional_image_sizes;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
	if ( isset( $_wp_additional_image_sizes[ $name ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		unset( $_wp_additional_image_sizes[ $name ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
		return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
 * Registers an image size for the post thumbnail.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
 * @see add_image_size() for details on cropping behavior.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
 * @param int        $width  Image width in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
 * @param int        $height Image height in pixels.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
 * @param bool|array $crop   Optional. Whether to crop images to specified width and height or resize.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
 *                           An array can specify positioning of the crop area. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	add_image_size( 'post-thumbnail', $width, $height, $crop );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
 * Gets an img tag for an image attachment, scaling it down if requested.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
 * The {@see 'get_image_tag_class'} filter allows for changing the class name for the
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
 * image without having to use regular expressions on the HTML content. The
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
 * parameters are: what WordPress will use for the class, the Attachment ID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
 * image align value, and the size the image should be.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
 * The second filter, {@see 'get_image_tag'}, has the HTML content, which can then be
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
 * further manipulated by a plugin to change all attribute values and even HTML
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
 * content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
 * @param int          $id    Attachment ID.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   366
 * @param string       $alt   Image description for the alt attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   367
 * @param string       $title Image description for the title attribute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
 * @param string       $align Part of the class name for aligning the image.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   369
 * @param string|int[] $size  Optional. Image size. Accepts any registered image size name, or an array of
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   370
 *                            width and height values in pixels (in that order). Default 'medium'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
 * @return string HTML IMG element for given image attachment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   375
	list( $img_src, $width, $height ) = image_downsize( $id, $size );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   376
	$hwstring                         = image_hwstring( $width, $height );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	$title = $title ? 'title="' . esc_attr( $title ) . '" ' : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   380
	$size_class = is_array( $size ) ? implode( 'x', $size ) : $size;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   381
	$class      = 'align' . esc_attr( $align ) . ' size-' . esc_attr( $size_class ) . ' wp-image-' . $id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   384
	 * Filters the value of the attachment's image tag class attribute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   388
	 * @param string       $class CSS class name or space-separated list of classes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   389
	 * @param int          $id    Attachment ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   390
	 * @param string       $align Part of the class name for aligning the image.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   391
	 * @param string|int[] $size  Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   392
	 *                            an array of width and height values in pixels (in that order).
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
	$class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   396
	$html = '<img src="' . esc_attr( $img_src ) . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
	 * Filters the HTML content for the image tag.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
	 * @param string       $html  HTML content for the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
	 * @param int          $id    Attachment ID.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   405
	 * @param string       $alt   Image description for the alt attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   406
	 * @param string       $title Image description for the title attribute.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
	 * @param string       $align Part of the class name for aligning the image.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   408
	 * @param string|int[] $size  Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   409
	 *                            an array of width and height values in pixels (in that order).
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
	return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
 * Calculates the new dimensions for a down-sampled image.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
 * If either width or height are empty, no constraint is applied on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
 * that dimension.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
 * @param int $current_width  Current width of the image.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
 * @param int $current_height Current height of the image.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
 * @param int $max_width      Optional. Max width in pixels to constrain to. Default 0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
 * @param int $max_height     Optional. Max height in pixels to constrain to. Default 0.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   426
 * @return int[] {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   427
 *     An array of width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   428
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   429
 *     @type int $0 The width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   430
 *     @type int $1 The height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   431
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   434
	if ( ! $max_width && ! $max_height ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		return array( $current_width, $current_height );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   436
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   438
	$width_ratio  = 1.0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   439
	$height_ratio = 1.0;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   440
	$did_width    = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   441
	$did_height   = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
		$width_ratio = $max_width / $current_width;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   445
		$did_width   = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		$height_ratio = $max_height / $current_height;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   450
		$did_height   = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   453
	// Calculate the larger/smaller ratios.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
	$smaller_ratio = min( $width_ratio, $height_ratio );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	$larger_ratio  = max( $width_ratio, $height_ratio );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
	if ( (int) round( $current_width * $larger_ratio ) > $max_width || (int) round( $current_height * $larger_ratio ) > $max_height ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   458
		// The larger ratio is too big. It would result in an overflow.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		$ratio = $smaller_ratio;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		// The larger ratio fits, and is likely to be a more "snug" fit.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		$ratio = $larger_ratio;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	// Very small dimensions may result in 0, 1 should be the minimum.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   466
	$w = max( 1, (int) round( $current_width * $ratio ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   467
	$h = max( 1, (int) round( $current_height * $ratio ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   469
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   470
	 * Sometimes, due to rounding, we'll end up with a result like this:
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   471
	 * 465x700 in a 177x177 box is 117x176... a pixel short.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   472
	 * We also have issues with recursive calls resulting in an ever-changing result.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   473
	 * Constraining to the result of a constraint should yield the original result.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   474
	 * Thus we look for dimensions that are one pixel shy of the max value and bump them up.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   475
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	// Note: $did_width means it is possible $smaller_ratio == $width_ratio.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   478
	if ( $did_width && $w === $max_width - 1 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   479
		$w = $max_width; // Round it up.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
	// Note: $did_height means it is possible $smaller_ratio == $height_ratio.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   483
	if ( $did_height && $h === $max_height - 1 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   484
		$h = $max_height; // Round it up.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   488
	 * Filters dimensions to constrain down-sampled images to.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   492
	 * @param int[] $dimensions     {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   493
	 *     An array of width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   494
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   495
	 *     @type int $0 The width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   496
	 *     @type int $1 The height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   497
	 * }
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   498
	 * @param int   $current_width  The current width of the image.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   499
	 * @param int   $current_height The current height of the image.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   500
	 * @param int   $max_width      The maximum width permitted.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
	 * @param int   $max_height     The maximum height permitted.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
	return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
 * Calculates dimensions and coordinates for a resized image that fits
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
 * within a specified width and height.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
 * Cropping behavior is dependent on the value of $crop:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
 * 1. If false (default), images will not be cropped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
 * 2. If an array in the form of array( x_crop_position, y_crop_position ):
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
 *    - x_crop_position accepts 'left' 'center', or 'right'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
 *    - y_crop_position accepts 'top', 'center', or 'bottom'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
 *    Images will be cropped to the specified dimensions within the defined crop area.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
 * 3. If true, images will be cropped to the specified dimensions using center positions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
 * @param int        $orig_w Original width in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
 * @param int        $orig_h Original height in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
 * @param int        $dest_w New width in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
 * @param int        $dest_h New height in pixels.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   526
 * @param bool|array $crop   Optional. Whether to crop image to specified width and height or resize.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
 *                           An array can specify positioning of the crop area. Default false.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   528
 * @return array|false Returned array matches parameters for `imagecopyresampled()`. False on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   530
function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   532
	if ( $orig_w <= 0 || $orig_h <= 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   534
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   535
	// At least one of $dest_w or $dest_h must be specific.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   536
	if ( $dest_w <= 0 && $dest_h <= 0 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   538
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   541
	 * Filters whether to preempt calculating the image resize dimensions.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   543
	 * Returning a non-null value from the filter will effectively short-circuit
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
	 * image_resize_dimensions(), returning that value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
	 * @param null|mixed $null   Whether to preempt output of the resize dimensions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
	 * @param int        $orig_w Original width in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
	 * @param int        $orig_h Original height in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
	 * @param int        $dest_w New width in pixels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
	 * @param int        $dest_h New height in pixels.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   553
	 * @param bool|array $crop   Whether to crop image to specified width and height or resize.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
	 *                           An array can specify positioning of the crop area. Default false.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   557
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   558
	if ( null !== $output ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		return $output;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   560
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   562
	// Stop if the destination size is larger than the original image dimensions.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   563
	if ( empty( $dest_h ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   564
		if ( $orig_w < $dest_w ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   565
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   566
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   567
	} elseif ( empty( $dest_w ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   568
		if ( $orig_h < $dest_h ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   569
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   570
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   571
	} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   572
		if ( $orig_w < $dest_w && $orig_h < $dest_h ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   573
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   574
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   575
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   576
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	if ( $crop ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   578
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   579
		 * Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   580
		 * Note that the requested crop dimensions are used as a maximum bounding box for the original image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   581
		 * If the original image's width or height is less than the requested width or height
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   582
		 * only the greater one will be cropped.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   583
		 * For example when the original image is 600x300, and the requested crop dimensions are 400x400,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   584
		 * the resulting image will be 400x300.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   585
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
		$aspect_ratio = $orig_w / $orig_h;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   587
		$new_w        = min( $dest_w, $orig_w );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   588
		$new_h        = min( $dest_h, $orig_h );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
		if ( ! $new_w ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
			$new_w = (int) round( $new_h * $aspect_ratio );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
		if ( ! $new_h ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
			$new_h = (int) round( $new_w / $aspect_ratio );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   598
		$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   599
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   600
		$crop_w = round( $new_w / $size_ratio );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   601
		$crop_h = round( $new_h / $size_ratio );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
		if ( ! is_array( $crop ) || count( $crop ) !== 2 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
			$crop = array( 'center', 'center' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
		list( $x, $y ) = $crop;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   608
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   609
		if ( 'left' === $x ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   610
			$s_x = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   611
		} elseif ( 'right' === $x ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
			$s_x = $orig_w - $crop_w;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   613
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
			$s_x = floor( ( $orig_w - $crop_w ) / 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   616
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
		if ( 'top' === $y ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
			$s_y = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
		} elseif ( 'bottom' === $y ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
			$s_y = $orig_h - $crop_h;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
			$s_y = floor( ( $orig_h - $crop_h ) / 2 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   625
		// Resize using $dest_w x $dest_h as a maximum bounding box.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		$crop_w = $orig_w;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
		$crop_h = $orig_h;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		$s_x = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		$s_y = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   635
	if ( wp_fuzzy_number_match( $new_w, $orig_w ) && wp_fuzzy_number_match( $new_h, $orig_h ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   636
		// The new size has virtually the same dimensions as the original image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   637
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   638
		/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   639
		 * Filters whether to proceed with making an image sub-size with identical dimensions
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   640
		 * with the original/source image. Differences of 1px may be due to rounding and are ignored.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   641
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   642
		 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   643
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   644
		 * @param bool $proceed The filtered value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   645
		 * @param int  $orig_w  Original image width.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   646
		 * @param int  $orig_h  Original image height.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   647
		 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   648
		$proceed = (bool) apply_filters( 'wp_image_resize_identical_dimensions', false, $orig_w, $orig_h );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   649
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   650
		if ( ! $proceed ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   651
			return false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   652
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   655
	// The return array matches the parameters to imagecopyresampled().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   661
 * Resizes an image to make a thumbnail or intermediate size.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
 * The returned array has the file size, the image width, and image height. The
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   664
 * {@see 'image_make_intermediate_size'} filter can be used to hook in and change the
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
 * values of the returned array. The only parameter is the resized file path.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   669
 * @param string $file   File path.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
 * @param int    $width  Image width.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
 * @param int    $height Image height.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   672
 * @param bool   $crop   Optional. Whether to crop image to specified width and height or resize.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   673
 *                       Default false.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   674
 * @return array|false Metadata array on success. False if no image was created.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	if ( $width || $height ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
		$editor = wp_get_image_editor( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   680
		if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
			return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   682
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		$resized_file = $editor->save();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		if ( ! is_wp_error( $resized_file ) && $resized_file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
			unset( $resized_file['path'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
			return $resized_file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   695
 * Helper function to test if aspect ratios for two images match.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   696
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   697
 * @since 4.6.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   698
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   699
 * @param int $source_width  Width of the first image in pixels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   700
 * @param int $source_height Height of the first image in pixels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   701
 * @param int $target_width  Width of the second image in pixels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   702
 * @param int $target_height Height of the second image in pixels.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   703
 * @return bool True if aspect ratios match within 1px. False if not.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   704
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   705
function wp_image_matches_ratio( $source_width, $source_height, $target_width, $target_height ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   706
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   707
	 * To test for varying crops, we constrain the dimensions of the larger image
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   708
	 * to the dimensions of the smaller image and see if they match.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   709
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
	if ( $source_width > $target_width ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   711
		$constrained_size = wp_constrain_dimensions( $source_width, $source_height, $target_width );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   712
		$expected_size    = array( $target_width, $target_height );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   713
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   714
		$constrained_size = wp_constrain_dimensions( $target_width, $target_height, $source_width );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   715
		$expected_size    = array( $source_width, $source_height );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   716
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   717
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   718
	// If the image dimensions are within 1px of the expected size, we consider it a match.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   719
	$matched = ( wp_fuzzy_number_match( $constrained_size[0], $expected_size[0] ) && wp_fuzzy_number_match( $constrained_size[1], $expected_size[1] ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   720
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
	return $matched;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   722
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   723
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   724
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
 * Retrieves the image's intermediate size (resized) path, width, and height.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
 * The $size parameter can be an array with the width and height respectively.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
 * If the size matches the 'sizes' metadata array for width and height, then it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
 * will be used. If there is no direct match, then the nearest image size larger
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
 * than the specified size will be used. If nothing is found, then the function
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
 * will break out and return false.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
 * The metadata 'sizes' is used for compatible sizes that can be used for the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
 * parameter $size value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
 * The url path will be given, when the $size parameter is a string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
 * If you are passing an array for the $size, you should consider using
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
 * add_image_size() so that a cropped version is generated. It's much more
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
 * efficient than having to find the closest-sized image and then having the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
 * browser scale down the image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
 * @param int          $post_id Attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   746
 * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   747
 *                              of width and height values in pixels (in that order). Default 'thumbnail'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   748
 * @return array|false {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   749
 *     Array of file relative path, width, and height on success. Additionally includes absolute
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   750
 *     path and URL if registered size is passed to `$size` parameter. False on failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   751
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   752
 *     @type string $file   Path of image relative to uploads directory.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   753
 *     @type int    $width  Width of image in pixels.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   754
 *     @type int    $height Height of image in pixels.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   755
 *     @type string $path   Absolute filesystem path of image.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   756
 *     @type string $url    URL of image.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   757
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   760
	$imagedata = wp_get_attachment_metadata( $post_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   761
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   762
	if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   764
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   765
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   766
	$data = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   767
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   768
	// Find the best match when '$size' is an array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   769
	if ( is_array( $size ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   770
		$candidates = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   771
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   772
		if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   773
			$imagedata['height'] = $imagedata['sizes']['full']['height'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   774
			$imagedata['width']  = $imagedata['sizes']['full']['width'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   775
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		foreach ( $imagedata['sizes'] as $_size => $data ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   778
			// If there's an exact match to an existing image size, short circuit.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   779
			if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   780
				$candidates[ $data['width'] * $data['height'] ] = $data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   781
				break;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   783
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   784
			// If it's not an exact match, consider larger sizes with the same aspect ratio.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   785
			if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   786
				// If '0' is passed to either size, we test ratios against the original file.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
				if ( 0 === $size[0] || 0 === $size[1] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   788
					$same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $imagedata['width'], $imagedata['height'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   789
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   790
					$same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $size[0], $size[1] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
				if ( $same_ratio ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   794
					$candidates[ $data['width'] * $data['height'] ] = $data;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   798
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   799
		if ( ! empty( $candidates ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   800
			// Sort the array by size if we have more than one candidate.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   801
			if ( 1 < count( $candidates ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   802
				ksort( $candidates );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   803
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   804
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   805
			$data = array_shift( $candidates );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   806
			/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   807
			* When the size requested is smaller than the thumbnail dimensions, we
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   808
			* fall back to the thumbnail size to maintain backward compatibility with
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   809
			* pre 4.6 versions of WordPress.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   810
			*/
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   811
		} elseif ( ! empty( $imagedata['sizes']['thumbnail'] ) && $imagedata['sizes']['thumbnail']['width'] >= $size[0] && $imagedata['sizes']['thumbnail']['width'] >= $size[1] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   812
			$data = $imagedata['sizes']['thumbnail'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   813
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   814
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   815
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   816
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   817
		// Constrain the width and height attributes to the requested values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   818
		list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   819
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   820
	} elseif ( ! empty( $imagedata['sizes'][ $size ] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   821
		$data = $imagedata['sizes'][ $size ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   824
	// If we still don't have a match at this point, return false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   825
	if ( empty( $data ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
		return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   827
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   828
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   829
	// Include the full filesystem path of the intermediate file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   830
	if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   831
		$file_url     = wp_get_attachment_url( $post_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   832
		$data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   833
		$data['url']  = path_join( dirname( $file_url ), $data['file'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   835
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   836
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   837
	 * Filters the output of image_get_intermediate_size()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   838
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   839
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   840
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   841
	 * @see image_get_intermediate_size()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   842
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   843
	 * @param array        $data    Array of file relative path, width, and height on success. May also include
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   844
	 *                              file absolute path and URL.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   845
	 * @param int          $post_id The ID of the image attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   846
	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   847
	 *                              an array of width and height values in pixels (in that order).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   848
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   849
	return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   853
 * Gets the available intermediate image size names.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
 * @since 3.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   857
 * @return string[] An array of image size names.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
function get_intermediate_image_sizes() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   860
	$default_sizes    = array( 'thumbnail', 'medium', 'medium_large', 'large' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   861
	$additional_sizes = wp_get_additional_image_sizes();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   862
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   863
	if ( ! empty( $additional_sizes ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   864
		$default_sizes = array_merge( $default_sizes, array_keys( $additional_sizes ) );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   865
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   868
	 * Filters the list of intermediate image sizes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   872
	 * @param string[] $default_sizes An array of intermediate image size names. Defaults
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   873
	 *                                are 'thumbnail', 'medium', 'medium_large', 'large'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   875
	return apply_filters( 'intermediate_image_sizes', $default_sizes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   879
 * Returns a normalized list of all currently registered image sub-sizes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   880
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   881
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   882
 * @uses wp_get_additional_image_sizes()
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   883
 * @uses get_intermediate_image_sizes()
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   884
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   885
 * @return array Associative array of the registered image sub-sizes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   886
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   887
function wp_get_registered_image_subsizes() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   888
	$additional_sizes = wp_get_additional_image_sizes();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   889
	$all_sizes        = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   890
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   891
	foreach ( get_intermediate_image_sizes() as $size_name ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   892
		$size_data = array(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   893
			'width'  => 0,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   894
			'height' => 0,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   895
			'crop'   => false,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   896
		);
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   897
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   898
		if ( isset( $additional_sizes[ $size_name ]['width'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   899
			// For sizes added by plugins and themes.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   900
			$size_data['width'] = (int) $additional_sizes[ $size_name ]['width'];
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   901
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   902
			// For default sizes set in options.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   903
			$size_data['width'] = (int) get_option( "{$size_name}_size_w" );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   904
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   905
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   906
		if ( isset( $additional_sizes[ $size_name ]['height'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   907
			$size_data['height'] = (int) $additional_sizes[ $size_name ]['height'];
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   908
		} else {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   909
			$size_data['height'] = (int) get_option( "{$size_name}_size_h" );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   910
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   911
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   912
		if ( empty( $size_data['width'] ) && empty( $size_data['height'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   913
			// This size isn't set.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   914
			continue;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   915
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   916
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   917
		if ( isset( $additional_sizes[ $size_name ]['crop'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   918
			$size_data['crop'] = $additional_sizes[ $size_name ]['crop'];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   919
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   920
			$size_data['crop'] = get_option( "{$size_name}_crop" );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   921
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   922
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   923
		if ( ! is_array( $size_data['crop'] ) || empty( $size_data['crop'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   924
			$size_data['crop'] = (bool) $size_data['crop'];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   925
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   926
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   927
		$all_sizes[ $size_name ] = $size_data;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   928
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   929
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   930
	return $all_sizes;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   931
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   932
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   933
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   934
 * Retrieves an image to represent an attachment.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   935
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
 * @param int          $attachment_id Image attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   939
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   940
 *                                    width and height values in pixels (in that order). Default 'thumbnail'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   941
 * @param bool         $icon          Optional. Whether the image should fall back to a mime type icon. Default false.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   942
 * @return array|false {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   943
 *     Array of image data, or boolean false if no image is available.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   944
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   945
 *     @type string $0 Image source URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   946
 *     @type int    $1 Image width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   947
 *     @type int    $2 Image height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   948
 *     @type bool   $3 Whether the image is a resized image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   949
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   951
function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   952
	// Get a thumbnail or intermediate image if there is one.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   953
	$image = image_downsize( $attachment_id, $size );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   954
	if ( ! $image ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   955
		$src = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   956
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   957
		if ( $icon ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   958
			$src = wp_mime_type_icon( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   959
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   960
			if ( $src ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   961
				/** This filter is documented in wp-includes/post.php */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   962
				$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   963
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   964
				$src_file               = $icon_dir . '/' . wp_basename( $src );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   965
				list( $width, $height ) = wp_getimagesize( $src_file );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   966
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   967
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   968
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   969
		if ( $src && $width && $height ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   970
			$image = array( $src, $width, $height, false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   971
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   973
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   974
	 * Filters the attachment image source result.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   975
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   976
	 * @since 4.3.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   977
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   978
	 * @param array|false  $image         {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   979
	 *     Array of image data, or boolean false if no image is available.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   980
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   981
	 *     @type string $0 Image source URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   982
	 *     @type int    $1 Image width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   983
	 *     @type int    $2 Image height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   984
	 *     @type bool   $3 Whether the image is a resized image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   985
	 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   986
	 * @param int          $attachment_id Image attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   987
	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   988
	 *                                    an array of width and height values in pixels (in that order).
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   989
	 * @param bool         $icon          Whether the image should be treated as an icon.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   990
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   991
	return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   995
 * Get an HTML img element representing an image attachment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   997
 * While `$size` will accept an array, it is better to register a size with
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
 * add_image_size() so that a cropped version is generated. It's much more
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
 * efficient than having to find the closest-sized image and then having the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
 * browser scale down the image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
 * @since 2.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1003
 * @since 4.4.0 The `$srcset` and `$sizes` attributes were added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1004
 * @since 5.5.0 The `$loading` attribute was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
 * @param int          $attachment_id Image attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1007
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1008
 *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1009
 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1010
 * @param string|array $attr {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1011
 *     Optional. Attributes for the image markup.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1012
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1013
 *     @type string       $src     Image attachment URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1014
 *     @type string       $class   CSS class name or space-separated list of classes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1015
 *                                 Default `attachment-$size_class size-$size_class`,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1016
 *                                 where `$size_class` is the image size being requested.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1017
 *     @type string       $alt     Image description for the alt attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1018
 *     @type string       $srcset  The 'srcset' attribute value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1019
 *     @type string       $sizes   The 'sizes' attribute value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1020
 *     @type string|false $loading The 'loading' attribute value. Passing a value of false
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1021
 *                                 will result in the attribute being omitted for the image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1022
 *                                 Defaults to 'lazy', depending on wp_lazy_loading_enabled().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1023
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
 * @return string HTML img element or empty string on failure.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1026
function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1027
	$html  = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1028
	$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1029
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
	if ( $image ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1031
		list( $src, $width, $height ) = $image;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1032
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1033
		$attachment = get_post( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1034
		$hwstring   = image_hwstring( $width, $height );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1035
		$size_class = $size;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1036
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
		if ( is_array( $size_class ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1038
			$size_class = implode( 'x', $size_class );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1040
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
		$default_attr = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1042
			'src'   => $src,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1043
			'class' => "attachment-$size_class size-$size_class",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1044
			'alt'   => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1046
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1047
		// Add `loading` attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1048
		if ( wp_lazy_loading_enabled( 'img', 'wp_get_attachment_image' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1049
			$default_attr['loading'] = 'lazy';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1050
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1051
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1052
		$attr = wp_parse_args( $attr, $default_attr );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1053
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1054
		// If the default value of `lazy` for the `loading` attribute is overridden
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1055
		// to omit the attribute for this image, ensure it is not included.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1056
		if ( array_key_exists( 'loading', $attr ) && ! $attr['loading'] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1057
			unset( $attr['loading'] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1058
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1059
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1060
		// Generate 'srcset' and 'sizes' if not already present.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1061
		if ( empty( $attr['srcset'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1062
			$image_meta = wp_get_attachment_metadata( $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1063
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1064
			if ( is_array( $image_meta ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
				$size_array = array( absint( $width ), absint( $height ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1066
				$srcset     = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1067
				$sizes      = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1068
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1069
				if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1070
					$attr['srcset'] = $srcset;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1072
					if ( empty( $attr['sizes'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1073
						$attr['sizes'] = $sizes;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1074
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1075
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1076
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1077
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1079
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1080
		 * Filters the list of attachment image attributes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1081
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
		 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1083
		 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1084
		 * @param string[]     $attr       Array of attribute values for the image markup, keyed by attribute name.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1085
		 *                                 See wp_get_attachment_image().
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
		 * @param WP_Post      $attachment Image attachment post.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1087
		 * @param string|int[] $size       Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1088
		 *                                 an array of width and height values in pixels (in that order).
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1089
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1090
		$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1091
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
		$attr = array_map( 'esc_attr', $attr );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1093
		$html = rtrim( "<img $hwstring" );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1094
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
		foreach ( $attr as $name => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
			$html .= " $name=" . '"' . $value . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1097
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1098
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
		$html .= ' />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1102
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1103
	 * HTML img element representing an image attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1104
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1105
	 * @since 5.6.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1106
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1107
	 * @param string       $html          HTML img element or empty string on failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1108
	 * @param int          $attachment_id Image attachment ID.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1109
	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1110
	 *                                    an array of width and height values in pixels (in that order).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1111
	 * @param bool         $icon          Whether the image should be treated as an icon.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1112
	 * @param string[]     $attr          Array of attribute values for the image markup, keyed by attribute name.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1113
	 *                                    See wp_get_attachment_image().
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1114
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1115
	return apply_filters( 'wp_get_attachment_image', $html, $attachment_id, $size, $icon, $attr );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
 * Get the URL of an image attachment.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1121
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1123
 * @param int          $attachment_id Image attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1124
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1125
 *                                    width and height values in pixels (in that order). Default 'thumbnail'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1126
 * @param bool         $icon          Optional. Whether the image should be treated as an icon. Default false.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1127
 * @return string|false Attachment URL or false if no image is available. If `$size` does not match
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1128
 *                      any registered image size, the original image URL will be returned.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1129
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1130
function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1131
	$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1132
	return isset( $image['0'] ) ? $image['0'] : false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1133
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1134
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1135
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1136
 * Get the attachment path relative to the upload directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1137
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1138
 * @since 4.4.1
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1139
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1140
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1141
 * @param string $file Attachment file name.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1142
 * @return string Attachment path relative to the upload directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1143
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1144
function _wp_get_attachment_relative_path( $file ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1145
	$dirname = dirname( $file );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
	if ( '.' === $dirname ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1148
		return '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1149
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1150
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1151
	if ( false !== strpos( $dirname, 'wp-content/uploads' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1152
		// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1153
		$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1154
		$dirname = ltrim( $dirname, '/' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1155
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1156
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1157
	return $dirname;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1158
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1159
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1160
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1161
 * Get the image size as array from its meta data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1162
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1163
 * Used for responsive images.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1164
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1165
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1166
 * @access private
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1167
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1168
 * @param string $size_name  Image size. Accepts any registered image size name.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1169
 * @param array  $image_meta The image meta data.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1170
 * @return array|false {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1171
 *     Array of width and height or false if the size isn't present in the meta data.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1172
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1173
 *     @type int $0 Image width.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1174
 *     @type int $1 Image height.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1175
 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1176
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1177
function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1178
	if ( 'full' === $size_name ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1179
		return array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1180
			absint( $image_meta['width'] ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1181
			absint( $image_meta['height'] ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1182
		);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1183
	} elseif ( ! empty( $image_meta['sizes'][ $size_name ] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1184
		return array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1185
			absint( $image_meta['sizes'][ $size_name ]['width'] ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1186
			absint( $image_meta['sizes'][ $size_name ]['height'] ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1187
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1188
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1189
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1190
	return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1191
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1192
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1193
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1194
 * Retrieves the value for an image attachment's 'srcset' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1195
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1196
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1197
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1198
 * @see wp_calculate_image_srcset()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1199
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1200
 * @param int          $attachment_id Image attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1201
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1202
 *                                    width and height values in pixels (in that order). Default 'medium'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1203
 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1204
 *                                    Default null.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1205
 * @return string|false A 'srcset' value string or false.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1206
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1207
function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1208
	$image = wp_get_attachment_image_src( $attachment_id, $size );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1209
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1210
	if ( ! $image ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1211
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1212
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1213
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1214
	if ( ! is_array( $image_meta ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1215
		$image_meta = wp_get_attachment_metadata( $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1216
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1217
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1218
	$image_src  = $image[0];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1219
	$size_array = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1220
		absint( $image[1] ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1221
		absint( $image[2] ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1222
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1223
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1224
	return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1225
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1226
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1227
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1228
 * A helper function to calculate the image sources to include in a 'srcset' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1229
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1230
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1231
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1232
 * @param int[]  $size_array    {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1233
 *     An array of width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1234
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1235
 *     @type int $0 The width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1236
 *     @type int $1 The height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1237
 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1238
 * @param string $image_src     The 'src' of the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1239
 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1240
 * @param int    $attachment_id Optional. The image attachment ID. Default 0.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1241
 * @return string|false The 'srcset' attribute value. False on error or when only one source exists.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1242
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1243
function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1244
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1245
	 * Let plugins pre-filter the image meta to be able to fix inconsistencies in the stored data.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1246
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1247
	 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1248
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1249
	 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1250
	 * @param int[]  $size_array    {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1251
	 *     An array of requested width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1252
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1253
	 *     @type int $0 The width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1254
	 *     @type int $1 The height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1255
	 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1256
	 * @param string $image_src     The 'src' of the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1257
	 * @param int    $attachment_id The image attachment ID or 0 if not supplied.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1258
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1259
	$image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1260
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1261
	if ( empty( $image_meta['sizes'] ) || ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1262
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1263
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1264
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1265
	$image_sizes = $image_meta['sizes'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1266
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1267
	// Get the width and height of the image.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1268
	$image_width  = (int) $size_array[0];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1269
	$image_height = (int) $size_array[1];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1270
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1271
	// Bail early if error/no width.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1272
	if ( $image_width < 1 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1273
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1274
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1275
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1276
	$image_basename = wp_basename( $image_meta['file'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1277
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1278
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1279
	 * WordPress flattens animated GIFs into one frame when generating intermediate sizes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1280
	 * To avoid hiding animation in user content, if src is a full size GIF, a srcset attribute is not generated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1281
	 * If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1282
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1283
	if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1284
		$image_sizes[] = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1285
			'width'  => $image_meta['width'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1286
			'height' => $image_meta['height'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1287
			'file'   => $image_basename,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1288
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1289
	} elseif ( strpos( $image_src, $image_meta['file'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1290
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1291
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1292
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1293
	// Retrieve the uploads sub-directory from the full size image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1294
	$dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1295
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1296
	if ( $dirname ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1297
		$dirname = trailingslashit( $dirname );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1298
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1299
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1300
	$upload_dir    = wp_get_upload_dir();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1301
	$image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1302
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1303
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1304
	 * If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1305
	 * (which is to say, when they share the domain name of the current request).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1306
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1307
	if ( is_ssl() && 'https' !== substr( $image_baseurl, 0, 5 ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1308
		$image_baseurl = set_url_scheme( $image_baseurl, 'https' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1309
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1310
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1311
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1312
	 * Images that have been edited in WordPress after being uploaded will
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1313
	 * contain a unique hash. Look for that hash and use it later to filter
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1314
	 * out images that are leftovers from previous versions.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1315
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1316
	$image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1317
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1318
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1319
	 * Filters the maximum image width to be included in a 'srcset' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1320
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1321
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1322
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1323
	 * @param int   $max_width  The maximum image width to be included in the 'srcset'. Default '2048'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1324
	 * @param int[] $size_array {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1325
	 *     An array of requested width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1326
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1327
	 *     @type int $0 The width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1328
	 *     @type int $1 The height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1329
	 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1330
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1331
	$max_srcset_image_width = apply_filters( 'max_srcset_image_width', 2048, $size_array );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1332
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1333
	// Array to hold URL candidates.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1334
	$sources = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1335
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1336
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1337
	 * To make sure the ID matches our image src, we will check to see if any sizes in our attachment
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1338
	 * meta match our $image_src. If no matches are found we don't return a srcset to avoid serving
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1339
	 * an incorrect image. See #35045.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1340
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1341
	$src_matched = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1342
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1343
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1344
	 * Loop through available images. Only use images that are resized
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1345
	 * versions of the same edit.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1346
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1347
	foreach ( $image_sizes as $image ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1348
		$is_src = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1349
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1350
		// Check if image meta isn't corrupted.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1351
		if ( ! is_array( $image ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1352
			continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1353
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1354
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1355
		// If the file name is part of the `src`, we've confirmed a match.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1356
		if ( ! $src_matched && false !== strpos( $image_src, $dirname . $image['file'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1357
			$src_matched = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1358
			$is_src      = true;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1359
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1360
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1361
		// Filter out images that are from previous edits.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1362
		if ( $image_edited && ! strpos( $image['file'], $image_edit_hash[0] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1363
			continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1364
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1365
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1366
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1367
		 * Filters out images that are wider than '$max_srcset_image_width' unless
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1368
		 * that file is in the 'src' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1369
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1370
		if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width && ! $is_src ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1371
			continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1372
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1373
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1374
		// If the image dimensions are within 1px of the expected size, use it.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1375
		if ( wp_image_matches_ratio( $image_width, $image_height, $image['width'], $image['height'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1376
			// Add the URL, descriptor, and value to the sources array to be returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1377
			$source = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1378
				'url'        => $image_baseurl . $image['file'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1379
				'descriptor' => 'w',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1380
				'value'      => $image['width'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1381
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1382
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1383
			// The 'src' image has to be the first in the 'srcset', because of a bug in iOS8. See #35030.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1384
			if ( $is_src ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1385
				$sources = array( $image['width'] => $source ) + $sources;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1386
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1387
				$sources[ $image['width'] ] = $source;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1388
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1389
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1390
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1391
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1392
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1393
	 * Filters an image's 'srcset' sources.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1394
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1395
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1396
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1397
	 * @param array  $sources {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1398
	 *     One or more arrays of source data to include in the 'srcset'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1399
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1400
	 *     @type array $width {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1401
	 *         @type string $url        The URL of an image source.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1402
	 *         @type string $descriptor The descriptor type used in the image candidate string,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1403
	 *                                  either 'w' or 'x'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1404
	 *         @type int    $value      The source width if paired with a 'w' descriptor, or a
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1405
	 *                                  pixel density value if paired with an 'x' descriptor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1406
	 *     }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1407
	 * }
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1408
	 * @param array $size_array     {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1409
	 *     An array of requested width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1410
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1411
	 *     @type int $0 The width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1412
	 *     @type int $1 The height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1413
	 * }
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1414
	 * @param string $image_src     The 'src' of the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1415
	 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1416
	 * @param int    $attachment_id Image attachment ID or 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1417
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1418
	$sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1419
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1420
	// Only return a 'srcset' value if there is more than one source.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1421
	if ( ! $src_matched || ! is_array( $sources ) || count( $sources ) < 2 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1422
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1423
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1424
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1425
	$srcset = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1426
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1427
	foreach ( $sources as $source ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1428
		$srcset .= str_replace( ' ', '%20', $source['url'] ) . ' ' . $source['value'] . $source['descriptor'] . ', ';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1429
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1430
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1431
	return rtrim( $srcset, ', ' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1432
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1433
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1434
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1435
 * Retrieves the value for an image attachment's 'sizes' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1436
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1437
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1438
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1439
 * @see wp_calculate_image_sizes()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1440
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1441
 * @param int          $attachment_id Image attachment ID.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1442
 * @param string|int[] $size          Optional. Image size. Accepts any registered image size name, or an array of
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1443
 *                                    width and height values in pixels (in that order). Default 'medium'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1444
 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1445
 *                                    Default null.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1446
 * @return string|false A valid source size value for use in a 'sizes' attribute or false.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1447
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1448
function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1449
	$image = wp_get_attachment_image_src( $attachment_id, $size );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1450
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1451
	if ( ! $image ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1452
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1453
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1454
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1455
	if ( ! is_array( $image_meta ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1456
		$image_meta = wp_get_attachment_metadata( $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1457
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1458
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1459
	$image_src  = $image[0];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1460
	$size_array = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1461
		absint( $image[1] ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1462
		absint( $image[2] ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1463
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1464
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1465
	return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1466
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1467
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1468
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1469
 * Creates a 'sizes' attribute value for an image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1470
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1471
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1472
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1473
 * @param string|int[] $size          Image size. Accepts any registered image size name, or an array of
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1474
 *                                    width and height values in pixels (in that order).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1475
 * @param string       $image_src     Optional. The URL to the image file. Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1476
 * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1477
 *                                    Default null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1478
 * @param int          $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id`
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1479
 *                                    is needed when using the image size name as argument for `$size`. Default 0.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1480
 * @return string|false A valid source size value for use in a 'sizes' attribute or false.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1481
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1482
function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null, $attachment_id = 0 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1483
	$width = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1484
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1485
	if ( is_array( $size ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1486
		$width = absint( $size[0] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1487
	} elseif ( is_string( $size ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1488
		if ( ! $image_meta && $attachment_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1489
			$image_meta = wp_get_attachment_metadata( $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1490
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1491
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1492
		if ( is_array( $image_meta ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1493
			$size_array = _wp_get_image_size_from_meta( $size, $image_meta );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1494
			if ( $size_array ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1495
				$width = absint( $size_array[0] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1496
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1497
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1498
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1499
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1500
	if ( ! $width ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1501
		return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1502
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1503
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1504
	// Setup the default 'sizes' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1505
	$sizes = sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', $width );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1506
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1507
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1508
	 * Filters the output of 'wp_calculate_image_sizes()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1509
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1510
	 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1511
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1512
	 * @param string       $sizes         A source size value for use in a 'sizes' attribute.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1513
	 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1514
	 *                                    an array of width and height values in pixels (in that order).
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1515
	 * @param string|null  $image_src     The URL to the image file or null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1516
	 * @param array|null   $image_meta    The image meta data as returned by wp_get_attachment_metadata() or null.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1517
	 * @param int          $attachment_id Image attachment ID of the original image or 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1518
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1519
	return apply_filters( 'wp_calculate_image_sizes', $sizes, $size, $image_src, $image_meta, $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1520
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1521
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1522
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1523
 * Determines if the image meta data is for the image source file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1524
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1525
 * The image meta data is retrieved by attachment post ID. In some cases the post IDs may change.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1526
 * For example when the website is exported and imported at another website. Then the
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1527
 * attachment post IDs that are in post_content for the exported website may not match
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1528
 * the same attachments at the new website.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1529
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1530
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1531
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1532
 * @param string $image_location The full path or URI to the image file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1533
 * @param array  $image_meta     The attachment meta data as returned by 'wp_get_attachment_metadata()'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1534
 * @param int    $attachment_id  Optional. The image attachment ID. Default 0.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1535
 * @return bool Whether the image meta is for this image file.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1536
 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1537
function wp_image_file_matches_image_meta( $image_location, $image_meta, $attachment_id = 0 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1538
	$match = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1539
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1540
	// Ensure the $image_meta is valid.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1541
	if ( isset( $image_meta['file'] ) && strlen( $image_meta['file'] ) > 4 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1542
		// Remove quiery args if image URI.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1543
		list( $image_location ) = explode( '?', $image_location );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1544
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1545
		// Check if the relative image path from the image meta is at the end of $image_location.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1546
		if ( strrpos( $image_location, $image_meta['file'] ) === strlen( $image_location ) - strlen( $image_meta['file'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1547
			$match = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1548
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1549
			// Retrieve the uploads sub-directory from the full size image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1550
			$dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1551
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1552
			if ( $dirname ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1553
				$dirname = trailingslashit( $dirname );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1554
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1555
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1556
			if ( ! empty( $image_meta['original_image'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1557
				$relative_path = $dirname . $image_meta['original_image'];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1558
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1559
				if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1560
					$match = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1561
				}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1562
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1563
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1564
			if ( ! $match && ! empty( $image_meta['sizes'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1565
				foreach ( $image_meta['sizes'] as $image_size_data ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1566
					$relative_path = $dirname . $image_size_data['file'];
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1567
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1568
					if ( strrpos( $image_location, $relative_path ) === strlen( $image_location ) - strlen( $relative_path ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1569
						$match = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1570
						break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1571
					}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1572
				}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1573
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1574
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1575
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1576
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1577
	/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1578
	 * Filters whether an image path or URI matches image meta.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1579
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1580
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1581
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1582
	 * @param bool   $match          Whether the image relative path from the image meta
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1583
	 *                               matches the end of the URI or path to the image file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1584
	 * @param string $image_location Full path or URI to the tested image file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1585
	 * @param array  $image_meta     The image meta data as returned by 'wp_get_attachment_metadata()'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1586
	 * @param int    $attachment_id  The image attachment ID or 0 if not supplied.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1587
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1588
	return apply_filters( 'wp_image_file_matches_image_meta', $match, $image_location, $image_meta, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1589
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1590
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1591
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1592
 * Determines an image's width and height dimensions based on the source file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1593
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1594
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1595
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1596
 * @param string $image_src     The image source file.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1597
 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1598
 * @param int    $attachment_id Optional. The image attachment ID. Default 0.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1599
 * @return array|false Array with first element being the width and second element being the height,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1600
 *                     or false if dimensions cannot be determined.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1601
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1602
function wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id = 0 ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1603
	$dimensions = false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1604
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1605
	// Is it a full size image?
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1606
	if (
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1607
		isset( $image_meta['file'] ) &&
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1608
		strpos( $image_src, wp_basename( $image_meta['file'] ) ) !== false
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1609
	) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1610
		$dimensions = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1611
			(int) $image_meta['width'],
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1612
			(int) $image_meta['height'],
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1613
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1614
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1615
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1616
	if ( ! $dimensions && ! empty( $image_meta['sizes'] ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1617
		$src_filename = wp_basename( $image_src );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1618
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1619
		foreach ( $image_meta['sizes'] as $image_size_data ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1620
			if ( $src_filename === $image_size_data['file'] ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1621
				$dimensions = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1622
					(int) $image_size_data['width'],
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1623
					(int) $image_size_data['height'],
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1624
				);
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1625
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1626
				break;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1627
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1628
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1629
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1630
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1631
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1632
	 * Filters the 'wp_image_src_get_dimensions' value.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1633
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1634
	 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1635
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1636
	 * @param array|false $dimensions    Array with first element being the width
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1637
	 *                                   and second element being the height, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1638
	 *                                   false if dimensions could not be determined.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1639
	 * @param string      $image_src     The image source file.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1640
	 * @param array       $image_meta    The image meta data as returned by
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1641
	 *                                   'wp_get_attachment_metadata()'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1642
	 * @param int         $attachment_id The image attachment ID. Default 0.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1643
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1644
	return apply_filters( 'wp_image_src_get_dimensions', $dimensions, $image_src, $image_meta, $attachment_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1645
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1646
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1647
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1648
 * Adds 'srcset' and 'sizes' attributes to an existing 'img' element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1649
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1650
 * @since 4.4.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1651
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1652
 * @see wp_calculate_image_srcset()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1653
 * @see wp_calculate_image_sizes()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1654
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1655
 * @param string $image         An HTML 'img' element to be filtered.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1656
 * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1657
 * @param int    $attachment_id Image attachment ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1658
 * @return string Converted 'img' element with 'srcset' and 'sizes' attributes added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1659
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1660
function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1661
	// Ensure the image meta exists.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1662
	if ( empty( $image_meta['sizes'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1663
		return $image;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1664
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1665
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1666
	$image_src         = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1667
	list( $image_src ) = explode( '?', $image_src );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1668
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1669
	// Return early if we couldn't get the image source.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1670
	if ( ! $image_src ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1671
		return $image;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1672
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1673
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1674
	// Bail early if an image has been inserted and later edited.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1675
	if ( preg_match( '/-e[0-9]{13}/', $image_meta['file'], $img_edit_hash ) &&
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1676
		strpos( wp_basename( $image_src ), $img_edit_hash[0] ) === false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1677
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1678
		return $image;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1679
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1680
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1681
	$width  = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : 0;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1682
	$height = preg_match( '/ height="([0-9]+)"/', $image, $match_height ) ? (int) $match_height[1] : 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1683
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1684
	if ( $width && $height ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1685
		$size_array = array( $width, $height );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1686
	} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1687
		$size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1688
		if ( ! $size_array ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1689
			return $image;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1690
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1691
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1692
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1693
	$srcset = wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1694
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1695
	if ( $srcset ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1696
		// Check if there is already a 'sizes' attribute.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1697
		$sizes = strpos( $image, ' sizes=' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1698
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1699
		if ( ! $sizes ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1700
			$sizes = wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1701
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1702
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1703
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1704
	if ( $srcset && $sizes ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1705
		// Format the 'srcset' and 'sizes' string and escape attributes.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1706
		$attr = sprintf( ' srcset="%s"', esc_attr( $srcset ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1707
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1708
		if ( is_string( $sizes ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1709
			$attr .= sprintf( ' sizes="%s"', esc_attr( $sizes ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1710
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1711
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1712
		// Add the srcset and sizes attributes to the image markup.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1713
		return preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1714
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1715
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1716
	return $image;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1717
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1718
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1719
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1720
 * Determines whether to add the `loading` attribute to the specified tag in the specified context.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1721
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1722
 * @since 5.5.0
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1723
 * @since 5.7.0 Now returns `true` by default for `iframe` tags.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1724
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1725
 * @param string $tag_name The tag name.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1726
 * @param string $context  Additional context, like the current filter name
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1727
 *                         or the function name from where this was called.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1728
 * @return bool Whether to add the attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1729
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1730
function wp_lazy_loading_enabled( $tag_name, $context ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1731
	// By default add to all 'img' and 'iframe' tags.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1732
	// See https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-loading
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1733
	// See https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-loading
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1734
	$default = ( 'img' === $tag_name || 'iframe' === $tag_name );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1735
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1736
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1737
	 * Filters whether to add the `loading` attribute to the specified tag in the specified context.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1738
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1739
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1740
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1741
	 * @param bool   $default  Default value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1742
	 * @param string $tag_name The tag name.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1743
	 * @param string $context  Additional context, like the current filter name
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1744
	 *                         or the function name from where this was called.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1745
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1746
	return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1747
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1748
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1749
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1750
 * Filters specific tags in post content and modifies their markup.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1751
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1752
 * Modifies HTML tags in post content to include new browser and HTML technologies
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1753
 * that may not have existed at the time of post creation. These modifications currently
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1754
 * include adding `srcset`, `sizes`, and `loading` attributes to `img` HTML tags, as well
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1755
 * as adding `loading` attributes to `iframe` HTML tags.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1756
 * Future similar optimizations should be added/expected here.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1757
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1758
 * @since 5.5.0
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1759
 * @since 5.7.0 Now supports adding `loading` attributes to `iframe` tags.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1760
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1761
 * @see wp_img_tag_add_width_and_height_attr()
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1762
 * @see wp_img_tag_add_srcset_and_sizes_attr()
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1763
 * @see wp_img_tag_add_loading_attr()
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1764
 * @see wp_iframe_tag_add_loading_attr()
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1765
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1766
 * @param string $content The HTML content to be filtered.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1767
 * @param string $context Optional. Additional context to pass to the filters.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1768
 *                        Defaults to `current_filter()` when not set.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1769
 * @return string Converted content with images modified.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1770
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1771
function wp_filter_content_tags( $content, $context = null ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1772
	if ( null === $context ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1773
		$context = current_filter();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1774
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1775
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1776
	$add_img_loading_attr    = wp_lazy_loading_enabled( 'img', $context );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1777
	$add_iframe_loading_attr = wp_lazy_loading_enabled( 'iframe', $context );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1778
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1779
	if ( ! preg_match_all( '/<(img|iframe)\s[^>]+>/', $content, $matches, PREG_SET_ORDER ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1780
		return $content;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1781
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1782
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1783
	// List of the unique `img` tags found in $content.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1784
	$images = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1785
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1786
	// List of the unique `iframe` tags found in $content.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1787
	$iframes = array();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1788
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1789
	foreach ( $matches as $match ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1790
		list( $tag, $tag_name ) = $match;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1791
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1792
		switch ( $tag_name ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1793
			case 'img':
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1794
				if ( preg_match( '/wp-image-([0-9]+)/i', $tag, $class_id ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1795
					$attachment_id = absint( $class_id[1] );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1796
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1797
					if ( $attachment_id ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1798
						// If exactly the same image tag is used more than once, overwrite it.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1799
						// All identical tags will be replaced later with 'str_replace()'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1800
						$images[ $tag ] = $attachment_id;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1801
						break;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1802
					}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1803
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1804
				$images[ $tag ] = 0;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1805
				break;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1806
			case 'iframe':
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1807
				$iframes[ $tag ] = 0;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1808
				break;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1809
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1810
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1811
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1812
	// Reduce the array to unique attachment IDs.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1813
	$attachment_ids = array_unique( array_filter( array_values( $images ) ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1814
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1815
	if ( count( $attachment_ids ) > 1 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1816
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1817
		 * Warm the object cache with post and meta information for all found
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1818
		 * images to avoid making individual database calls.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1819
		 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1820
		_prime_post_caches( $attachment_ids, false, true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1821
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1822
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1823
	foreach ( $images as $image => $attachment_id ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1824
		$filtered_image = $image;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1825
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1826
		// Add 'width' and 'height' attributes if applicable.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1827
		if ( $attachment_id > 0 && false === strpos( $filtered_image, ' width=' ) && false === strpos( $filtered_image, ' height=' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1828
			$filtered_image = wp_img_tag_add_width_and_height_attr( $filtered_image, $context, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1829
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1830
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1831
		// Add 'srcset' and 'sizes' attributes if applicable.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1832
		if ( $attachment_id > 0 && false === strpos( $filtered_image, ' srcset=' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1833
			$filtered_image = wp_img_tag_add_srcset_and_sizes_attr( $filtered_image, $context, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1834
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1835
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1836
		// Add 'loading' attribute if applicable.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1837
		if ( $add_img_loading_attr && false === strpos( $filtered_image, ' loading=' ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1838
			$filtered_image = wp_img_tag_add_loading_attr( $filtered_image, $context );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1839
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1840
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1841
		if ( $filtered_image !== $image ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1842
			$content = str_replace( $image, $filtered_image, $content );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1843
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1844
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1845
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1846
	foreach ( $iframes as $iframe => $attachment_id ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1847
		$filtered_iframe = $iframe;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1848
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1849
		// Add 'loading' attribute if applicable.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1850
		if ( $add_iframe_loading_attr && false === strpos( $filtered_iframe, ' loading=' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1851
			$filtered_iframe = wp_iframe_tag_add_loading_attr( $filtered_iframe, $context );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1852
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1853
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1854
		if ( $filtered_iframe !== $iframe ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1855
			$content = str_replace( $iframe, $filtered_iframe, $content );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1856
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1857
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1858
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1859
	return $content;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1860
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1861
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1862
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1863
 * Adds `loading` attribute to an `img` HTML tag.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1864
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1865
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1866
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1867
 * @param string $image   The HTML `img` tag where the attribute should be added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1868
 * @param string $context Additional context to pass to the filters.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1869
 * @return string Converted `img` tag with `loading` attribute added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1870
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1871
function wp_img_tag_add_loading_attr( $image, $context ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1872
	// Images should have source and dimension attributes for the `loading` attribute to be added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1873
	if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1874
		return $image;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1875
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1876
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1877
	/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1878
	 * Filters the `loading` attribute value to add to an image. Default `lazy`.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1879
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1880
	 * Returning `false` or an empty string will not add the attribute.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1881
	 * Returning `true` will add the default value.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1882
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1883
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1884
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1885
	 * @param string|bool $value   The `loading` attribute value. Returning a falsey value will result in
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1886
	 *                             the attribute being omitted for the image. Default 'lazy'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1887
	 * @param string      $image   The HTML `img` tag to be filtered.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1888
	 * @param string      $context Additional context about how the function was called or where the img tag is.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1889
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1890
	$value = apply_filters( 'wp_img_tag_add_loading_attr', 'lazy', $image, $context );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1891
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1892
	if ( $value ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1893
		if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1894
			$value = 'lazy';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1895
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1896
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1897
		return str_replace( '<img', '<img loading="' . esc_attr( $value ) . '"', $image );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1898
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1899
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1900
	return $image;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1901
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1902
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1903
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1904
 * Adds `width` and `height` attributes to an `img` HTML tag.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1905
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1906
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1907
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1908
 * @param string $image         The HTML `img` tag where the attribute should be added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1909
 * @param string $context       Additional context to pass to the filters.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1910
 * @param int    $attachment_id Image attachment ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1911
 * @return string Converted 'img' element with 'width' and 'height' attributes added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1912
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1913
function wp_img_tag_add_width_and_height_attr( $image, $context, $attachment_id ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1914
	$image_src         = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1915
	list( $image_src ) = explode( '?', $image_src );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1916
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1917
	// Return early if we couldn't get the image source.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1918
	if ( ! $image_src ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1919
		return $image;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1920
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1921
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1922
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1923
	 * Filters whether to add the missing `width` and `height` HTML attributes to the img tag. Default `true`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1924
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1925
	 * Returning anything else than `true` will not add the attributes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1926
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1927
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1928
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1929
	 * @param bool   $value         The filtered value, defaults to `true`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1930
	 * @param string $image         The HTML `img` tag where the attribute should be added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1931
	 * @param string $context       Additional context about how the function was called or where the img tag is.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1932
	 * @param int    $attachment_id The image attachment ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1933
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1934
	$add = apply_filters( 'wp_img_tag_add_width_and_height_attr', true, $image, $context, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1935
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1936
	if ( true === $add ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1937
		$image_meta = wp_get_attachment_metadata( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1938
		$size_array = wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1939
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1940
		if ( $size_array ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1941
			$hw = trim( image_hwstring( $size_array[0], $size_array[1] ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1942
			return str_replace( '<img', "<img {$hw}", $image );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1943
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1944
	}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1945
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1946
	return $image;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1947
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1948
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1949
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1950
 * Adds `srcset` and `sizes` attributes to an existing `img` HTML tag.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1951
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1952
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1953
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1954
 * @param string $image         The HTML `img` tag where the attribute should be added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1955
 * @param string $context       Additional context to pass to the filters.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1956
 * @param int    $attachment_id Image attachment ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1957
 * @return string Converted 'img' element with 'loading' attribute added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1958
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1959
function wp_img_tag_add_srcset_and_sizes_attr( $image, $context, $attachment_id ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1960
	/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1961
	 * Filters whether to add the `srcset` and `sizes` HTML attributes to the img tag. Default `true`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1962
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1963
	 * Returning anything else than `true` will not add the attributes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1964
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1965
	 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1966
	 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1967
	 * @param bool   $value         The filtered value, defaults to `true`.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1968
	 * @param string $image         The HTML `img` tag where the attribute should be added.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1969
	 * @param string $context       Additional context about how the function was called or where the img tag is.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1970
	 * @param int    $attachment_id The image attachment ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1971
	 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1972
	$add = apply_filters( 'wp_img_tag_add_srcset_and_sizes_attr', true, $image, $context, $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1973
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1974
	if ( true === $add ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1975
		$image_meta = wp_get_attachment_metadata( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1976
		return wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1977
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1978
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1979
	return $image;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1980
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1981
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1982
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1983
 * Adds `loading` attribute to an `iframe` HTML tag.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1984
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1985
 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1986
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1987
 * @param string $iframe  The HTML `iframe` tag where the attribute should be added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1988
 * @param string $context Additional context to pass to the filters.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1989
 * @return string Converted `iframe` tag with `loading` attribute added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1990
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1991
function wp_iframe_tag_add_loading_attr( $iframe, $context ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1992
	// Iframes with fallback content (see `wp_filter_oembed_result()`) should not be lazy-loaded because they are
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1993
	// visually hidden initially.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1994
	if ( false !== strpos( $iframe, ' data-secret="' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1995
		return $iframe;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1996
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1997
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1998
	// Iframes should have source and dimension attributes for the `loading` attribute to be added.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1999
	if ( false === strpos( $iframe, ' src="' ) || false === strpos( $iframe, ' width="' ) || false === strpos( $iframe, ' height="' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2000
		return $iframe;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2001
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2002
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2003
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2004
	 * Filters the `loading` attribute value to add to an iframe. Default `lazy`.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2005
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2006
	 * Returning `false` or an empty string will not add the attribute.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2007
	 * Returning `true` will add the default value.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2008
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2009
	 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2010
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2011
	 * @param string|bool $value   The `loading` attribute value. Returning a falsey value will result in
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2012
	 *                             the attribute being omitted for the iframe. Default 'lazy'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2013
	 * @param string      $iframe  The HTML `iframe` tag to be filtered.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2014
	 * @param string      $context Additional context about how the function was called or where the iframe tag is.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2015
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2016
	$value = apply_filters( 'wp_iframe_tag_add_loading_attr', 'lazy', $iframe, $context );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2017
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2018
	if ( $value ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2019
		if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2020
			$value = 'lazy';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2021
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2022
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2023
		return str_replace( '<iframe', '<iframe loading="' . esc_attr( $value ) . '"', $iframe );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2024
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2025
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2026
	return $iframe;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2027
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2028
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2029
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2030
 * Adds a 'wp-post-image' class to post thumbnails. Internal use only.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2031
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2032
 * Uses the {@see 'begin_fetch_post_thumbnail_html'} and {@see 'end_fetch_post_thumbnail_html'}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2033
 * action hooks to dynamically add/remove itself so as to only filter post thumbnails.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2035
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2037
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2038
 * @param string[] $attr Array of thumbnail attributes including src, class, alt, title, keyed by attribute name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2039
 * @return string[] Modified array of attributes including the new 'wp-post-image' class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
function _wp_post_thumbnail_class_filter( $attr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
	$attr['class'] .= ' wp-post-image';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
	return $attr;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2047
 * Adds '_wp_post_thumbnail_class_filter' callback to the 'wp_get_attachment_image_attributes'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2048
 * filter hook. Internal use only.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2050
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2052
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2053
 * @param string[] $attr Array of thumbnail attributes including src, class, alt, title, keyed by attribute name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
function _wp_post_thumbnail_class_filter_add( $attr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
	add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2060
 * Removes the '_wp_post_thumbnail_class_filter' callback from the 'wp_get_attachment_image_attributes'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2061
 * filter hook. Internal use only.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2063
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2065
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2066
 * @param string[] $attr Array of thumbnail attributes including src, class, alt, title, keyed by attribute name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2068
function _wp_post_thumbnail_class_filter_remove( $attr ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2069
	remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2072
add_shortcode( 'wp_caption', 'img_caption_shortcode' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2073
add_shortcode( 'caption', 'img_caption_shortcode' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2076
 * Builds the Caption shortcode output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2077
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
 * Allows a plugin to replace the content that would otherwise be returned. The
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2079
 * filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
 * parameter and the content parameter values.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2081
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2082
 * The supported attributes for the shortcode are 'id', 'caption_id', 'align',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2083
 * 'width', 'caption', and 'class'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
 * @since 2.6.0
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2086
 * @since 3.9.0 The `class` attribute was added.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2087
 * @since 5.1.0 The `caption_id` attribute was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2089
 * @param array  $attr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2090
 *     Attributes of the caption shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2091
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2092
 *     @type string $id         ID of the image and caption container element, i.e. `<figure>` or `<div>`.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2093
 *     @type string $caption_id ID of the caption element, i.e. `<figcaption>` or `<p>`.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2094
 *     @type string $align      Class name that aligns the caption. Default 'alignnone'. Accepts 'alignleft',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2095
 *                              'aligncenter', alignright', 'alignnone'.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2096
 *     @type int    $width      The width of the caption, in pixels.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2097
 *     @type string $caption    The caption text.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2098
 *     @type string $class      Additional class name(s) added to the caption container.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2099
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2100
 * @param string $content Shortcode content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2101
 * @return string HTML content to display the caption.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2103
function img_caption_shortcode( $attr, $content = null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
	// New-style shortcode with the caption inside the shortcode with the link and image tags.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
	if ( ! isset( $attr['caption'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
		if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2107
			$content         = $matches[1];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
			$attr['caption'] = trim( $matches[2] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2110
	} elseif ( strpos( $attr['caption'], '<' ) !== false ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2111
		$attr['caption'] = wp_kses( $attr['caption'], 'post' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2114
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2115
	 * Filters the default caption shortcode output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2116
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2117
	 * If the filtered output isn't empty, it will be used instead of generating
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2118
	 * the default caption template.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2119
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2120
	 * @since 2.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2121
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2122
	 * @see img_caption_shortcode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2123
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2124
	 * @param string $output  The caption output. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2125
	 * @param array  $attr    Attributes of the caption shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2126
	 * @param string $content The image element, possibly wrapped in a hyperlink.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2127
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2128
	$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2129
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2130
	if ( ! empty( $output ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2131
		return $output;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2132
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2133
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2134
	$atts = shortcode_atts(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2135
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2136
			'id'         => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2137
			'caption_id' => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2138
			'align'      => 'alignnone',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2139
			'width'      => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2140
			'caption'    => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2141
			'class'      => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2142
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2143
		$attr,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2144
		'caption'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2145
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
	$atts['width'] = (int) $atts['width'];
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2148
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2149
	if ( $atts['width'] < 1 || empty( $atts['caption'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
		return $content;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2151
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2152
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2153
	$id          = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2154
	$caption_id  = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2155
	$describedby = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2156
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2157
	if ( $atts['id'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2158
		$atts['id'] = sanitize_html_class( $atts['id'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2159
		$id         = 'id="' . esc_attr( $atts['id'] ) . '" ';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2160
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2161
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2162
	if ( $atts['caption_id'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2163
		$atts['caption_id'] = sanitize_html_class( $atts['caption_id'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2164
	} elseif ( $atts['id'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2165
		$atts['caption_id'] = 'caption-' . str_replace( '_', '-', $atts['id'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2166
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2167
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2168
	if ( $atts['caption_id'] ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2169
		$caption_id  = 'id="' . esc_attr( $atts['caption_id'] ) . '" ';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2170
		$describedby = 'aria-describedby="' . esc_attr( $atts['caption_id'] ) . '" ';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2171
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2173
	$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2174
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2175
	$html5 = current_theme_supports( 'html5', 'caption' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2176
	// HTML5 captions never added the extra 10px to the image width.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2177
	$width = $html5 ? $atts['width'] : ( 10 + $atts['width'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2180
	 * Filters the width of an image's caption.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2181
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2182
	 * By default, the caption is 10 pixels greater than the width of the image,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
	 * to prevent post content from running up against a floated image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
	 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2187
	 * @see img_caption_shortcode()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2189
	 * @param int    $width    Width of the caption in pixels. To remove this inline style,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2190
	 *                         return zero.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2191
	 * @param array  $atts     Attributes of the caption shortcode.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2192
	 * @param string $content  The image element, possibly wrapped in a hyperlink.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2194
	$caption_width = apply_filters( 'img_caption_shortcode_width', $width, $atts, $content );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
	$style = '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2197
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2198
	if ( $caption_width ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
		$style = 'style="width: ' . (int) $caption_width . 'px" ';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2200
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2201
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2202
	if ( $html5 ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2203
		$html = sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2204
			'<figure %s%s%sclass="%s">%s%s</figure>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2205
			$id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2206
			$describedby,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2207
			$style,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2208
			esc_attr( $class ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2209
			do_shortcode( $content ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2210
			sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2211
				'<figcaption %sclass="wp-caption-text">%s</figcaption>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2212
				$caption_id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2213
				$atts['caption']
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2214
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2215
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2216
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2217
		$html = sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2218
			'<div %s%sclass="%s">%s%s</div>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2219
			$id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2220
			$style,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2221
			esc_attr( $class ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2222
			str_replace( '<img ', '<img ' . $describedby, do_shortcode( $content ) ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2223
			sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2224
				'<p %sclass="wp-caption-text">%s</p>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2225
				$caption_id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2226
				$atts['caption']
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2227
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2228
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2229
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2230
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2231
	return $html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2232
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2234
add_shortcode( 'gallery', 'gallery_shortcode' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2236
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2237
 * Builds the Gallery shortcode output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
 * This implements the functionality of the Gallery Shortcode for displaying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
 * WordPress images on a post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2244
 * @param array $attr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2245
 *     Attributes of the gallery shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2246
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2247
 *     @type string       $order      Order of the images in the gallery. Default 'ASC'. Accepts 'ASC', 'DESC'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2248
 *     @type string       $orderby    The field to use when ordering the images. Default 'menu_order ID'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2249
 *                                    Accepts any valid SQL ORDERBY statement.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2250
 *     @type int          $id         Post ID.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2251
 *     @type string       $itemtag    HTML tag to use for each image in the gallery.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2252
 *                                    Default 'dl', or 'figure' when the theme registers HTML5 gallery support.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2253
 *     @type string       $icontag    HTML tag to use for each image's icon.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2254
 *                                    Default 'dt', or 'div' when the theme registers HTML5 gallery support.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2255
 *     @type string       $captiontag HTML tag to use for each image's caption.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2256
 *                                    Default 'dd', or 'figcaption' when the theme registers HTML5 gallery support.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2257
 *     @type int          $columns    Number of columns of images to display. Default 3.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2258
 *     @type string|int[] $size       Size of the images to display. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2259
 *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2260
 *     @type string       $ids        A comma-separated list of IDs of attachments to display. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2261
 *     @type string       $include    A comma-separated list of IDs of attachments to include. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2262
 *     @type string       $exclude    A comma-separated list of IDs of attachments to exclude. Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2263
 *     @type string       $link       What to link each image to. Default empty (links to the attachment page).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2264
 *                                    Accepts 'file', 'none'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2265
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
 * @return string HTML content to display gallery.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2268
function gallery_shortcode( $attr ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
	$post = get_post();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
	static $instance = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2272
	$instance++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
	if ( ! empty( $attr['ids'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
		// 'ids' is explicitly ordered, unless you specify otherwise.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2276
		if ( empty( $attr['orderby'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
			$attr['orderby'] = 'post__in';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2278
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
		$attr['include'] = $attr['ids'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2282
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2283
	 * Filters the default gallery shortcode output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2284
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2285
	 * If the filtered output isn't empty, it will be used instead of generating
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2286
	 * the default gallery template.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2287
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2288
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2289
	 * @since 4.2.0 The `$instance` parameter was added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2290
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2291
	 * @see gallery_shortcode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2292
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2293
	 * @param string $output   The gallery output. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2294
	 * @param array  $attr     Attributes of the gallery shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2295
	 * @param int    $instance Unique numeric ID of this gallery shortcode instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2296
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2297
	$output = apply_filters( 'post_gallery', '', $attr, $instance );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2298
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2299
	if ( ! empty( $output ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2300
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2301
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2302
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2303
	$html5 = current_theme_supports( 'html5', 'gallery' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2304
	$atts  = shortcode_atts(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2305
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2306
			'order'      => 'ASC',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2307
			'orderby'    => 'menu_order ID',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2308
			'id'         => $post ? $post->ID : 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2309
			'itemtag'    => $html5 ? 'figure' : 'dl',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2310
			'icontag'    => $html5 ? 'div' : 'dt',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2311
			'captiontag' => $html5 ? 'figcaption' : 'dd',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2312
			'columns'    => 3,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2313
			'size'       => 'thumbnail',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2314
			'include'    => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2315
			'exclude'    => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2316
			'link'       => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2317
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2318
		$attr,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2319
		'gallery'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2320
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2321
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2322
	$id = (int) $atts['id'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2323
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2324
	if ( ! empty( $atts['include'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2325
		$_attachments = get_posts(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2326
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2327
				'include'        => $atts['include'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2328
				'post_status'    => 'inherit',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2329
				'post_type'      => 'attachment',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2330
				'post_mime_type' => 'image',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2331
				'order'          => $atts['order'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2332
				'orderby'        => $atts['orderby'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2333
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2334
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
		$attachments = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
		foreach ( $_attachments as $key => $val ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2338
			$attachments[ $val->ID ] = $_attachments[ $key ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2340
	} elseif ( ! empty( $atts['exclude'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2341
		$attachments = get_children(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2342
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2343
				'post_parent'    => $id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2344
				'exclude'        => $atts['exclude'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2345
				'post_status'    => 'inherit',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2346
				'post_type'      => 'attachment',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2347
				'post_mime_type' => 'image',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2348
				'order'          => $atts['order'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2349
				'orderby'        => $atts['orderby'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2350
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2351
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2352
	} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2353
		$attachments = get_children(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2354
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2355
				'post_parent'    => $id,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2356
				'post_status'    => 'inherit',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2357
				'post_type'      => 'attachment',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2358
				'post_mime_type' => 'image',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2359
				'order'          => $atts['order'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2360
				'orderby'        => $atts['orderby'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2361
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2362
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2365
	if ( empty( $attachments ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
		return '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2367
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2369
	if ( is_feed() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2370
		$output = "\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2371
		foreach ( $attachments as $att_id => $attachment ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2372
			if ( ! empty( $atts['link'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2373
				if ( 'none' === $atts['link'] ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2374
					$output .= wp_get_attachment_image( $att_id, $atts['size'], false, $attr );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2375
				} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2376
					$output .= wp_get_attachment_link( $att_id, $atts['size'], false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2377
				}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2378
			} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2379
				$output .= wp_get_attachment_link( $att_id, $atts['size'], true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2380
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2381
			$output .= "\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2382
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2383
		return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2385
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2386
	$itemtag    = tag_escape( $atts['itemtag'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2387
	$captiontag = tag_escape( $atts['captiontag'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2388
	$icontag    = tag_escape( $atts['icontag'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
	$valid_tags = wp_kses_allowed_html( 'post' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2390
	if ( ! isset( $valid_tags[ $itemtag ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2391
		$itemtag = 'dl';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2392
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2393
	if ( ! isset( $valid_tags[ $captiontag ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2394
		$captiontag = 'dd';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2395
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2396
	if ( ! isset( $valid_tags[ $icontag ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2397
		$icontag = 'dt';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2398
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2399
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2400
	$columns   = (int) $atts['columns'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2401
	$itemwidth = $columns > 0 ? floor( 100 / $columns ) : 100;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2402
	$float     = is_rtl() ? 'right' : 'left';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
	$selector = "gallery-{$instance}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2406
	$gallery_style = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2407
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2408
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2409
	 * Filters whether to print default gallery styles.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2410
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2411
	 * @since 3.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2412
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2413
	 * @param bool $print Whether to print default gallery styles.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2414
	 *                    Defaults to false if the theme supports HTML5 galleries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2415
	 *                    Otherwise, defaults to true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2416
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2417
	if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2418
		$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2419
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
		$gallery_style = "
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2421
		<style{$type_attr}>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
			#{$selector} {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
				margin: auto;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
			#{$selector} .gallery-item {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
				float: {$float};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
				margin-top: 10px;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
				text-align: center;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
				width: {$itemwidth}%;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
			#{$selector} img {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
				border: 2px solid #cfcfcf;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
			#{$selector} .gallery-caption {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
				margin-left: 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
			/* see gallery_shortcode() in wp-includes/media.php */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2438
		</style>\n\t\t";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2439
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2440
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2441
	$size_class  = sanitize_html_class( is_array( $atts['size'] ) ? implode( 'x', $atts['size'] ) : $atts['size'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
	$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2443
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2444
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2445
	 * Filters the default gallery shortcode CSS styles.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2446
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2447
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2448
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2449
	 * @param string $gallery_style Default CSS styles and opening HTML div container
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2450
	 *                              for the gallery shortcode output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2451
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2452
	$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2454
	$i = 0;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2455
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2456
	foreach ( $attachments as $id => $attachment ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2457
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2458
		$attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2459
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2460
		if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2461
			$image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2462
		} elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2463
			$image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2464
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2465
			$image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2466
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2467
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2468
		$image_meta = wp_get_attachment_metadata( $id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
		$orientation = '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2471
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2472
		if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
			$orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2474
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2475
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
		$output .= "<{$itemtag} class='gallery-item'>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
		$output .= "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
			<{$icontag} class='gallery-icon {$orientation}'>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
				$image_output
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
			</{$icontag}>";
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2481
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2482
		if ( $captiontag && trim( $attachment->post_excerpt ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
			$output .= "
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2484
				<{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2485
				" . wptexturize( $attachment->post_excerpt ) . "
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
				</{$captiontag}>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2488
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
		$output .= "</{$itemtag}>";
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2490
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2491
		if ( ! $html5 && $columns > 0 && 0 === ++$i % $columns ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2492
			$output .= '<br style="clear: both" />';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2493
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2494
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2495
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2496
	if ( ! $html5 && $columns > 0 && 0 !== $i % $columns ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2497
		$output .= "
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2498
			<br style='clear: both' />";
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2499
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2501
	$output .= "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2502
		</div>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2504
	return $output;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2505
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2506
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2507
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2508
 * Outputs the templates used by playlists.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2509
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2510
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2511
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2512
function wp_underscore_playlist_templates() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2513
	?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2514
<script type="text/html" id="tmpl-wp-playlist-current-item">
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2515
	<# if ( data.thumb && data.thumb.src ) { #>
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2516
		<img src="{{ data.thumb.src }}" alt="" />
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2517
	<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2518
	<div class="wp-playlist-caption">
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2519
		<span class="wp-playlist-item-meta wp-playlist-item-title">
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2520
		<?php
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2521
			/* translators: %s: Playlist item title. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2522
			printf( _x( '&#8220;%s&#8221;', 'playlist item title' ), '{{ data.title }}' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2523
		?>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2524
		</span>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2525
		<# if ( data.meta.album ) { #><span class="wp-playlist-item-meta wp-playlist-item-album">{{ data.meta.album }}</span><# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2526
		<# if ( data.meta.artist ) { #><span class="wp-playlist-item-meta wp-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2527
	</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2528
</script>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2529
<script type="text/html" id="tmpl-wp-playlist-item">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2530
	<div class="wp-playlist-item">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2531
		<a class="wp-playlist-caption" href="{{ data.src }}">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2532
			{{ data.index ? ( data.index + '. ' ) : '' }}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2533
			<# if ( data.caption ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2534
				{{ data.caption }}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2535
			<# } else { #>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2536
				<span class="wp-playlist-item-title">
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2537
				<?php
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2538
					/* translators: %s: Playlist item title. */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2539
					printf( _x( '&#8220;%s&#8221;', 'playlist item title' ), '{{{ data.title }}}' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2540
				?>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2541
				</span>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2542
				<# if ( data.artists && data.meta.artist ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2543
				<span class="wp-playlist-item-artist"> &mdash; {{ data.meta.artist }}</span>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2544
				<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2545
			<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2546
		</a>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2547
		<# if ( data.meta.length_formatted ) { #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2548
		<div class="wp-playlist-item-length">{{ data.meta.length_formatted }}</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2549
		<# } #>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2550
	</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2551
</script>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2552
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2553
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2554
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2555
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2556
 * Outputs and enqueue default scripts and styles for playlists.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2557
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2558
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2559
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2560
 * @param string $type Type of playlist. Accepts 'audio' or 'video'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2561
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2562
function wp_playlist_scripts( $type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2563
	wp_enqueue_style( 'wp-mediaelement' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2564
	wp_enqueue_script( 'wp-playlist' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2565
	?>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2566
<!--[if lt IE 9]><script>document.createElement('<?php echo esc_js( $type ); ?>');</script><![endif]-->
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2567
	<?php
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2568
	add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2569
	add_action( 'admin_footer', 'wp_underscore_playlist_templates', 0 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2570
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2571
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2572
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2573
 * Builds the Playlist shortcode output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2574
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2575
 * This implements the functionality of the playlist shortcode for displaying
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2576
 * a collection of WordPress audio or video files in a post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2577
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2578
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2579
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2580
 * @global int $content_width
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2581
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2582
 * @param array $attr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2583
 *     Array of default playlist attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2584
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2585
 *     @type string  $type         Type of playlist to display. Accepts 'audio' or 'video'. Default 'audio'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2586
 *     @type string  $order        Designates ascending or descending order of items in the playlist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2587
 *                                 Accepts 'ASC', 'DESC'. Default 'ASC'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2588
 *     @type string  $orderby      Any column, or columns, to sort the playlist. If $ids are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2589
 *                                 passed, this defaults to the order of the $ids array ('post__in').
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2590
 *                                 Otherwise default is 'menu_order ID'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2591
 *     @type int     $id           If an explicit $ids array is not present, this parameter
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2592
 *                                 will determine which attachments are used for the playlist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2593
 *                                 Default is the current post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2594
 *     @type array   $ids          Create a playlist out of these explicit attachment IDs. If empty,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2595
 *                                 a playlist will be created from all $type attachments of $id.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2596
 *                                 Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2597
 *     @type array   $exclude      List of specific attachment IDs to exclude from the playlist. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2598
 *     @type string  $style        Playlist style to use. Accepts 'light' or 'dark'. Default 'light'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2599
 *     @type bool    $tracklist    Whether to show or hide the playlist. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2600
 *     @type bool    $tracknumbers Whether to show or hide the numbers next to entries in the playlist. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2601
 *     @type bool    $images       Show or hide the video or audio thumbnail (Featured Image/post
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2602
 *                                 thumbnail). Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2603
 *     @type bool    $artists      Whether to show or hide artist name in the playlist. Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2604
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2605
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2606
 * @return string Playlist output. Empty string if the passed type is unsupported.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2607
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2608
function wp_playlist_shortcode( $attr ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2609
	global $content_width;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2610
	$post = get_post();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2611
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2612
	static $instance = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2613
	$instance++;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2614
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2615
	if ( ! empty( $attr['ids'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2616
		// 'ids' is explicitly ordered, unless you specify otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2617
		if ( empty( $attr['orderby'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2618
			$attr['orderby'] = 'post__in';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2619
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2620
		$attr['include'] = $attr['ids'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2621
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2622
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2623
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2624
	 * Filters the playlist output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2625
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2626
	 * Returning a non-empty value from the filter will short-circuit generation
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2627
	 * of the default playlist output, returning the passed value instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2628
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2629
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2630
	 * @since 4.2.0 The `$instance` parameter was added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2631
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2632
	 * @param string $output   Playlist output. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2633
	 * @param array  $attr     An array of shortcode attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2634
	 * @param int    $instance Unique numeric ID of this playlist shortcode instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2635
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2636
	$output = apply_filters( 'post_playlist', '', $attr, $instance );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2637
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2638
	if ( ! empty( $output ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2639
		return $output;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2640
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2641
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2642
	$atts = shortcode_atts(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2643
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2644
			'type'         => 'audio',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2645
			'order'        => 'ASC',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2646
			'orderby'      => 'menu_order ID',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2647
			'id'           => $post ? $post->ID : 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2648
			'include'      => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2649
			'exclude'      => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2650
			'style'        => 'light',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2651
			'tracklist'    => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2652
			'tracknumbers' => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2653
			'images'       => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2654
			'artists'      => true,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2655
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2656
		$attr,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2657
		'playlist'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2658
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2659
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2660
	$id = (int) $atts['id'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2661
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2662
	if ( 'audio' !== $atts['type'] ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2663
		$atts['type'] = 'video';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2664
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2665
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2666
	$args = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2667
		'post_status'    => 'inherit',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2668
		'post_type'      => 'attachment',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2669
		'post_mime_type' => $atts['type'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2670
		'order'          => $atts['order'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2671
		'orderby'        => $atts['orderby'],
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2672
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2673
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2674
	if ( ! empty( $atts['include'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2675
		$args['include'] = $atts['include'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2676
		$_attachments    = get_posts( $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2677
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2678
		$attachments = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2679
		foreach ( $_attachments as $key => $val ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2680
			$attachments[ $val->ID ] = $_attachments[ $key ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2681
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2682
	} elseif ( ! empty( $atts['exclude'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2683
		$args['post_parent'] = $id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2684
		$args['exclude']     = $atts['exclude'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2685
		$attachments         = get_children( $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2686
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2687
		$args['post_parent'] = $id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2688
		$attachments         = get_children( $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2689
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2690
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2691
	if ( empty( $attachments ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2692
		return '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2693
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2694
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2695
	if ( is_feed() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2696
		$output = "\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2697
		foreach ( $attachments as $att_id => $attachment ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2698
			$output .= wp_get_attachment_link( $att_id ) . "\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2699
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2700
		return $output;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2701
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2702
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2703
	$outer = 22; // Default padding and border of wrapper.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2704
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2705
	$default_width  = 640;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2706
	$default_height = 360;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2707
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2708
	$theme_width  = empty( $content_width ) ? $default_width : ( $content_width - $outer );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2709
	$theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2710
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2711
	$data = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2712
		'type'         => $atts['type'],
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2713
		// Don't pass strings to JSON, will be truthy in JS.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2714
		'tracklist'    => wp_validate_boolean( $atts['tracklist'] ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2715
		'tracknumbers' => wp_validate_boolean( $atts['tracknumbers'] ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2716
		'images'       => wp_validate_boolean( $atts['images'] ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2717
		'artists'      => wp_validate_boolean( $atts['artists'] ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2718
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2719
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2720
	$tracks = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2721
	foreach ( $attachments as $attachment ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2722
		$url   = wp_get_attachment_url( $attachment->ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2723
		$ftype = wp_check_filetype( $url, wp_get_mime_types() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2724
		$track = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2725
			'src'         => $url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2726
			'type'        => $ftype['type'],
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2727
			'title'       => $attachment->post_title,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2728
			'caption'     => $attachment->post_excerpt,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2729
			'description' => $attachment->post_content,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2730
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2731
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2732
		$track['meta'] = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2733
		$meta          = wp_get_attachment_metadata( $attachment->ID );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2734
		if ( ! empty( $meta ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2735
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2736
			foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2737
				if ( ! empty( $meta[ $key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2738
					$track['meta'][ $key ] = $meta[ $key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2739
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2740
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2741
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2742
			if ( 'video' === $atts['type'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2743
				if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2744
					$width        = $meta['width'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2745
					$height       = $meta['height'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2746
					$theme_height = round( ( $height * $theme_width ) / $width );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2747
				} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2748
					$width  = $default_width;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2749
					$height = $default_height;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2750
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2751
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2752
				$track['dimensions'] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2753
					'original' => compact( 'width', 'height' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2754
					'resized'  => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2755
						'width'  => $theme_width,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2756
						'height' => $theme_height,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2757
					),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2758
				);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2759
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2760
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2761
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2762
		if ( $atts['images'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2763
			$thumb_id = get_post_thumbnail_id( $attachment->ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2764
			if ( ! empty( $thumb_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2765
				list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2766
				$track['image']               = compact( 'src', 'width', 'height' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2767
				list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2768
				$track['thumb']               = compact( 'src', 'width', 'height' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2769
			} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2770
				$src            = wp_mime_type_icon( $attachment->ID );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2771
				$width          = 48;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2772
				$height         = 64;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2773
				$track['image'] = compact( 'src', 'width', 'height' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2774
				$track['thumb'] = compact( 'src', 'width', 'height' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2775
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2776
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2777
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2778
		$tracks[] = $track;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2779
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2780
	$data['tracks'] = $tracks;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2781
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2782
	$safe_type  = esc_attr( $atts['type'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2783
	$safe_style = esc_attr( $atts['style'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2784
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2785
	ob_start();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2786
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2787
	if ( 1 === $instance ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2788
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2789
		 * Prints and enqueues playlist scripts, styles, and JavaScript templates.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2790
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2791
		 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2792
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2793
		 * @param string $type  Type of playlist. Possible values are 'audio' or 'video'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2794
		 * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2795
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2796
		do_action( 'wp_playlist_scripts', $atts['type'], $atts['style'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2797
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2798
	?>
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2799
<div class="wp-playlist wp-<?php echo $safe_type; ?>-playlist wp-playlist-<?php echo $safe_style; ?>">
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2800
	<?php if ( 'audio' === $atts['type'] ) : ?>
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2801
		<div class="wp-playlist-current-item"></div>
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2802
	<?php endif; ?>
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2803
	<<?php echo $safe_type; ?> controls="controls" preload="none" width="<?php echo (int) $theme_width; ?>"
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2804
		<?php
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2805
		if ( 'video' === $safe_type ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2806
			echo ' height="', (int) $theme_height, '"';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2807
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2808
		?>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2809
	></<?php echo $safe_type; ?>>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2810
	<div class="wp-playlist-next"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2811
	<div class="wp-playlist-prev"></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2812
	<noscript>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2813
	<ol>
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2814
		<?php
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2815
		foreach ( $attachments as $att_id => $attachment ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2816
			printf( '<li>%s</li>', wp_get_attachment_link( $att_id ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2817
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  2818
		?>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2819
	</ol>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2820
	</noscript>
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2821
	<script type="application/json" class="wp-playlist-script"><?php echo wp_json_encode( $data ); ?></script>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2822
</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2823
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2824
	return ob_get_clean();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2825
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2826
add_shortcode( 'playlist', 'wp_playlist_shortcode' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2827
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2828
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2829
 * Provides a No-JS Flash fallback as a last resort for audio / video.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2830
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2831
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2832
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2833
 * @param string $url The media element URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2834
 * @return string Fallback HTML.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2835
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2836
function wp_mediaelement_fallback( $url ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2837
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2838
	 * Filters the Mediaelement fallback output for no-JS.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2839
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2840
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2841
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2842
	 * @param string $output Fallback output for no-JS.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2843
	 * @param string $url    Media file URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2844
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2845
	return apply_filters( 'wp_mediaelement_fallback', sprintf( '<a href="%1$s">%1$s</a>', esc_url( $url ) ), $url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2846
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2847
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2848
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2849
 * Returns a filtered list of supported audio formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2850
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2851
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2852
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2853
 * @return string[] Supported audio formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2854
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2855
function wp_get_audio_extensions() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2856
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2857
	 * Filters the list of supported audio formats.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2858
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2859
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2860
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2861
	 * @param string[] $extensions An array of supported audio formats. Defaults are
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2862
	 *                            'mp3', 'ogg', 'flac', 'm4a', 'wav'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2863
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2864
	return apply_filters( 'wp_audio_extensions', array( 'mp3', 'ogg', 'flac', 'm4a', 'wav' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2865
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2867
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2868
 * Returns useful keys to use to lookup data from an attachment's stored metadata.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2869
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2870
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2871
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2872
 * @param WP_Post $attachment The current attachment, provided for context.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2873
 * @param string  $context    Optional. The context. Accepts 'edit', 'display'. Default 'display'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2874
 * @return string[] Key/value pairs of field keys to labels.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2875
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2876
function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2877
	$fields = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2878
		'artist' => __( 'Artist' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2879
		'album'  => __( 'Album' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2880
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2881
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2882
	if ( 'display' === $context ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2883
		$fields['genre']            = __( 'Genre' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2884
		$fields['year']             = __( 'Year' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2885
		$fields['length_formatted'] = _x( 'Length', 'video or audio' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2886
	} elseif ( 'js' === $context ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2887
		$fields['bitrate']      = __( 'Bitrate' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2888
		$fields['bitrate_mode'] = __( 'Bitrate Mode' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2889
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2890
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2891
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2892
	 * Filters the editable list of keys to look up data from an attachment's metadata.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2893
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2894
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2895
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2896
	 * @param array   $fields     Key/value pairs of field keys to labels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2897
	 * @param WP_Post $attachment Attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2898
	 * @param string  $context    The context. Accepts 'edit', 'display'. Default 'display'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2899
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2900
	return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2901
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2902
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2903
 * Builds the Audio shortcode output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2904
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2905
 * This implements the functionality of the Audio Shortcode for displaying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2906
 * WordPress mp3s in a post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2907
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2908
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2909
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2910
 * @param array  $attr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2911
 *     Attributes of the audio shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2912
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2913
 *     @type string $src      URL to the source of the audio file. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2914
 *     @type string $loop     The 'loop' attribute for the `<audio>` element. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2915
 *     @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2916
 *     @type string $preload  The 'preload' attribute for the `<audio>` element. Default 'none'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2917
 *     @type string $class    The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2918
 *     @type string $style    The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2919
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2920
 * @param string $content Shortcode content.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2921
 * @return string|void HTML content to display audio.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2922
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2923
function wp_audio_shortcode( $attr, $content = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2924
	$post_id = get_post() ? get_the_ID() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2925
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2926
	static $instance = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2927
	$instance++;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2929
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2930
	 * Filters the default audio shortcode output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2931
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2932
	 * If the filtered output isn't empty, it will be used instead of generating the default audio template.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2933
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2934
	 * @since 3.6.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2935
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2936
	 * @param string $html     Empty variable to be replaced with shortcode markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2937
	 * @param array  $attr     Attributes of the shortcode. @see wp_audio_shortcode()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2938
	 * @param string $content  Shortcode content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2939
	 * @param int    $instance Unique numeric ID of this audio shortcode instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2940
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2941
	$override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2942
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2943
	if ( '' !== $override ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2944
		return $override;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2945
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2946
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2947
	$audio = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2948
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2949
	$default_types = wp_get_audio_extensions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2950
	$defaults_atts = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2951
		'src'      => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2952
		'loop'     => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2953
		'autoplay' => '',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2954
		'preload'  => 'none',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  2955
		'class'    => 'wp-audio-shortcode',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2956
		'style'    => 'width: 100%;',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2957
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2958
	foreach ( $default_types as $type ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2959
		$defaults_atts[ $type ] = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2960
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2961
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2962
	$atts = shortcode_atts( $defaults_atts, $attr, 'audio' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2963
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2964
	$primary = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2965
	if ( ! empty( $atts['src'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2966
		$type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2967
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2968
		if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2969
			return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2970
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2971
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2972
		$primary = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2973
		array_unshift( $default_types, 'src' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2974
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2975
		foreach ( $default_types as $ext ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2976
			if ( ! empty( $atts[ $ext ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2977
				$type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2978
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2979
				if ( strtolower( $type['ext'] ) === $ext ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2980
					$primary = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2981
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2982
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2983
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2984
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2985
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2986
	if ( ! $primary ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2987
		$audios = get_attached_media( 'audio', $post_id );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2988
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2989
		if ( empty( $audios ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2990
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2991
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2992
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  2993
		$audio       = reset( $audios );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2994
		$atts['src'] = wp_get_attachment_url( $audio->ID );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  2995
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2996
		if ( empty( $atts['src'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2997
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2998
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2999
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3000
		array_unshift( $default_types, 'src' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3001
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3002
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3003
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3004
	 * Filters the media library used for the audio shortcode.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3005
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3006
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3007
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3008
	 * @param string $library Media library used for the audio shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3009
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3010
	$library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3011
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3012
	if ( 'mediaelement' === $library && did_action( 'init' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3013
		wp_enqueue_style( 'wp-mediaelement' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3014
		wp_enqueue_script( 'wp-mediaelement' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3015
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3016
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3017
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3018
	 * Filters the class attribute for the audio shortcode output container.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3019
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3020
	 * @since 3.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3021
	 * @since 4.9.0 The `$atts` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3022
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3023
	 * @param string $class CSS class or list of space-separated classes.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3024
	 * @param array  $atts  Array of audio shortcode attributes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3025
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3026
	$atts['class'] = apply_filters( 'wp_audio_shortcode_class', $atts['class'], $atts );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3027
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3028
	$html_atts = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3029
		'class'    => $atts['class'],
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3030
		'id'       => sprintf( 'audio-%d-%d', $post_id, $instance ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3031
		'loop'     => wp_validate_boolean( $atts['loop'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3032
		'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3033
		'preload'  => $atts['preload'],
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3034
		'style'    => $atts['style'],
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3035
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3036
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3037
	// These ones should just be omitted altogether if they are blank.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3038
	foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3039
		if ( empty( $html_atts[ $a ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3040
			unset( $html_atts[ $a ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3041
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3042
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3043
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3044
	$attr_strings = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3045
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3046
	foreach ( $html_atts as $k => $v ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3047
		$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3048
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3049
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3050
	$html = '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3051
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3052
	if ( 'mediaelement' === $library && 1 === $instance ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3053
		$html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3054
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3055
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3056
	$html .= sprintf( '<audio %s controls="controls">', implode( ' ', $attr_strings ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3057
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3058
	$fileurl = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3059
	$source  = '<source type="%s" src="%s" />';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3060
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3061
	foreach ( $default_types as $fallback ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3062
		if ( ! empty( $atts[ $fallback ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3063
			if ( empty( $fileurl ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3064
				$fileurl = $atts[ $fallback ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3065
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3066
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3067
			$type  = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3068
			$url   = add_query_arg( '_', $instance, $atts[ $fallback ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3069
			$html .= sprintf( $source, $type['type'], esc_url( $url ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3070
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3071
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3072
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3073
	if ( 'mediaelement' === $library ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3074
		$html .= wp_mediaelement_fallback( $fileurl );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3075
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3076
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3077
	$html .= '</audio>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3078
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3079
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3080
	 * Filters the audio shortcode output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3081
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3082
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3083
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3084
	 * @param string $html    Audio shortcode HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3085
	 * @param array  $atts    Array of audio shortcode attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3086
	 * @param string $audio   Audio file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3087
	 * @param int    $post_id Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3088
	 * @param string $library Media library used for the audio shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3089
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3090
	return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id, $library );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3091
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3092
add_shortcode( 'audio', 'wp_audio_shortcode' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3093
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3094
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3095
 * Returns a filtered list of supported video formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3096
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3097
 * @since 3.6.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3098
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3099
 * @return string[] List of supported video formats.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3100
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3101
function wp_get_video_extensions() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3102
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3103
	 * Filters the list of supported video formats.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3104
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3105
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3106
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3107
	 * @param string[] $extensions An array of supported video formats. Defaults are
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3108
	 *                             'mp4', 'm4v', 'webm', 'ogv', 'flv'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3109
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3110
	return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'flv' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3111
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3113
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3114
 * Builds the Video shortcode output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3115
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3116
 * This implements the functionality of the Video Shortcode for displaying
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3117
 * WordPress mp4s in a post.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3119
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3120
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3121
 * @global int $content_width
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3122
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3123
 * @param array  $attr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3124
 *     Attributes of the shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3125
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3126
 *     @type string $src      URL to the source of the video file. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3127
 *     @type int    $height   Height of the video embed in pixels. Default 360.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3128
 *     @type int    $width    Width of the video embed in pixels. Default $content_width or 640.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3129
 *     @type string $poster   The 'poster' attribute for the `<video>` element. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3130
 *     @type string $loop     The 'loop' attribute for the `<video>` element. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3131
 *     @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3132
 *     @type string $preload  The 'preload' attribute for the `<video>` element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3133
 *                            Default 'metadata'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3134
 *     @type string $class    The 'class' attribute for the `<video>` element.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3135
 *                            Default 'wp-video-shortcode'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3136
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3137
 * @param string $content Shortcode content.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3138
 * @return string|void HTML content to display video.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3139
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3140
function wp_video_shortcode( $attr, $content = '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3141
	global $content_width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3142
	$post_id = get_post() ? get_the_ID() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3143
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3144
	static $instance = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3145
	$instance++;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3147
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3148
	 * Filters the default video shortcode output.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3149
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3150
	 * If the filtered output isn't empty, it will be used instead of generating
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3151
	 * the default video template.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3152
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3153
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3154
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3155
	 * @see wp_video_shortcode()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3156
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3157
	 * @param string $html     Empty variable to be replaced with shortcode markup.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3158
	 * @param array  $attr     Attributes of the shortcode. @see wp_video_shortcode()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3159
	 * @param string $content  Video shortcode content.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3160
	 * @param int    $instance Unique numeric ID of this video shortcode instance.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3161
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3162
	$override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3163
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3164
	if ( '' !== $override ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3165
		return $override;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3166
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3168
	$video = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3170
	$default_types = wp_get_video_extensions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3171
	$defaults_atts = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3172
		'src'      => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3173
		'poster'   => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3174
		'loop'     => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3175
		'autoplay' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3176
		'preload'  => 'metadata',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3177
		'width'    => 640,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3178
		'height'   => 360,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3179
		'class'    => 'wp-video-shortcode',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3180
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3181
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3182
	foreach ( $default_types as $type ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3183
		$defaults_atts[ $type ] = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3184
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3186
	$atts = shortcode_atts( $defaults_atts, $attr, 'video' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3187
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3188
	if ( is_admin() ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3189
		// Shrink the video so it isn't huge in the admin.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3190
		if ( $atts['width'] > $defaults_atts['width'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3191
			$atts['height'] = round( ( $atts['height'] * $defaults_atts['width'] ) / $atts['width'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3192
			$atts['width']  = $defaults_atts['width'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3193
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3194
	} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3195
		// If the video is bigger than the theme.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3196
		if ( ! empty( $content_width ) && $atts['width'] > $content_width ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3197
			$atts['height'] = round( ( $atts['height'] * $content_width ) / $atts['width'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3198
			$atts['width']  = $content_width;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3199
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3200
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3201
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3202
	$is_vimeo      = false;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3203
	$is_youtube    = false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3204
	$yt_pattern    = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3205
	$vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3207
	$primary = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3208
	if ( ! empty( $atts['src'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3209
		$is_vimeo   = ( preg_match( $vimeo_pattern, $atts['src'] ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3210
		$is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3211
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3212
		if ( ! $is_youtube && ! $is_vimeo ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3213
			$type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3214
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3215
			if ( ! in_array( strtolower( $type['ext'] ), $default_types, true ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3216
				return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3217
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3218
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3219
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3220
		if ( $is_vimeo ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3221
			wp_enqueue_script( 'mediaelement-vimeo' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3222
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3223
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3224
		$primary = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3225
		array_unshift( $default_types, 'src' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3226
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3227
		foreach ( $default_types as $ext ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3228
			if ( ! empty( $atts[ $ext ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3229
				$type = wp_check_filetype( $atts[ $ext ], wp_get_mime_types() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3230
				if ( strtolower( $type['ext'] ) === $ext ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3231
					$primary = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3232
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3233
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3234
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3235
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3237
	if ( ! $primary ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3238
		$videos = get_attached_media( 'video', $post_id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3239
		if ( empty( $videos ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3240
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3241
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3242
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3243
		$video       = reset( $videos );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3244
		$atts['src'] = wp_get_attachment_url( $video->ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3245
		if ( empty( $atts['src'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3246
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3247
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3249
		array_unshift( $default_types, 'src' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3250
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3251
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3252
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3253
	 * Filters the media library used for the video shortcode.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3254
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3255
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3256
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3257
	 * @param string $library Media library used for the video shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3258
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3259
	$library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3260
	if ( 'mediaelement' === $library && did_action( 'init' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3261
		wp_enqueue_style( 'wp-mediaelement' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3262
		wp_enqueue_script( 'wp-mediaelement' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3263
		wp_enqueue_script( 'mediaelement-vimeo' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3264
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3265
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3266
	// MediaElement.js has issues with some URL formats for Vimeo and YouTube,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3267
	// so update the URL to prevent the ME.js player from breaking.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3268
	if ( 'mediaelement' === $library ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3269
		if ( $is_youtube ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3270
			// Remove `feature` query arg and force SSL - see #40866.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3271
			$atts['src'] = remove_query_arg( 'feature', $atts['src'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3272
			$atts['src'] = set_url_scheme( $atts['src'], 'https' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3273
		} elseif ( $is_vimeo ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3274
			// Remove all query arguments and force SSL - see #40866.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3275
			$parsed_vimeo_url = wp_parse_url( $atts['src'] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3276
			$vimeo_src        = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3277
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3278
			// Add loop param for mejs bug - see #40977, not needed after #39686.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3279
			$loop        = $atts['loop'] ? '1' : '0';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3280
			$atts['src'] = add_query_arg( 'loop', $loop, $vimeo_src );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3281
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3282
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3283
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3284
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3285
	 * Filters the class attribute for the video shortcode output container.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3286
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3287
	 * @since 3.6.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3288
	 * @since 4.9.0 The `$atts` parameter was added.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3289
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3290
	 * @param string $class CSS class or list of space-separated classes.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3291
	 * @param array  $atts  Array of video shortcode attributes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3292
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3293
	$atts['class'] = apply_filters( 'wp_video_shortcode_class', $atts['class'], $atts );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3294
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3295
	$html_atts = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3296
		'class'    => $atts['class'],
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3297
		'id'       => sprintf( 'video-%d-%d', $post_id, $instance ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3298
		'width'    => absint( $atts['width'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3299
		'height'   => absint( $atts['height'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3300
		'poster'   => esc_url( $atts['poster'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3301
		'loop'     => wp_validate_boolean( $atts['loop'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3302
		'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3303
		'preload'  => $atts['preload'],
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3304
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3305
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3306
	// These ones should just be omitted altogether if they are blank.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3307
	foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3308
		if ( empty( $html_atts[ $a ] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3309
			unset( $html_atts[ $a ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3310
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3311
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3312
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3313
	$attr_strings = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3314
	foreach ( $html_atts as $k => $v ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3315
		$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3316
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3318
	$html = '';
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3319
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3320
	if ( 'mediaelement' === $library && 1 === $instance ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3321
		$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3322
	}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3323
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3324
	$html .= sprintf( '<video %s controls="controls">', implode( ' ', $attr_strings ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3326
	$fileurl = '';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3327
	$source  = '<source type="%s" src="%s" />';
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3328
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3329
	foreach ( $default_types as $fallback ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3330
		if ( ! empty( $atts[ $fallback ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3331
			if ( empty( $fileurl ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3332
				$fileurl = $atts[ $fallback ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3333
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3334
			if ( 'src' === $fallback && $is_youtube ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3335
				$type = array( 'type' => 'video/youtube' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3336
			} elseif ( 'src' === $fallback && $is_vimeo ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3337
				$type = array( 'type' => 'video/vimeo' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3338
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3339
				$type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3340
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3341
			$url   = add_query_arg( '_', $instance, $atts[ $fallback ] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3342
			$html .= sprintf( $source, $type['type'], esc_url( $url ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3343
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3344
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3345
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3346
	if ( ! empty( $content ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3347
		if ( false !== strpos( $content, "\n" ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3348
			$content = str_replace( array( "\r\n", "\n", "\t" ), '', $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3349
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3350
		$html .= trim( $content );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3351
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3352
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3353
	if ( 'mediaelement' === $library ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3354
		$html .= wp_mediaelement_fallback( $fileurl );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3355
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3356
	$html .= '</video>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3357
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3358
	$width_rule = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3359
	if ( ! empty( $atts['width'] ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3360
		$width_rule = sprintf( 'width: %dpx;', $atts['width'] );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3361
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3362
	$output = sprintf( '<div style="%s" class="wp-video">%s</div>', $width_rule, $html );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3363
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3364
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3365
	 * Filters the output of the video shortcode.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3366
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3367
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3368
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3369
	 * @param string $output  Video shortcode HTML output.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3370
	 * @param array  $atts    Array of video shortcode attributes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3371
	 * @param string $video   Video file.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3372
	 * @param int    $post_id Post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3373
	 * @param string $library Media library used for the video shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3374
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3375
	return apply_filters( 'wp_video_shortcode', $output, $atts, $video, $post_id, $library );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3376
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3377
add_shortcode( 'video', 'wp_video_shortcode' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3378
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3379
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3380
 * Gets the previous image link that has the same post parent.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3381
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3382
 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3383
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3384
 * @see get_adjacent_image_link()
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3385
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3386
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3387
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3388
 * @param string|false $text Optional. Link text. Default false.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3389
 * @return string Markup for previous image link.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3390
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3391
function get_previous_image_link( $size = 'thumbnail', $text = false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3392
	return get_adjacent_image_link( true, $size, $text );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3393
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3394
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3395
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3396
 * Displays previous image link that has the same post parent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3397
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3398
 * @since 2.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3399
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3400
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3401
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3402
 * @param string|false $text Optional. Link text. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3403
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3404
function previous_image_link( $size = 'thumbnail', $text = false ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3405
	echo get_previous_image_link( $size, $text );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3406
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3407
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3408
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3409
 * Gets the next image link that has the same post parent.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3410
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3411
 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3412
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3413
 * @see get_adjacent_image_link()
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3414
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3415
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3416
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3417
 * @param string|false $text Optional. Link text. Default false.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3418
 * @return string Markup for next image link.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3419
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3420
function get_next_image_link( $size = 'thumbnail', $text = false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3421
	return get_adjacent_image_link( false, $size, $text );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3422
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3424
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3425
 * Displays next image link that has the same post parent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3426
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3427
 * @since 2.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3428
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3429
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3430
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3431
 * @param string|false $text Optional. Link text. Default false.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3432
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3433
function next_image_link( $size = 'thumbnail', $text = false ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3434
	echo get_next_image_link( $size, $text );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3435
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3437
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3438
 * Gets the next or previous image link that has the same post parent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3439
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3440
 * Retrieves the current attachment object from the $post global.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3441
 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3442
 * @since 5.8.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3443
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3444
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3445
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3446
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3447
 * @param bool         $text Optional. Link text. Default false.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3448
 * @return string Markup for image link.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3449
 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3450
function get_adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3451
	$post        = get_post();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3452
	$attachments = array_values(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3453
		get_children(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3454
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3455
				'post_parent'    => $post->post_parent,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3456
				'post_status'    => 'inherit',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3457
				'post_type'      => 'attachment',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3458
				'post_mime_type' => 'image',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3459
				'order'          => 'ASC',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3460
				'orderby'        => 'menu_order ID',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3461
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3462
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3463
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3464
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3465
	foreach ( $attachments as $k => $attachment ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3466
		if ( (int) $attachment->ID === (int) $post->ID ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3467
			break;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3468
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3469
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3470
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3471
	$output        = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3472
	$attachment_id = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3473
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3474
	if ( $attachments ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3475
		$k = $prev ? $k - 1 : $k + 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3476
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3477
		if ( isset( $attachments[ $k ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3478
			$attachment_id = $attachments[ $k ]->ID;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3479
			$attr          = array( 'alt' => get_the_title( $attachment_id ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3480
			$output        = wp_get_attachment_link( $attachment_id, $size, true, false, $text, $attr );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3481
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3482
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3484
	$adjacent = $prev ? 'previous' : 'next';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3485
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3486
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3487
	 * Filters the adjacent image link.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3488
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3489
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3490
	 * either 'next', or 'previous'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3491
	 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3492
	 * Possible hook names include:
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3493
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3494
	 *  - `next_image_link`
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3495
	 *  - `previous_image_link`
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3496
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3497
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3498
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3499
	 * @param string $output        Adjacent image HTML markup.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3500
	 * @param int    $attachment_id Attachment ID
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3501
	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3502
	 *                              an array of width and height values in pixels (in that order).
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3503
	 * @param string $text          Link text.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3504
	 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3505
	return apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3506
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3507
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3508
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3509
 * Displays next or previous image link that has the same post parent.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3510
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3511
 * Retrieves the current attachment object from the $post global.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3512
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3513
 * @since 2.5.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3514
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3515
 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3516
 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3517
 *                           of width and height values in pixels (in that order). Default 'thumbnail'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3518
 * @param bool         $text Optional. Link text. Default false.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3519
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3520
function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3521
	echo get_adjacent_image_link( $prev, $size, $text );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3522
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3523
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3524
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3525
 * Retrieves taxonomies attached to given the attachment.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3526
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3527
 * @since 2.5.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3528
 * @since 4.7.0 Introduced the `$output` parameter.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3529
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3530
 * @param int|array|object $attachment Attachment ID, data array, or data object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3531
 * @param string           $output     Output type. 'names' to return an array of taxonomy names,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3532
 *                                     or 'objects' to return an array of taxonomy objects.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3533
 *                                     Default is 'names'.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3534
 * @return string[]|WP_Taxonomy[] List of taxonomies or taxonomy names. Empty array on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3535
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3536
function get_attachment_taxonomies( $attachment, $output = 'names' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3537
	if ( is_int( $attachment ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3538
		$attachment = get_post( $attachment );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3539
	} elseif ( is_array( $attachment ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3540
		$attachment = (object) $attachment;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3541
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3542
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3543
	if ( ! is_object( $attachment ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3544
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3545
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3546
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3547
	$file     = get_attached_file( $attachment->ID );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3548
	$filename = wp_basename( $file );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3549
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3550
	$objects = array( 'attachment' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3551
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3552
	if ( false !== strpos( $filename, '.' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3553
		$objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3554
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3555
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3556
	if ( ! empty( $attachment->post_mime_type ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3557
		$objects[] = 'attachment:' . $attachment->post_mime_type;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3558
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3559
		if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3560
			foreach ( explode( '/', $attachment->post_mime_type ) as $token ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3561
				if ( ! empty( $token ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3562
					$objects[] = "attachment:$token";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3563
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3564
			}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3565
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3566
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3567
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3568
	$taxonomies = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3569
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3570
	foreach ( $objects as $object ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3571
		$taxes = get_object_taxonomies( $object, $output );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3572
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3573
		if ( $taxes ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3574
			$taxonomies = array_merge( $taxonomies, $taxes );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3575
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3576
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3577
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3578
	if ( 'names' === $output ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3579
		$taxonomies = array_unique( $taxonomies );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3580
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3581
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3582
	return $taxonomies;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3583
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3584
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3585
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3586
 * Retrieves all of the taxonomies that are registered for attachments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3587
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3588
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3589
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3590
 * @since 3.5.0
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3591
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3592
 * @see get_taxonomies()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3593
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3594
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3595
 *                       Default 'names'.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3596
 * @return string[]|WP_Taxonomy[] Array of names or objects of registered taxonomies for attachments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3597
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3598
function get_taxonomies_for_attachments( $output = 'names' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3599
	$taxonomies = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3600
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3601
	foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3602
		foreach ( $taxonomy->object_type as $object_type ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3603
			if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3604
				if ( 'names' === $output ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3605
					$taxonomies[] = $taxonomy->name;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3606
				} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3607
					$taxonomies[ $taxonomy->name ] = $taxonomy;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3608
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3609
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3610
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3611
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3612
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3614
	return $taxonomies;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3615
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3617
/**
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3618
 * Determines whether the value is an acceptable type for GD image functions.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3619
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3620
 * In PHP 8.0, the GD extension uses GdImage objects for its data structures.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3621
 * This function checks if the passed value is either a resource of type `gd`
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3622
 * or a GdImage object instance. Any other type will return false.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3623
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3624
 * @since 5.6.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3625
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3626
 * @param resource|GdImage|false $image A value to check the type for.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3627
 * @return bool True if $image is either a GD image resource or GdImage instance,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3628
 *              false otherwise.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3629
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3630
function is_gd_image( $image ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3631
	if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3632
		|| is_object( $image ) && $image instanceof GdImage
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3633
	) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3634
		return true;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3635
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3636
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3637
	return false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3638
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3639
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3640
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3641
 * Create new GD image resource with transparency support
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3642
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3643
 * @todo Deprecate if possible.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3644
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3645
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3646
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3647
 * @param int $width  Image width in pixels.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3648
 * @param int $height Image height in pixels.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3649
 * @return resource|GdImage|false The GD image resource or GdImage instance on success.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3650
 *                                False on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3651
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3652
function wp_imagecreatetruecolor( $width, $height ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3653
	$img = imagecreatetruecolor( $width, $height );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3654
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3655
	if ( is_gd_image( $img )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3656
		&& function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3657
	) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3658
		imagealphablending( $img, false );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3659
		imagesavealpha( $img, true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3660
	}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3661
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3662
	return $img;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3663
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3664
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3665
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3666
 * Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3667
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3668
 * @since 2.9.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3669
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3670
 * @see wp_constrain_dimensions()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3671
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3672
 * @param int $example_width  The width of an example embed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3673
 * @param int $example_height The height of an example embed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3674
 * @param int $max_width      The maximum allowed width.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3675
 * @param int $max_height     The maximum allowed height.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3676
 * @return int[] {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3677
 *     An array of maximum width and height values.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3678
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3679
 *     @type int $0 The maximum width in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3680
 *     @type int $1 The maximum height in pixels.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3681
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3682
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3683
function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3684
	$example_width  = (int) $example_width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3685
	$example_height = (int) $example_height;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3686
	$max_width      = (int) $max_width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3687
	$max_height     = (int) $max_height;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3689
	return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3690
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3692
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3693
 * Determines the maximum upload size allowed in php.ini.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3694
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3695
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3696
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3697
 * @return int Allowed upload size.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3698
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3699
function wp_max_upload_size() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3700
	$u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3701
	$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3702
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3703
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3704
	 * Filters the maximum upload size allowed in php.ini.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3705
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3706
	 * @since 2.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3707
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3708
	 * @param int $size    Max upload size limit in bytes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3709
	 * @param int $u_bytes Maximum upload filesize in bytes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3710
	 * @param int $p_bytes Maximum size of POST data in bytes.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3711
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3712
	return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3713
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3715
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3716
 * Returns a WP_Image_Editor instance and loads file into it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3717
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3718
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3719
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3720
 * @param string $path Path to the file to load.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3721
 * @param array  $args Optional. Additional arguments for retrieving the image editor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3722
 *                     Default empty array.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3723
 * @return WP_Image_Editor|WP_Error The WP_Image_Editor object on success,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3724
 *                                  a WP_Error object otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3725
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3726
function wp_get_image_editor( $path, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3727
	$args['path'] = $path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3728
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3729
	if ( ! isset( $args['mime_type'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3730
		$file_info = wp_check_filetype( $args['path'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3731
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3732
		// If $file_info['type'] is false, then we let the editor attempt to
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3733
		// figure out the file type, rather than forcing a failure based on extension.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3734
		if ( isset( $file_info ) && $file_info['type'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3735
			$args['mime_type'] = $file_info['type'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3736
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3737
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3739
	$implementation = _wp_image_editor_choose( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3740
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3741
	if ( $implementation ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3742
		$editor = new $implementation( $path );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3743
		$loaded = $editor->load();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3744
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3745
		if ( is_wp_error( $loaded ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3746
			return $loaded;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3747
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3749
		return $editor;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3750
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3751
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3752
	return new WP_Error( 'image_no_editor', __( 'No editor could be selected.' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3753
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3755
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3756
 * Tests whether there is an editor that supports a given mime type or methods.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3757
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3758
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3759
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3760
 * @param string|array $args Optional. Array of arguments to retrieve the image editor supports.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3761
 *                           Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3762
 * @return bool True if an eligible editor is found; false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3763
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3764
function wp_image_editor_supports( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3765
	return (bool) _wp_image_editor_choose( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3766
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3767
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3768
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3769
 * Tests which editors are capable of supporting the request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3770
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3771
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3772
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3773
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3774
 * @param array $args Optional. Array of arguments for choosing a capable editor. Default empty array.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3775
 * @return string|false Class name for the first editor that claims to support the request.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3776
 *                      False if no editor claims to support the request.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3777
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3778
function _wp_image_editor_choose( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3779
	require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3780
	require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3781
	require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3782
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3783
	 * Filters the list of image editing library classes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3784
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3785
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3786
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3787
	 * @param string[] $image_editors Array of available image editor class names. Defaults are
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3788
	 *                                'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3789
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3790
	$implementations = apply_filters( 'wp_image_editors', array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3791
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3792
	foreach ( $implementations as $implementation ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3793
		if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3794
			continue;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3795
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3796
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3797
		if ( isset( $args['mime_type'] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3798
			! call_user_func(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3799
				array( $implementation, 'supports_mime_type' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3800
				$args['mime_type']
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3801
			) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3802
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3803
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3805
		if ( isset( $args['methods'] ) &&
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3806
			array_diff( $args['methods'], get_class_methods( $implementation ) ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3807
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3808
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3809
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3810
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3811
		return $implementation;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3812
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3814
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3815
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3816
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3817
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3818
 * Prints default Plupload arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3819
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3820
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3821
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3822
function wp_plupload_default_settings() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3823
	$wp_scripts = wp_scripts();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3824
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3825
	$data = $wp_scripts->get_data( 'wp-plupload', 'data' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3826
	if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3827
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3828
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3829
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3830
	$max_upload_size    = wp_max_upload_size();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3831
	$allowed_extensions = array_keys( get_allowed_mime_types() );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3832
	$extensions         = array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3833
	foreach ( $allowed_extensions as $extension ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3834
		$extensions = array_merge( $extensions, explode( '|', $extension ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3835
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3836
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3837
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3838
	 * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3839
	 * and the `flash_swf_url` and `silverlight_xap_url` are not used.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3840
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3841
	$defaults = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3842
		'file_data_name' => 'async-upload', // Key passed to $_FILE.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3843
		'url'            => admin_url( 'async-upload.php', 'relative' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3844
		'filters'        => array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3845
			'max_file_size' => $max_upload_size . 'b',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3846
			'mime_types'    => array( array( 'extensions' => implode( ',', $extensions ) ) ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3847
		),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3848
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3849
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3850
	/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3851
	 * Currently only iOS Safari supports multiple files uploading,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3852
	 * but iOS 7.x has a bug that prevents uploading of videos when enabled.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3853
	 * See #29602.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3854
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3855
	if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3856
		strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3857
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3858
		$defaults['multi_selection'] = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3859
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3860
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3861
	// Check if WebP images can be edited.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3862
	if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3863
		$defaults['webp_upload_error'] = true;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3864
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3865
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3866
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3867
	 * Filters the Plupload default settings.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3868
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3869
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3870
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3871
	 * @param array $defaults Default Plupload settings array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3872
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3873
	$defaults = apply_filters( 'plupload_default_settings', $defaults );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3874
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3875
	$params = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3876
		'action' => 'upload-attachment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3877
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3878
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3879
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  3880
	 * Filters the Plupload default parameters.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3881
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3882
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3883
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3884
	 * @param array $params Default Plupload parameters array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3885
	 */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3886
	$params = apply_filters( 'plupload_default_params', $params );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3887
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3888
	$params['_wpnonce'] = wp_create_nonce( 'media-form' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3889
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3890
	$defaults['multipart_params'] = $params;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3891
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3892
	$settings = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3893
		'defaults'      => $defaults,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3894
		'browser'       => array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3895
			'mobile'    => wp_is_mobile(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3896
			'supported' => _device_can_upload(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3897
		),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3898
		'limitExceeded' => is_multisite() && ! is_upload_space_available(),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3899
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3900
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  3901
	$script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3902
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3903
	if ( $data ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3904
		$script = "$data\n$script";
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3905
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3906
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3907
	$wp_scripts->add_data( 'wp-plupload', 'data', $script );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3908
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3909
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3910
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3911
 * Prepares an attachment post object for JS, where it is expected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3912
 * to be JSON-encoded and fit into an Attachment model.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3913
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3914
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3915
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3916
 * @param int|WP_Post $attachment Attachment ID or object.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3917
 * @return array|void {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3918
 *     Array of attachment details, or void if the parameter does not correspond to an attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3919
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3920
 *     @type string $alt                   Alt text of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3921
 *     @type string $author                ID of the attachment author, as a string.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3922
 *     @type string $authorName            Name of the attachment author.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3923
 *     @type string $caption               Caption for the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3924
 *     @type array  $compat                Containing item and meta.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3925
 *     @type string $context               Context, whether it's used as the site icon for example.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3926
 *     @type int    $date                  Uploaded date, timestamp in milliseconds.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3927
 *     @type string $dateFormatted         Formatted date (e.g. June 29, 2018).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3928
 *     @type string $description           Description of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3929
 *     @type string $editLink              URL to the edit page for the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3930
 *     @type string $filename              File name of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3931
 *     @type string $filesizeHumanReadable Filesize of the attachment in human readable format (e.g. 1 MB).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3932
 *     @type int    $filesizeInBytes       Filesize of the attachment in bytes.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3933
 *     @type int    $height                If the attachment is an image, represents the height of the image in pixels.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3934
 *     @type string $icon                  Icon URL of the attachment (e.g. /wp-includes/images/media/archive.png).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3935
 *     @type int    $id                    ID of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3936
 *     @type string $link                  URL to the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3937
 *     @type int    $menuOrder             Menu order of the attachment post.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3938
 *     @type array  $meta                  Meta data for the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3939
 *     @type string $mime                  Mime type of the attachment (e.g. image/jpeg or application/zip).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3940
 *     @type int    $modified              Last modified, timestamp in milliseconds.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3941
 *     @type string $name                  Name, same as title of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3942
 *     @type array  $nonces                Nonces for update, delete and edit.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3943
 *     @type string $orientation           If the attachment is an image, represents the image orientation
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3944
 *                                         (landscape or portrait).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3945
 *     @type array  $sizes                 If the attachment is an image, contains an array of arrays
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3946
 *                                         for the images sizes: thumbnail, medium, large, and full.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3947
 *     @type string $status                Post status of the attachment (usually 'inherit').
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3948
 *     @type string $subtype               Mime subtype of the attachment (usually the last part, e.g. jpeg or zip).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3949
 *     @type string $title                 Title of the attachment (usually slugified file name without the extension).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3950
 *     @type string $type                  Type of the attachment (usually first part of the mime type, e.g. image).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3951
 *     @type int    $uploadedTo            Parent post to which the attachment was uploaded.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3952
 *     @type string $uploadedToLink        URL to the edit page of the parent post of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3953
 *     @type string $uploadedToTitle       Post title of the parent of the attachment.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3954
 *     @type string $url                   Direct URL to the attachment file (from wp-content).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3955
 *     @type int    $width                 If the attachment is an image, represents the width of the image in pixels.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3956
 * }
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  3957
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3958
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3959
function wp_prepare_attachment_for_js( $attachment ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3960
	$attachment = get_post( $attachment );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3961
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3962
	if ( ! $attachment ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3963
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3964
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3965
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  3966
	if ( 'attachment' !== $attachment->post_type ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3967
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3968
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3969
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3970
	$meta = wp_get_attachment_metadata( $attachment->ID );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3971
	if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3972
		list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3973
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3974
		list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3975
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3976
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3977
	$attachment_url = wp_get_attachment_url( $attachment->ID );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3978
	$base_url       = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  3980
	$response = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3981
		'id'            => $attachment->ID,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3982
		'title'         => $attachment->post_title,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3983
		'filename'      => wp_basename( get_attached_file( $attachment->ID ) ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3984
		'url'           => $attachment_url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3985
		'link'          => get_attachment_link( $attachment->ID ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3986
		'alt'           => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3987
		'author'        => $attachment->post_author,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3988
		'description'   => $attachment->post_content,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3989
		'caption'       => $attachment->post_excerpt,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3990
		'name'          => $attachment->post_name,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3991
		'status'        => $attachment->post_status,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3992
		'uploadedTo'    => $attachment->post_parent,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3993
		'date'          => strtotime( $attachment->post_date_gmt ) * 1000,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3994
		'modified'      => strtotime( $attachment->post_modified_gmt ) * 1000,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3995
		'menuOrder'     => $attachment->menu_order,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3996
		'mime'          => $attachment->post_mime_type,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3997
		'type'          => $type,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3998
		'subtype'       => $subtype,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  3999
		'icon'          => wp_mime_type_icon( $attachment->ID ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4000
		'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4001
		'nonces'        => array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4002
			'update' => false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4003
			'delete' => false,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4004
			'edit'   => false,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4005
		),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4006
		'editLink'      => false,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4007
		'meta'          => false,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4008
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4009
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4010
	$author = new WP_User( $attachment->post_author );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4011
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4012
	if ( $author->exists() ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4013
		$author_name            = $author->display_name ? $author->display_name : $author->nickname;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4014
		$response['authorName'] = html_entity_decode( $author_name, ENT_QUOTES, get_bloginfo( 'charset' ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4015
		$response['authorLink'] = get_edit_user_link( $author->ID );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4016
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4017
		$response['authorName'] = __( '(no author)' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4018
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4019
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4020
	if ( $attachment->post_parent ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4021
		$post_parent = get_post( $attachment->post_parent );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4022
		if ( $post_parent ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4023
			$response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4024
			$response['uploadedToLink']  = get_edit_post_link( $attachment->post_parent, 'raw' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4025
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4026
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4027
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4028
	$attached_file = get_attached_file( $attachment->ID );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4029
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4030
	if ( isset( $meta['filesize'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4031
		$bytes = $meta['filesize'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4032
	} elseif ( file_exists( $attached_file ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4033
		$bytes = filesize( $attached_file );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4034
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4035
		$bytes = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4036
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4037
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4038
	if ( $bytes ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4039
		$response['filesizeInBytes']       = $bytes;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4040
		$response['filesizeHumanReadable'] = size_format( $bytes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4041
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4042
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4043
	$context             = get_post_meta( $attachment->ID, '_wp_attachment_context', true );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4044
	$response['context'] = ( $context ) ? $context : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4045
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4046
	if ( current_user_can( 'edit_post', $attachment->ID ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4047
		$response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4048
		$response['nonces']['edit']   = wp_create_nonce( 'image_editor-' . $attachment->ID );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4049
		$response['editLink']         = get_edit_post_link( $attachment->ID, 'raw' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4050
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4051
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4052
	if ( current_user_can( 'delete_post', $attachment->ID ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4053
		$response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4054
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4055
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4056
	if ( $meta && ( 'image' === $type || ! empty( $meta['sizes'] ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4057
		$sizes = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4058
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4059
		/** This filter is documented in wp-admin/includes/media.php */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4060
		$possible_sizes = apply_filters(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4061
			'image_size_names_choose',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4062
			array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4063
				'thumbnail' => __( 'Thumbnail' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4064
				'medium'    => __( 'Medium' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4065
				'large'     => __( 'Large' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4066
				'full'      => __( 'Full Size' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4067
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4068
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4069
		unset( $possible_sizes['full'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4070
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4071
		/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4072
		 * Loop through all potential sizes that may be chosen. Try to do this with some efficiency.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4073
		 * First: run the image_downsize filter. If it returns something, we can use its data.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4074
		 * If the filter does not return something, then image_downsize() is just an expensive way
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4075
		 * to check the image metadata, which we do second.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4076
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4077
		foreach ( $possible_sizes as $size => $label ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4078
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4079
			/** This filter is documented in wp-includes/media.php */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4080
			$downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4081
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4082
			if ( $downsize ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4083
				if ( empty( $downsize[3] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4084
					continue;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4085
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4086
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4087
				$sizes[ $size ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4088
					'height'      => $downsize[2],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4089
					'width'       => $downsize[1],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4090
					'url'         => $downsize[0],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4091
					'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4092
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4093
			} elseif ( isset( $meta['sizes'][ $size ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4094
				// Nothing from the filter, so consult image metadata if we have it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4095
				$size_meta = $meta['sizes'][ $size ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4097
				// We have the actual image size, but might need to further constrain it if content_width is narrower.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4098
				// Thumbnail, medium, and full sizes are also checked against the site's height/width options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4099
				list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4100
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4101
				$sizes[ $size ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4102
					'height'      => $height,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4103
					'width'       => $width,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4104
					'url'         => $base_url . $size_meta['file'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4105
					'orientation' => $height > $width ? 'portrait' : 'landscape',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4106
				);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4107
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4108
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4109
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4110
		if ( 'image' === $type ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4111
			if ( ! empty( $meta['original_image'] ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4112
				$response['originalImageURL']  = wp_get_original_image_url( $attachment->ID );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4113
				$response['originalImageName'] = wp_basename( wp_get_original_image_path( $attachment->ID ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4114
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4115
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4116
			$sizes['full'] = array( 'url' => $attachment_url );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4117
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4118
			if ( isset( $meta['height'], $meta['width'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4119
				$sizes['full']['height']      = $meta['height'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4120
				$sizes['full']['width']       = $meta['width'];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4121
				$sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4122
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4123
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4124
			$response = array_merge( $response, $sizes['full'] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4125
		} elseif ( $meta['sizes']['full']['file'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4126
			$sizes['full'] = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4127
				'url'         => $base_url . $meta['sizes']['full']['file'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4128
				'height'      => $meta['sizes']['full']['height'],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4129
				'width'       => $meta['sizes']['full']['width'],
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4130
				'orientation' => $meta['sizes']['full']['height'] > $meta['sizes']['full']['width'] ? 'portrait' : 'landscape',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4131
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4132
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4133
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4134
		$response = array_merge( $response, array( 'sizes' => $sizes ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4135
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4136
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4137
	if ( $meta && 'video' === $type ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4138
		if ( isset( $meta['width'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4139
			$response['width'] = (int) $meta['width'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4140
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4141
		if ( isset( $meta['height'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4142
			$response['height'] = (int) $meta['height'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4143
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4144
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4146
	if ( $meta && ( 'audio' === $type || 'video' === $type ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4147
		if ( isset( $meta['length_formatted'] ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4148
			$response['fileLength']              = $meta['length_formatted'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4149
			$response['fileLengthHumanReadable'] = human_readable_duration( $meta['length_formatted'] );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4150
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4151
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4152
		$response['meta'] = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4153
		foreach ( wp_get_attachment_id3_keys( $attachment, 'js' ) as $key => $label ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4154
			$response['meta'][ $key ] = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4155
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4156
			if ( ! empty( $meta[ $key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4157
				$response['meta'][ $key ] = $meta[ $key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4158
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4159
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4160
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4161
		$id = get_post_thumbnail_id( $attachment->ID );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4162
		if ( ! empty( $id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4163
			list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4164
			$response['image']            = compact( 'src', 'width', 'height' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4165
			list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4166
			$response['thumb']            = compact( 'src', 'width', 'height' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4167
		} else {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4168
			$src               = wp_mime_type_icon( $attachment->ID );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4169
			$width             = 48;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4170
			$height            = 64;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4171
			$response['image'] = compact( 'src', 'width', 'height' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4172
			$response['thumb'] = compact( 'src', 'width', 'height' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4173
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4174
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4175
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4176
	if ( function_exists( 'get_compat_media_markup' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4177
		$response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4178
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4179
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4180
	if ( function_exists( 'get_media_states' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4181
		$media_states = get_media_states( $attachment );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4182
		if ( ! empty( $media_states ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4183
			$response['mediaStates'] = implode( ', ', $media_states );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4184
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4185
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4186
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4187
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4188
	 * Filters the attachment data prepared for JavaScript.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4189
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4190
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4191
	 *
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4192
	 * @param array       $response   Array of prepared attachment data. @see wp_prepare_attachment_for_js().
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4193
	 * @param WP_Post     $attachment Attachment object.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4194
	 * @param array|false $meta       Array of attachment meta data, or false if there is none.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4195
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4196
	return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4197
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4199
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4200
 * Enqueues all scripts, styles, settings, and templates necessary to use
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4201
 * all media JS APIs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4202
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4203
 * @since 3.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4204
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4205
 * @global int       $content_width
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4206
 * @global wpdb      $wpdb          WordPress database abstraction object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4207
 * @global WP_Locale $wp_locale     WordPress date and time locale object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4208
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4209
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4210
 *     Arguments for enqueuing media scripts.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4211
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4212
 *     @type int|WP_Post A post object or ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4213
 * }
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4214
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4215
function wp_enqueue_media( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4216
	// Enqueue me just once per page, please.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4217
	if ( did_action( 'wp_enqueue_media' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4218
		return;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4219
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4220
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4221
	global $content_width, $wpdb, $wp_locale;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4222
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4223
	$defaults = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4224
		'post' => null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4225
	);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4226
	$args     = wp_parse_args( $args, $defaults );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4228
	// We're going to pass the old thickbox media tabs to `media_upload_tabs`
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4229
	// to ensure plugins will work. We will then unset those tabs.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4230
	$tabs = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4231
		// handler action suffix => tab label
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4232
		'type'     => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4233
		'type_url' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4234
		'gallery'  => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4235
		'library'  => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4236
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4237
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4238
	/** This filter is documented in wp-admin/includes/media.php */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4239
	$tabs = apply_filters( 'media_upload_tabs', $tabs );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4240
	unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4242
	$props = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4243
		'link'  => get_option( 'image_default_link_type' ), // DB default is 'file'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4244
		'align' => get_option( 'image_default_align' ),     // Empty default.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4245
		'size'  => get_option( 'image_default_size' ),      // Empty default.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4246
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4247
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4248
	$exts      = array_merge( wp_get_audio_extensions(), wp_get_video_extensions() );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4249
	$mimes     = get_allowed_mime_types();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4250
	$ext_mimes = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4251
	foreach ( $exts as $ext ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4252
		foreach ( $mimes as $ext_preg => $mime_match ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4253
			if ( preg_match( '#' . $ext . '#i', $ext_preg ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4254
				$ext_mimes[ $ext ] = $mime_match;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4255
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4256
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4257
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4258
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4259
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4260
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4261
	 * Allows showing or hiding the "Create Audio Playlist" button in the media library.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4262
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4263
	 * By default, the "Create Audio Playlist" button will always be shown in
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4264
	 * the media library.  If this filter returns `null`, a query will be run
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4265
	 * to determine whether the media library contains any audio items.  This
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4266
	 * was the default behavior prior to version 4.8.0, but this query is
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4267
	 * expensive for large media libraries.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4268
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4269
	 * @since 4.7.4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4270
	 * @since 4.8.0 The filter's default value is `true` rather than `null`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4271
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4272
	 * @link https://core.trac.wordpress.org/ticket/31071
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4273
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4274
	 * @param bool|null $show Whether to show the button, or `null` to decide based
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4275
	 *                        on whether any audio files exist in the media library.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4276
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4277
	$show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4278
	if ( null === $show_audio_playlist ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4279
		$show_audio_playlist = $wpdb->get_var(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4280
			"
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4281
			SELECT ID
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4282
			FROM $wpdb->posts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4283
			WHERE post_type = 'attachment'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4284
			AND post_mime_type LIKE 'audio%'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4285
			LIMIT 1
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4286
		"
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4287
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4288
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4289
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4290
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4291
	 * Allows showing or hiding the "Create Video Playlist" button in the media library.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4292
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4293
	 * By default, the "Create Video Playlist" button will always be shown in
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4294
	 * the media library.  If this filter returns `null`, a query will be run
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4295
	 * to determine whether the media library contains any video items.  This
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4296
	 * was the default behavior prior to version 4.8.0, but this query is
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4297
	 * expensive for large media libraries.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4298
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4299
	 * @since 4.7.4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4300
	 * @since 4.8.0 The filter's default value is `true` rather than `null`.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4301
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4302
	 * @link https://core.trac.wordpress.org/ticket/31071
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4303
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4304
	 * @param bool|null $show Whether to show the button, or `null` to decide based
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4305
	 *                        on whether any video files exist in the media library.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4306
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4307
	$show_video_playlist = apply_filters( 'media_library_show_video_playlist', true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4308
	if ( null === $show_video_playlist ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4309
		$show_video_playlist = $wpdb->get_var(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4310
			"
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4311
			SELECT ID
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4312
			FROM $wpdb->posts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4313
			WHERE post_type = 'attachment'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4314
			AND post_mime_type LIKE 'video%'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4315
			LIMIT 1
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4316
		"
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4317
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4318
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4319
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4320
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4321
	 * Allows overriding the list of months displayed in the media library.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4322
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4323
	 * By default (if this filter does not return an array), a query will be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4324
	 * run to determine the months that have media items.  This query can be
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4325
	 * expensive for large media libraries, so it may be desirable for sites to
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4326
	 * override this behavior.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4327
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4328
	 * @since 4.7.4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4329
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4330
	 * @link https://core.trac.wordpress.org/ticket/31071
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4331
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4332
	 * @param array|null $months An array of objects with `month` and `year`
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4333
	 *                           properties, or `null` (or any other non-array value)
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4334
	 *                           for default behavior.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4335
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4336
	$months = apply_filters( 'media_library_months_with_files', null );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4337
	if ( ! is_array( $months ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4338
		$months = $wpdb->get_results(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4339
			$wpdb->prepare(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4340
				"
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4341
			SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4342
			FROM $wpdb->posts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4343
			WHERE post_type = %s
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4344
			ORDER BY post_date DESC
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4345
		",
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4346
				'attachment'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4347
			)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4348
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4349
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4350
	foreach ( $months as $month_year ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4351
		$month_year->text = sprintf(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4352
			/* translators: 1: Month, 2: Year. */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4353
			__( '%1$s %2$d' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4354
			$wp_locale->get_month( $month_year->month ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4355
			$month_year->year
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4356
		);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4357
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4358
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4359
	/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4360
	 * Filters whether the Media Library grid has infinite scrolling. Default `false`.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4361
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4362
	 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4363
	 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4364
	 * @param bool $infinite Whether the Media Library grid has infinite scrolling.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4365
	 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4366
	$infinite_scrolling = apply_filters( 'media_library_infinite_scrolling', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4367
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4368
	$settings = array(
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4369
		'tabs'              => $tabs,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4370
		'tabUrl'            => add_query_arg( array( 'chromeless' => true ), admin_url( 'media-upload.php' ) ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4371
		'mimeTypes'         => wp_list_pluck( get_post_mime_types(), 0 ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4372
		/** This filter is documented in wp-admin/includes/media.php */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4373
		'captions'          => ! apply_filters( 'disable_captions', '' ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4374
		'nonce'             => array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4375
			'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4376
		),
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4377
		'post'              => array(
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4378
			'id' => 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4379
		),
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4380
		'defaultProps'      => $props,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4381
		'attachmentCounts'  => array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4382
			'audio' => ( $show_audio_playlist ) ? 1 : 0,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4383
			'video' => ( $show_video_playlist ) ? 1 : 0,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4384
		),
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4385
		'oEmbedProxyUrl'    => rest_url( 'oembed/1.0/proxy' ),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4386
		'embedExts'         => $exts,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4387
		'embedMimes'        => $ext_mimes,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4388
		'contentWidth'      => $content_width,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4389
		'months'            => $months,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4390
		'mediaTrash'        => MEDIA_TRASH ? 1 : 0,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4391
		'infiniteScrolling' => ( $infinite_scrolling ) ? 1 : 0,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4392
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4393
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4394
	$post = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4395
	if ( isset( $args['post'] ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4396
		$post             = get_post( $args['post'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4397
		$settings['post'] = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4398
			'id'    => $post->ID,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4399
			'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4400
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4401
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4402
		$thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4403
		if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4404
			if ( wp_attachment_is( 'audio', $post ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4405
				$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4406
			} elseif ( wp_attachment_is( 'video', $post ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4407
				$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4408
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4409
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4410
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4411
		if ( $thumbnail_support ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4412
			$featured_image_id                   = get_post_meta( $post->ID, '_thumbnail_id', true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4413
			$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4414
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4415
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4416
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4417
	if ( $post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4418
		$post_type_object = get_post_type_object( $post->post_type );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4419
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4420
		$post_type_object = get_post_type_object( 'post' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4421
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4423
	$strings = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4424
		// Generic.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4425
		'mediaFrameDefaultTitle'      => __( 'Media' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4426
		'url'                         => __( 'URL' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4427
		'addMedia'                    => __( 'Add media' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4428
		'search'                      => __( 'Search' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4429
		'select'                      => __( 'Select' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4430
		'cancel'                      => __( 'Cancel' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4431
		'update'                      => __( 'Update' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4432
		'replace'                     => __( 'Replace' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4433
		'remove'                      => __( 'Remove' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4434
		'back'                        => __( 'Back' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4435
		/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4436
		 * translators: This is a would-be plural string used in the media manager.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4437
		 * If there is not a word you can use in your language to avoid issues with the
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4438
		 * lack of plural support here, turn it into "selected: %d" then translate it.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4439
		 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4440
		'selected'                    => __( '%d selected' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4441
		'dragInfo'                    => __( 'Drag and drop to reorder media files.' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4442
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4443
		// Upload.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4444
		'uploadFilesTitle'            => __( 'Upload files' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4445
		'uploadImagesTitle'           => __( 'Upload images' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4446
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4447
		// Library.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4448
		'mediaLibraryTitle'           => __( 'Media Library' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4449
		'insertMediaTitle'            => __( 'Add media' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4450
		'createNewGallery'            => __( 'Create a new gallery' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4451
		'createNewPlaylist'           => __( 'Create a new playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4452
		'createNewVideoPlaylist'      => __( 'Create a new video playlist' ),
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4453
		'returnToLibrary'             => __( '&#8592; Go to library' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4454
		'allMediaItems'               => __( 'All media items' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4455
		'allDates'                    => __( 'All dates' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4456
		'noItemsFound'                => __( 'No items found.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4457
		'insertIntoPost'              => $post_type_object->labels->insert_into_item,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4458
		'unattached'                  => __( 'Unattached' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4459
		'mine'                        => _x( 'Mine', 'media items' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4460
		'trash'                       => _x( 'Trash', 'noun' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4461
		'uploadedToThisPost'          => $post_type_object->labels->uploaded_to_this_item,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4462
		'warnDelete'                  => __( "You are about to permanently delete this item from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4463
		'warnBulkDelete'              => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4464
		'warnBulkTrash'               => __( "You are about to trash these items.\n  'Cancel' to stop, 'OK' to delete." ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4465
		'bulkSelect'                  => __( 'Bulk select' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4466
		'trashSelected'               => __( 'Move to Trash' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4467
		'restoreSelected'             => __( 'Restore from Trash' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4468
		'deletePermanently'           => __( 'Delete permanently' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4469
		'apply'                       => __( 'Apply' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4470
		'filterByDate'                => __( 'Filter by date' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4471
		'filterByType'                => __( 'Filter by type' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4472
		'searchLabel'                 => __( 'Search' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4473
		'searchMediaLabel'            => __( 'Search media' ),          // Backward compatibility pre-5.3.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4474
		'searchMediaPlaceholder'      => __( 'Search media items...' ), // Placeholder (no ellipsis), backward compatibility pre-5.3.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4475
		/* translators: %d: Number of attachments found in a search. */
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4476
		'mediaFound'                  => __( 'Number of media items found: %d' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4477
		'noMedia'                     => __( 'No media items found.' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4478
		'noMediaTryNewSearch'         => __( 'No media items found. Try a different search.' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4479
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4480
		// Library Details.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4481
		'attachmentDetails'           => __( 'Attachment details' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4482
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4483
		// From URL.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4484
		'insertFromUrlTitle'          => __( 'Insert from URL' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4485
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4486
		// Featured Images.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4487
		'setFeaturedImageTitle'       => $post_type_object->labels->featured_image,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4488
		'setFeaturedImage'            => $post_type_object->labels->set_featured_image,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4489
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4490
		// Gallery.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4491
		'createGalleryTitle'          => __( 'Create gallery' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4492
		'editGalleryTitle'            => __( 'Edit gallery' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4493
		'cancelGalleryTitle'          => __( '&#8592; Cancel gallery' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4494
		'insertGallery'               => __( 'Insert gallery' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4495
		'updateGallery'               => __( 'Update gallery' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4496
		'addToGallery'                => __( 'Add to gallery' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4497
		'addToGalleryTitle'           => __( 'Add to gallery' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4498
		'reverseOrder'                => __( 'Reverse order' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4499
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4500
		// Edit Image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4501
		'imageDetailsTitle'           => __( 'Image details' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4502
		'imageReplaceTitle'           => __( 'Replace image' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4503
		'imageDetailsCancel'          => __( 'Cancel edit' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4504
		'editImage'                   => __( 'Edit image' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4505
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4506
		// Crop Image.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4507
		'chooseImage'                 => __( 'Choose image' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4508
		'selectAndCrop'               => __( 'Select and crop' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4509
		'skipCropping'                => __( 'Skip cropping' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4510
		'cropImage'                   => __( 'Crop image' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4511
		'cropYourImage'               => __( 'Crop your image' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4512
		'cropping'                    => __( 'Cropping&hellip;' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4513
		/* translators: 1: Suggested width number, 2: Suggested height number. */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4514
		'suggestedDimensions'         => __( 'Suggested image dimensions: %1$s by %2$s pixels.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4515
		'cropError'                   => __( 'There has been an error cropping your image.' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4516
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4517
		// Edit Audio.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4518
		'audioDetailsTitle'           => __( 'Audio details' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4519
		'audioReplaceTitle'           => __( 'Replace audio' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4520
		'audioAddSourceTitle'         => __( 'Add audio source' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4521
		'audioDetailsCancel'          => __( 'Cancel edit' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4522
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4523
		// Edit Video.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4524
		'videoDetailsTitle'           => __( 'Video details' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4525
		'videoReplaceTitle'           => __( 'Replace video' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4526
		'videoAddSourceTitle'         => __( 'Add video source' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4527
		'videoDetailsCancel'          => __( 'Cancel edit' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4528
		'videoSelectPosterImageTitle' => __( 'Select poster image' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4529
		'videoAddTrackTitle'          => __( 'Add subtitles' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4530
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4531
		// Playlist.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4532
		'playlistDragInfo'            => __( 'Drag and drop to reorder tracks.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4533
		'createPlaylistTitle'         => __( 'Create audio playlist' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4534
		'editPlaylistTitle'           => __( 'Edit audio playlist' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4535
		'cancelPlaylistTitle'         => __( '&#8592; Cancel audio playlist' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4536
		'insertPlaylist'              => __( 'Insert audio playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4537
		'updatePlaylist'              => __( 'Update audio playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4538
		'addToPlaylist'               => __( 'Add to audio playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4539
		'addToPlaylistTitle'          => __( 'Add to Audio Playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4540
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4541
		// Video Playlist.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4542
		'videoPlaylistDragInfo'       => __( 'Drag and drop to reorder videos.' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4543
		'createVideoPlaylistTitle'    => __( 'Create video playlist' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4544
		'editVideoPlaylistTitle'      => __( 'Edit video playlist' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4545
		'cancelVideoPlaylistTitle'    => __( '&#8592; Cancel video playlist' ),
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4546
		'insertVideoPlaylist'         => __( 'Insert video playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4547
		'updateVideoPlaylist'         => __( 'Update video playlist' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4548
		'addToVideoPlaylist'          => __( 'Add to video playlist' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4549
		'addToVideoPlaylistTitle'     => __( 'Add to video Playlist' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4550
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4551
		// Headings.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4552
		'filterAttachments'           => __( 'Filter media' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4553
		'attachmentsList'             => __( 'Media list' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4554
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4555
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4556
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4557
	 * Filters the media view settings.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4558
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4559
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4560
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4561
	 * @param array   $settings List of media view settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4562
	 * @param WP_Post $post     Post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4563
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4564
	$settings = apply_filters( 'media_view_settings', $settings, $post );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4565
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4566
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4567
	 * Filters the media view strings.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4568
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4569
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4570
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4571
	 * @param string[] $strings Array of media view strings keyed by the name they'll be referenced by in JavaScript.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4572
	 * @param WP_Post  $post    Post object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4573
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4574
	$strings = apply_filters( 'media_view_strings', $strings, $post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4575
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4576
	$strings['settings'] = $settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4577
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4578
	// Ensure we enqueue media-editor first, that way media-views
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4579
	// is registered internally before we try to localize it. See #24724.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4580
	wp_enqueue_script( 'media-editor' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4581
	wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4582
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4583
	wp_enqueue_script( 'media-audiovideo' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4584
	wp_enqueue_style( 'media-views' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4585
	if ( is_admin() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4586
		wp_enqueue_script( 'mce-view' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4587
		wp_enqueue_script( 'image-edit' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4588
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4589
	wp_enqueue_style( 'imgareaselect' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4590
	wp_plupload_default_settings();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4591
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4592
	require_once ABSPATH . WPINC . '/media-template.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4593
	add_action( 'admin_footer', 'wp_print_media_templates' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4594
	add_action( 'wp_footer', 'wp_print_media_templates' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4595
	add_action( 'customize_controls_print_footer_scripts', 'wp_print_media_templates' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4596
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4597
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4598
	 * Fires at the conclusion of wp_enqueue_media().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4599
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4600
	 * @since 3.5.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4601
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4602
	do_action( 'wp_enqueue_media' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4603
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4604
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4605
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4606
 * Retrieves media attached to the passed post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4607
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4608
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4609
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4610
 * @param string      $type Mime type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4611
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4612
 * @return WP_Post[] Array of media attached to the given post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4613
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4614
function get_attached_media( $type, $post = 0 ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4615
	$post = get_post( $post );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4616
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4617
	if ( ! $post ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4618
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4619
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4620
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4621
	$args = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4622
		'post_parent'    => $post->ID,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4623
		'post_type'      => 'attachment',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4624
		'post_mime_type' => $type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4625
		'posts_per_page' => -1,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4626
		'orderby'        => 'menu_order',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4627
		'order'          => 'ASC',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4628
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4629
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4630
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4631
	 * Filters arguments used to retrieve media attached to the given post.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4632
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4633
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4634
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4635
	 * @param array   $args Post query arguments.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4636
	 * @param string  $type Mime type of the desired media.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4637
	 * @param WP_Post $post Post object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4638
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4639
	$args = apply_filters( 'get_attached_media_args', $args, $type, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4640
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4641
	$children = get_children( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4642
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4643
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4644
	 * Filters the list of media attached to the given post.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4645
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4646
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4647
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4648
	 * @param WP_Post[] $children Array of media attached to the given post.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4649
	 * @param string    $type     Mime type of the media desired.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4650
	 * @param WP_Post   $post     Post object.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4651
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4652
	return (array) apply_filters( 'get_attached_media', $children, $type, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4653
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4654
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4655
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4656
 * Check the content HTML for a audio, video, object, embed, or iframe tags.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4657
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4658
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4659
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4660
 * @param string   $content A string of HTML which might contain media elements.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4661
 * @param string[] $types   An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4662
 * @return string[] Array of found HTML media elements.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4663
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4664
function get_media_embedded_in_content( $content, $types = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4665
	$html = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4666
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4667
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4668
	 * Filters the embedded media types that are allowed to be returned from the content blob.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4669
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4670
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4671
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4672
	 * @param string[] $allowed_media_types An array of allowed media types. Default media types are
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4673
	 *                                      'audio', 'video', 'object', 'embed', and 'iframe'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4674
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4675
	$allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4676
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4677
	if ( ! empty( $types ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4678
		if ( ! is_array( $types ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4679
			$types = array( $types );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4680
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4681
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4682
		$allowed_media_types = array_intersect( $allowed_media_types, $types );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4683
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4684
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4685
	$tags = implode( '|', $allowed_media_types );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4686
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4687
	if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4688
		foreach ( $matches[0] as $match ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4689
			$html[] = $match;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4690
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4691
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4692
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4693
	return $html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4694
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4696
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4697
 * Retrieves galleries from the passed post's content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4698
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4699
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4700
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4701
 * @param int|WP_Post $post Post ID or object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4702
 * @param bool        $html Optional. Whether to return HTML or data in the array. Default true.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4703
 * @return array A list of arrays, each containing gallery data and srcs parsed
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4704
 *               from the expanded shortcode.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4705
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4706
function get_post_galleries( $post, $html = true ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4707
	$post = get_post( $post );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4708
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4709
	if ( ! $post ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4710
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4711
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4712
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4713
	if ( ! has_shortcode( $post->post_content, 'gallery' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4714
		return array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4715
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4716
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4717
	$galleries = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4718
	if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4719
		foreach ( $matches as $shortcode ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4720
			if ( 'gallery' === $shortcode[2] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4721
				$srcs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4722
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4723
				$shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4724
				if ( ! is_array( $shortcode_attrs ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4725
					$shortcode_attrs = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4726
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4727
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4728
				// Specify the post ID of the gallery we're viewing if the shortcode doesn't reference another post already.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4729
				if ( ! isset( $shortcode_attrs['id'] ) ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  4730
					$shortcode[3] .= ' id="' . (int) $post->ID . '"';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4731
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4732
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4733
				$gallery = do_shortcode_tag( $shortcode );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4734
				if ( $html ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4735
					$galleries[] = $gallery;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4736
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4737
					preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4738
					if ( ! empty( $src ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4739
						foreach ( $src as $s ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4740
							$srcs[] = $s[2];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4741
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4742
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4743
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4744
					$galleries[] = array_merge(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4745
						$shortcode_attrs,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4746
						array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4747
							'src' => array_values( array_unique( $srcs ) ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4748
						)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4749
					);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4750
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4751
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4752
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4753
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4754
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4755
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4756
	 * Filters the list of all found galleries in the given post.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4757
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4758
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4759
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4760
	 * @param array   $galleries Associative array of all found post galleries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4761
	 * @param WP_Post $post      Post object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4762
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4763
	return apply_filters( 'get_post_galleries', $galleries, $post );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4764
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4765
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4766
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4767
 * Check a specified post's content for gallery and, if present, return the first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4768
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4769
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4770
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4771
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4772
 * @param bool        $html Optional. Whether to return HTML or data. Default is true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4773
 * @return string|array Gallery data and srcs parsed from the expanded shortcode.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4774
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4775
function get_post_gallery( $post = 0, $html = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4776
	$galleries = get_post_galleries( $post, $html );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4777
	$gallery   = reset( $galleries );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4778
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4779
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4780
	 * Filters the first-found post gallery.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4781
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4782
	 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4783
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4784
	 * @param array       $gallery   The first-found post gallery.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4785
	 * @param int|WP_Post $post      Post ID or object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4786
	 * @param array       $galleries Associative array of all found post galleries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4787
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4788
	return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4789
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4790
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4791
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4792
 * Retrieve the image srcs from galleries from a post's content, if present
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4793
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4794
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4795
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4796
 * @see get_post_galleries()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4797
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4798
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4799
 * @return array A list of lists, each containing image srcs parsed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4800
 *               from an expanded shortcode
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4801
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4802
function get_post_galleries_images( $post = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4803
	$galleries = get_post_galleries( $post, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4804
	return wp_list_pluck( $galleries, 'src' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4805
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4807
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4808
 * Checks a post's content for galleries and return the image srcs for the first found gallery
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4809
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4810
 * @since 3.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4811
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4812
 * @see get_post_gallery()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4813
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4814
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4815
 * @return string[] A list of a gallery's image srcs in order.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4816
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4817
function get_post_gallery_images( $post = 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4818
	$gallery = get_post_gallery( $post, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4819
	return empty( $gallery['src'] ) ? array() : $gallery['src'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  4820
}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4821
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4822
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4823
 * Maybe attempts to generate attachment metadata, if missing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4824
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4825
 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4826
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4827
 * @param WP_Post $attachment Attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4828
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4829
function wp_maybe_generate_attachment_metadata( $attachment ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4830
	if ( empty( $attachment ) || empty( $attachment->ID ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4831
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4832
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4833
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4834
	$attachment_id = (int) $attachment->ID;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4835
	$file          = get_attached_file( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4836
	$meta          = wp_get_attachment_metadata( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4837
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4838
	if ( empty( $meta ) && file_exists( $file ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4839
		$_meta = get_post_meta( $attachment_id );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4840
		$_lock = 'wp_generating_att_' . $attachment_id;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4841
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4842
		if ( ! array_key_exists( '_wp_attachment_metadata', $_meta ) && ! get_transient( $_lock ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4843
			set_transient( $_lock, $file );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4844
			wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4845
			delete_transient( $_lock );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4846
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4847
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4848
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4849
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4850
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4851
 * Tries to convert an attachment URL into a post ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4852
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4853
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4854
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4855
 * @global wpdb $wpdb WordPress database abstraction object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4856
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4857
 * @param string $url The URL to resolve.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4858
 * @return int The found post ID, or 0 on failure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4859
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4860
function attachment_url_to_postid( $url ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4861
	global $wpdb;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4862
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4863
	$dir  = wp_get_upload_dir();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4864
	$path = $url;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4865
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4866
	$site_url   = parse_url( $dir['url'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4867
	$image_path = parse_url( $path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4868
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4869
	// Force the protocols to match if needed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4870
	if ( isset( $image_path['scheme'] ) && ( $image_path['scheme'] !== $site_url['scheme'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4871
		$path = str_replace( $image_path['scheme'], $site_url['scheme'], $path );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4872
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4873
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4874
	if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4875
		$path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4876
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4877
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4878
	$sql = $wpdb->prepare(
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4879
		"SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4880
		$path
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4881
	);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4882
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4883
	$results = $wpdb->get_results( $sql );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4884
	$post_id = null;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4885
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4886
	if ( $results ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4887
		// Use the first available result, but prefer a case-sensitive match, if exists.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4888
		$post_id = reset( $results )->post_id;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4889
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4890
		if ( count( $results ) > 1 ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4891
			foreach ( $results as $result ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4892
				if ( $path === $result->meta_value ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4893
					$post_id = $result->post_id;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4894
					break;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4895
				}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4896
			}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4897
		}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4898
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4899
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4900
	/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4901
	 * Filters an attachment ID found by URL.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4902
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4903
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4904
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4905
	 * @param int|null $post_id The post_id (if any) found by the function.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4906
	 * @param string   $url     The URL being looked up.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4907
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4908
	return (int) apply_filters( 'attachment_url_to_postid', $post_id, $url );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4909
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4910
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4911
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4912
 * Returns the URLs for CSS files used in an iframe-sandbox'd TinyMCE media view.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4913
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4914
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4915
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4916
 * @return string[] The relevant CSS file URLs.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4917
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4918
function wpview_media_sandbox_styles() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4919
	$version        = 'ver=' . get_bloginfo( 'version' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4920
	$mediaelement   = includes_url( "js/mediaelement/mediaelementplayer-legacy.min.css?$version" );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4921
	$wpmediaelement = includes_url( "js/mediaelement/wp-mediaelement.css?$version" );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4922
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4923
	return array( $mediaelement, $wpmediaelement );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  4924
}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4925
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4926
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4927
 * Registers the personal data exporter for media.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4928
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4929
 * @param array[] $exporters An array of personal data exporters, keyed by their ID.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4930
 * @return array[] Updated array of personal data exporters.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4931
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4932
function wp_register_media_personal_data_exporter( $exporters ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4933
	$exporters['wordpress-media'] = array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4934
		'exporter_friendly_name' => __( 'WordPress Media' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4935
		'callback'               => 'wp_media_personal_data_exporter',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4936
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4937
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4938
	return $exporters;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4939
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4940
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4941
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4942
 * Finds and exports attachments associated with an email address.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4943
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4944
 * @since 4.9.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4945
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4946
 * @param string $email_address The attachment owner email address.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4947
 * @param int    $page          Attachment page.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4948
 * @return array An array of personal data.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4949
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4950
function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4951
	// Limit us to 50 attachments at a time to avoid timing out.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4952
	$number = 50;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4953
	$page   = (int) $page;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4954
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4955
	$data_to_export = array();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4956
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4957
	$user = get_user_by( 'email', $email_address );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4958
	if ( false === $user ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4959
		return array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4960
			'data' => $data_to_export,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4961
			'done' => true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4962
		);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4963
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4964
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4965
	$post_query = new WP_Query(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4966
		array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4967
			'author'         => $user->ID,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4968
			'posts_per_page' => $number,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4969
			'paged'          => $page,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4970
			'post_type'      => 'attachment',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4971
			'post_status'    => 'any',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4972
			'orderby'        => 'ID',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4973
			'order'          => 'ASC',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4974
		)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4975
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4976
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4977
	foreach ( (array) $post_query->posts as $post ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4978
		$attachment_url = wp_get_attachment_url( $post->ID );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4979
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4980
		if ( $attachment_url ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4981
			$post_data_to_export = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4982
				array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4983
					'name'  => __( 'URL' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4984
					'value' => $attachment_url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  4985
				),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4986
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4987
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4988
			$data_to_export[] = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4989
				'group_id'          => 'media',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4990
				'group_label'       => __( 'Media' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4991
				'group_description' => __( 'User&#8217;s media data.' ),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4992
				'item_id'           => "post-{$post->ID}",
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  4993
				'data'              => $post_data_to_export,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4994
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4995
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4996
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4997
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4998
	$done = $post_query->max_num_pages <= $page;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  4999
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5000
	return array(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5001
		'data' => $data_to_export,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5002
		'done' => $done,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5003
	);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  5004
}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5005
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5006
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5007
 * Add additional default image sub-sizes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5008
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5009
 * These sizes are meant to enhance the way WordPress displays images on the front-end on larger,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5010
 * high-density devices. They make it possible to generate more suitable `srcset` and `sizes` attributes
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5011
 * when the users upload large images.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5012
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5013
 * The sizes can be changed or removed by themes and plugins but that is not recommended.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5014
 * The size "names" reflect the image dimensions, so changing the sizes would be quite misleading.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5015
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5016
 * @since 5.3.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5017
 * @access private
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5018
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5019
function _wp_add_additional_image_sizes() {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5020
	// 2x medium_large size.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5021
	add_image_size( '1536x1536', 1536, 1536 );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5022
	// 2x large size.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5023
	add_image_size( '2048x2048', 2048, 2048 );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5024
}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5025
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5026
/**
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5027
 * Callback to enable showing of the user error when uploading .heic images.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5028
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5029
 * @since 5.5.0
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5030
 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5031
 * @param array[] $plupload_settings The settings for Plupload.js.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5032
 * @return array[] Modified settings for Plupload.js.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5033
 */
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5034
function wp_show_heic_upload_error( $plupload_settings ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5035
	$plupload_settings['heic_upload_error'] = true;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5036
	return $plupload_settings;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  5037
}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5038
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5039
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5040
 * Allows PHP's getimagesize() to be debuggable when necessary.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5041
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5042
 * @since 5.7.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5043
 * @since 5.8.0 Added support for WebP images.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5044
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5045
 * @param string $filename   The file path.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5046
 * @param array  $image_info Optional. Extended image information (passed by reference).
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5047
 * @return array|false Array of image information or false on failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5048
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5049
function wp_getimagesize( $filename, array &$image_info = null ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5050
	// Don't silence errors when in debug mode, unless running unit tests.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5051
	if ( defined( 'WP_DEBUG' ) && WP_DEBUG
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5052
		&& ! defined( 'WP_RUN_CORE_TESTS' )
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5053
	) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5054
		if ( 2 === func_num_args() ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5055
			$info = getimagesize( $filename, $image_info );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5056
		} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5057
			$info = getimagesize( $filename );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5058
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5059
	} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5060
		/*
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5061
		 * Silencing notice and warning is intentional.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5062
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5063
		 * getimagesize() has a tendency to generate errors, such as
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5064
		 * "corrupt JPEG data: 7191 extraneous bytes before marker",
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5065
		 * even when it's able to provide image size information.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5066
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5067
		 * See https://core.trac.wordpress.org/ticket/42480
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5068
		 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5069
		if ( 2 === func_num_args() ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5070
			// phpcs:ignore WordPress.PHP.NoSilencedErrors
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5071
			$info = @getimagesize( $filename, $image_info );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5072
		} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5073
			// phpcs:ignore WordPress.PHP.NoSilencedErrors
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5074
			$info = @getimagesize( $filename );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5075
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5076
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5077
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5078
	if ( false !== $info ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5079
		return $info;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5080
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5081
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5082
	// For PHP versions that don't support WebP images,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5083
	// extract the image size info from the file headers.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5084
	if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5085
		$webp_info = wp_get_webp_info( $filename );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5086
		$width     = $webp_info['width'];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5087
		$height    = $webp_info['height'];
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5088
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5089
		// Mimic the native return format.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5090
		if ( $width && $height ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5091
			return array(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5092
				$width,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5093
				$height,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5094
				IMAGETYPE_WEBP, // phpcs:ignore PHPCompatibility.Constants.NewConstants.imagetype_webpFound
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5095
				sprintf(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5096
					'width="%d" height="%d"',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5097
					$width,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5098
					$height
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5099
				),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5100
				'mime' => 'image/webp',
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5101
			);
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5102
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5103
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5104
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5105
	// The image could not be parsed.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5106
	return false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5107
}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5108
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5109
/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5110
 * Extracts meta information about a webp file: width, height and type.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5111
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5112
 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5113
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5114
 * @param string $filename Path to a WebP file.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5115
 * @return array $webp_info {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5116
 *     An array of WebP image information.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5117
 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5118
 *     @type array $size {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5119
 *         @type int|false    $width  Image width on success, false on failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5120
 *         @type int|false    $height Image height on success, false on failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5121
 *         @type string|false $type   The WebP type: one of 'lossy', 'lossless' or 'animated-alpha'.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5122
 *                                    False on failure.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5123
 *     }
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5124
 */
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5125
function wp_get_webp_info( $filename ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5126
	$width  = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5127
	$height = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5128
	$type   = false;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5129
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5130
	if ( 'image/webp' !== wp_get_image_mime( $filename ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5131
		return compact( 'width', 'height', 'type' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5132
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5133
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5134
	try {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5135
		$handle = fopen( $filename, 'rb' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5136
		if ( $handle ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5137
			$magic = fread( $handle, 40 );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5138
			fclose( $handle );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5139
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5140
			// Make sure we got enough bytes.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5141
			if ( strlen( $magic ) < 40 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5142
				return compact( 'width', 'height', 'type' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5143
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5144
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5145
			// The headers are a little different for each of the three formats.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5146
			// Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5147
			switch ( substr( $magic, 12, 4 ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5148
				// Lossy WebP.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5149
				case 'VP8 ':
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5150
					$parts  = unpack( 'v2', substr( $magic, 26, 4 ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5151
					$width  = (int) ( $parts[1] & 0x3FFF );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5152
					$height = (int) ( $parts[2] & 0x3FFF );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5153
					$type   = 'lossy';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5154
					break;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5155
				// Lossless WebP.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5156
				case 'VP8L':
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5157
					$parts  = unpack( 'C4', substr( $magic, 21, 4 ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5158
					$width  = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5159
					$height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5160
					$type   = 'lossless';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5161
					break;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5162
				// Animated/alpha WebP.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5163
				case 'VP8X':
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5164
					// Pad 24-bit int.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5165
					$width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5166
					$width = (int) ( $width[1] & 0xFFFFFF ) + 1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5167
					// Pad 24-bit int.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5168
					$height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5169
					$height = (int) ( $height[1] & 0xFFFFFF ) + 1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5170
					$type   = 'animated-alpha';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5171
					break;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5172
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5173
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5174
	} catch ( Exception $e ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5175
	}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5176
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5177
	return compact( 'width', 'height', 'type' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  5178
}