当前位置: 首页>>代码示例>>PHP>>正文


PHP media_sideload_image函数代码示例

本文整理汇总了PHP中media_sideload_image函数的典型用法代码示例。如果您正苦于以下问题:PHP media_sideload_image函数的具体用法?PHP media_sideload_image怎么用?PHP media_sideload_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了media_sideload_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_product_getters_and_setters

 /**
  * Test product setters and getters
  * @since 2.7.0
  */
 public function test_product_getters_and_setters()
 {
     global $wpdb;
     $attributes = array();
     $attribute = new WC_Product_Attribute();
     $attribute->set_id(0);
     $attribute->set_name('Test Attribute');
     $attribute->set_options(array('Fish', 'Fingers'));
     $attribute->set_position(0);
     $attribute->set_visible(true);
     $attribute->set_variation(false);
     $attributes['test-attribute'] = $attribute;
     $getters_and_setters = array('name' => 'Test', 'slug' => 'test', 'status' => 'publish', 'catalog_visibility' => 'search', 'featured' => false, 'description' => 'Hello world', 'short_description' => 'hello', 'sku' => 'TEST SKU', 'regular_price' => 15.0, 'sale_price' => 10.0, 'date_on_sale_from' => '1475798400', 'date_on_sale_to' => '1477267200', 'total_sales' => 20, 'tax_status' => 'none', 'tax_class' => '', 'manage_stock' => true, 'stock_quantity' => 10, 'stock_status' => 'instock', 'backorders' => 'notify', 'sold_individually' => false, 'weight' => 100, 'length' => 10, 'width' => 10, 'height' => 10, 'upsell_ids' => array(2, 3), 'cross_sell_ids' => array(4, 5), 'parent_id' => 0, 'reviews_allowed' => true, 'default_attributes' => array(), 'purchase_note' => 'A note', 'menu_order' => 2, 'gallery_image_ids' => array(), 'download_expiry' => -1, 'download_limit' => 5, 'attributes' => $attributes);
     $product = new WC_Product();
     foreach ($getters_and_setters as $function => $value) {
         $product->{"set_{$function}"}($value);
     }
     $product->save();
     $product = new WC_Product_Simple($product->get_id());
     foreach ($getters_and_setters as $function => $value) {
         $this->assertEquals($value, $product->{"get_{$function}"}(), $function);
     }
     $image_url = media_sideload_image("https://cldup.com/Dr1Bczxq4q.png", $product->get_id(), '', 'src');
     $image_id = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $image_url));
     $product->set_image_id($image_id[0]);
     $product->save();
     $this->assertEquals($image_id[0], $product->get_image_id());
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:32,代码来源:data.php

示例2: side_load_images

 /**
  * Get the source's images and save them locally, for posterity, unless we can't.
  *
  * @since 4.2.0
  * @access public
  *
  * @param int    $post_id Post ID.
  * @param string $content Optional. Current expected markup for Press This. Expects slashed. Default empty.
  * @return string New markup with old image URLs replaced with the local attachment ones if swapped.
  */
 public function side_load_images($post_id, $content = '')
 {
     $content = wp_unslash($content);
     if (preg_match_all('/<img [^>]+>/', $content, $matches) && current_user_can('upload_files')) {
         foreach ((array) $matches[0] as $image) {
             // This is inserted from our JS so HTML attributes should always be in double quotes.
             if (!preg_match('/src="([^"]+)"/', $image, $url_matches)) {
                 continue;
             }
             $image_src = $url_matches[1];
             // Don't try to sideload a file without a file extension, leads to WP upload error.
             if (!preg_match('/[^\\?]+\\.(?:jpe?g|jpe|gif|png)(?:\\?|$)/i', $image_src)) {
                 continue;
             }
             // Sideload image, which gives us a new image src.
             $new_src = media_sideload_image($image_src, $post_id, null, 'src');
             if (!is_wp_error($new_src)) {
                 // Replace the POSTED content <img> with correct uploaded ones.
                 // Need to do it in two steps so we don't replace links to the original image if any.
                 $new_image = str_replace($image_src, $new_src, $image);
                 $content = str_replace($image, $new_image, $content);
             }
         }
     }
     // Edxpected slashed
     return wp_slash($content);
 }
