WordPress主题选项保存在本地开发环境中,只有四分之一保存在登台服务器上

时间:2019-02-07 00:01:46

标签: wordpress

我在“主题选项”页面上有四个字段。在本地开发环境中,所有四个都保存输入值,将其保留在页面重载中,然后将值吐出到主题模板本身中。

但是,当这些更改被推送到登台服务器时。只有一个字段(最后一个字段)保存该值,保留它并在主题本身中吐出该值。

我在做什么错了?

这是我的theme-options.php所包含的functions.php的内容:

<?php

function add_new_menu_items()
    {
        //add a new menu item. This is a top level menu item i.e., this menu item can have sub menus
        add_menu_page(
            "Theme Options", //Required. Text in browser title bar when the page associated with this menu item is displayed.
            "Theme Options", //Required. Text to be displayed in the menu.
            "manage_options", //Required. The required capability of users to access this menu item.
            "theme-options", //Required. A unique identifier to identify this menu item.
            "theme_options_page", //Optional. This callback outputs the content of the page associated with this menu item.
            "", //Optional. The URL to the menu item icon.
            100 //Optional. Position of the menu item in the menu.
        );

    }

    function theme_options_page()
    {
        ?>
            <div class="wrap">
            <div id="icon-options-general" class="icon32"></div>
            <h1>Theme Options</h1>
            <form method="post" action="options.php">
                <?php

                    //add_settings_section callback is displayed here. For every new section we need to call settings_fields.
                    settings_fields("header_section");
                    settings_fields("pitch_section");
                    settings_fields("tracker_section");

                    // all the add_settings_field callbacks is displayed here
                    do_settings_sections("theme-options");

                    // Add the submit button to serialize the options
                    submit_button(); 

                ?>          
            </form>
        </div>
        <?php
    }

    //this action callback is triggered when wordpress is ready to add new items to menu.
    add_action("admin_menu", "add_new_menu_items");

    function display_options()
    {
        //section name, display name, callback to print description of section, page to which section is attached.
        add_settings_section("header_section", "Header", "display_header_options_content", "theme-options");
        add_settings_section("pitch_section", "Pitch", "display_pitch_options_content", "theme-options");
        add_settings_section("tracker_section", "Candidate Tracker", "display_tracker_options_content", "theme-options");

        //setting name, display name, callback to print form element, page in which field is displayed, section to which it belongs.
        //last field section is optional.
        add_settings_field("hero_image", "Featured hero image URL", "display_hero_image_element", "theme-options", "header_section");
        add_settings_field("hero_text", "Featured hero text", "display_hero_text_element", "theme-options", "header_section");
        add_settings_field("pitch_text", "Pitch text", "display_pitch_text_element", "theme-options", "pitch_section");
        add_settings_field("tracker_text", "Tracker text", "display_tracker_text_element", "theme-options", "tracker_section");

        //section name, form element name, callback for sanitization
        register_setting("header_section", "hero_image");
        register_setting("header_section", "hero_text");
        register_setting("pitch_section", "pitch_text");
        register_setting("tracker_section", "tracker_text");
    }

    function display_header_options_content(){echo "Update the hero image and text in the featured section of the website's homepage.";}
    function display_hero_image_element()
    {
        //id and name of form element should be same as the setting name.
        ?>
            <input type="text" name="hero_image" id="hero_image" value="<?php echo get_option('hero_image'); ?>" size="100" />
            <p class="description" id="tagline-description">Upload a suitable hero image for the website homepage and add the full URL to the image here. Recommended dimensions: 1430 x 953.</p>
        <?php
    }
    function display_hero_text_element()
    {
        //id and name of form element should be same as the setting name.
        ?>
            <textarea name="hero_text" id="hero_text" rows="5" cols="102"><?php echo get_option('hero_text'); ?></textarea>
            <p class="description" id="tagline-description">Add a tagline in the hero section on the website homepage. Use paragraph tags, if necessary.</p>
        <?php
    }

    function display_pitch_options_content(){echo "Update the text of the pitch section of the website's homepage.";}
    function display_pitch_text_element()
    {
        //id and name of form element should be same as the setting name.
        ?>
            <textarea name="pitch_text" id="pitch_text" rows="10" cols="102"><?php echo get_option('pitch_text'); ?></textarea>
            <p class="description" id="tagline-description">Add pitch content in the main section on the website homepage. Use paragraph tags and other HTML style tags as necessary.</p>
        <?php
    }

    function display_tracker_options_content(){echo "Update the text of the Candidate Tracker section.";}
    function display_tracker_text_element()
    {
        //id and name of form element should be same as the setting name.
        ?>
            <textarea name="tracker_text" id="tracker_text" rows="10" cols="102"><?php echo get_option('tracker_text'); ?></textarea>
            <p class="description" id="tagline-description">Add text above the main index of the Tracker. Use paragraph tags and other HTML style tags as necessary.</p>
        <?php
    }

    //this action is executed after loads its core, after registering all actions, finds out what page to execute and before producing the actual output(before calling any action callback)
    add_action("admin_init", "display_options");

?>

0 个答案:

没有答案