function est_image_src($html, $post_id, $post_thumbnail_id, $size, $attr) { $post = get_post($post_id); // Only support posts if ('post' !== $post->post_type) { return $html; } // Do nothing if featured image exists if (!empty($html)) { return $html; } // Do nothing if post doesn't exist if (!$post) { return $html; } $category = get_the_category($post_id); $category_slug = $category[0]->slug; // Build URL $src = paf('external_slugified_thumbnails_pattern'); $src = str_replace(array('{{POST_SLUG}}', '{{CATEGORY_SLUG}}'), array($post->post_name, $category_slug), $src); // Do nothing if URL doesn't exist $file_exists = url_works($src); if (!$file_exists) { return $html; } // Do nothing if URL doesn't lead to an image $size = getimagesize_cached($src); if (!$size) { return $html; } if (!$html) { $html = '<img src="{{src}}" tite="{{title}}" alt="{{alt}}" height="{{height}}" width="{{width}}"> '; $html = str_replace(array('{{src}}', '{{title}}', '{{alt}}', '{{width}}', '{{height}}'), array($src, $post->post_title, $post->post_title, $size[0], $size[1]), $html); } return $html; }
function paf_print_option_type_media($option_def) { $option_id = key($option_def); $option = $option_def[$option_id]; if ('~' === K::get_var('description', $option)) { $option['description'] = paf_option_return_dump($option_id); } $button_text = K::get_var('button_text', $option, __('Select media')); // Output K::input('paf[' . $option_id . ']', array('class' => 'paf-option-type-media regular-text', 'placeholder' => K::get_var('placeholder', $option), 'value' => isset($option['value']) ? $option['value'] : paf($option_id), 'data-paf-conditions' => K::get_var('conditions', $option) ? urlencode(json_encode(K::get_var('conditions', $option), JSON_FORCE_OBJECT)) : null, 'data-paf-default' => K::get_var('default', $option)), array('format' => sprintf(paf_option_return_format('media'), paf_option_return_title($option_def), '<a class="button">' . $button_text . '</a>', K::get_var('description', $option, '')))); }