/** * Displays preview * @author jtsternberg * @since 5.3.2 * @param $args * @param $field * @return mixed */ function cmb_update_title_description($args, $field) { if ($field->id() == 'twitter_featured_size') { $args['desc'] = JM_TC_Thumbs::get_post_thumbnail_weight($field->object_id); } if ($field->id() == 'preview_title') { $args['desc'] = JM_TC_Preview::show_preview($field->object_id); } return $args; }
public function image($post_ID = false) { $cardImage = get_post_meta($post_ID, 'cardImage', true); //gallery if (($cardType = get_post_meta($post_ID, 'twitterCardType', true)) != 'gallery') { if (get_the_post_thumbnail($post_ID) != '') { if (!empty($cardImage)) { // cardImage is set $image = $cardImage; } else { $size = JM_TC_Thumbs::thumbnail_sizes($post_ID); $image_attributes = wp_get_attachment_image_src(get_post_thumbnail_id($post_ID), $size); $image = $image_attributes[0]; } } elseif (get_the_post_thumbnail($post_ID) == '' && !empty($cardImage)) { $image = $cardImage; } elseif ('attachment' == get_post_type()) { $image = wp_get_attachment_url($post_ID); } elseif ($post_ID == false) { $image = $this->opts['twitterImage']; } else { //fallback $image = $this->opts['twitterImage']; } //In case Open Graph is on $img_meta = $this->opts['twitterCardOg'] == 'yes' ? 'image' : 'image:src'; return array($img_meta => apply_filters('jm_tc_image_source', $image)); } else { // markup will be different global $post; if (is_a($post, 'WP_Post') && function_exists('has_shortcode')) { if (has_shortcode($post->post_content, 'gallery')) { $query_img = get_post_gallery() ? get_post_gallery($post_ID, false) : array(); //no backward compatibility before 3.6 $pic = array(); $i = 0; foreach ($query_img['src'] as $img) { // get attachment array with the ID from the returned posts $pic['image' . $i . ':src'] = $img; $i++; if ($i > 3) { break; } //in case there are more than 4 images in post, we are not allowed to add more than 4 images in our card by Twitter } return $pic; } else { return self::error(__('Warning : Gallery Card is not set properly ! There is no gallery in this post !', JM_TC_TEXTDOMAIN)); } } } }