我正在本地主机上开发我的网站(WordPress版本4.9.3.2)现在,每当我切换到任何默认主题,如二十四,我非常能够在媒体库中上传和查看图像,但每当我在我自己的主题上,我既不能查看任何图像,也不能上传。
错误如下-
-
不能上传特色图片
-
不能通过post上传图片
-
媒体库中看不到任何图像
-
我尝试通过媒体库上传的图像,保存在'uploads'文件夹中,所以我知道我的文件夹位置是正确的,但即使这样我也看不到它们。
-
如果我试图通过帖子或其他方式上传图像,则图像不会保存在'uploads'文件夹中,只有通过媒体库才能保存。
我尝试过的解决方案-
-
我还没有安装任何插件,所以禁用/启用一个是不可能的
-
我将内存限制增加到256M,没有任何反应
-
我也试着重新安装wordpress,什么也没发生
-
我尝试在函数中将图像编辑器更改为默认gb -没有任何反应
我不知道我做错了什么,但这真的让我沮丧了一个多星期。如果有人能帮忙,我将不胜感激。
谢谢!
太晚了,希望你能解决这个问题。然而,这可能会帮助别人。
我刚刚遇到了同样的问题,在我的情况下,我有一个回调的问题,在这里:
add_theme_support( 'custom-header',
apply_filters( 'ivana_custom_header_args', [
'default-image' => '',
'default-text-color' => '000',
'width' => 1000,
'height' => 250,
'flex-width' => true,
'flex-height' => true,
'wp-head-callback' => [ $this, 'site_branding_style' ]
]; )
);
我在一个面向对象的方式组织代码,通过遵循这个架构,但回调('wp-head-callback')没有被正确调用。在我的情况下,它是进入另一个类,它是一个私有方法,所以我把它移动到同一个类,我添加所有主题支持,使其成为一个公共方法。
Setup.php
<?php
/**
* @package ivana
*/
namespace IvanaSetup;
use IvanaSetupCustomArguments;
class Setup
{
private $custom_arguments;
public function register()
{
$custom_arguments_instance = new CustomArguments();
$this->custom_arguments = $custom_arguments_instance->start();
add_action( 'after_setup_theme', [ $this, 'setup' ] );
// Why isn't the setup function being
// called? We don't (8)
// echo '<pre>';
// var_dump( $this->custom_arguments['header'] );
// var_dump( $this->custom_arguments['background'] );
// var_dump( $this->custom_arguments['logo'] );
// echo '</pre>';
}
public function setup()
{
// Uncomment this for multilingual theme.
// Currentlly there is no support whatsoever for
// multilingual theme.
// load_theme_textdomain( 'ivana', get_template_directory() . '/languages' );
// Uncomment this if using WooCommerce
// add_theme_support( 'woocommerce' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_theme_support( 'html5', [
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption'
] );
add_theme_support( 'custom-header',
apply_filters( 'ivana_custom_header_args', $this->custom_arguments['header'] )
);
add_theme_support( 'custom-background',
apply_filters( 'ivana_custom_background_args', $this->custom_arguments['background'] )
);
add_theme_support( 'custom-logo',
apply_filters( 'ivana_custom_logo_args', $this->custom_arguments['logo'] )
);
add_theme_support( 'post-formats', [
'aside',
'gallery',
'link',
'image',
'quote',
'status',
'video',
'audio',
'chat'
] );
}
}
CustomArguments.php
<?php
/**
* @package ivana
*/
namespace IvanaSetup;
class CustomArguments
{
private $custom_arguments = [];
public function start()
{
$this->custom_header_arguments();
$this->custom_background_arguments();
$this->custom_logo_arguments();
return $this->custom_arguments;
}
private function custom_header_arguments()
{
$this->custom_arguments['header'] = [
'default-image' => '',
'default-text-color' => '000',
'width' => 1000,
'height' => 250,
'flex-width' => true,
'flex-height' => true,
'wp-head-callback' => [ $this, 'site_branding_style' ]
];
}
private function custom_background_arguments()
{
$this->custom_arguments['background'] = [
'default-color' => 'fff',
'default-image' => ''
];
}
private function custom_logo_arguments()
{
$this->custom_arguments['logo'] = [
'height' => 250,
'width' => 250,
'flex-height' => true,
'flex-width' => true
];
}
public function site_branding_style()
{ ?>
<style type="text/css">
.site-title,
.site-description {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
}
</style>
<?php
}
}
在任何情况下,我的调试方法是开始注释掉行或整个文件并重新加载媒体库。当我注释掉设置中的所有内容时,图像正确加载,然后我开始注释单个行或函数,直到发现问题。