: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if( !defined('ABSPATH') ){ exit();}
/*add_action('publish_post', 'xyz_twap_link_publish');
add_action('publish_page', 'xyz_twap_link_publish');
$xyz_twap_future_to_publish=get_option('xyz_twap_future_to_publish');
if($xyz_twap_future_to_publish==1)
add_action('future_to_publish', 'xyz_link_twap_future_to_publish');
function xyz_link_twap_future_to_publish($post){
xyz_twap_link_publish($postid);
///////////////////////////////////////////////////////////////
add_action( 'transition_post_status', 'xyz_link_twap_future_to_publish', 10, 3 );
function xyz_link_twap_future_to_publish($new_status, $old_status, $post){
if (isset($_GET['_locale']) && empty($_POST))
if(!isset($GLOBALS['twap_dup_publish']))
$GLOBALS['twap_dup_publish']=array();
$get_post_meta=get_post_meta($postid,"xyz_twap",true);
$post_twitter_permission=get_option('xyz_twap_twpost_permission');
if(isset($_POST['xyz_twap_twpost_permission'])){
$post_twitter_permission=$_POST['xyz_twap_twpost_permission'];
if ( (isset($_POST['xyz_twap_twpost_permission']) && isset($_POST['xyz_twap_twpost_image_permission'])) )
$futToPubDataArray=array( 'xyz_twap_twpost_permission' => $_POST['xyz_twap_twpost_permission'],
'xyz_twap_twpost_image_permission' => $_POST['xyz_twap_twpost_image_permission'],
'xyz_twap_twmessage' => $_POST['xyz_twap_twmessage']);
update_post_meta($postid, "xyz_twap_future_to_publish", $futToPubDataArray);
if ($post_twitter_permission == 1) {
if($new_status == 'publish')
if ($get_post_meta == 1 ) {
if($post_twitter_permission == 1)
if($new_status == 'publish')
if(!in_array($postid,$GLOBALS['twap_dup_publish'])) {
$GLOBALS['twap_dup_publish'][]=$postid;
xyz_twap_link_publish($postid);
////////////////////////////////////////////////////////////////////////////////////
/*$xyz_twap_include_customposttypes=get_option('xyz_twap_include_customposttypes');
$carr=explode(',', $xyz_twap_include_customposttypes);
foreach ($carr as $cstyps ) {
add_action('publish_'.$cstyps, 'xyz_twap_link_publish');
function xyz_twap_link_publish($post_ID) {
$_POST=stripslashes_deep($_POST);
$post_twitter_image_permission=0;$messagetopost='';
$get_post_meta_future_data=get_post_meta($post_ID,"xyz_twap_future_to_publish",true);
$post_twitter_permission=get_option('xyz_twap_twpost_permission');
if(isset($_POST['xyz_twap_twpost_permission']))
$post_twitter_permission=$_POST['xyz_twap_twpost_permission'];
elseif(!empty($get_post_meta_future_data) && get_option('xyz_twap_default_selection_edit')==2 )///select values from post meta
$post_twitter_permission=$get_post_meta_future_data['xyz_twap_twpost_permission'];
$post_twitter_image_permission=$get_post_meta_future_data['xyz_twap_twpost_image_permission'];
$messagetopost=$get_post_meta_future_data['xyz_twap_twmessage'];
if ($post_twitter_permission != 1) {
} else if(( (isset($_POST['_inline_edit'])) || (isset($_REQUEST['bulk_edit'])) ) && (get_option('xyz_twap_default_selection_edit') == 0) ) {
//$af=get_option('xyz_twap_af');
/////////////twitter//////////
$tappid=get_option('xyz_twap_twconsumer_id');
$tappsecret=get_option('xyz_twap_twconsumer_secret');
$twid=get_option('xyz_twap_tw_id');
$taccess_token=get_option('xyz_twap_current_twappln_token');
$taccess_token_secret=get_option('xyz_twap_twaccestok_secret');
$xyz_twap_tw_app_sel_mode=get_option('xyz_twap_tw_app_sel_mode');
$xyz_twap_smapsoln_userid=get_option('xyz_twap_smapsoln_userid');
$xyz_twap_smapsoln_secret_key=get_option('xyz_twap_smapsoln_secret_key');
$xyz_twap_xyzscripts_user_id=get_option('xyz_twap_xyzscripts_user_id');
$xyz_twap_xyzscripts_hash_val=get_option('xyz_twap_xyzscripts_hash_val');
$messagetopost=get_option('xyz_twap_twmessage');
if(isset($_POST['xyz_twap_twmessage']))
$messagetopost=$_POST['xyz_twap_twmessage'];
if ($post_twitter_image_permission==0)
$post_twitter_image_permission=get_option('xyz_twap_twpost_image_permission');
if(isset($_POST['xyz_twap_twpost_image_permission']))
$post_twitter_image_permission=$_POST['xyz_twap_twpost_image_permission'];
$postpp= get_post($post_ID);global $wpdb;
$reg_exUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$entries0 = $wpdb->get_results($wpdb->prepare( 'SELECT user_nicename,display_name FROM '.$wpdb->base_prefix.'users WHERE ID=%d',$postpp->post_author));
foreach( $entries0 as $entry ) {
$user_nicename=$entry->user_nicename;
$user_displayname=$entry->display_name;
if ($postpp->post_status == 'publish')
$posttype=$postpp->post_type;
$xyz_twap_include_pages=get_option('xyz_twap_include_pages');
if($xyz_twap_include_pages==0)
$_POST=$_POST_CPY;return;
else if($posttype=="post")
$xyz_twap_include_posts=get_option('xyz_twap_include_posts');
if($xyz_twap_include_posts==0)
$_POST=$_POST_CPY;return;
$xyz_twap_include_categories=get_option('xyz_twap_include_categories');
if($xyz_twap_include_categories!="All")
$carr1=explode(',', $xyz_twap_include_categories);
$defaults = array('fields' => 'ids');
$carr2=wp_get_post_categories( $post_ID, $defaults );
foreach ($carr2 as $key=>$catg_ids)
if(in_array($catg_ids, $carr1))
{$_POST=$_POST_CPY;return;}
$xyz_twap_include_customposttypes=get_option('xyz_twap_include_customposttypes');
if($xyz_twap_include_customposttypes!='')
$carr=explode(',', $xyz_twap_include_customposttypes);
if(!in_array($posttype, $carr))
$_POST=$_POST_CPY;return;
$_POST=$_POST_CPY;return;
$get_post_meta=get_post_meta($post_ID,"xyz_twap",true);
add_post_meta($post_ID, "xyz_twap", "1");
include_once ABSPATH.'wp-admin/includes/plugin.php';
$pluginName = 'bitly/bitly.php';
if (is_plugin_active($pluginName)) {
remove_all_filters('post_link');
$link = get_permalink($postpp->ID);
$xyz_twap_apply_filters=get_option('xyz_twap_apply_filters');
$ar2=explode(",",$xyz_twap_apply_filters);
$con_flag=$exc_flag=$tit_flag=0;
if(in_array(1, $ar2)) $con_flag=1;
if(in_array(2, $ar2)) $exc_flag=1;
if(in_array(3, $ar2)) $tit_flag=1;
$content = $postpp->post_content;
$content = apply_filters('the_content', $content);
$content = html_entity_decode($content, ENT_QUOTES, get_bloginfo('charset'));
$excerpt = $postpp->post_excerpt;
$excerpt = apply_filters('the_excerpt', $excerpt);
$excerpt = html_entity_decode($excerpt, ENT_QUOTES, get_bloginfo('charset'));
$content = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $content);
$content= preg_replace("/\\[caption.*?\\].*?\\[.caption\\]/is","", $content);
$content = preg_replace('/\[.+?\]/', '', $content);
$excerpt = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $excerpt);
$content1=strip_tags($content1);
$content1=strip_shortcodes($content1);
$excerpt=implode(' ', array_slice(explode(' ', $content1), 0, 50));
$excerpt=strip_tags($excerpt);
$excerpt=strip_shortcodes($excerpt);
$description_org=$description;
$attachmenturl=xyz_twap_getimage($post_ID, $postpp->post_content);
if(!empty($attachmenturl))
$name = $postpp->post_title;
$caption = html_entity_decode(get_bloginfo('title'), ENT_QUOTES, get_bloginfo('charset'));
$name = apply_filters('the_title', $name,$post_ID);
$name = html_entity_decode($name, ENT_QUOTES, get_bloginfo('charset'));
$name=strip_shortcodes($name);
$description=strip_tags($description);
$description=strip_shortcodes($description);
$description=str_replace(" ","",$description);
$excerpt=str_replace(" ","",$excerpt);
if((($xyz_twap_tw_app_sel_mode==1 && !empty($xyz_twap_smapsoln_userid) && !empty($xyz_twap_smapsoln_secret_key) ) || ($taccess_token!="" && $taccess_token_secret!="" && $tappid!="" && $tappsecret!="" && $xyz_twap_tw_app_sel_mode==0) ) && $post_twitter_permission==1)
$api_exceed_err=0;$remaining_tw_api_count=0;$tw_api_count=0;
if($post_twitter_image_permission==1)
update_post_meta($post_ID, "xyz_twap_insert_twitter_card", "1");
if(!empty($attachmenturl))
$img = wp_remote_get($attachmenturl,array('sslverify'=> (get_option('xyz_twap_peer_verification')=='1') ? true : false));
if(is_array($img) && ! is_wp_error( $img ) )
if (isset($img['body'])&& trim($img['body'])!='')
if (($img['headers']['content-length']) && trim($img['headers']['content-length'])!='')
$img_size=$img['headers']['content-length']/(1024*1024);
$image_found=0;$img_status="Image skipped(greater than 3MB)";
///////////////////////Create temp folder ß
$wp_twap_img_targetfolder = realpath(dirname(__FILE__) . '/../../../')."/uploads/xyz_twap_temp_images";
if (file_exists($wp_twap_img_targetfolder)==false)
if (mkdir($wp_twap_img_targetfolder, 0777, true))
chmod($wp_twap_img_targetfolder,0777);
////////////upload image to temporary folder and get path
$xyz_twap_ext = pathinfo($attachmenturl, PATHINFO_EXTENSION);
$xyz_twap_filename=pathinfo($attachmenturl, PATHINFO_FILENAME);
$xyz_twap_image_files=$wp_twap_img_targetfolder."/".$xyz_twap_filename.".".$xyz_twap_ext;
file_put_contents($xyz_twap_image_files, $img);
////////////////////////////
///Twitter upload image end/////
$messagetopost=str_replace(" ","",$messagetopost);
$substring="";$islink=0;$issubstr=0;
$substring=str_replace('{POST_TITLE}', $name, $messagetopost);
$substring=str_replace('{BLOG_TITLE}', $caption,$substring);
$substring=str_replace('{PERMALINK}', ' '.$link.' ', $substring);
$substring=str_replace('{POST_EXCERPT}', $excerpt, $substring);
$substring=str_replace('{POST_CONTENT}', $description, $substring);
$substring=str_replace('{USER_NICENAME}', $user_nicename, $substring);
$substring=str_replace('{USER_DISPLAY_NAME}', $user_displayname, $substring);
$publish_time=get_the_time(get_option('date_format'),$post_ID );
$substring=str_replace('{POST_PUBLISH_DATE}', $publish_time, $substring);
$substring=str_replace('{POST_ID}', $post_ID, $substring);
preg_match_all($reg_exUrl,$substring,$matches); // @ is same as /
if(is_array($matches) && isset($matches[0]))
$tw_max_len=get_option('xyz_twap_tw_char_limit');
if (function_exists('mb_strlen') && function_exists('mb_substr') && function_exists('mb_strpos')) {
foreach ($matches as $key=>$val)
$url_max_len=23;//23 for https and 22 for http
$messagepart=mb_substr($substring, 0, mb_strpos($substring, $val));
if(mb_strlen($messagepart)>($tw_max_len-$len))
$final_str.=mb_substr($messagepart,0,$tw_max_len-$len-3)."...";
$len+=($tw_max_len-$len);
$final_str.=$messagepart;
$len+=mb_strlen($messagepart);
$cur_url_len=mb_strlen($val);
if(mb_strlen($val)>$url_max_len)
$cur_url_len=$url_max_len;
$substring=mb_substr($substring, mb_strpos($substring, $val)+strlen($val));
if($cur_url_len>($tw_max_len-$len))
if(mb_strlen($substring)>0 && $tw_max_len>$len)
if(mb_strlen($substring)>($tw_max_len-$len))
$final_str.=mb_substr($substring,0,$tw_max_len-$len-3)."...";
foreach ($matches as $key=>$val)
$messagepart=substr($substring, 0, strpos($substring, $val));
if(strlen($messagepart)>($tw_max_len-$len))
$final_str.=substr($messagepart,0,$tw_max_len-$len-3)."...";
$len+=($tw_max_len-$len);
$final_str.=$messagepart;
$len+=strlen($messagepart);
$cur_url_len=strlen($val);
if(strlen($val)>$url_max_len)
$cur_url_len=$url_max_len;
$substring=substr($substring, strpos($substring, $val)+strlen($val));
if($cur_url_len>($tw_max_len-$len))
if(strlen($substring)>0 && $tw_max_len>$len)
if(strlen($substring)>($tw_max_len-$len))
$final_str.=substr($substring,0,$tw_max_len-$len-3)."...";
/* if (strlen($substring)>$tw_max_len)
$substring=substr($substring, 0, $tw_max_len-3)."...";*/
if($xyz_twap_tw_app_sel_mode==0)
$twobj = new Abraham\TwitterOAuth\TwitterOAuth(
$twobj->userId = explode('-', $taccess_token)[0];
$twobj->setApiVersion('2');
if($image_found==1 && $post_twitter_image_permission==1 && $xyz_twap_tw_app_sel_mode==0)
$twobj->setTimeouts( 10, 60 );
$twobj->setApiVersion( '1.1' );
$response = $twobj->upload( 'media/upload', array( 'media' => $xyz_twap_image_files ) );
if ( ! isset( $response->media_id ) ) {
$media_upload_id = $response->media_id;
if ( $media_upload_id ) {
$twobj->setTimeouts( 10, 30 );
$twobj->setApiVersion( '2' );
$resultfrtw = $twobj->post(
array('text' =>$substring,'media'=>array(
'media_ids' => [ (string) $media_upload_id ],
if ( isset( $resultfrtw->data ) && ! is_wp_error( $resultfrtw->data ) ) {
// Tweet posted successfully
$tw_publish_status="<span style=\"color:green\">statuses/update : Success.</span>";
} else if( is_wp_error( $resultfrtw->data )) {
$error_string = $resultfrtw->data->get_error_message();
$tw_publish_status="<span style=\"color:red\">".$error_string.".</span>";
if(!empty($resultfrtw->detail))
$tw_publish_status="<span style=\"color:red\">".$resultfrtw->status.":".$resultfrtw->detail.".</span>";
$tw_publish_status="<span style=\"color:red\">Not Available</span>";