ThemeShaper Forums » Thematic

[closed]

Tons of trouble w "child theme options" header code

(2 posts)
  • Started 2 years ago by theed
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. theed
    Member

    Hi all. I've been using this:

    <?php
    // ---------- "Child Theme Options" menu STARTS HERE
    
    add_action('admin_menu' , 'childtheme_add_admin');
    
    function childtheme_add_admin() {
    	add_submenu_page('themes.php', 'Child Theme Options', 'Child Theme Options', 'edit_themes', basename(__FILE__), 'childtheme_admin');
    }
    
    function childtheme_admin() {
    
    	$child_theme_image = get_option('child_theme_image');
    	$enabled = get_option('child_theme_logo_enabled');
    
    	if ($_POST['options-submit']){
    		$enabled = htmlspecialchars($_POST['enabled']);
    		update_option('child_theme_logo_enabled', $enabled);
    
    		$file_name = $_FILES['logo_image']['name'];
    		$temp_file = $_FILES['logo_image']['tmp_name'];
    		$file_type = $_FILES['logo_image']['type'];
    
    		if($file_type=="image/gif" || $file_type=="image/jpeg" || $file_type=="image/pjpeg" || $file_type=="image/png"){
    			$fd = fopen($temp_file,’rb’);
    			$file_content=file_get_contents($temp_file);
    			fclose($fd);
    
    			$wud = wp_upload_dir();
    
    			if (file_exists($wud[path].'/'.strtolower($file_name))){
    				unlink ($wud[path].'/'.strtolower($file_name));
    			}
    
    			$upload = wp_upload_bits( $file_name, '', $file_content);
    		//	echo $upload['error'];
    
    			$child_theme_image = $wud[url].'/'.strtolower($file_name);
    			update_option('child_theme_image', $child_theme_image);
    		}
    
    		?>
    			<div class="updated"><p>Your new options have been successfully saved.</p></div>
    		<?php
    
    	}
    
    	if($enabled) $checked='checked="checked"';
    
    	?>
    		<div class="wrap">
    			<div id="icon-themes" class="icon32"></div>
    			<h2>Child Theme Options</h2>
    			<form name="theform" method="post" enctype="multipart/form-data" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']);?>">
    				<table class="form-table">
    					<tr>
    						<td width="200">Use logo image instead of blog title and description:</td>
    						<td><input type="checkbox" name="enabled" value="1" <?php echo $checked; ?>/></td>
    					</tr>
    					<tr>
    						<td>Current image:</td>
    						<td><img src="<?php echo $child_theme_image; ?>" /></td>
    					</tr>
    					<tr>
    						<td>Logo image to use (gif/jpeg/png):</td>
    						<td><input type="file" name="logo_image">(you must have writing permissions for your uploads directory)</td>
    					</tr>
    				</table>
    				<input type="hidden" name="options-submit" value="1" />
    				<p class="submit"><input type="submit" name="submit" value="Save Options" /></p>
    			</form>
    		</div>
    	<?php
    }
    
    // ---------- "Child Theme Options" menu ENDS HERE
    
    // ---------- Adding the logo image to the header STARTS HERE
    
    if(get_option('child_theme_logo_enabled')){
    	function remove_thematic_blogtitle() {
    	 remove_action('thematic_header','thematic_blogtitle',3);
    	}
    	add_action('init','remove_thematic_blogtitle');
    
    	function remove_thematic_blogdescription() {
    	 remove_action('thematic_header','thematic_blogdescription',5);
    	}
    	add_action('init','remove_thematic_blogdescription');
    
    	function thematic_logo_image() {
    		echo '<div id="logo-image"><a href="'.get_option('home').'"><img src="'.get_option('child_theme_image').'" /></a></div>';
    	}
    	add_action('thematic_header','thematic_logo_image',4);
    }
    // ---------- Adding the logo image to the header ENDS HERE
    ?>

    By cozmos labs on a few sites for a few years. This code adds something called "child theme options" to the wordpress admin menu and allows you to upload/swap out header banners right through the wordpress interface and replace the blog/title description with them. I have never had a problem with it until now.

    I've recently completed a new site and when the code above is placed in the functions.php file (that's where it goes), I get this message upon trying to load the site:

    "Fatal error: Call to undefined function thematic_create_doctype() in /home/content/89/8917489/html/wp-content/themes/thematic/header.php on line 4"

    In order to correct this I had to put fresh functions.php files in the theme. When I added the child theme options code again, it worked fine and I had the banner uploaded and displayed correctly. HOWEVER, upon going to the site again, in the same browser, I got another error message. I can't recreate this message exactly now because the site is live and I can't take it down or my client will freak out. : )

    The message was something like the above but instead said "header already called" or something like that.

    Can anyone give me any insight on this? I'm not to familiar with these php errors!

    Thanks!

    Posted 2 years ago #
  2. i highly recommend Devin price's options framework for all theme option endeavors:

    http://wordpress.org/extend/plugins/options-framework/

    you are reporting 2 different errors. unless you've monkeyed w/ thematic, thematic_create_doctype() is the first function in header-extensions.php

    headers already sent error, usually means you have extra space after a closing ?> at the end of a file

    so

    <?php
    //all your code
    ?>
    
    oh what is this extra space?
    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.