本文整理汇总了PHP中_wp_image_editor_choose函数的典型用法代码示例。如果您正苦于以下问题:PHP _wp_image_editor_choose函数的具体用法?PHP _wp_image_editor_choose怎么用?PHP _wp_image_editor_choose使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_wp_image_editor_choose函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_image_editor_supports
/**
* Tests whether there is an editor that supports a given mime type or methods.
*
* @since 3.5.0
*
* @param string|array $args Optional. Array of arguments to retrieve the image editor supports.
* Default empty array.
* @return bool True if an eligible editor is found; false otherwise.
*/
function wp_image_editor_supports($args = array())
{
return (bool) _wp_image_editor_choose($args);
}
示例2: dln_download_image_from_url
public function dln_download_image_from_url()
{
check_ajax_referer(DLN_ABE_NONCE . '_download_image_from_url', 'security');
$data = isset($_POST['data']) ? $_POST['data'] : '';
$image_data = isset($data['image_data']) ? $data['image_data'] : '';
if ($image_data) {
$image_data = json_decode(stripcslashes($image_data));
}
$result_data = array();
foreach ($image_data as $i => $image) {
// Get external id
$external_id = '';
if ($image) {
$external_id = isset($image->id) ? $image->id : '';
}
$url = isset($image->url) ? $image->url : '';
$url = urldecode($url);
if (!empty($url) && filter_var($url, FILTER_VALIDATE_URL) !== false && !empty($external_id)) {
// Check external image exists in system
global $wpdb;
$wpdb->postmeta;
$sql = $wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s", array(esc_sql('_dln_external_id'), esc_sql($external_id)));
$result = $wpdb->get_row($sql);
if (!empty($result->post_id)) {
$id = $result->post_id;
} else {
$name = basename($url);
$name = substr($name, 0, strpos($name, '?'));
$tmp_name = WP_CONTENT_DIR . '/uploads/dln_product_cache/' . $name;
$implementation = _wp_image_editor_choose();
$editor = new $implementation($url);
$loaded = $editor->load();
if (is_wp_error($loaded)) {
return $loaded;
}
$editor->set_quality(100);
$editor->resize(DLN_MAX_IMAGE_SIZE, DLN_MAX_IMAGE_SIZE, false);
$editor->save($tmp_name);
$file_array = array('name' => $name, 'tmp_name' => $tmp_name);
// Check for download errors
if (is_wp_error($tmp_name)) {
@unlink($file_array['tmp_name']);
return $tmp_name;
}
$id = media_handle_sideload($file_array, 0);
// Check for handle sideload errors.
if (is_wp_error($id)) {
@unlink($file_array['tmp_name']);
return $id;
}
update_post_meta($id, '_dln_external_id', $external_id);
$user_ids = get_post_meta($id, '_dln_user_used', true);
$arr_user_ids = array();
if ($user_ids) {
$arr_user_ids = json_decode($user_ids);
}
$user_id = get_current_user_id();
if ($user_id && is_array($arr_user_ids)) {
$arr_user_ids[] = $user_id;
update_post_meta($id, '_dln_user_used', json_encode($arr_user_ids));
}
}
$attachment_url = wp_get_attachment_image_src($id, array(DLN_MAIN_IMAGE_SIZE, DLN_MAIN_IMAGE_SIZE));
$attachment_url = count($attachment_url) ? $attachment_url[0] : DLN_DEFAULT_IMAGE;
// Build img data
$img_data = esc_attr(serialize(array('type' => 'local', 'external_id' => $id)));
$result_data[] = array('id' => $id, 'url' => $attachment_url);
}
}
$result = array('status' => 'success', 'image_json' => $result_data);
echo json_encode($result);
exit;
}