【问题标题】:Warning: Illegal string offset 'Name' in after php upgrade警告:php 升级后存在非法字符串偏移“名称”
【发布时间】:2014-09-23 20:01:06
【问题描述】:

收到此错误,阻止访问 wordpress 后端并且无法更改主题。 错误: 警告:第 9 行 /home/holiday1/public_html/reviewmyvisit.com/wp-content/themes/themia-lite/functions/theme-options.php 中的非法字符串偏移“名称”

这里是代码,但我对 php 不是很熟悉...只是学习。任何帮助表示赞赏。

<?php

add_action('init', 'inkthemes_options');
if (!function_exists('inkthemes_options')) {

    function inkthemes_options() {
        // VARIABLES
        $themename = function_exists( 'wp_get_theme' ) ? wp_get_theme() : get_current_theme();
        $themename = $themename['Name'];
        $shortname = "of";
        // Populate OptionsFramework option in array for use in theme
        global $of_options;
        $of_options = inkthemes_get_option('of_options');

        // Background Defaults

        $background_defaults = array('color' => '', 'image' => '', 'repeat' => 'repeat', 'position' => 'top center', 'attachment' => 'scroll');


        // Pull all the categories into an array
        $options_categories = array();
        $options_categories_obj = get_categories();
        foreach ($options_categories_obj as $category) {
            $options_categories[$category->cat_ID] = $category->cat_name;
        }

        // Pull all the pages into an array
        $options_pages = array();
        $options_pages_obj = get_pages('sort_column=post_parent,menu_order');
        $options_pages[''] = 'Select a page:';
        foreach ($options_pages_obj as $page) {
            $options_pages[$page->ID] = $page->post_title;
        }

        // If using image radio buttons, define a directory path
        $imagepath = get_template_directory_uri() . '/images/';

        $options = array(
            array("name" => "General Settings",
                "type" => "heading"),
            array("name" => "Custom Logo",
                "desc" => "Choose your own logo. Optimal Size: 160px Wide by 30px Height",
                "id" => "inkthemes_logo",
                "type" => "upload"),
            array("name" => "Custom Favicon",
                "desc" => "Specify a 16px x 16px image that will represent your website's favicon.",
                "id" => "inkthemes_favicon",
                "type" => "upload"),
            array("name" => "Tracking Code",
                "desc" => "Paste your Google Analytics (or other) tracking code here.",
                "id" => "inkthemes_analytics",
                "std" => "",
                "type" => "textarea"),
//****=============================================================================****//
//****-----------This code is used for creating home page feature content----------****//                           
//****=============================================================================****//   
            array("name" => "Home Page Settings",
                "type" => "heading"),
            array("name" => "Top Feature Image",
                "desc" => "Choose a image for top feature. Optimal size: 928px x 355px",
                "id" => "inkthemes_featureimg",
                "std" => "",
                "type" => "upload"),
            //***Code for first column***//
            array("name" => "First Feature Heading",
                "desc" => "Enter your heading line one",
                "id" => "inkthemes_headline1",
                "std" => "",
                "type" => "textarea"),
            array("name" => "First Feature Image",
                "desc" => "Upload image for your feature column one",
                "id" => "inkthemes_img1",
                "std" => "",
                "type" => "upload"),
            array("name" => "First Feature Content",
                "desc" => "Paste your feature content here... you can also put embed html code but the html
                            content should not exceed the maximum width size. Any content of maximum width is 272px.",
                "id" => "inkthemes_feature1",
                "std" => "",
                "type" => "textarea"),
            array("name" => "First Feature link",
                "desc" => "Enter your link for feature content column one",
                "id" => "inkthemes_link1",
                "std" => "",
                "type" => "text"),
            //***Code for second column***//                        
            array("name" => "Second Feature Heading",
                "desc" => "Enter your heading line second",
                "id" => "inkthemes_headline2",
                "std" => "",
                "type" => "textarea"),
            array("name" => "Second Feature Image",
                "desc" => "Upload image for your feature column second",
                "id" => "inkthemes_img2",
                "std" => "",
                "type" => "upload"),
            array("name" => "Second Feature Content",
                "desc" => "Paste your feature content here... you can also put embed html code but the html
                            content should not exceed the maximum width size. Any content of maximum width is 272px.",
                "id" => "inkthemes_feature2",
                "std" => "",
                "type" => "textarea"),
            array("name" => "Second Feature link",
                "desc" => "Enter your link for feature content column second",
                "id" => "inkthemes_link2",
                "std" => "",
                "type" => "text"),
            //***Code for third column***//                     
            array("name" => "Third Feature Heading",
                "desc" => "Enter your heading line third",
                "id" => "inkthemes_headline3",
                "std" => "",
                "type" => "textarea"),
            array("name" => "Third Feature Image",
                "desc" => "Upload image for your feature column third",
                "id" => "inkthemes_img3",
                "std" => "",
                "type" => "upload"),
            array("name" => "Third Feature Content",
                "desc" => "Paste your feature content here... you can also put embed html code but the html
                            content should not exceed the maximum width size. Any content of maximum width is 272px.",
                "id" => "inkthemes_feature3",
                "std" => "",
                "type" => "textarea"),
            array("name" => "Third Feature link",
                "desc" => "Enter your link for feature content column third",
                "id" => "inkthemes_link3",
                "std" => "",
                "type" => "text"));
        inkthemes_update_option('of_template', $options);
        inkthemes_update_option('of_themename', $themename);
        inkthemes_update_option('of_shortname', $shortname);
    }

}
?>

【问题讨论】:

  • @wumm 我在想它的$themename = $themename['Name'];,但希望 OP 澄清一下。
  • 我认为 PHP 升级可能会执行更严格的规则。您是否检查过相关的 SO 问题?例如stackoverflow.com/questions/16264115/…stackoverflow.com/questions/9869150/… ?
  • @ʰᵈˑ:有道理,因为那是唯一包含Name的行。 Imo 缺少一些重要信息:Wordpress 版本、旧 php 版本、新 php 版本。
  • @Arjan 我完全同意。

标签: php wordpress


【解决方案1】:

查看文档:http://codex.wordpress.org/Function_Reference/get_current_theme 看起来它没有返回数组。

然后我会假设您没有函数wp_get_themehttp://codex.wordpress.org/Function_Reference/wp_get_theme

通过阅读文档和您的原始帖子,我会将逻辑更改为;

$themename = get_current_theme();
if(function_exists( 'wp_get_theme' )) {
   $themename = wp_get_theme();
   $themename = $themename->get('Name');
}

【讨论】:

  • 非常感谢..删除了错误消息,但在管理员中时,我仍然只看到左侧菜单和右侧的空白屏幕。所以我看不到或更改任何选项。我正在学习任何方向,对此或在礼仪张贴thx上表示赞赏..![在此处输入图像描述][1] [1]:i.stack.imgur.com/2Bt09.png
  • 不客气 :) - 嗯,我会检查您的错误日志,看看里面是否有任何内容,很可能是导致白屏的致命错误。
猜你喜欢
  • 2013-04-11
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
  • 2016-05-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多