重定向不适用于自定义插件 wordpress
Redirect doesn't work on a custom plugin wordpress
当媒体库中的文件上传到 crop/resize 时,我正在尝试重定向。
我正在添加一个自定义模板,并在管理员将媒体添加到媒体库(管理面板)后尝试重定向。
但是当我上传媒体时,wordpress 出现错误:"An error occurred during upload. Please try again later."
什么也没有。
我的文件已上传并保存,但未显示在媒体库中。
我已经经历了很多话题,但没有找到答案。也许我不能在插件中那样重定向。
我在 wp-contents/plugins/myplugin/plugin.php 和自定义 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 :)';
?>
Network console log
很确定我做错了,但我是 wordpress 的新手,我愿意接受任何建设性的评论。
如果您需要更多信息,请询问。提前谢谢你。
好像我不能那样做,所以我所做的就是用 jQuery 来做。
我正在我的媒体库中添加一个按钮并隐藏已存在的按钮。
jQuery(document).ready(function($){
$("#wp-media-grid > a").after("<form action=\"/wp-content/plugins/waouh_pictures/function.php\"><input type=\"file\" id=\"button_upload_waouh\" name=\"filename\" method=\"POST\"><input type=\"submit\" value=\"Ajouter\"></form>");
$("#wp-media-grid > a").hide();
});
我可以在使用 croppie 将文件上传到服务器之前修改文件。
我希望我能帮助别人。
当媒体库中的文件上传到 crop/resize 时,我正在尝试重定向。 我正在添加一个自定义模板,并在管理员将媒体添加到媒体库(管理面板)后尝试重定向。 但是当我上传媒体时,wordpress 出现错误:"An error occurred during upload. Please try again later." 什么也没有。 我的文件已上传并保存,但未显示在媒体库中。 我已经经历了很多话题,但没有找到答案。也许我不能在插件中那样重定向。
我在 wp-contents/plugins/myplugin/plugin.php 和自定义 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 :)';
?>
Network console log
很确定我做错了,但我是 wordpress 的新手,我愿意接受任何建设性的评论。 如果您需要更多信息,请询问。提前谢谢你。
好像我不能那样做,所以我所做的就是用 jQuery 来做。 我正在我的媒体库中添加一个按钮并隐藏已存在的按钮。
jQuery(document).ready(function($){
$("#wp-media-grid > a").after("<form action=\"/wp-content/plugins/waouh_pictures/function.php\"><input type=\"file\" id=\"button_upload_waouh\" name=\"filename\" method=\"POST\"><input type=\"submit\" value=\"Ajouter\"></form>");
$("#wp-media-grid > a").hide();
});
我可以在使用 croppie 将文件上传到服务器之前修改文件。
我希望我能帮助别人。