Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/interact.../src/Plugin
File: Field.php
<?php
[0] Fix | Delete
namespace Saltus\WP\Plugin\Saltus\InteractiveMaps\Plugin;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* Wrapper for meta fields
[4] Fix | Delete
*
[5] Fix | Delete
*/
[6] Fix | Delete
class Field {
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Wrapper for get_post_meta.
[10] Fix | Delete
*
[11] Fix | Delete
* Retrieve post meta field for a post.
[12] Fix | Delete
*
[13] Fix | Delete
* @see get_post_meta
[14] Fix | Delete
*
[15] Fix | Delete
* @param int $post_id Post ID.
[16] Fix | Delete
* @param string $key Optional. The meta key to retrieve. By default, returns
[17] Fix | Delete
* data for all keys. Default empty.
[18] Fix | Delete
* @param bool $single Optional. Whether to return a single value. Default false.
[19] Fix | Delete
* @return mixed Will be an array if $single is false. Will be value of meta data
[20] Fix | Delete
* field if $single is true.
[21] Fix | Delete
*/
[22] Fix | Delete
public static function get( int $post_id, string $key = '', bool $single = false ) {
[23] Fix | Delete
[24] Fix | Delete
return get_post_meta( $post_id, $key, $single );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Wrapper for get_post_meta.
[29] Fix | Delete
*
[30] Fix | Delete
* Retrieve **all** post meta fields for a post.
[31] Fix | Delete
*
[32] Fix | Delete
* @see get_post_meta
[33] Fix | Delete
*
[34] Fix | Delete
* @param int $post_id Post ID.
[35] Fix | Delete
* @return array All the post meta values, in a multidimensional array.
[36] Fix | Delete
*/
[37] Fix | Delete
public static function get_all( int $post_id ) {
[38] Fix | Delete
[39] Fix | Delete
return get_post_meta( $post_id );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Parses the postmeta array, and returns a text value
[44] Fix | Delete
*
[45] Fix | Delete
* @param array $postmeta A multidemensional array with meta fields
[46] Fix | Delete
* @param string $meta_key The key for the meta field
[47] Fix | Delete
* @return string The value for the supplied key, else empty if nothing found.
[48] Fix | Delete
*/
[49] Fix | Delete
public static function get_meta_text( array $postmeta, string $meta_key ) {
[50] Fix | Delete
$value = '';
[51] Fix | Delete
if ( ! empty( $postmeta[ $meta_key ][0] ) ) {
[52] Fix | Delete
$value = $postmeta[ $meta_key ][0];
[53] Fix | Delete
}
[54] Fix | Delete
return $value;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Parses the postmeta array, and returns a image tag
[59] Fix | Delete
*
[60] Fix | Delete
* @param array $postmeta A multidemensional array with meta fields
[61] Fix | Delete
* @param string $meta_key The key for the meta field
[62] Fix | Delete
* @param string $size Optional. An existing image size. Defaults to 'full'.
[63] Fix | Delete
* @return string A string with the img tag
[64] Fix | Delete
*/
[65] Fix | Delete
public static function get_meta_img( array $postmeta, string $meta_key, string $size = 'full' ) {
[66] Fix | Delete
[67] Fix | Delete
$image_src = self::get_meta_img_src( $postmeta, $meta_key, $size );
[68] Fix | Delete
if ( empty( $image_src ) ) {
[69] Fix | Delete
return '';
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$image_id = self::get_meta_img_id( $postmeta, $meta_key );
[73] Fix | Delete
$image_alt = '';
[74] Fix | Delete
if ( ! empty( $image_id ) ) {
[75] Fix | Delete
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
return sprintf(
[79] Fix | Delete
'<img src="%1$s" alt="%2$s">',
[80] Fix | Delete
esc_url( $image_src ),
[81] Fix | Delete
esc_attr( $image_alt )
[82] Fix | Delete
);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Parses the postmeta array, and returns an image id
[87] Fix | Delete
*
[88] Fix | Delete
* @param array $postmeta A multidemensional array with meta fields
[89] Fix | Delete
* @param string $meta_key The key for the meta field
[90] Fix | Delete
* @return string The image id
[91] Fix | Delete
*/
[92] Fix | Delete
protected static function get_meta_img_id( array $postmeta, string $meta_key ) {
[93] Fix | Delete
[94] Fix | Delete
$meta_key_id = $meta_key . '_id';
[95] Fix | Delete
if ( empty( $postmeta[ $meta_key_id ][0] ) ) {
[96] Fix | Delete
return '';
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
return $postmeta[ $meta_key_id ][0];
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Parses the postmeta array, and returns a image src.
[105] Fix | Delete
*
[106] Fix | Delete
* @param array $postmeta A multidemensional array with meta fields
[107] Fix | Delete
* @param string $meta_key The key for the meta field
[108] Fix | Delete
* @param string $size Optional. An existing image size. Defaults to 'full'.
[109] Fix | Delete
* @return string A URL for the image src
[110] Fix | Delete
*/
[111] Fix | Delete
public static function get_meta_img_src( array $postmeta, string $meta_key, string $size = 'full' ) {
[112] Fix | Delete
[113] Fix | Delete
$image_src = '';
[114] Fix | Delete
[115] Fix | Delete
if ( empty( $postmeta[ $meta_key ][0] ) ) {
[116] Fix | Delete
return '';
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
// could be a remote or local file
[120] Fix | Delete
$image_src = $postmeta[ $meta_key ][0];
[121] Fix | Delete
[122] Fix | Delete
// cmb2 stores the attachment full image url on the main key
[123] Fix | Delete
if ( $size === 'full' ) {
[124] Fix | Delete
return $image_src;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
// cmb2 stores the attachment id with a different suffix, if local
[128] Fix | Delete
$image_id = self::get_meta_img_id( $postmeta, $meta_key );
[129] Fix | Delete
if ( empty( $image_id ) ) {
[130] Fix | Delete
return $image_src;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
// check if if local file
[134] Fix | Delete
$image_src_maybe = wp_get_attachment_image_src( $image_id, $size );
[135] Fix | Delete
// if exists, return the src, at index 0
[136] Fix | Delete
if ( $image_src_maybe && isset( $image_src_maybe[0] ) ) {
[137] Fix | Delete
return $image_src_maybe[0];
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
return $image_src;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Parses the postmeta array, and returns a image src.
[146] Fix | Delete
*
[147] Fix | Delete
* @param array $postmeta A multidemensional array with meta fields
[148] Fix | Delete
* @param string $meta_key The key for the meta field
[149] Fix | Delete
* @param bool $single Optional. Expect just a single group
[150] Fix | Delete
* @return string The meta value, or empty if nothing found.
[151] Fix | Delete
*/
[152] Fix | Delete
public static function get_meta_group( array $postmeta, string $meta_key, bool $single = true ) {
[153] Fix | Delete
[154] Fix | Delete
if ( empty( $postmeta[ $meta_key ][0] ) ) {
[155] Fix | Delete
return '';
[156] Fix | Delete
}
[157] Fix | Delete
if ( $single ) {
[158] Fix | Delete
return maybe_unserialize( $postmeta[ $meta_key ][0] );
[159] Fix | Delete
} else {
[160] Fix | Delete
return array_map( 'maybe_unserialize', $postmeta[ $meta_key ] );
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function