: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$uploads = wp_upload_dir();
$path = $uploads['basedir'] . '/' . $metadata['file'];
require_once ABSPATH . 'wp-admin/includes/image.php';
$metadata_new = prtfl_wp_generate_attachment_metadata( $id, $path, $metadata );
wp_update_attachment_metadata( $id, array_merge( $metadata, $metadata_new ) );
unset( $prtfl_options['need_image_update'] );
update_option( 'prtfl_options', $prtfl_options );
if ( ! function_exists( 'prtfl_wp_generate_attachment_metadata' ) ) {
* Add attachment metadata for portfolio images
* @param int $attachment_id Attachment ID.
* @param string $file File string.
* @param array $metadata Array with metadata.
function prtfl_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) {
$attachment = get_post( $attachment_id );
$image_size = array( 'thumbnail' );
if ( 'portfolio-thumb' === $prtfl_options['image_size_album'] ) {
add_image_size( 'portfolio-thumb', $prtfl_options['custom_size_px']['portfolio-thumb'][0], $prtfl_options['custom_size_px']['portfolio-thumb'][1], true );
$image_size[] = 'portfolio-thumb';
if ( 'portfolio-photo-thumb' === $prtfl_options['image_size_photo'] ) {
add_image_size( 'portfolio-photo-thumb', $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0], $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1], true );
$image_size[] = 'portfolio-photo-thumb';
if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
$imagesize = getimagesize( $file );
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
list( $uwidth, $uheight ) = wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
/* Make the file path relative to the upload dir */
$metadata['file'] = _wp_relative_upload_path( $file );
/* Make thumbnails and other intermediate sizes */
global $_wp_additional_image_sizes;
foreach ( $image_size as $s ) {
if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
$sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] ); /* For theme-added sizes */
$sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); /* For default sizes set in options */
if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] ); /* For theme-added sizes */
$sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); /* For default sizes set in options */
if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
$sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[ $s ]['crop'] ); /* For theme-added sizes */
$sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); /* For default sizes set in options */
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
foreach ( $sizes as $size => $size_data ) {
$resized = prtfl_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
$metadata['sizes'][ $size ] = $resized;
/* Fetch additional metadata from exif/iptc */
$image_meta = wp_read_image_metadata( $file );
$metadata['image_meta'] = $image_meta;
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
if ( ! function_exists( 'prtfl_image_make_intermediate_size' ) ) {
* Change size for attachment
* @param string $file File string.
* @param int $width Width for attachment.
* @param int $height Height for attachment.
* @param bool $crop Flag for crop.
function prtfl_image_make_intermediate_size( $file, $width, $height, $crop = false ) {
if ( $width || $height ) {
$resized_file = prtfl_image_resize( $file, $width, $height, $crop );
if ( ! is_wp_error( $resized_file ) && $resized_file ) {
$info = getimagesize( $resized_file );
if ( ! empty( $info ) ) {
$resized_file = apply_filters( 'image_make_intermediate_size', $resized_file );
'file' => wp_basename( $resized_file ),
if ( ! function_exists( 'prtfl_image_resize' ) ) {
* @param string $file File string.
* @param int $max_w Max width for attachment.
* @param int $max_h Max height for attachment.
* @param bool $crop Flag for crop.
* @param string $suffix Suffix for file name.
* @param string $dest_path Destination path.
* @param int $jpeg_quality Quality for attachment.
function prtfl_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
$size = @getimagesize( $file );
return new WP_Error( 'invalid_image', __( 'Image size not defined', 'portfolio' ), $file );
$image = imagecreatefrompng( $file );
} elseif ( 2 === $type ) {
$image = imagecreatefromjpeg( $file );
} elseif ( 1 === $type ) {
$image = imagecreatefromgif( $file );
} elseif ( 15 === $type ) {
$image = imagecreatefromwbmp( $file );
} elseif ( 16 === $type ) {
$image = imagecreatefromxbm( $file );
return new WP_Error( 'invalid_image', __( 'We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other image formats, please manually reload image.', 'portfolio' ), $file );
if ( ! is_resource( $image ) ) {
return new WP_Error( 'error_loading_image', $image, $file );
/* $size = @getimagesize( $file ); */
list( $orig_w, $orig_h, $orig_type ) = $size;
$dims = prtfl_image_resize_dimensions( $orig_w, $orig_h, $max_w, $max_h, $crop );
return new WP_Error( 'error_getting_dimensions', __( 'Image size changes not defined', 'portfolio' ) );
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
/* Convert from full colors to index colors, like original PNG. */
if ( IMAGETYPE_PNG === $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
/* We don't need the original in memory anymore */
/* $suffix will be appended to the destination filename, just before the extension */
$suffix = "{$dst_w}x{$dst_h}";
$info = pathinfo( $file );
$ext = $info['extension'];
$name = wp_basename( $file, ".$ext" );
if ( ! is_null( $dest_path ) ) {
$_dest_path = realpath( $dest_path );
$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
if ( IMAGETYPE_GIF === $orig_type ) {
if ( ! imagegif( $newimage, $destfilename ) ) {
return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
} elseif ( IMAGETYPE_PNG === $orig_type ) {
if ( ! imagepng( $newimage, $destfilename ) ) {
return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
/* All other formats are converted to jpg */
$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) {
return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
imagedestroy( $newimage );
/* Set correct file permissions */
$stat = stat( dirname( $destfilename ) );
$perms = $stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
@chmod( $destfilename, $perms );
if ( ! function_exists( 'prtfl_image_resize_dimensions' ) ) {
* Resize dimensions for attachment
* @param int $orig_w Original width for attachment.
* @param int $orig_h Original height for attachment.
* @param int $dest_w New width for attachment.
* @param int $dest_h New height for attachment.
* @param bool $crop Flag for crop.
function prtfl_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
if ( 0 >= $orig_w || 0 >= $orig_h ) {
/* At least one of dest_w or dest_h must be specific */
if ( 0 >= $dest_w && 0 >= $dest_h ) {
/* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h */
$aspect_ratio = $orig_w / $orig_h;
$new_w = min( $dest_w, $orig_w );
$new_h = min( $dest_h, $orig_h );
$new_w = intval( $new_h * $aspect_ratio );
$new_h = intval( $new_w / $aspect_ratio );
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
$crop_w = round( $new_w / $size_ratio );
$crop_h = round( $new_h / $size_ratio );
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
/* Don't crop, just resize using $dest_w x $dest_h as a maximum bounding box */
list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
/* If the resulting image would be the same size or larger we don't want to resize it */
if ( $new_w >= $orig_w && $new_h >= $orig_h ) {
* The return array matches the parameters to imagecopyresampled()
* Int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
if ( ! function_exists( 'prtfl_theme_body_classes' ) ) {
* @param array $classes Classes array.
function prtfl_theme_body_classes( $classes ) {
if ( function_exists( 'wp_get_theme' ) ) {
$current_theme = wp_get_theme();
$classes[] = 'prtfl_' . basename( $current_theme->get( 'ThemeURI' ) );
if ( in_array( 'page-id-' . $prtfl_options['page_id_portfolio_template'], $classes ) ) {
$classes[] = 'prtfl-page-template';
$classes[] = 'has-sidebar';
if ( ! function_exists( 'prtfl_register_plugin_links' ) ) {
* Add Settings and Support links
* @param array $links Action link array.
* @param file $file Plugin file.
* @return array $links Returned link array.
function prtfl_register_plugin_links( $links, $file ) {
$base = plugin_basename( __FILE__ );
if ( ! is_network_admin() ) {
$links[] = '<a href="edit.php?post_type=' . $prtfl_options['post_type_name'] . '&page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
$links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538929" target="_blank">' . __( 'FAQ', 'portfolio' ) . '</a>';
$links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'portfolio' ) . '</a>';
if ( ! function_exists( 'prtfl_plugin_action_links' ) ) {
* @param array $links Action link array.
* @param file $file Plugin file.
* @return array $links Returned link array.
function prtfl_plugin_action_links( $links, $file ) {
if ( ! is_network_admin() ) {
/* Static so we don't call plugin_basename on every plugin row. */
$this_plugin = plugin_basename( __FILE__ );
if ( $file === $this_plugin ) {
$settings_link = '<a href="edit.php?post_type=' . $prtfl_options['post_type_name'] . '&page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
array_unshift( $links, $settings_link );
if ( ! function_exists( 'prtfl_admin_notices' ) ) {
* Display notice in the main dashboard page / plugins page
function prtfl_admin_notices() {
global $hook_suffix, $prtfl_plugin_info, $prtfl_options, $prtfl_bws_demo_data;
if ( 'plugins.php' === $hook_suffix || ( isset( $_GET['page'] ) && 'portfolio.php' === $_GET['page'] ) ) {
if ( ! $prtfl_bws_demo_data ) {
prtfl_include_demo_data();
if ( isset( $_GET['page'] ) && 'portfolio.php' === $_GET['page'] ) {
$prtfl_bws_demo_data->bws_handle_demo_notice( $prtfl_options['display_demo_notice'] );
if ( 'plugins.php' === $hook_suffix ) {
if ( ! is_network_admin() ) {
bws_plugin_banner_to_settings( $prtfl_plugin_info, 'prtfl_options', 'portfolio', 'edit.php?post_type=portfolio&page=portfolio.php', 'Portfolio' );
if ( 0 === absint( $prtfl_options['widget_updated'] ) ) {
/* Save data for settings page */
if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ) ) {
$prtfl_options['widget_updated'] = 1;
update_option( 'prtfl_options', $prtfl_options );
<div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
<div class="prtfl_admin_notices bws_banner_on_plugin_page">
<form method="post" action="<?php echo esc_attr( $hook_suffix ); ?>">
<strong><?php esc_html_e( 'ATTENTION!', 'portfolio' ); ?></strong>
<?php esc_html_e( 'In the current version of Portfolio plugin we updated the Technologies widget. If it was added to the sidebar, it will disappear and you will have to add it again.', 'portfolio' ); ?>
<input type="hidden" name="prtfl_form_submit" value="submit" />
<input type="submit" class="button-primary" value="<?php esc_html_e( 'Read and Understood', 'portfolio' ); ?>" />
<?php wp_nonce_field( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ); ?>
bws_plugin_suggest_feature_banner( $prtfl_plugin_info, 'prtfl_options', 'portfolio' );
if ( ! function_exists( 'prtfl_template_title' ) ) {
* This function will display title for portfolio type template
function prtfl_template_title() {
global $wp_query, $prtfl_options;
if ( isset( $wp_query->query_vars['technologies'] ) ) {
$term = get_term_by( 'slug', $wp_query->query_vars['technologies'], 'portfolio_technologies' );
echo esc_html( $prtfl_options['technologies_text_field'] . ' ' . $term->name );
} elseif ( isset( $wp_query->query_vars['portfolio_executor_profile'] ) ) {
$term = get_term_by( 'slug', $wp_query->query_vars['portfolio_executor_profile'], 'portfolio_executor_profile' );
echo esc_html( $prtfl_options['executor_text_field'] ) . ' <h1>' . esc_html( $term->name ) . '</h1>';
$_SESSION['prtfl_page_name'] = $prtfl_options['executor_text_field'] . ' ' . $term->name;
$_SESSION['prtfl_page_url'] = get_pagenum_link( $wp_query->query_vars['paged'] );
the_title( '<h1>', '</h1>' );
if ( ! function_exists( 'prtfl_post_template_title' ) ) {
* This function will display title for portfolio post type template
function prtfl_post_template_title() {
$title = get_the_title();
echo empty( $title ) ? '(' . esc_html__( 'No title', 'portfolio' ) . ')' : '<h1>' . esc_html( $title ) . '</h1>';
if ( ! function_exists( 'prtfl_get_query_args' ) ) {
* Prepare arguments for post query
function prtfl_get_query_args() {
global $prtfl_options, $wp_query;
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
$per_page = get_option( 'posts_per_page' );
if ( ! empty( $wp_query->query_vars['technologies'] ) ) {
'post_type' => $prtfl_options['post_type_name'],
'post_status' => 'publish',
'orderby' => $prtfl_options['order_by'],
'order' => $prtfl_options['order'],
'posts_per_page' => $per_page,
'taxonomy' => 'portfolio_technologies',
'terms' => $wp_query->query_vars['technologies'],
} elseif ( ! empty( $wp_query->query_vars['portfolio_executor_profile'] ) ) {
'post_type' => $prtfl_options['post_type_name'],
'post_status' => 'publish',
'orderby' => $prtfl_options['order_by'],
'order' => $prtfl_options['order'],
'posts_per_page' => $per_page,
'taxonomy' => 'portfolio_executor_profile',
'terms' => $wp_query->query_vars['portfolio_executor_profile'],
'post_type' => $prtfl_options['post_type_name'],
'post_status' => 'publish',
'orderby' => $prtfl_options['order_by'],
'order' => $prtfl_options['order'],
'posts_per_page' => $per_page,
if ( ! function_exists( 'prtfl_get_content' ) ) {