/** * get_post_share_details * * Generate post sharing details * * @param string $position * @return array */ function get_post_share_details($position) { global $post; if ($this->general_options['reset_postdata']) { wp_reset_postdata(); } if (ESSBOptionValuesHelper::options_bool_value($this->options, 'force_wp_query_postid')) { $current_query_id = get_queried_object_id(); $post = get_post($current_query_id); } $url = ""; $title = ""; $image = ""; $description = ""; $title_plain = ""; $twitter_user = $this->network_options['twitter_user']; $twitter_hashtags = $this->network_options['twitter_hashtags']; $twitter_customtweet = ""; $url = $post ? get_permalink() : ESSBUrlHelper::get_current_url('raw'); if (ESSBOptionValuesHelper::options_bool_value($this->options, 'avoid_nextpage')) { $url = $post ? get_permalink(get_the_ID()) : ESSBUrlHelper::get_current_url('raw'); } if (ESSBOptionValuesHelper::options_bool_value($this->options, 'force_wp_fullurl')) { $url = ESSBUrlHelper::get_current_page_url(); } if (ESSBOptionValuesHelper::options_bool_value($this->options, 'always_use_http')) { $url = str_replace("https://", "http://", $url); } if (!defined('ESSB3_LIGHTMODE')) { $mycred_referral_activate = ESSBOptionValuesHelper::options_bool_value($this->options, 'mycred_referral_activate'); if ($mycred_referral_activate && function_exists('mycred_render_affiliate_link')) { $url = mycred_render_affiliate_link(array('url' => $url)); } } if (isset($post)) { $title = esc_attr(urlencode($post->post_title)); $title_plain = $post->post_title; $image = ESSBCoreHelper::get_post_featured_image($post->ID); $description = $post->post_excerpt; if ($position == "heroshare") { if ($description == "") { $working_post_content = $post->post_content; $working_post_content = strip_tags($working_post_content); $working_post_content = preg_replace('/\\s+/', ' ', $working_post_content); $working_post_content = strip_shortcodes($working_post_content); $working_post_content = trim($working_post_content); $working_post_content = substr($working_post_content, 0, 400); $description = $working_post_content; } } } $list_of_articles_mode = false; if (is_archive() || is_front_page() || is_search() || is_tag() || is_post_type_archive()) { if ($position == "sidebar" || $position == "flyin" || $position == "popup" || $position == "topbar" || $position == "bottombar") { if (ESSBOptionValuesHelper::options_bool_value($this->options, 'force_archive_pages')) { $list_of_articles_mode = true; $url = ESSBUrlHelper::get_current_page_url(); if (is_front_page()) { $title = get_bloginfo('name'); $title_plain = $title; $description = get_bloginfo('description'); } else { $title = get_the_archive_title(); $title_plain = $title; $description = get_the_archive_description(); } } } } // apply custom share options if ($this->general_options['customshare']) { if ($this->general_options['customshare_text'] != '') { $title = $this->general_options['customshare_text']; $title_plain = $title; } if ($this->general_options['customshare_url'] != '') { $url = $this->general_options['customshare_url']; } if ($this->general_options['customshare_image'] != '') { $image = $this->general_options['customshare_image']; } if ($this->general_options['customshare_description'] != '') { $description = $this->general_options['customshare_description']; } } $twitter_customtweet = $title; $post_pin_image = ""; // apply post custom share options if (isset($post) && !$list_of_articles_mode) { $twitter_message_tags_to_hashtags = ESSBOptionValuesHelper::options_bool_value($this->options, 'twitter_message_tags_to_hashtags'); if ($twitter_message_tags_to_hashtags) { $post_tags = wp_get_post_tags($post->ID); if ($post_tags) { $generated_tags = array(); foreach ($post_tags as $tag) { $current_tag = $tag->name; $current_tag = str_replace(' ', '', $current_tag); $generated_tags[] = $current_tag; } if (count($generated_tags) > 0) { $twitter_hashtags = implode(',', $generated_tags); } } } $post_essb_post_share_message = get_post_meta($post->ID, 'essb_post_share_message', true); $post_essb_post_share_url = get_post_meta($post->ID, 'essb_post_share_url', true); $post_essb_post_share_image = get_post_meta($post->ID, 'essb_post_share_image', true); $post_essb_post_share_text = get_post_meta($post->ID, 'essb_post_share_text', true); $post_pin_image = get_post_meta($post->ID, 'essb_post_pin_image', true); $post_essb_twitter_username = get_post_meta($post->ID, 'essb_post_twitter_username', true); $post_essb_twitter_hastags = get_post_meta($post->ID, 'essb_post_twitter_hashtags', true); $post_essb_twitter_tweet = get_post_meta($post->ID, 'essb_post_twitter_tweet', true); if ($post_essb_post_share_image != '') { $image = $post_essb_post_share_image; } if ($post_essb_post_share_message != '') { $description = $post_essb_post_share_message; } if ($post_essb_post_share_text != '') { $title = $post_essb_post_share_text; $title_plain = $post_essb_post_share_text; } if ($post_essb_post_share_url != '') { $url = $post_essb_post_share_url; } if ($post_essb_twitter_hastags != '') { $twitter_hashtags = $post_essb_twitter_hastags; } if ($post_essb_twitter_tweet != '') { $twitter_customtweet = $post_essb_twitter_tweet; } if ($post_essb_twitter_username != '') { $twitter_user = $post_essb_twitter_username; } } // inetegration with affiliate plugins is not availalbe as option in easy mode if (!defined('ESSB3_LIGHTMODE')) { $affwp_active = ESSBOptionValuesHelper::options_bool_value($this->options, 'affwp_active'); if ($affwp_active) { $url = ESSBUrlHelper::generate_affiliatewp_referral_link($url); } $affs_active = ESSBOptionValuesHelper::options_bool_value($this->options, 'affs_active'); if ($affs_active) { $url = do_shortcode('[affiliates_url]' . $url . '[/affiliates_url]'); } } $title = str_replace("'", "\\'", $title); $description = str_replace("'", "\\'", $description); $twitter_customtweet = str_replace("'", "\\'", $twitter_customtweet); $title_plain = str_replace("'", "\\'", $title_plain); return array("url" => $url, "title" => $title, "image" => $image, "description" => $description, "twitter_user" => $twitter_user, "twitter_hashtags" => $twitter_hashtags, "twitter_tweet" => $twitter_customtweet, "post_id" => isset($post) ? $post->ID : 0, "user_image_url" => "", "title_plain" => $title_plain, 'short_url_whatsapp' => '', 'short_url_twitter' => '', 'short_url' => '', 'pinterest_image' => $post_pin_image); }
function get_post_share_details() { global $post, $essb_options; if ($this->general_options['reset_postdata']) { wp_reset_postdata(); } if (ESSBOptionValuesHelper::options_bool_value($this->options, 'force_wp_query_postid')) { $current_query_id = get_queried_object_id(); $post = get_post($current_query_id); } $url = ""; $title = ""; $image = ""; $description = ""; $title_plain = ""; $twitter_user = $this->network_options['twitter_user']; $twitter_hashtags = $this->network_options['twitter_hashtags']; $twitter_customtweet = ""; $url = $post ? get_permalink() : ESSBUrlHelper::get_current_url('raw'); if (ESSBOptionValuesHelper::options_bool_value($this->options, 'avoid_nextpage')) { $url = $post ? get_permalink(get_the_ID()) : ESSBUrlHelper::get_current_url('raw'); } if (ESSBOptionValuesHelper::options_bool_value($this->options, 'force_wp_fullurl')) { $url = ESSBUrlHelper::get_current_page_url(); } if (ESSBOptionValuesHelper::options_bool_value($this->options, 'always_use_http')) { $url = str_replace("https://", "http://", $url); } $mycred_referral_activate = ESSBOptionValuesHelper::options_bool_value($this->options, 'mycred_referral_activate'); if ($mycred_referral_activate && function_exists('mycred_render_affiliate_link')) { $url = mycred_render_affiliate_link(array('url' => $url)); } if (isset($post)) { $title = esc_attr(urlencode($post->post_title)); $title_plain = $post->post_title; $post_image = has_post_thumbnail($post->ID) ? wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail') : ''; $image = $post_image != '' ? $post_image[0] : ''; $description = $post->post_excerpt; } // apply custom share options if ($this->general_options['customshare']) { if ($this->general_options['customshare_text'] != '') { $title = $this->general_options['customshare_text']; $title_plain = $title; } if ($this->general_options['customshare_url'] != '') { $url = $this->general_options['customshare_url']; } if ($this->general_options['customshare_image'] != '') { $image = $this->general_options['customshare_image']; } if ($this->general_options['customshare_description'] != '') { $description = $this->general_options['customshare_description']; } } $twitter_customtweet = $title; $post_pin_image = ""; // apply post custom share options if (isset($post)) { $twitter_message_tags_to_hashtags = ESSBOptionValuesHelper::options_bool_value($essb_options, 'twitter_message_tags_to_hashtags'); if ($twitter_message_tags_to_hashtags) { $post_tags = wp_get_post_tags($post->ID); if ($post_tags) { $generated_tags = array(); foreach ($post_tags as $tag) { $current_tag = $tag->name; $current_tag = str_replace(' ', '', $current_tag); $generated_tags[] = $current_tag; } if (count($generated_tags) > 0) { $twitter_hashtags = implode(',', $generated_tags); } } } $post_essb_post_share_message = get_post_meta($post->ID, 'essb_post_share_message', true); $post_essb_post_share_url = get_post_meta($post->ID, 'essb_post_share_url', true); $post_essb_post_share_image = get_post_meta($post->ID, 'essb_post_share_image', true); $post_essb_post_share_text = get_post_meta($post->ID, 'essb_post_share_text', true); $post_pin_image = get_post_meta($post->ID, 'essb_post_pin_image', true); $post_essb_twitter_username = get_post_meta($post->ID, 'essb_post_twitter_username', true); $post_essb_twitter_hastags = get_post_meta($post->ID, 'essb_post_twitter_hashtags', true); $post_essb_twitter_tweet = get_post_meta($post->ID, 'essb_post_twitter_tweet', true); if ($post_essb_post_share_image != '') { $image = $post_essb_post_share_image; } if ($post_essb_post_share_message != '') { $description = $post_essb_post_share_message; } if ($post_essb_post_share_text != '') { $title = $post_essb_post_share_text; $title_plain = $post_essb_post_share_text; } if ($post_essb_post_share_url != '') { $url = $post_essb_post_share_url; } if ($post_essb_twitter_hastags != '') { $twitter_hashtags = $post_essb_twitter_hastags; } if ($post_essb_twitter_tweet != '') { $twitter_customtweet = $post_essb_twitter_tweet; } if ($post_essb_twitter_username != '') { $twitter_user = $post_essb_twitter_username; } } $affwp_active = ESSBOptionValuesHelper::options_bool_value($essb_options, 'affwp_active'); if ($affwp_active) { $url = ESSBUrlHelper::generate_affiliatewp_referral_link($url); } $title = str_replace("'", "\\'", $title); $description = str_replace("'", "\\'", $description); $twitter_customtweet = str_replace("'", "\\'", $twitter_customtweet); $title_plain = str_replace("'", "\\'", $title_plain); return array("url" => $url, "title" => $title, "image" => $image, "description" => $description, "twitter_user" => $twitter_user, "twitter_hashtags" => $twitter_hashtags, "twitter_tweet" => $twitter_customtweet, "post_id" => isset($post) ? $post->ID : 0, "user_image_url" => "", "title_plain" => $title_plain, 'short_url_whatsapp' => '', 'short_url_twitter' => '', 'short_url' => '', 'pinterest_image' => $post_pin_image); }