• Hi there.
    I made a theme which contains an custom the options panel.
    When I install the theme on a single wordpress blog it works perfect.
    But when I install the samen theme on a blog in an multisite setup, it fails.
    Users can add and edit the custom theme options, and the’re being saved but in the frontpage theses eddited settings don’t show up.

    Here’s the code in header.php, where the problem seems to be:

    <?
            /* This code retrieves all our admin options. */
            global $options;
            foreach ($options as $value) {
                if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
            }
            ?>
            <? /* If a title has been provided, we'll use that. */
    			if ($bl_intro_title) { ?>
    
        		<h1><? echo $bl_intro_title; ?></h1>
    
    			<? /* Otherwise we'll use a generic message. */
                } else { ?>
    
                    <h1>Activiteiten bij Hoeve Bouwlust</h1>
    
                <? } ?>

    Here’s the code in functions.php:

    <? $themename = "Hoeve Bouwlust Main";
    $shortname = "bl";
    
    $options = array (
    
    	array(	"name" => "Intro Stukje",
    			"type" => "title"),
    
    	array(	"type" => "open"),
    
    	array(	"name" => "Titel",
    			"desc" => "Wat wordt de titel van het intro stukje?",
    			"id" => $shortname."_intro_title",
    			"std" => "",
    			"type" => "text"),
    
    	array(	"name" => "Intro Tekst",
    			"desc" => "De tekst van het intro stukje",
                "id" => $shortname."_intro_text",
                "type" => "textarea"),
    
    	array(	"type" => "close")
    
    );
    
    function blmain_add_admin() {
    
        global $themename, $shortname, $options;
    
        if ( $_GET['page'] == basename(__FILE__) ) {
    
            if ( 'save' == $_REQUEST['action'] ) {
    
                    foreach ($options as $value) {
                        update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
                    foreach ($options as $value) {
                        if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], stripslashes($_REQUEST[ $value['id'] ] ) ); } else { delete_option( $value['id'] ); } }
    
                    header("Location: themes.php?page=functions.php&saved=true");
                    die;
    
            } else if( 'reset' == $_REQUEST['action'] ) {
    
                foreach ($options as $value) {
                    delete_option( $value['id'] ); }
    
                header("Location: themes.php?page=functions.php&reset=true");
                die;
    
            }
        }
    
        add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'blmain_admin');
    
    }
    
    function blmain_admin() {
    
        global $themename, $shortname, $options;
    
        if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>De thema instellingen zijn opgeslagen.</strong></p></div>';
        if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>De thema instellingen zijn gereset.</strong></p></div>';
    
    ?>
    <div class="wrap">
    <h2><?php echo $themename; ?> thema instellingen</h2>
    
    <form method="post">
    
    <?php foreach ($options as $value) { 
    
    	switch ( $value['type'] ) {
    
    		case "open":
    		?>
            <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
    
    		<?php break;
    
    		case "close":
    		?>
    
            </table>
    
    		<?php break;
    
    		case "title":
    		?>
    		<table width="100%" border="0" style="background-color:#dceefc; padding:5px 10px;"><tr>
            	<td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
            </tr>
    
    		<?php break;
    
    		case 'text':
    		?>
    
            <tr>
                <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
            </tr>
    
            <tr>
                <td><small><?php echo $value['desc']; ?></small></td>
            </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">?</td></tr><tr><td colspan="2">?</td></tr>
    
    		<?php
    		break;
    
    		case 'textarea':
    		?>
    
            <tr>
                <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
    
            </tr>
    
            <tr>
                <td><small><?php echo $value['desc']; ?></small></td>
            </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">?</td></tr><tr><td colspan="2">?</td></tr>
    
    		<?php
    		break;
    
    		case 'select':
    		?>
            <tr>
                <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
           </tr>
    
           <tr>
                <td><small><?php echo $value['desc']; ?></small></td>
           </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">?</td></tr><tr><td colspan="2">?</td></tr>
    
    		<?php
            break;
    
    		case "checkbox":
    		?>
                <tr>
                <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                    <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                            <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
                            </td>
                </tr>
    
                <tr>
                    <td><small><?php echo $value['desc']; ?></small></td>
               </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">?</td></tr><tr><td colspan="2">?</td></tr>
    
            <?php 		break;
    
    }
    }
    ?>
    
    <!--</table>-->
    
    <p class="submit">
    <input name="save" type="submit" value="Instellingen opslaan" />
    <input type="hidden" name="action" value="save" />
    </p>
    </form>
    <form method="post">
    <p class="submit">
    <input name="reset" type="submit" value="Reset instellingen" />
    <input type="hidden" name="action" value="reset" />
    </p>
    </form>
    
    <?php
    }
    
    add_action('admin_menu', 'blmain_add_admin'); ?>

