• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_image_editor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: wp_ajax_image_editor

/**
 * Ajax handler for image editing.
 *
 * @since 3.1.0
 */
function wp_ajax_image_editor()
{
    $attachment_id = intval($_POST['postid']);
    if (empty($attachment_id) || !current_user_can('edit_post', $attachment_id)) {
        wp_die(-1);
    }
    check_ajax_referer("image_editor-{$attachment_id}");
    include_once ABSPATH . 'wp-admin/includes/image-edit.php';
    $msg = false;
    switch ($_POST['do']) {
        case 'save':
            $msg = wp_save_image($attachment_id);
            $msg = wp_json_encode($msg);
            wp_die($msg);
            break;
        case 'scale':
            $msg = wp_save_image($attachment_id);
            break;
        case 'restore':
            $msg = wp_restore_image($attachment_id);
            break;
    }
    wp_image_editor($attachment_id, $msg);
    wp_die();
}
开发者ID:hughnet,项目名称:WordPress,代码行数:30,代码来源:ajax-actions.php


示例2: edit_form_image_editor

/**
 * Displays the image and editor in the post editor
 *
 * @since 3.5.0
 */
function edit_form_image_editor($post)
{
    $open = isset($_GET['image-editor']);
    if ($open) {
        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    }
    $thumb_url = false;
    if ($attachment_id = intval($post->ID)) {
        $thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 450), true);
    }
    $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
    $att_url = wp_get_attachment_url($post->ID);
    ?>
	<div class="wp_attachment_holder">
	<?php 
    if (wp_attachment_is_image($post->ID)) {
        $image_edit_button = '';
        if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
            $nonce = wp_create_nonce("image_editor-{$post->ID}");
            $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
        }
        ?>

		<div class="imgedit-response" id="imgedit-response-<?php 
        echo $attachment_id;
        ?>
"></div>

		<div<?php 
        if ($open) {
            echo ' style="display:none"';
        }
        ?>
 class="wp_attachment_image" id="media-head-<?php 
        echo $attachment_id;
        ?>
">
			<p id="thumbnail-head-<?php 
        echo $attachment_id;
        ?>
"><img class="thumbnail" src="<?php 
        echo set_url_scheme($thumb_url[0]);
        ?>
" style="max-width:100%" alt="" /></p>
			<p><?php 
        echo $image_edit_button;
        ?>
</p>
		</div>
		<div<?php 
        if (!$open) {
            echo ' style="display:none"';
        }
        ?>
 class="image-editor" id="image-editor-<?php 
        echo $attachment_id;
        ?>
">
			<?php 
        if ($open) {
            wp_image_editor($attachment_id);
        }
        ?>
		</div>
	<?php 
    } elseif ($attachment_id && 0 === strpos($post->post_mime_type, 'audio/')) {
        wp_maybe_generate_attachment_metadata($post);
        echo wp_audio_shortcode(array('src' => $att_url));
    } elseif ($attachment_id && 0 === strpos($post->post_mime_type, 'video/')) {
        wp_maybe_generate_attachment_metadata($post);
        $meta = wp_get_attachment_metadata($attachment_id);
        $w = !empty($meta['width']) ? min($meta['width'], 640) : 0;
        $h = !empty($meta['height']) ? $meta['height'] : 0;
        if ($h && $w < $meta['width']) {
            $h = round($meta['height'] * $w / $meta['width']);
        }
        $attr = array('src' => $att_url);
        if (!empty($w) && !empty($h)) {
            $attr['width'] = $w;
            $attr['height'] = $h;
        }
        $thumb_id = get_post_thumbnail_id($attachment_id);
        if (!empty($thumb_id)) {
            $attr['poster'] = wp_get_attachment_url($thumb_id);
        }
        echo wp_video_shortcode($attr);
    }
    ?>
	</div>
	<div class="wp_attachment_details edit-form-section">
		<p>
			<label for="attachment_caption"><strong><?php 
    _e('Caption');
    ?>
</strong></label><br />
//.........这里部分代码省略.........
开发者ID:HaraShun,项目名称:WordPress,代码行数:101,代码来源:media.php


示例3: edit_form_image_editor

/**
 * Displays the image and editor in the post editor
 *
 * @since 3.5.0
 */
