: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace NetworkPosts\Components;
use NetworkPosts\Components\Resizer\NetsPostsThumbnailBlogSettings;
use NetworkPosts\Components\resizer\NetsPostsThumbnailSizeSettings;
class NetsPostsThumbnailManager
private static $instance;
private function __construct(){}
private static function init_thumbnail_sizes()
$allowed_blogs = NetsPostsThumbnailBlogSettings::get_allowed_blogs();
$global_blogs = NetsPostsThumbnailBlogSettings::get_globals();
$blogs = array_intersect($allowed_blogs, $global_blogs);
$blog_id = get_current_blog_id();
// append current blog id if it isn't global and has been removed
if (!in_array($blog_id, $blogs) &&
NetsPostsThumbnailBlogSettings::is_allowed_for_blog($blog_id)) {
self::$sizes = self::get_thumbnail_sizes($blogs);
private static function get_thumbnail_sizes($blog_ids)
global $_wp_additional_image_sizes;
foreach ($blog_ids as $id) {
foreach (get_intermediate_image_sizes() as $_size) {
if (in_array($_size, array('thumbnail', 'medium', 'medium_large', 'large'))) {
$sizes[$_size]['width'] = get_option("{$_size}_size_w");
$sizes[$_size]['height'] = get_option("{$_size}_size_h");
$sizes[$_size]['crop'] = (bool)get_option("{$_size}_crop");
} elseif (isset($_wp_additional_image_sizes[$_size])) {
'width' => $_wp_additional_image_sizes[$_size]['width'],
'height' => $_wp_additional_image_sizes[$_size]['height'],
'crop' => $_wp_additional_image_sizes[$_size]['crop'],
$blog_custom_sizes = NetsPostsThumbnailSizeSettings::get_blog_image_sizes();
foreach ($blog_custom_sizes as $size_id => $db_size){
$size = $db_size['data'];
$size['crop'] = $db_size['crop'];
if( isset( $db_size['crop_x'] ) ) {
$size['crop_x'] = $db_size['crop_x'];
$size['crop_x'] = 'center';
if( isset( $db_size['crop_y'] ) ) {
$size['crop_y'] = $db_size['crop_y'];
$size['crop_y'] = 'center';
$sizes[$size['alias']] = $size;
* @required $size_name string - size alias name
* $args[image_class] string
* $args[column] int - decide whether posts are divided to columns or not
* $args[compress_images] boolean
* @return string - returns img html string
public static function get_thumbnail( $post_id, $size_name, array $args = [] ) {
if(self::is_initialized()) {
$thumb_id = has_post_thumbnail($post_id);
if (isset($args['image_class'])) {
$image_class = esc_html($args['image_class']);
$attrs = array('class' => $image_class, 'srcset' => '');
$use_compressed_images = isset($args['compress_images']) && $args['compress_images'];
if ($use_compressed_images) {
$img = get_the_post_thumbnail($post_id, $size_name, $attrs);
$img = get_the_post_thumbnail($post_id, $size_name, $attrs);
$img = preg_replace('/(\bsizes\=.*?\")[\s\/]/', "", $img);
$img = preg_replace('/(\bsrcset\=.*?\\")[\s\/]/', "", $img);
private static function register_sizes(){
foreach (self::$sizes as $name => $size){
if(isset($size['crop_x'])){
$crop[] = $size['crop_x'];
if(isset($size['crop_y'])){
$crop[] = $size['crop_y'];
add_image_size($name, $size['width'], $size['height'], true);
add_image_size($name, $size['width'], $size['height'], $crop);
add_image_size($name, $size['width'], $size['height']);
static function get_estore_product_thumbnail( $image_url, $alt, $size = 'thumbnail', $image_class = '' ) {
if(self::is_initialized()) {
if (!empty($image_url)) {
$img = '<img src="' . $image_url . '" alt="' . $alt . '" ';
$img .= 'class="' . $image_class;
if (array_key_exists($size, self::$sizes)) {
$img .= 'width="' . self::$sizes[$size]['width'] . 'px" ';
$img .= 'height="' . self::$sizes[$size]['height'] . 'px"';
static function initialize(){
self::$instance = new NetsPostsThumbnailManager();
self::init_thumbnail_sizes();
private static function is_initialized(){
return isset(self::$sizes);