开发者ID:binarydroids,项目名称:WordPress,代码行数:37,代码来源:class-wp-press-this.php

示例3: press_it

function press_it() {
	// define some basic variables
	$quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft';
	$quick['post_category'] = $_REQUEST['post_category'];
	$quick['tags_input'] = $_REQUEST['tags_input'];
	$quick['post_title'] = $_REQUEST['post_title'];
	$quick['post_content'] = '';

	// insert the post with nothing in it, to get an ID
	$post_ID = wp_insert_post($quick, true);

	$content = '';
	switch ( $_REQUEST['post_type'] ) {
		case 'text':
		case 'quote':
			$content .= $_REQUEST['content'];
			break;

		case 'photo':
			$content = $_REQUEST['content'];

			foreach( (array) $_REQUEST['photo_src'] as $key => $image) {
				
				// see if files exist in content - we don't want to upload non-used selected files.
				if( strpos($_REQUEST['content'], $image) !== false ) {
					$upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]);
					 
					// Replace the POSTED content <img> with correct uploaded ones.
					// escape quote for matching
					$quoted = preg_quote2($image);
					if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content);
				}
			}

			break;

		case "video":
			if($_REQUEST['embed_code']) 
				$content .= $_REQUEST['embed_code']."\n\n";
			$content .= $_REQUEST['content'];
			break;
		}
	// set the post_content
	$quick['post_content'] = $content;

	// error handling for $post
	if ( is_wp_error($post_ID)) {
		wp_die($id);
		wp_delete_post($post_ID);
	// error handling for media_sideload
	} elseif ( is_wp_error($upload)) {
		wp_die($upload);
		wp_delete_post($post_ID);
	} else {
		$quick['ID'] = $post_ID;
		wp_update_post($quick);
	}
	return $post_ID;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:59,代码来源:press-this.php

示例4: __copyFiles

 private function __copyFiles($szFileName)
 {
     $upload_dir = wp_upload_dir();
     $_szFileName = $szFileName;
     if (!$this->__checkRecursiveFileExists($szFileName, $upload_dir["basedir"])) {
         // $filename should be the path to a file in the upload directory.
         $szPath = plugins_url() . "/" . $this->_szPluginDir . "/images/" . $_szFileName;
         media_sideload_image($szPath, 0);
     }
 }
开发者ID:ncrayon,项目名称:ncrayon.github.io,代码行数:10,代码来源:ctl-puzzle-deluxe.php

示例5: fpd_admin_upload_image_to_wp

function fpd_admin_upload_image_to_wp($name, $base64_image, $add_to_library = true)
{
    //upload to wordpress
    $upload = wp_upload_bits($name, null, base64_decode($base64_image));
    //add to media library
    if ($add_to_library && isset($upload['url'])) {
        media_sideload_image($upload['url'], 0);
    }
    return $upload['error'] === false ? $upload['url'] : false;
}
开发者ID:pcuervo,项目名称:ur-imprint,代码行数:10,代码来源:fpd-admin-functions.php

示例6: press_it

/**
 * Press It form handler.
 *
 * @package WordPress
 * @subpackage Press_This
 * @since 2.6.0
 *
 * @return int Post ID
 */
function press_it() {

	$post = get_default_post_to_edit();
	$post = get_object_vars($post);
	$post_ID = $post['ID'] = (int) $_POST['post_id'];

	if ( !current_user_can('edit_post', $post_ID) )
		wp_die(__('You are not allowed to edit this post.'));

	$post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
	$post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
	$post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
	$content = isset($_POST['content']) ? $_POST['content'] : '';

	$upload = false;
	if ( !empty($_POST['photo_src']) && current_user_can('upload_files') ) {
		foreach( (array) $_POST['photo_src'] as $key => $image) {
			// see if files exist in content - we don't want to upload non-used selected files.
			if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
				$desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
				$upload = media_sideload_image($image, $post_ID, $desc);

				// Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
				if ( !is_wp_error($upload) )
					$content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
			}
		}
	}
	// set the post_content and status
	$post['post_content'] = $content;
	if ( isset( $_POST['publish'] ) && current_user_can( 'publish_posts' ) )
		$post['post_status'] = 'publish';
	elseif ( isset( $_POST['review'] ) )
		$post['post_status'] = 'pending';
	else
		$post['post_status'] = 'draft';

	// error handling for media_sideload
	if ( is_wp_error($upload) ) {
		wp_delete_post($post_ID);
		wp_die($upload);
	} else {
		// Post formats
		if ( isset( $_POST['post_format'] ) ) {
			if ( current_theme_supports( 'post-formats', $_POST['post_format'] ) )
				set_post_format( $post_ID, $_POST['post_format'] );
			elseif ( '0' == $_POST['post_format'] )
				set_post_format( $post_ID, false );
		}

		$post_ID = wp_update_post($post);
	}

	return $post_ID;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:64,代码来源:press-this.php