function edit_form_image_editor()
{
    $post = get_post();
    $open = isset($_GET['image-editor']);
    if ($open) {
        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    }
    $thumb_url = false;
    if ($attachment_id = intval($post->ID)) {
        $thumb_url = wp_get_attachment_image_src($attachment_id, array(900, 450), true);
    }
    $filename = esc_html(basename($post->guid));
    $title = esc_attr($post->post_title);
    $alt_text = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
    $att_url = wp_get_attachment_url($post->ID);
    if (wp_attachment_is_image($post->ID)) {
        $image_edit_button = '';
        if (wp_image_editor_supports(array('mime_type' => $post->post_mime_type))) {
            $nonce = wp_create_nonce("image_editor-{$post->ID}");
            $image_edit_button = "<input type='button' id='imgedit-open-btn-{$post->ID}' onclick='imageEdit.open( {$post->ID}, \"{$nonce}\" )' class='button' value='" . esc_attr__('Edit Image') . "' /> <span class='spinner'></span>";
        }
        ?>
	<div class="wp_attachment_holder">
		<div class="imgedit-response" id="imgedit-response-<?php 
        echo $attachment_id;
        ?>
"></div>

		<div<?php 
        if ($open) {
            echo ' style="display:none"';
        }
        ?>
 class="wp_attachment_image" id="media-head-<?php 
        echo $attachment_id;
        ?>
">
			<p id="thumbnail-head-<?php 
        echo $attachment_id;
        ?>
"><img class="thumbnail" src="<?php 
        echo set_url_scheme($thumb_url[0]);
        ?>
" style="max-width:100%" alt="" /></p>
			<p><?php 
        echo $image_edit_button;
        ?>
</p>
		</div>
		<div<?php 
        if (!$open) {
            echo ' style="display:none"';
        }
        ?>
 class="image-editor" id="image-editor-<?php 
        echo $attachment_id;
        ?>
">
			<?php 
        if ($open) {
            wp_image_editor($attachment_id);
        }
        ?>
		</div>
	</div>
	<?php 
    }
    ?>

	<div class="wp_attachment_details">
		<p>
			<label for="attachment_caption"><strong><?php 
    _e('Caption');
    ?>
</strong></label><br />
			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php 
    echo $post->post_excerpt;
    ?>
</textarea>
		</p>

	<?php 
    if ('image' === substr($post->post_mime_type, 0, 5)) {
        ?>
		<p>
			<label for="attachment_alt"><strong><?php 
        _e('Alternative Text');
        ?>
</strong></label><br />
			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php 
        echo esc_attr($alt_text);
        ?>
" />
		</p>
	<?php 
//.........这里部分代码省略.........
开发者ID:adisonc,项目名称:MaineLearning,代码行数:101,代码来源:media.php


示例4: switch

     include_once ABSPATH . 'wp-admin/includes/image-edit.php';
     $msg = false;
     switch ($_POST['do']) {
         case 'save':
             $msg = wp_save_image($attachment_id);
             $msg = json_encode($msg);
             die($msg);
             break;
         case 'scale':
             $msg = wp_save_image($attachment_id);
             break;
         case 'restore':
             $msg = wp_restore_image($attachment_id);
             break;
     }
     wp_image_editor($attachment_id, $msg);
     die;
     break;
 case 'set-post-thumbnail':
     $post_id = intval($_POST['post_id']);
     if (!current_user_can('edit_post', $post_id)) {
         die('-1');
     }
     $thumbnail_id = intval($_POST['thumbnail_id']);
     if ($thumbnail_id == '-1') {
         delete_post_meta($post_id, '_thumbnail_id');
         die(_wp_post_thumbnail_html());
     }
     if ($thumbnail_id && get_post($thumbnail_id)) {
         $thumbnail_html = wp_get_attachment_image($thumbnail_id, 'thumbnail');
         if (!empty($thumbnail_html)) {
开发者ID:nagyist,项目名称:laura-wordpress,代码行数:31,代码来源:admin-ajax.php


示例5: call_user_func_array

        if ($form = $wp_registered_widget_controls[$widget_id]) {
            call_user_func_array($form['callback'], $form['params']);
        }
        die;
        break;
    case 'image-edit-save':
        // $post_id is the attachment ID
        $post_id = intval($_POST['postid']);
        if (empty($post_id) || !current_user_can('edit_post', $post_id)) {
            die('-1');
        }
        check_ajax_referer("image_editor-{$post_id}");
        include_once ABSPATH . 'wp-admin/includes/image-edit.php';
        $msg = wp_save_image($post_id);
        die($msg);
        break;
    case 'open-image-editor':
        $post_id = intval($_POST['postid']);
        if (empty($post_id) || !current_user_can('edit_post', $post_id)) {
            die('-1');
        }
        check_ajax_referer("image_editor-{$post_id}");
        include_once ABSPATH . 'wp-admin/includes/image-edit.php';
        wp_image_editor($post_id);
        die;
        break;
    default:
        do_action('wp_ajax_' . $_POST['action']);
        die('0');
        break;
}
开发者ID:bluedanbob,项目名称:wordpress,代码行数:31,代码来源:admin-ajax.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_image_editor_supports函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_image_add_srcset_and_sizes函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap