【发布时间】:2020-06-02 08:43:35
【问题描述】:
当文件上传到媒体库以裁剪/调整大小时,我正在尝试重定向。 我正在添加一个自定义模板,并在管理员将媒体添加到库(管理面板)后尝试重定向。 但是当我上传媒体时,我在 wordpress 中遇到错误:“上传过程中发生错误。请稍后再试。” 什么都没有。 我的文件已上传并保存,但未显示在媒体库中。 我浏览了许多主题,但没有找到答案。也许我不能在插件中那样重定向。
我在 wp-contents/plugins/myplugin/plugin.php 和 custom-template.php 中有两个 php 文件
<?php
/*
Plugin name: Waouh_pictures
Description:
Version: 1.0
Author: Waouh
*/
require_once("lib/shortpixel-php-req.php");
if(!defined('ABSPATH'))
exit;
class plugin{
public function __construct(){
// Some code here
/* Add cropping template to wordpress */
function page_template( $page_template )
{
if ( is_page( 'cropping-waouh' ) ) {
$page_template = dirname( __FILE__ ) . '/crop_waouh.php';
}
return $page_template;
}
add_filter( 'page_template', 'page_template' );
/* Redirect to cropping-waouh when a file is uploaded */
function redirect_to_crop( $upload ) {
$url = get_site_url() . "/cropping-waouh";
wp_redirect( $url );
exit;
return $upload;
}
add_filter( 'wp_handle_upload', 'redirect_to_crop' );
}
}
new plugin();
?>
还有我的自定义模板:
<?php
/* Template Name: Cropping Waouh */
echo 'This is my cropping page :)';
?>
很确定我做错了,但我是 wordpress 的新手,我对任何有建设性的 cmets 持开放态度。 如果您需要更多信息,请询问。提前谢谢你。
【问题讨论】:
-
redirect_to_crop 函数的视图是否出现?
-