示例7: press_it

/**
 * Press It form handler.
 *
 * @package WordPress
 * @subpackage Press_This
 * @since 2.6.0
 *
 * @return int Post ID
 */
function press_it()
{
    // define some basic variables
    $quick = array();
    $quick['post_status'] = 'draft';
    // set as draft first
    $quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null;
    $quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : null;
    $quick['post_title'] = trim($_POST['title']) != '' ? $_POST['title'] : '  ';
    $quick['post_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : '';
    // insert the post with nothing in it, to get an ID
    $post_ID = wp_insert_post($quick, true);
    if (is_wp_error($post_ID)) {
        wp_die($post_ID);
    }
    $content = isset($_POST['content']) ? $_POST['content'] : '';
    $upload = false;
    if (!empty($_POST['photo_src']) && current_user_can('upload_files')) {
        foreach ((array) $_POST['photo_src'] as $key => $image) {
            // see if files exist in content - we don't want to upload non-used selected files.
            if (strpos($_POST['content'], htmlspecialchars($image)) !== false) {
                $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
                $upload = media_sideload_image($image, $post_ID, $desc);
                // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
                if (!is_wp_error($upload)) {
                    $content = preg_replace('/<img ([^>]*)src=\\\\?(\\"|\')' . preg_quote(htmlspecialchars($image), '/') . '\\\\?(\\2)([^>\\/]*)\\/*>/is', $upload, $content);
                }
            }
        }
    }
    // set the post_content and status
    $quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft';
    $quick['post_content'] = $content;
    // error handling for media_sideload
    if (is_wp_error($upload)) {
        wp_delete_post($post_ID);
        wp_die($upload);
    } else {
        // Post formats
        if (current_theme_supports('post-formats') && isset($_POST['post_format'])) {
            $post_formats = get_theme_support('post-formats');
            if (is_array($post_formats)) {
                $post_formats = $post_formats[0];
                if (in_array($_POST['post_format'], $post_formats)) {
                    set_post_format($post_ID, $_POST['post_format']);
                } elseif ('0' == $_POST['post_format']) {
                    set_post_format($post_ID, false);
                }
            }
        }
        $quick['ID'] = $post_ID;
        wp_update_post($quick);
    }
    return $post_ID;
}
开发者ID:Weissenberger13,项目名称:web.portugalrentalcottages,代码行数:64,代码来源:press-this.php

示例8: press_it

/**
 * Press It form handler.
 *
 * @package WordPress
 * @subpackage Press_This
 * @since 2.6.0
 *
 * @return int Post ID
 */
function press_it()
{
    // define some basic variables
    $quick['post_status'] = 'draft';
    // set as draft first
    $quick['post_category'] = isset($_REQUEST['post_category']) ? $_REQUEST['post_category'] : null;
    $quick['tax_input'] = isset($_REQUEST['tax_input']) ? $_REQUEST['tax_input'] : '';
    $quick['post_title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
    $quick['post_content'] = '';
    // insert the post with nothing in it, to get an ID
    $post_ID = wp_insert_post($quick, true);
    $content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
    $upload = false;
    if (!empty($_REQUEST['photo_src']) && current_user_can('upload_files')) {
        foreach ((array) $_REQUEST['photo_src'] as $key => $image) {
            // see if files exist in content - we don't want to upload non-used selected files.
            if (strpos($_REQUEST['content'], $image) !== false) {
                $desc = isset($_REQUEST['photo_description'][$key]) ? $_REQUEST['photo_description'][$key] : '';
                $upload = media_sideload_image($image, $post_ID, $desc);
                // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
                if (!is_wp_error($upload)) {
                    $content = preg_replace('/<img ([^>]*)src=\\\\?(\\"|\')' . preg_quote($image, '/') . '\\\\?(\\2)([^>\\/]*)\\/*>/is', $upload, $content);
                }
            }
        }
    }
    // set the post_content and status
    $quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft';
    $quick['post_content'] = $content;
    $quick['post_title'] = $_REQUEST['title'];
    $url = $_REQUEST['URL'];
    $quick['ID'] = $post_ID;
    wp_update_post($quick);
    if ($url && $url != "External URL (optional)") {
        add_post_meta($post_ID, 'linked_list_url', $url, false);
    }
    // error handling for $post
    if (is_wp_error($post_ID)) {
        wp_die($id);
        wp_delete_post($post_ID);
        // error handling for media_sideload
    } elseif (is_wp_error($upload)) {
        wp_die($upload);
        wp_delete_post($post_ID);
    } else {
        $quick['ID'] = $post_ID;
        wp_update_post($quick);
    }
    return $post_ID;
}
开发者ID:kindaodd,项目名称:press-this-linklog,代码行数:59,代码来源:press-this-linklog.php

示例9: grab_image_from_url

 function grab_image_from_url($image, $post_ID)
 {
     // Set a big timelimt for processing as we are pulling in potentially big files.
     set_time_limit(600);
     // get the image
     $img = media_sideload_image($image, $post_ID);
     if (!is_wp_error($img)) {
         preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $img, $newimage);
         if (!empty($newimage[1][0])) {
             $this->db->query($this->db->prepare("UPDATE {$this->db->posts} SET post_content = REPLACE(post_content, %s, %s);", $image, $newimage[1][0]));
         }
     }
     return $image;
 }
开发者ID:hscale,项目名称:webento,代码行数:14,代码来源:cacheimages.php

示例10: doImport

 /**
  * Imports galleries from WP Flickr Background
  *
  * @param object $main The object of the Main class
  */
 public static function doImport(Main $main)
 {
     global $wpdb;
     $options = get_option(static::WP_OPTION_NAME);
     $galleries = new Galleries($main);
     $images = new Images($main);
     // Turn how many gallery's we process into chunks for progress bar
     $chunks = ceil(100 / count($options['galleries']) - 1);
     $chunk = 0;
     foreach ($options['galleries'] as $wpfbg_gallery) {
         $image_set = sprintf(__('%s (Imported)', $main->getName()), $wpfbg_gallery['name']);
         $gallery_id = $galleries->save(0, $image_set, $wpfbg_gallery['desc']);
         if (!$gallery_id) {
             $main->addDelayedNotice(sprintf(__('Unable to create Image Set <strong>%s</strong>', $main->getName()), $image_set), true);
             continue;
         }
         // If we have custom CSS, add this as a meta to the gallery
         if (!empty($wpfbg_gallery['customcss'])) {
             add_post_meta($gallery_id, \Myatu\WordPress\BackgroundManager\Meta\Stylesheet::MT_CSS, $wpfbg_gallery['customcss'], true);
         }
         foreach ($wpfbg_gallery['photos'] as $photo) {
             if ($photo['id'][0] != 'L') {
                 // Images that do not start with an "L" are only available via a remote URL.
                 $r = media_sideload_image($photo['background'], $gallery_id);
                 if (is_wp_error($r)) {
                     $main->addDelayedNotice(sprintf(__('Unable to import image <em>%s</em> into Image Set <strong>%s</strong>', $main->getName()), $photo['background'], $image_set), true);
                 }
             } else {
                 // Strip any -DDDxDDD from the filename within the URL
                 $background_image_url = preg_replace('#^(.*?)(-\\d{2,4}x\\d{2,4}(?=\\.))(.*)$#', '$1$3', $photo['background']);
                 // Fetch the image ID from the posts/attachments
                 $background_image_id = $wpdb->get_var($wpdb->prepare("SELECT `ID` FROM `{$wpdb->posts}` WHERE `guid` = %s", $background_image_url));
                 // Change the parent of the image attachment to that of the gallery
                 if ($background_image_id && ($image = get_post($background_image_id))) {
                     $r = wp_insert_attachment($image, false, $gallery_id);
                 }
                 if (!$background_image_id || !$image || !$r) {
                     $main->addDelayedNotice(sprintf(__('Unable to import image <em>%s</em> into Image Set <strong>%s</strong>', $main->getName()), $background_image_url, $image_set), true);
                 }
             }
         }
         $chunk++;
         static::setProgress($chunk * $chunks);
     }
     // And voila!
     $main->addDelayedNotice(__('Completed import from WP Flickr Background', $main->getName()));
     unset($galleries);
     unset($images);
 }
开发者ID:zhengxiexie,项目名称:wordpress,代码行数:54,代码来源:WpFlickrBackground.php

示例11: check_recipe_demo

 public function check_recipe_demo()
 {
     if (isset($_GET['wpurp_reset_demo_recipe'])) {
         update_option('wpurp_demo_recipe', false);
         WPUltimateRecipe::get()->helper('notices')->add_admin_notice('<strong>WP Ultimate Recipe</strong> The Recipe Demo has been reset');
     }
     if (!get_option('wpurp_demo_recipe', false)) {
         // Demo Recipe content
         $_POST = array('recipe_meta_box_nonce' => wp_create_nonce('recipe'), 'recipe_description' => __('This must be the best demo recipe I have ever seen. I could eat this every single day.', 'wp-ultimate-recipe'), 'recipe_rating' => '4', 'recipe_servings' => '2', 'recipe_servings_type' => __('people', 'wp-ultimate-recipe'), 'recipe_prep_time' => '10', 'recipe_prep_time_text' => __('minutes', 'wp-ultimate-recipe'), 'recipe_cook_time' => '20', 'recipe_cook_time_text' => __('minutes', 'wp-ultimate-recipe'), 'recipe_passive_time' => '1', 'recipe_passive_time_text' => __('hour', 'wp-ultimate-recipe'), 'recipe_ingredients' => array(array('group' => '', 'amount' => '175', 'unit' => 'g', 'ingredient' => 'tagliatelle', 'notes' => ''), array('group' => '', 'amount' => '200', 'unit' => 'g', 'ingredient' => 'bacon', 'notes' => 'tiny strips'), array('group' => 'Fresh Pesto', 'amount' => '1', 'unit' => 'clove', 'ingredient' => 'garlic', 'notes' => ''), array('group' => 'Fresh Pesto', 'amount' => '12.5', 'unit' => 'g', 'ingredient' => 'pine kernels', 'notes' => ''), array('group' => 'Fresh Pesto', 'amount' => '50', 'unit' => 'g', 'ingredient' => 'basil leaves', 'notes' => ''), array('group' => 'Fresh Pesto', 'amount' => '6.25', 'unit' => 'cl', 'ingredient' => 'olive oil', 'notes' => 'extra virgin'), array('group' => 'Fresh Pesto', 'amount' => '27.5', 'unit' => 'g', 'ingredient' => 'Parmesan cheese', 'notes' => 'freshly grated')), 'recipe_instructions' => array(array('group' => 'Fresh Pesto (you can make this in advance)', 'description' => 'We\'ll be using a food processor to make the pesto. Put the garlic, pine kernels and some salt in there and process briefly.', 'image' => ''), array('group' => 'Fresh Pesto (you can make this in advance)', 'description' => 'Add the basil leaves (but keep some for the presentation) and blend to a green paste.', 'image' => ''), array('group' => 'Fresh Pesto (you can make this in advance)', 'description' => 'While processing, gradually add the olive oil and finally add the Parmesan cheese.', 'image' => ''), array('group' => 'Finishing the dish', 'description' => 'Bring a pot of salted water to the boil and cook your tagliatelle al dente.', 'image' => ''), array('group' => 'Finishing the dish', 'description' => 'Use the cooking time of the pasta to sauté your bacon strips.', 'image' => ''), array('group' => 'Finishing the dish', 'description' => 'After about 8 to 10 minutes, the pasta should be done. Drain it and put it back in the pot to mix it with the pesto.', 'image' => ''), array('group' => 'Finishing the dish', 'description' => 'Present the dish with some fresh basil leaves on top.', 'image' => '')), 'recipe_notes' => __('Use this section for whatever you like.', 'wp-ultimate-recipe'));
         $post_content = '<p>' . __('Use this like normal post content. The recipe will automatically be included at the end of the post, or wherever you place the shortcode:', 'wp-ultimate-recipe') . '</p>[recipe]<br/><p>' . __('This text will appear below your recipe.', 'wp-ultimate-recipe');
         if (WPUltimateRecipe::is_addon_active('nutritional-information')) {
             $post_content .= ' ' . __('Followed by the nutrition label:', 'wp-ultimate-recipe') . '</p>[nutrition-label]<br/>';
         } else {
             $post_content .= '</p>';
         }
         // Insert post
         $post = array('post_title' => __('Demo Recipe', 'wp-ultimate-recipe'), 'post_content' => $post_content, 'post_type' => 'recipe', 'post_status' => 'private', 'post_author' => get_current_user_id());
         $post_id = wp_insert_post($post);
         update_option('wpurp_demo_recipe', $post_id);
         // Update post taxonomies
         $tags = array('cuisine' => array('Italian'), 'course' => array('Main Dish'));
         foreach ($tags as $tag => $terms) {
             $term_ids = array();
             foreach ($terms as $term) {
                 $existing_term = term_exists($term, $tag);
                 if ($existing_term == 0 || $existing_term == null) {
                     $new_term = wp_insert_term($term, $tag);
                     $term_ids[] = (int) $new_term['term_id'];
                 } else {
                     $term_ids[] = (int) $existing_term['term_id'];
                 }
             }
             wp_set_object_terms($post_id, $term_ids, $tag);
         }
         // Recipe image
         $url = WPUltimateRecipe::get()->coreUrl . '/img/demo-recipe.jpg';
         media_sideload_image($url, $post_id);
         $attachments = get_posts(array('numberposts' => '1', 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));
         if (sizeof($attachments) > 0) {
             set_post_thumbnail($post_id, $attachments[0]->ID);
         }
         // Nutritional Information
         $nutritional = array('calories' => '1276', 'carbohydrate' => '71', 'protein' => '57', 'fat' => '85', 'saturated_fat' => '22', 'polyunsaturated_fat' => '10', 'monounsaturated_fat' => '44', 'trans_fat' => '', 'cholesterol' => '238', 'sodium' => '2548', 'potassium' => '620', 'fiber' => '4', 'sugar' => '4', 'vitamin_a' => '2', 'vitamin_c' => '0.1', 'calcium' => '16', 'iron' => '12');
         update_post_meta($post_id, 'recipe_nutritional', $nutritional);
         // Update recipe content
         WPUltimateRecipe::get()->helper('recipe_save')->save($post_id, get_post($post_id));
     }
 }
开发者ID:robertoperata,项目名称:bbqverona.com,代码行数:48,代码来源:recipe_demo.php

示例12: doClone

 public function doClone()
 {
     $postFinder = PostFinder::getInstance();
     $lastPost = $postFinder->getRandomPost();
     $url = $lastPost->href;
     $advancedCloner = new PostCloner($url, TRUE);
     $post = $advancedCloner->getPost();
     if (!$this->is_post_exist($post->title)) {
         $postArr = array('post_title' => $post->title, 'post_content' => $post->content, 'post_status' => 'publish', 'post_author' => 1);
         $postId = wp_insert_post($postArr);
         require_once ABSPATH . 'wp-admin/includes/media.php';
         require_once ABSPATH . 'wp-admin/includes/file.php';
         require_once ABSPATH . 'wp-admin/includes/image.php';
         media_sideload_image($post->thumbnail, $postId);
     }
 }
开发者ID:nguyenvanduocit,项目名称:WP-Translatable-Cloner,代码行数:16,代码来源:Schedule.php

示例13: addProfilePhoto

 private function addProfilePhoto($user_id, $newUser, $value, $membername)
 {
     $addPhoto = false;
     $newPhoto = trim($value);
     if ($newUser) {
         $addPhoto = true;
     } else {
         $currUserPhoto = basename(get_user_meta($user_id, 'profilepicture', true));
         if (strcasecmp($currUserPhoto, $newPhoto) != 0) {
             $addPhoto = true;
         }
     }
     if ($addPhoto && $newPhoto) {
         $photoHTML = media_sideload_image($this->rotaryImageURL . $value, 1, $membername);
         if (!is_wp_error($photoHTML)) {
             $doc = new DOMDocument();
             @$doc->loadHTML($photoHTML);
             $tags = $doc->getElementsByTagName('img');
             update_user_meta($user_id, 'profilepicture', $tags->item(0)->getAttribute('src'));
         }
     }
 }
开发者ID:cshort,项目名称:rotary-dacdb,代码行数:22,代码来源:rotary-dacdb-memberdata.php

示例14: td_get_video_thumb

function td_get_video_thumb($post_id)
{
    //verify post is not a revision
    if (!wp_is_post_revision($post_id)) {
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return;
        }
        $td_post_video = get_post_meta($post_id, 'td_post_video', true);
        //load video support
        $td_video_support = new td_video_support();
        //check to see if the url is valid
        if (empty($td_post_video['td_video']) or $td_video_support->validateVideoUrl($td_post_video['td_video']) === false) {
            return;
        }
        if (!empty($td_post_video['td_last_video']) and $td_post_video['td_last_video'] == $td_post_video['td_video']) {
            //we did not update the url
            return;
        }
        //$myFile = "D:/td_video.txt";
        //$fh = fopen($myFile, 'a') or die("can't open file");
        $stringData = $post_id . ' - ' . print_r($td_post_video, true) . "\n";
        //return;
        $videoThumbUrl = $td_video_support->getThumbUrl($td_post_video['td_video']);
        /*
                $stringData .= $post_id . ' - ' . $videoThumbUrl . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
        */
        if (!empty($videoThumbUrl)) {
            // add the function above to catch the attachments creation
            add_action('add_attachment', 'td_add_featured_image');
            // load the attachment from the URL
            media_sideload_image($videoThumbUrl, $post_id, $post_id);
            // we have the Image now, and the function above will have fired too setting the thumbnail ID in the process, so lets remove the hook so we don't cause any more trouble
            remove_action('add_attachment', 'td_add_featured_image');
        }
    }
}
开发者ID:Che234,项目名称:andreatelo,代码行数:38,代码来源:td_video_support.php

