: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
Plugin Name: Network Posts Ext
Plugin URI: https://wordpress.org/plugins/network-posts-extended/
Description: Network Posts Extended plugin enables you to share posts over WP Multi Site network. You can display on any blog in your network the posts selected by taxonomy from any blogs including main.
Author: John Cardell, Andrey Islentiev
Author URI: https://www.johncardell.com
Text Domain: network-posts-extended
if ( realpath( __FILE__ ) == realpath( $_SERVER['SCRIPT_FILENAME'] ) ) {
exit( 'Please don\'t access this file directly.' );
define( 'NETSPOSTS_MAIN_PLUGIN_FILE', __FILE__ );
use NetworkPosts\Components\db\NetsPostsQuery;
use NetworkPosts\Components\db\NetsPostsReviewQuery;
use NetworkPosts\Components\NetsPostsDBQuery;
use NetworkPosts\Components\NetsPostsHtmlHelper;
use NetworkPosts\Components\NetsPostsShortcodeContainer;
use NetworkPosts\Components\NetsPostsThumbnailManager;
use NetworkPosts\DB\Category\CategoryInclusionMode;
use NetworkPosts\DB\Category\NetsPostsCategoryQuery;
function netsposts_path( $file ) {
return plugin_dir_path( __FILE__ ) . $file;
require_once netsposts_path( 'network-posts-init.php' );
function netsposts_shortcode( $atts ) {
if ( is_string( $atts ) ) {
$shortcode_mgr = NetsPostsShortcodeContainer::newInstance( $atts );
if( $shortcode_mgr->get_boolean( 'debug' ) ) {
$GLOBALS['NETSPOSTS_DEBUG'] = true;
//$can_paginate = is_single() || is_singular() || is_page() || $shortcode_mgr->get_boolean( 'load_posts_dynamically' );
//if ( ! $can_paginate ) {
//$atts['paginate'] = false;
//$shortcode_mgr->set_shortcode_attributes( $atts );
$db_manager = NetsPostsDBQuery::new_instance( $wpdb );
$use_single_images_folder = get_option( 'use_single_images_folder', false );
if ( ! empty( $_GET ) ) {
$shortcode_mgr->add_attributes( $_GET );
######## OUTPUT STAFF ####################
$titles_only = $shortcode_mgr->get_boolean( 'titles_only' );
$thumbnail = $shortcode_mgr->get_boolean( 'thumbnail' );
$paginate = $shortcode_mgr->get_boolean( 'paginate' );
$auto_excerpt = $shortcode_mgr->get_boolean( 'auto_excerpt' );
$show_author = $shortcode_mgr->get_boolean( 'show_author' );
$full_text = $shortcode_mgr->get_boolean( 'full_text' );
$prev_next = $shortcode_mgr->get_boolean( 'prev_next' );
$random = $shortcode_mgr->get_boolean( 'random' );
/* my updates are finished here */
$price_woocommerce = false;
$key_name = 'exclude_link_title_posts';
if ( $shortcode_mgr->has_value( 'exclude_link_title_posts' ) ) {
$exclude_title_links = $shortcode_mgr->split_array( 'exclude_link_title_posts', ',' );
$key_name = 'include_price';
if ( $shortcode_mgr->has_value( $key_name ) ) {
$is_match = $shortcode_mgr->is_match( $key_name, '/(\|)+/' );
$exs = $shortcode_mgr->split_array( $key_name, '|' );
$exs = [ $shortcode_mgr->get( $key_name ) ];
foreach ( $exs as $ex ) {
if ( $ex == 'woocommerce' ) {
$price_woocommerce = true;
} elseif ( $ex == 'estore' ) {
$woocommerce_installed = $db_manager->is_woocommerce_installed();
$estore_installed = $db_manager->is_estore_installed();
if( ! defined( 'WOOCOMMERCE' ) ) {
define( "WOOCOMMERCE", "woocommerce" );
if( ! defined( 'WPESTORE' ) ) {
define( "WPESTORE", "estore" );
/* below is my updates */
if ( is_archive() || $shortcode_mgr->get_boolean( 'load_posts_dynamically' ) ) {
$page = isset( $_GET['npage'] ) ? (int)$_GET['npage'] : 1;
$page = get_query_var( 'paged' );
$page = get_query_var( 'page' );
if( isset( $_GET['npe-page'] ) ){
$page = (int) $_GET['npe-page'];
$is_paginate = $page > 1 && $paginate;
$blogs = netsposts_get_blogs( $shortcode_mgr );
$posts_query = new NetsPostsQuery( $wpdb );
$posts_query->include_blogs( $blogs );
if ( $shortcode_mgr->has_value( 'days' ) ) {
$days = $shortcode_mgr->get( 'days' );
$posts_query->set_days( $days );
if ( $shortcode_mgr->has_value( 'limit' ) ) {
$value = $shortcode_mgr->get( 'limit' );
$posts_query->set_limit( intval( $value ) );
if ( $shortcode_mgr->has_value( 'offset' ) ) {
$value = $shortcode_mgr->get( 'offset' );
$posts_query->set_limit( intval( $value ) );
if ( $shortcode_mgr->has_value( 'random' ) ) {
$posts_query->set_random();
if( $shortcode_mgr->has_value( 'author' ) ){
$author_name = strtolower( $shortcode_mgr->get( 'author' ) );
if( $author_name === 'current_user' ){
if( is_user_logged_in() ){
$author = wp_get_current_user();
$author = get_user_by( 'login', $author_name );
$posts_query->set_author_id( $author->ID );
if( $shortcode_mgr->has_value( 'exclude_author' ) ){
$author_name = strtolower( $shortcode_mgr->get( 'exclude_author' ) );
$author = get_user_by( 'login', $author_name );
$posts_query->exclude_author_id( $author->ID );
if ( $shortcode_mgr->has_value( 'filter_by_title_keywords' ) ) {
$keywords = $shortcode_mgr->split_array( 'filter_by_title_keywords', ',' );
$posts_query->set_title_keywords( $keywords );
if ( $shortcode_mgr->get_boolean( 'page_has_no_child' ) ) {
$posts_query->without_children();
if ( $shortcode_mgr->has_value( 'post_type' ) ) {
$post_type_array = $shortcode_mgr->split_array( 'post_type', ',' );
$posts_query->set_post_type( $post_type_array );
if ( $shortcode_mgr->has_value( 'order_post_by_acf_date' ) ) {
$sort_values = $shortcode_mgr->split_array( 'order_post_by_acf_date', ' ' );
$meta_keys[] = $sort_values[0];
if ( $shortcode_mgr->has_value( 'show_after_date' ) ||
$shortcode_mgr->has_value( 'exclude_all_past_events' ) ) {
if ( $shortcode_mgr->has_value( 'show_after_date' ) ) {
$filter_values = $shortcode_mgr->split_array( 'show_after_date', '::' );
$filter_column = $filter_values[0];
$date_str = $filter_values[1];
$date_format = $shortcode_mgr->get( 'date_format' );
$date = DateTime::createFromFormat( $date_format, $date_str );
$filter_column = $shortcode_mgr->get( 'exclude_all_past_events' );
if ( $filter_column !== 'post_date' ) {
$meta_keys[] = $filter_column;
$posts_query->set_acf_date_filter_field( $filter_column );
if ( class_exists( 'Jet_Engine' ) ) {
$posts_query->filter_after_acf_date( $date->getTimestamp() );
$posts_query->filter_after_acf_date( $date->format( 'Ymd' ) );
if ( $shortcode_mgr->has_value( 'show_before_date' ) ||
$shortcode_mgr->has_value( 'show_past_events' ) ) {
if ( $shortcode_mgr->has_value( 'show_before_date' ) ) {
$filter_values = $shortcode_mgr->split_array( 'show_before_date', '::' );
$filter_column = $filter_values[0];
$date_str = $filter_values[1];
$date_format = $shortcode_mgr->get( 'date_format' );
$date = DateTime::createFromFormat( $date_format, $date_str );
$filter_column = $shortcode_mgr->get( 'show_past_events' );
if ( $filter_column !== 'post_date' ) {
$meta_keys[] = $filter_column;
$posts_query->set_acf_date_filter_field( $filter_column );
$posts_query->filter_before_acf_date( $date->format( 'Ymd' ) );
if ( $shortcode_mgr->has_value( 'show_for_today' ) ) {
$filter_column = $shortcode_mgr->get( 'show_for_today' );
if ( $filter_column !== 'post_date' ) {
$meta_keys[] = $filter_column;
$posts_query->set_acf_date_filter_field( $filter_column );
$posts_query->filter_acf_date( $date );
if ( $shortcode_mgr->has_value( 'show_only_after_x_days_old' ) ) {
$after_days = $shortcode_mgr->get_int( 'show_only_after_x_days_old' );
$posts_query->filter_after_days( $after_days );
$home_url = get_home_url();
if ( $shortcode_mgr->get_boolean( 'remove_blog_prefix' ) ) {
add_filter( 'pre_post_link', 'netsposts_remove_blog_prefix', 10, 3 );
if ( $shortcode_mgr->has_value( 'include_post' ) ) {
$include_posts_id = $shortcode_mgr->split_array( 'include_post', ',' );
foreach ( $blogs as $blog ) {
$posts_query->include_blog_posts( $blog, $include_posts_id );
if ( $shortcode_mgr->has_value( 'exclude_post' ) ) {
$exclude_posts = $shortcode_mgr->split_array( 'exclude_post', ',' );
foreach ( $blogs as $blog ) {
$posts_query->exclude_posts( $blog, $exclude_posts );
if ( $shortcode_mgr->has_value( 'order_post_by' ) ) {
$tab_order_by1 = $shortcode_mgr->split_array( 'order_post_by', ' ' );
$ordad = ( $tab_order_by1[1] ) ? $tab_order_by1[1] : "ASC";
$posts_query->set_sort_type( $ordad );
if ( $tab_order_by1[0] == "date_order" ) {
} elseif ( $tab_order_by1[0] == "alphabetical_order" ) {
$posts_query->set_order_by( $ordad0 );
} elseif ( $shortcode_mgr->has_value( 'order_post_by_acf_date' ) ) {
$tab_order_by1 = $shortcode_mgr->split_array( 'order_post_by_acf_date', ' ' );
if ( strtoupper( $tab_order_by1[1] ) == "DESC" ) {
$posts_query->set_acf_date_filter_field( $tab_order_by1[0] );
$posts_query->order_by_acf( $ordad1 );
} elseif ( $shortcode_mgr->has_value( 'order_by_acf' ) ) {
$tab_order_by1 = $shortcode_mgr->split_array( 'order_by_acf', ' ' );
if ( strtoupper( $tab_order_by1[1] ) == "DESC" ) {
$posts_query->set_primary_acf_field( $tab_order_by1[0] );
$posts_query->order_by_acf( $ordad1 );
if ( $shortcode_mgr->get_boolean( 'hide_password_protected_posts' ) ){
$posts_query->exclude_protected_posts();
$category_query = new NetsPostsCategoryQuery( $wpdb );
$category_query->include_blogs( $blogs );
if ( $shortcode_mgr->get_boolean( 'show_all_taxonomy_types' ) ) {
$taxonomy_types = get_taxonomies();
$category_query->set_taxonomy_type( $taxonomy_types );
} elseif ( $shortcode_mgr->has_value( 'taxonomy_type' ) ) {
$category_query->set_taxonomy_type( $shortcode_mgr->split_array( 'taxonomy_type', ',' ) );
$category_query->set_taxonomy_type( array( 'category', 'tag' ) );
if ( $shortcode_mgr->get_boolean( 'show_all_taxonomies' ) ) {
$mode = CategoryInclusionMode::INCLUDE_ANY;
} elseif ( $shortcode_mgr->has_value( 'taxonomy' ) ) {
$taxonomy = $shortcode_mgr->split_array( 'taxonomy', ',' );
if( $shortcode_mgr->get_boolean( 'must_include_categories' ) ){
$mode = CategoryInclusionMode::INCLUDE_ALL;
} elseif ( $shortcode_mgr->get_boolean( 'must_be_in_taxonomies_only' ) ){
$mode = CategoryInclusionMode::INCLUDE_ONLY;
$mode = CategoryInclusionMode::INCLUDE_ANY;
if( isset( $taxonomy ) ){
$taxonomy_posts_table = $category_query->get_query_table( $taxonomy, $mode );
} catch ( Exception $e ) {
error_log( $e->getMessage() );
$taxonomy_posts_table = false;
if ( isset( $taxonomy_posts_table ) && $taxonomy_posts_table ) {
$posts_query->include_posts_from_table( $taxonomy_posts_table );
if ( $shortcode_mgr->has_value( 'exclude_taxonomy' ) ) {
$exclude_taxonomy = $shortcode_mgr->split_array( 'exclude_taxonomy', ',' );
$exclude_taxonomy_posts = $category_query->get_query_table( $exclude_taxonomy );
$posts_query->exclude_posts_from_table( $exclude_taxonomy_posts );
} catch ( Exception $e ) {
error_log( $e->getMessage() );
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
$post_ids = $posts_query->get_ids();
foreach ( $post_ids as $post ) {
if ( ! isset( $blog_posts[ $post['blog_id'] ] ) ) {
$blog_posts[ $post['blog_id'] ] = array();
$blog_posts[ $post['blog_id'] ][] = $post['ID'];
$translation_query = new NetsPostsQuery( $wpdb );
$translation_query->include_blogs( array_keys( $blog_posts ) );
$translation_query->set_sort_type( $ordad );
$translation_query->set_order_by( $ordad0 );
foreach ( $blog_posts as $blog_id => $posts ) {
switch_to_blog( $blog_id );
foreach ( $posts as $post_id ) {
$type = get_post_type( $post_id );
$translation_id = apply_filters( 'wpml_object_id', $post_id, $type, true );
$translations[] = $translation_id;
$translation_query->include_blog_posts( $blog_id, $translations );
$the_post = $translation_query->get_posts();
$the_post = $posts_query->get_posts();
$category_query->drop_temp_tables();
$count = count( $the_post );
for ( $i = 0; $i < $count; $i ++ ) {
if ( isset( $the_post[ $i ] ) ) {
switch_to_blog( $item['blog_id'] );
if ( $the_post[ $i ]['post_type'] === 'product' ) {
if ( defined( 'WOOCOMMERCE' ) ) {
$id = $the_post[ $i ]['ID'];
$the_post[ $i ]['categories'] = wp_get_post_terms( $id, 'product_cat' );
$the_post[ $i ]['terms'] = wp_get_post_terms( $id, 'product_tag' );
$the_post[ $i ]['categories'] = wp_get_post_categories( $item['ID'],
array( 'fields' => 'all' ) );
$the_post[ $i ]['terms'] = wp_get_post_terms( $item['ID'] );
$the_post[ $i ]['guid'] = get_permalink( $item['ID'] );
if ( $shortcode_mgr->has_value( 'show_custom_taxonomies' ) ) {
$show_custom_taxonomies = $shortcode_mgr->get_boolean( 'show_custom_taxonomies' );
if ( $show_custom_taxonomies ) {
$the_post[ $i ]['custom_taxonomies'] = netsposts_get_post_custom_taxonomies( $item['ID'] );
$custom_taxonomy = $shortcode_mgr->split_array( 'show_custom_taxonomies', ',' );
$the_post[ $i ]['custom_taxonomies'] = netsposts_get_post_taxonomies( $item['ID'], $custom_taxonomy );
$the_post[ $i ]['custom_taxonomies'] = netsposts_get_post_custom_taxonomies( $item['ID'] );
if ( $shortcode_mgr->get( 'domain_mapping' ) === 'home_url' ) {
$site_url = get_site_url();
$the_post[ $i ]['guid'] = str_replace( $site_url, $home_url, $the_post[ $i ]['guid'] );
/* exclude latest n elements from categories */
if ( $shortcode_mgr->has_value( 'taxonomy_offsets' ) ) {
$taxonomy_offsets = $shortcode_mgr->split_array( 'taxonomy_offsets', ',' );
if ( $shortcode_mgr->has_value( 'taxonomy_offset_names' ) ) {
$skipped_categories = $shortcode_mgr->split_array( 'taxonomy_offset_names', ',' );
} elseif ( $shortcode_mgr->has_value( 'taxonomy' ) ) {
$skipped_categories = $shortcode_mgr->split_array( 'taxonomy', ',' );
$skipped_categories = [];
if ( count( $skipped_categories ) > 0 ) {
$taxonomy_offsets = array_slice( $taxonomy_offsets, 0, count( $skipped_categories ) );
$skipped_category_regex = array_map( function ( $cat_name ) {
$name = str_replace( '%', '', preg_quote( $cat_name ) );
return '/\b' . $name . '\b/i';
}, $skipped_categories );
for ( $i = 0; $i < count( $skipped_categories ); $i ++ ) {