本文整理汇总了PHP中attachment_url_to_postid函数的典型用法代码示例。如果您正苦于以下问题:PHP attachment_url_to_postid函数的具体用法?PHP attachment_url_to_postid怎么用?PHP attachment_url_to_postid使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attachment_url_to_postid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: siteorigin_north_display_logo
/**
* Display the logo or site title
*/
function siteorigin_north_display_logo()
{
$logo = siteorigin_setting('branding_logo');
if (!empty($logo)) {
$logo_id = attachment_url_to_postid($logo);
$attrs = apply_filters('siteorigin_north_logo_attributes', array());
?>
<a href="<?php
echo esc_url(home_url('/'));
?>
" rel="home"><?php
echo wp_get_attachment_image($logo_id, 'full', false, $attrs);
?>
</a><?php
} else {
?>
<h1 class="site-title"><a href="<?php
echo esc_url(home_url('/'));
?>
" rel="home"><?php
bloginfo('name');
?>
</a></h1><?php
}
}
示例2: jr_mt_convert_url_arrays
function jr_mt_convert_url_arrays($settings)
{
global $jr_mt_url_types;
foreach ($jr_mt_url_types as $setting_key) {
if (isset($settings[$setting_key]) && is_array($settings[$setting_key])) {
foreach ($settings[$setting_key] as $url_key => $url_array) {
$url = $url_array['url'];
if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
$new_url_array['url'] = $url_array['url'];
$new_url_array['theme'] = $url_array['theme'];
$rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
$new_url_array['rel'] = $rel_url;
/* Create the URL Prep array for each of the current Site Aliases,
including the Current Site URL
*/
$new_url_array['prep'] = array();
foreach ($settings['aliases'] as $index => $alias) {
$new_url_array['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
}
/* Only for URL type Setting, not Prefix types.
*/
if ('url' === $setting_key) {
/* Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
*/
if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
$id = attachment_url_to_postid($url);
}
if (!empty($id)) {
$new_url_array['id'] = (string) $id;
if (NULL !== ($post = get_post($id))) {
switch ($post->post_type) {
case 'post':
$new_url_array['id_kw'] = 'p';
break;
case 'page':
$new_url_array['id_kw'] = 'page_id';
break;
case 'attachment':
$new_url_array['id_kw'] = 'attachment_id';
break;
}
}
}
}
$settings[$setting_key][$url_key] = $new_url_array;
} else {
/* Error:
Cannot convert, as URL is from a different Site Home URL,
so have to delete this URL entry.
*/
unset($settings[$setting_key][$url_key]);
jr_mt_messages('Setting deleted during Conversion to Version 6 format because Site URL has changed');
}
}
}
}
return $settings;
}
示例3: render_widget
/**
* Display widget content on frontend
*
* @param array $data
* @param string $id
* @param int $number
*/
public static function render_widget(array $data, $id, $number)
{
if (!empty($data['video'])) {
echo wp_oembed_get($data['video']);
}
if (!empty($data['thumbnail']) && ($image_id = absint(attachment_url_to_postid($data['thumbnail']))) && wp_attachment_is_image($image_id)) {
echo wp_get_attachment_image($image_id, 'medium');
}
}
示例4: to_json
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @since 3.4.0
*
* @uses WP_Customize_Media_Control::to_json()
*/
public function to_json()
{
parent::to_json();
$value = $this->value();
if ($value) {
// Get the attachment model for the existing file.
$attachment_id = attachment_url_to_postid($value);
if ($attachment_id) {
$this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
}
}
}
示例5: widget
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget($args, $instance)
{
extract($args);
extract($instance);
$client_image = empty($instance['client_image']) ? false : $instance['client_image'];
$client_name = empty($instance['client_name']) ? false : $instance['client_name'];
$client_designation = empty($instance['client_designation']) ? false : $instance['client_designation'];
$client_testimonial = empty($instance['client_testimonial']) ? false : $instance['client_testimonial'];
$img_id = attachment_url_to_postid($client_image);
$image = wp_get_attachment_image_src($img_id, 'accesspress-basic-testimonial-thumbnail');
echo $before_widget;
?>
<div class="testimonials-wrap clearfix">
<figure class="testimonial-image-wrap">
<div class="testimonial-img">
<?php
if (!empty($image[0])) {
?>
<img src="<?php
echo $image[0];
?>
" />
<?php
} else {
?>
<img src="<?php
echo get_template_directory_uri() . '/images/no-testimonial-thumbnail.png';
?>
" />
<?php
}
?>
</div>
<span class="client-name"><?php
echo esc_attr($client_name);
?>
</span>
<span class="client-designation"><?php
echo esc_attr($client_designation);
?>
</span>
</figure>
<div class="testimonial">
<?php
echo esc_textarea($client_testimonial);
?>
</div>
</div>
<?php
echo $after_widget;
}
示例6: create_image
protected function create_image()
{
$attachment_id = attachment_url_to_postid($this->main_image_url);
if (!$attachment_id) {
die(__('Unknown attachment.', 'crb'));
}
$image_sizes = Helper::get_image_sizes();
$image_size_name = $this->find_attachment_image_size($attachment_id, $this->requested_image_width, $this->requested_image_height);
if (empty($image_size_name) || empty($image_sizes[$image_size_name])) {
die(__('Unknown image size.', 'crb'));
}
$image_details = Helper::get_image_src($attachment_id, $image_size_name);
$this->new_image_url = $image_details['src'];
$this->new_image_path = str_replace($this->upload_dir['baseurl'], $this->upload_dir['basedir'], $this->new_image_url);
return $this;
}
示例7: extract_from_attachment_metadata
public static function extract_from_attachment_metadata($dimensions, $url)
{
if (is_array($dimensions)) {
return $dimensions;
}
$url = strtok($url, '?');
$attachment_id = attachment_url_to_postid($url);
if (empty($attachment_id)) {
return false;
}
$metadata = wp_get_attachment_metadata($attachment_id);
if (!$metadata) {
return false;
}
return array($metadata['width'], $metadata['height']);
}
示例8: convert
/**
* Convert markdown image to html image tag
*
* @return string
*/
public function convert()
{
$time = get_the_time('Y/m', $this->post_id);
$wp_upload_dir = wp_upload_dir($time, $this->post_id);
$this->upload_url = untrailingslashit($wp_upload_dir['url']);
return preg_replace_callback('/\\!\\[(.*?)\\]\\((.+?)\\)/sm', function ($matches) {
$pathinfo = pathinfo($matches[2]);
$Unicode_Normalization = new Markdown_Importer_Unicode_Normalization($matches[2]);
$filename = $Unicode_Normalization->convert();
$filename = sha1($filename) . '.' . $pathinfo['extension'];
$attachment_url = $this->upload_url . '/' . $filename;
$attachment_id = attachment_url_to_postid($attachment_url);
$full = wp_get_attachment_image_url($attachment_id, 'full');
$large = wp_get_attachment_image_url($attachment_id, 'large');
if (!$full || !$large) {
return;
}
return sprintf('<a class="markdown-importer-image-link" href="%1$s"><img class="size-large wp-image-%2$d markdown-importer-image" src="%3$s" alt="%4$s" /></a>', esc_url($full), esc_attr($attachment_id), esc_url($large), esc_attr($matches[1]));
}, $this->content);
}
示例9: update
/**
* Overwrites the `update()` method so we can save some extra data.
*
* @since 3.0.0
* @access public
* @param string $value
* @return string
*/
protected function update($value)
{
if ($value) {
$post_id = attachment_url_to_postid($value);
if ($post_id) {
$image = wp_get_attachment_image_src($post_id);
if ($image) {
// Set up a custom array of data to save.
$data = array('url' => esc_url_raw($image[0]), 'width' => absint($image[1]), 'height' => absint($image[2]), 'id' => absint($post_id));
set_theme_mod("{$this->id_data['base']}_data", $data);
}
}
}
// No media? Remove the data mod.
if (empty($value) || empty($post_id) || empty($image)) {
remove_theme_mod("{$this->id_data['base']}_data");
}
// Let's send this back up and let the parent class do its thing.
return parent::update($value);
}
示例10: to_json
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
*
* highly based on WP_Customize_Media_Control merged with WP_Customize_Upload_Control ::to_json()
*/
public function to_json()
{
$this->json['mime_type'] = $this->mime_type;
$this->json['button_labels'] = $this->button_labels;
$this->json['bg_repeat_options'] = $this->bg_repeat_options;
$this->json['bg_attachment_options'] = $this->bg_attachment_options;
$this->json['bg_position_options'] = $this->bg_position_options;
$this->json['canUpload'] = current_user_can('upload_files');
$this->json['default_model'] = $this->default_model;
$value = $this->value();
if (isset($this->setting) && is_object($this->setting)) {
$_defaults = isset($this->setting->default) ? $this->setting->default : null;
$default_bg_img = isset($_defaults['background-image']) ? $_defaults['background-image'] : null;
}
$default_bg_im = isset($default_bg_img) ? $default_bg_img : null;
if ($default_bg_img) {
// Fake an attachment model - needs all fields used by template.
// Note that the default value must be a URL, NOT an attachment ID.
$type = in_array(substr($default_bg_img, -3), array('jpg', 'png', 'gif', 'bmp', 'svg')) ? 'image' : 'document';
$default_attachment = array('id' => 1, 'url' => $default_bg_img, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($default_bg_img));
$default_attachment['sizes'] = array('full' => array('url' => $default_bg_img));
$this->json['defaultAttachment'] = $default_attachment;
}
$background_image = isset($value['background-image']) ? $value['background-image'] : null;
if ($background_image && $default_bg_img && $background_image === $default_bg_img) {
// Set the default as the attachment.
$this->json['attachment'] = $this->json['defaultAttachment'];
} elseif ($background_image) {
$attachment_id = attachment_url_to_postid($background_image);
if ($attachment_id) {
$this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
} else {
//already an id
$this->json['attachment'] = wp_prepare_attachment_for_js($background_image);
}
}
parent::to_json();
}
示例11: to_json
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
*
* @Override
* @see WP_Customize_Control::to_json()
*/
public function to_json()
{
parent::to_json();
$this->json['title'] = !empty($this->title) ? esc_html($this->title) : '';
$this->json['notice'] = !empty($this->notice) ? $this->notice : '';
$this->json['dst_width'] = isset($this->dst_width) ? $this->dst_width : $this->width;
$this->json['dst_height'] = isset($this->dst_height) ? $this->dst_height : $this->height;
//overload WP_Customize_Upload_Control
//we need to re-build the absolute url of the logo src set in old Customizr
$value = $this->value();
if ($value) {
//re-build the absolute url if the value isn't an attachment id before retrieving the id
if ((int) esc_attr($value) < 1) {
$upload_dir = wp_upload_dir();
$value = false !== strpos($value, '/wp-content/') ? $value : $upload_dir['baseurl'] . $value;
}
// Get the attachment model for the existing file.
$attachment_id = attachment_url_to_postid($value);
if ($attachment_id) {
$this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
}
}
//end overload
}
示例12: test_attachment_url_to_postid_with_empty_url
/**
* @ticket 31044
*/
function test_attachment_url_to_postid_with_empty_url()
{
$post_id = attachment_url_to_postid('');
$this->assertInternalType('int', $post_id);
$this->assertEquals(0, $post_id);
}
示例13: accesspress_basic_widgets_show_widget_field
//.........这里部分代码省略.........
?>
</small>
<?php
}
?>
</p>
<?php
break;
case 'upload':
$output = '';
$id = $instance->get_field_id($apbasic_widgets_name);
$class = '';
$int = '';
$value = $athm_field_value;
$name = $instance->get_field_name($apbasic_widgets_name);
if ($value) {
$class = ' has-file';
}
$output .= '<div class="sub-option widget-upload">';
$output .= '<label for="' . $instance->get_field_id($apbasic_widgets_name) . '">' . $apbasic_widgets_title . '</label><br/>';
$output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="' . $name . '" value="' . $value . '" placeholder="' . __('No file chosen', 'accesspress-basic') . '" />' . "\n";
if (function_exists('wp_enqueue_media')) {
//if (( $value == '')) {
$output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __('Upload', 'accesspress-basic') . '" />' . "\n";
//} else {
// $output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __('Remove', 'accesspress-basic') . '" />' . "\n";
//}
} else {
$output .= '<p><i>' . __('Upgrade your version of WordPress for full media support.', 'accesspress-basic') . '</i></p>';
}
$output .= '<div class="screenshot team-thumb" id="' . $id . '-image">' . "\n";
if ($value != '') {
$remove = '<a class="remove-image remove-screenshot">Remove</a>';
$attachment_id = attachment_url_to_postid($value);
$image_array = wp_get_attachment_image_src($attachment_id, 'medium');
$image = preg_match('/(^.*\\.jpg|jpeg|png|gif|ico*)/i', $value);
if ($image) {
$output .= '<img src="' . $image_array[0] . '" alt="" />' . $remove;
} else {
$parts = explode("/", $value);
for ($i = 0; $i < sizeof($parts); ++$i) {
$title = $parts[$i];
}
// No output preview if it's not an image.
$output .= '';
// Standard generic output if it's not an image.
$title = __('View File', 'textdomain');
$output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">' . $title . '</a></span></div>';
}
}
$output .= '</div></div>' . "\n";
echo $output;
break;
case 'select_theme':
?>
<p>
<label for="<?php
echo $instance->get_field_id($apbasic_widgets_name);
?>
"><?php
echo $apbasic_widgets_title;
?>
:</label>
<select name="<?php
echo $instance->get_field_name($apbasic_widgets_name);
?>
示例14: maybe_convert_to_custom_logo
/**
* For users upgrading Reach who are on WordPress 4.5, migrate core's Custom Logo.
*
* @return void
* @access public
* @since 1.0.3
*/
public function maybe_convert_to_custom_logo()
{
/* Return if update has already been run */
if (-1 != get_theme_mod('custom_logo', -1)) {
return;
}
/* Make sure we're on WP 4.5 */
if (!function_exists('the_custom_logo')) {
return;
}
$custom_logo = false;
$current_logo = reach_get_customizer_image_data('logo');
if ($current_logo) {
/* Bail early if we don't have a valid logo anyway. */
if (!isset($current_logo['image'])) {
set_theme_mod('custom_logo', $custom_logo);
return;
}
/* Swap the retina image for the standard. */
if (isset($current_logo['id'])) {
$logo = intval($current_logo['id']);
} else {
$logo = attachment_url_to_postid($current_logo['image']);
}
if (is_int($logo)) {
$custom_logo = $logo;
}
remove_theme_mod('logo');
}
set_theme_mod('custom_logo', $custom_logo);
}
示例15: to_json
/**
* Add custom parameters to pass to the JS via JSON.
*
* @since 1.0.0
* @access public
* @return void
*/
public function to_json()
{
parent::to_json();
$background_choices = $this->background_choices;
$field_labels = $this->field_labels;
// Loop through each of the settings and set up the data for it.
foreach ($this->settings as $setting_key => $setting_id) {
$this->json[$setting_key] = array('link' => $this->get_link($setting_key), 'value' => $this->value($setting_key), 'label' => isset($field_labels[$setting_key]) ? $field_labels[$setting_key] : '');
if ('image_url' === $setting_key) {
if ($this->value($setting_key)) {
// Get the attachment model for the existing file.
$attachment_id = attachment_url_to_postid($this->value($setting_key));
if ($attachment_id) {
$this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
}
}
} elseif ('repeat' === $setting_key) {
$this->json[$setting_key]['choices'] = $background_choices['repeat'];
} elseif ('size' === $setting_key) {
$this->json[$setting_key]['choices'] = $background_choices['size'];
} elseif ('position' === $setting_key) {
$this->json[$setting_key]['choices'] = $background_choices['position'];
} elseif ('attach' === $setting_key) {
$this->json[$setting_key]['choices'] = $background_choices['attach'];
}
}
}
开发者ID:devinsays,项目名称:customizer-background-control,代码行数:34,代码来源:class-customize-background-image-control.php