示例15: upload

 /**
  * Side upload the image and set it as the post thumbnail
  */
 private function upload()
 {
     // Not an image ?
     if (!preg_match('/[^\\?]+\\.(?:jpe?g|jpe|gif|png)(?:\\?|$)/i', $this->src)) {
         $this->result = new WP_Error('not_an_image', __('This image file type is not supported.', 'wp-idea-stream'));
         // We can proceed
     } else {
         // First there can be a chance the src is already saved as an attachment
         $thumbnail_id = self::get_existing_attachment($this->src);
         if (!empty($thumbnail_id)) {
             $this->result = set_post_thumbnail($this->post_id, $thumbnail_id);
             // Otherwise, we need to save it
         } else {
             // Temporarly filter the attachment url to set the Thumbnail ID
             add_filter('wp_get_attachment_url', array($this, 'intercept_id'), 10, 2);
             $this->new_src = media_sideload_image($this->src, $this->post_id, null, 'src');
             remove_filter('wp_get_attachment_url', array($this, 'intercept_id'), 10, 2);
             if (!is_wp_error($this->new_src) && isset($this->thumbnail_id)) {
                 $this->result = set_post_thumbnail($this->post_id, $this->thumbnail_id);
                 update_post_meta($this->thumbnail_id, '_ideastream_original_src', esc_url_raw($this->src));
             } else {
                 $this->result = new WP_Error('sideload_failed');
             }
         }
     }
 }
开发者ID:mrjarbenne,项目名称:wp-idea-stream,代码行数:29,代码来源:classes.php


注:本文中的media_sideload_image函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。