Viewing 14 replies - 1 through 14 (of 14 total)
  • Please do not paste long bits of code. Use pastebin instead and then link to it.

    add_theme_page($themename.” Options”, “”.$themename.” Options”, ‘edit_themes’, basename(__FILE__), ‘blmain_admin’);

    This is your issue. in multisite the edit_themes cap applies only to super admins. Use a lower one.

    Yes, we have posted about this before. ??

    Thread Starter dhunink

    (@dhunink)

    Hi Andrea,
    sorry, I’ll do that next time.
    I read about that indeed.
    But I do see the options and are able to update thoses options.
    The problem is they don’t actually appear on my weblog, in the header.php part.
    Am I confusing some things, or is that really another problem?

    I did changed ‘edit_themes’ to ‘edit_theme_options’, but it still didn’t show up on my blog frontpage.

    The problem is they don’t actually appear on my weblog, in the header.php part.
    Am I confusing some things, or is that really another problem?

    Yeah, that woudl be a different issue.

    Thread Starter dhunink

    (@dhunink)

    Thanks for your quick response.
    That do is my issue. I can’t find an solution for it anywhere on the web, nor on the wp forum or wp codex. Searched for hours now…

    What wonders me most is that when i tested the theme on another blog of mine it worked perfect, but when i run it inside this multisite network it fails to show the edited custom options on my blog in the header.php

    Have you checked your error logs?
    And what do you mean by it fails? They don’t get saved in the backend, or they do not display on the frontend? Are they getting saved in the database in the right spot?

    Thread Starter dhunink

    (@dhunink)

    Which error logs should i check for what kind of error?

    When I save a new value for an custum option it in the backend, and reload the custom options page, or revisited it, the saved value is displayed. So that means, I guess, that it is saved in the database. So they do get saved in the backend.
    They just don’t display on the frontend (when install the theme on multisite network).

    Which error logs should i check for what kind of error?

    Your php error logs on the server? It’s a server thing, not wp dependent.

    the saved value is displayed. So that means, I guess, that it is saved in the database.

    Don’t guess: go look. ??

    Thread Starter dhunink

    (@dhunink)

    Sure it’s server thing? Because the problem don’t appears on a non-multisite installation. Which is, indeed on a different server. I could install another WP on the same server too double check. Since your advise could be translated as ‘assumptions are the mother of all failure’. In which you’re right.

    I did take a look. In my code one of the options as an ID ‘bl_intro_title’. When searching in mysql that doesn’t give any matches. Not on the multi blog, nor on the single blog.
    Seems like i’m loosing the logics…

    (btw, did I say thank you so far already? No? Thank You!)

    Thread Starter dhunink

    (@dhunink)

    I guess Andrea is right. It’s a server problem.
    I installed another single WP blog on the same server, different database.
    Same problem.

    The next question is what the server side problem could be… What should i search for?

    EDIT:
    When checking the database, the option is present and stored correctly.
    So the problem is somewhere in the interaction between the script in header.php and the server… But where??

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Whelp, what can you tell us about your server?

    Apache? PHP? SQL? Cpanel/Plesk? ??

    Thread Starter dhunink

    (@dhunink)

    It’s a testing server, containing Xampp, running Apache/php 5.3

    So far I was thinking about the register_global that’s turned off in the php.ini.
    Trying to edit the php.ini and simpley changing to register_globals = on doesn’t give the desired effect.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    You have to restart the http service afterwards.

    Thread Starter dhunink

    (@dhunink)

    Thanks, I knew that. My fault.
    Register_globals is on now, but the problem stays exact the same

    you need to put the following code on header.php as well even you have already used that code on function.php or somewhere else except header.php

    global $options;
    foreach ($options as $value) {
        if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_option( $value['id'] ); }
    }

    I solved this issue like this, even I know this is not a good idea.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Custom Theme Options on multisite not working’ is closed to new replies.