WordPress.org

Ready to get started?Download WordPress

Forums

functions.php problem (11 posts)

  1. Risean Militia
    Member
    Posted 1 year ago #

    Not sure what's going wrong with this site, as the dev site is on php 5.2.17 as is the destination server, which also hosts dozens of other WP sites. Is there something missing, or is there an adjustment to php.ini that's needed?

    The error: Parse error: syntax error, unexpected '}' in /.../public_html/wp-content/themes/cres/functions.php on line 360

    the functions php code:

    <?
    //Init
    wp_enqueue_script("jquery");
    
    add_action( 'init', 'register_my_menu' );
    
    function register_my_menu() {
    	register_nav_menu( 'primary-menu', __( 'Main menu' ) );
    }
    
    class em_Walker extends Walker_Nav_Menu
    {
    	/**
    	 * Start the element output.
    	 *
    	 * @param  string $output Passed by reference. Used to append additional content.
    	 * @param  object $item   Menu item data object.
    	 * @param  int $depth     Depth of menu item. May be used for padding.
    	 * @param  array $args    Additional strings.
    	 * @return void
    	 */
    	public function start_el( &$output, $item, $depth, $args )
    	{
    		$output     .= '';
    		$attributes  = '';
    
    		! empty ( $item->attr_title )
    			// Avoid redundant titles
    			and $item->attr_title !== $item->title
    			and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"';
    
    		! empty ( $item->url )
    			and $attributes .= ' href="' . esc_attr( $item->url ) .'"';
    
    		$attributes  = trim( $attributes );
    		$title       = apply_filters( 'the_title', $item->title, $item->ID );
    		$item_output = "$args->before<a $attributes>$args->link_before<br>$title</a>"
    						. "$args->link_after$args->after";
    
    		// Since $output is called by reference we don't need to return anything.
    		$output .= apply_filters(
    			'walker_nav_menu_start_el'
    			,   $item_output
    			,   $item
    			,   $depth
    			,   $args
    		);
    	}
    
    	/**
    	 * @see Walker::start_lvl()
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @return void
    	 */
    	public function start_lvl( &$output )
    	{
    		$output .= '<ul class="sub-menu">';
    	}
    
    	/**
    	 * @see Walker::end_lvl()
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @return void
    	 */
    	public function end_lvl( &$output )
    	{
    		$output .= '</ul>';
    	}
    
    	/**
    	 * @see Walker::end_el()
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @return void
    	 */
    	function end_el( &$output )
    	{
    		$output .= '';
    	}
    }
    
    //Sidebars
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'name' => 'Footer bar',
    		'id' => 'footlinks',
    		'before_widget' => '',
            'after_widget' => '',
            'before_title' => '',
            'after_title' => '',
        ));
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'name' => 'Language bar',
    		'id' => 'toplinks',
    		'before_widget' => '',
            'after_widget' => '',
            'before_title' => '',
            'after_title' => '',
        ));
    
    //Theme options
    $themename = "Cres-AM";
    $shortname = "crs";
    
    $categories = get_categories('hide_empty=0&orderby=name');
    $wp_cats = array();
    foreach ($categories as $category_list ) {
           $wp_cats[$category_list->cat_ID] = $category_list->cat_name;
    }
    array_unshift($wp_cats, "Choose Category"); 
    
    $options = array (
    
    array( "name" => $themename." Options",
    	"type" => "title"),
    
    array( "name" => "General",
    	"type" => "section"),
    array( "type" => "open"),
    
    array( "name" => "Logo URL",
    	"desc" => "URL of Logo image",
    	"id" => $shortname."_logo",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Footer Text",
    	"desc" => "",
    	"id" => $shortname."_footer",
    	"type" => "text",
    	"std" => ""),
    
    array( "type" => "close"),
    
    array( "name" => "Slider",
    	"type" => "section"),
    array( "type" => "open"),
    
    array( "name" => "Image 1 URL",
    	"desc" => "",
    	"id" => $shortname."_s1",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 2 URL",
    	"desc" => "",
    	"id" => $shortname."_s2",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 3 URL",
    	"desc" => "",
    	"id" => $shortname."_s3",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 4 URL",
    	"desc" => "",
    	"id" => $shortname."_s4",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 5 URL",
    	"desc" => "",
    	"id" => $shortname."_s5",
    	"type" => "text",
    	"std" => ""),
    
    array( "type" => "close")
    
    );
    
    function mytheme_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'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
    	header("Location: admin.php?page=functions.php&saved=true");
    die;
    
    }
    else if( 'reset' == $_REQUEST['action'] ) {
    
    	foreach ($options as $value) {
    		delete_option( $value['id'] ); }
    
    	header("Location: admin.php?page=functions.php&reset=true");
    die;
    
    }
    }
    
    add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
    }
    
    function mytheme_add_init() {
    
    $file_dir=get_bloginfo('template_directory');
    wp_enqueue_style("functions", $file_dir."/functions.css", false, "1.0", "all");
    wp_enqueue_script("rm_script", $file_dir."/js/rm_script.js", false, "1.0");
    
    }
    function mytheme_admin() {
    
    global $themename, $shortname, $options;
    $i=0;
    
    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' options are saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' options are set to default values.</strong></p></div>';
    
    ?>
    <div class="wrap rm_wrap">
    <h2><?php echo $themename; ?> Options</h2>
    
    <div class="rm_opts">
    <form method="post">
    <?php foreach ($options as $value) {
    switch ( $value['type'] ) {
    
    case "open":
    ?>
    
    <?php break;
    
    case "close":
    ?>
    
    </div>
    </div>
    <br />
    
    <?php break;
    
    case "title":
    ?>
    <?
    break;
    
    case 'code':
    ?>
    
    <div class="rm_input rm_text">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
     	<textarea name="<?php echo $value['id']; ?>" type="text" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripcslashes(get_settings( $value['id'])) ; } else { echo $value['std']; } ?></textarea>
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    
     </div>
    <?php break;
    
    case 'text':
    ?>
    
    <div class="rm_input rm_text">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
     	<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>" />
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    
     </div>
    <?php
    break;
    
    case 'textarea':
    ?>
    
    <div class="rm_input rm_textarea">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
     	<textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea>
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    
     </div>
    
    <?php
    break;
    
    case 'select':
    ?>
    
    <div class="rm_input rm_select">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
    
    <select 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"'; } ?>><?php echo $option; ?></option><?php } ?>
    </select>
    
    	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    </div>
    <?php
    break;
    
    case "checkbox":
    ?>
    
    <div class="rm_input rm_checkbox">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
    
    <?php if(get_option($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; ?> />
    
    	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
     </div>
    <?php break;
    case "section":
    
    $i++;
    
    ?>
    
    <div class="rm_section">
    <div class="rm_title"><h3><img src="<?php bloginfo('template_directory')?>/images/trans.gif" class="inactive" alt="""><?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save" />
    </span><div class="clearfix"></div></div>
    <div class="rm_options">
    
    <?php break;
    
    }
    }
    ?>
    
    <input type="hidden" name="action" value="save" />
    </form>
    <form method="post">
    <p class="submit">
    <input name="reset" type="submit" value="Reset" />
    <input type="hidden" name="action" value="reset" />
    </p>
    </form>
    </div>
    <?php
    }
    ?>
    <?php
    add_action('admin_init', 'mytheme_add_init');
    add_action('admin_menu', 'mytheme_add_admin');
    ?>
  2. Risean Militia
    Member
    Posted 1 year ago #

    <?php
    }
    ?>

    at the very end is the offending line, specifically the }

  3. Andrew Bartel
    Member
    Posted 1 year ago #

    What theme is this?

    You don't need to worry about the environment. It's just a php parse error, which means that php is improperly written in the specific file.

  4. Risean Militia
    Member
    Posted 1 year ago #

    it's a custom theme. Thing is, it works fine on the old server, but not on the new, despite the same version of php. I've tried variations of the code, and still got nothing.

  5. ak.singla
    Member
    Posted 1 year ago #

    You may want to use -- some function/script -- on the internet - that can search and count characters in a file.

    And, then you can search for ''{'' and ''}'' and check, if the count for both opening and closing brace is equal.

    I remember creating a small c++ program to do this, but you can also find that on Google.

  6. Jose Castaneda
    Member
    Posted 1 year ago #

    Most likely a missing delimiter somewhere.

  7. Jose Castaneda
    Member
    Posted 1 year ago #

    Use pastebin to paste the full functions file because there are only 349 that were displayed.

  8. Risean Militia
    Member
    Posted 1 year ago #

    That IS the full functions file.

    30 { 17 } (used dreamweaver find all to check) That doesn't look good, but I swear it works on the other server. It's not my custom theme.

  9. Risean Militia
    Member
    Posted 1 year ago #

    Not sure why it only showed 349, direct copy/paste from file manager. Trying again.

    <?
    //Init
    wp_enqueue_script("jquery");
    
    add_action( 'init', 'register_my_menu' );
    
    function register_my_menu() {
    	register_nav_menu( 'primary-menu', __( 'Main menu' ) );
    }
    
    class em_Walker extends Walker_Nav_Menu
    {
    	/**
    	 * Start the element output.
    	 *
    	 * @param  string $output Passed by reference. Used to append additional content.
    	 * @param  object $item   Menu item data object.
    	 * @param  int $depth     Depth of menu item. May be used for padding.
    	 * @param  array $args    Additional strings.
    	 * @return void
    	 */
    	public function start_el( &$output, $item, $depth, $args )
    	{
    		$output     .= '';
    		$attributes  = '';
    
    		! empty ( $item->attr_title )
    			// Avoid redundant titles
    			and $item->attr_title !== $item->title
    			and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"';
    
    		! empty ( $item->url )
    			and $attributes .= ' href="' . esc_attr( $item->url ) .'"';
    
    		$attributes  = trim( $attributes );
    		$title       = apply_filters( 'the_title', $item->title, $item->ID );
    		$item_output = "$args->before<a $attributes>$args->link_before<br>$title</a>"
    						. "$args->link_after$args->after";
    
    		// Since $output is called by reference we don't need to return anything.
    		$output .= apply_filters(
    			'walker_nav_menu_start_el'
    			,   $item_output
    			,   $item
    			,   $depth
    			,   $args
    		);
    	}
    
    	/**
    	 * @see Walker::start_lvl()
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @return void
    	 */
    	public function start_lvl( &$output )
    	{
    		$output .= '<ul class="sub-menu">';
    	}
    
    	/**
    	 * @see Walker::end_lvl()
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @return void
    	 */
    	public function end_lvl( &$output )
    	{
    		$output .= '</ul>';
    	}
    
    	/**
    	 * @see Walker::end_el()
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @return void
    	 */
    	function end_el( &$output )
    	{
    		$output .= '';
    	}
    }
    
    //Sidebars
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'name' => 'Footer bar',
    		'id' => 'footlinks',
    		'before_widget' => '',
            'after_widget' => '',
            'before_title' => '',
            'after_title' => '',
        ));
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'name' => 'Language bar',
    		'id' => 'toplinks',
    		'before_widget' => '',
            'after_widget' => '',
            'before_title' => '',
            'after_title' => '',
        ));
    
    //Theme options
    $themename = "Cres-AM";
    $shortname = "crs";
    
    $categories = get_categories('hide_empty=0&orderby=name');
    $wp_cats = array();
    foreach ($categories as $category_list ) {
           $wp_cats[$category_list->cat_ID] = $category_list->cat_name;
    }
    array_unshift($wp_cats, "Choose Category"); 
    
    $options = array (
    
    array( "name" => $themename." Options",
    	"type" => "title"),
    
    array( "name" => "General",
    	"type" => "section"),
    array( "type" => "open"),
    
    array( "name" => "Logo URL",
    	"desc" => "URL of Logo image",
    	"id" => $shortname."_logo",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Footer Text",
    	"desc" => "",
    	"id" => $shortname."_footer",
    	"type" => "text",
    	"std" => ""),
    
    array( "type" => "close"),
    
    array( "name" => "Slider",
    	"type" => "section"),
    array( "type" => "open"),
    
    array( "name" => "Image 1 URL",
    	"desc" => "",
    	"id" => $shortname."_s1",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 2 URL",
    	"desc" => "",
    	"id" => $shortname."_s2",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 3 URL",
    	"desc" => "",
    	"id" => $shortname."_s3",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 4 URL",
    	"desc" => "",
    	"id" => $shortname."_s4",
    	"type" => "text",
    	"std" => ""),
    
    array( "name" => "Image 5 URL",
    	"desc" => "",
    	"id" => $shortname."_s5",
    	"type" => "text",
    	"std" => ""),
    
    array( "type" => "close")
    
    );
    
    function mytheme_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'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
    	header("Location: admin.php?page=functions.php&saved=true");
    die;
    
    }
    else if( 'reset' == $_REQUEST['action'] ) {
    
    	foreach ($options as $value) {
    		delete_option( $value['id'] ); }
    
    	header("Location: admin.php?page=functions.php&reset=true");
    die;
    
    }
    }
    
    add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
    }
    
    function mytheme_add_init() {
    
    $file_dir=get_bloginfo('template_directory');
    wp_enqueue_style("functions", $file_dir."/functions.css", false, "1.0", "all");
    wp_enqueue_script("rm_script", $file_dir."/js/rm_script.js", false, "1.0");
    
    }
    function mytheme_admin() {
    
    global $themename, $shortname, $options;
    $i=0;
    
    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' options are saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' options are set to default values.</strong></p></div>';
    
    ?>
    <div class="wrap rm_wrap">
    <h2><?php echo $themename; ?> Options</h2>
    
    <div class="rm_opts">
    <form method="post">
    <?php foreach ($options as $value) {
    switch ( $value['type'] ) {
    
    case "open":
    ?>
    
    <?php break;
    
    case "close":
    ?>
    
    </div>
    </div>
    <br />
    
    <?php break;
    
    case "title":
    ?>
    <?
    break;
    
    case 'code':
    ?>
    
    <div class="rm_input rm_text">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
     	<textarea name="<?php echo $value['id']; ?>" type="text" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripcslashes(get_settings( $value['id'])) ; } else { echo $value['std']; } ?></textarea>
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    
     </div>
    <?php break;
    
    case 'text':
    ?>
    
    <div class="rm_input rm_text">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
     	<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>" />
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    
     </div>
    <?php
    break;
    
    case 'textarea':
    ?>
    
    <div class="rm_input rm_textarea">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
     	<textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea>
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    
     </div>
    
    <?php
    break;
    
    case 'select':
    ?>
    
    <div class="rm_input rm_select">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
    
    <select 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"'; } ?>><?php echo $option; ?></option><?php } ?>
    </select>
    
    	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
    </div>
    <?php
    break;
    
    case "checkbox":
    ?>
    
    <div class="rm_input rm_checkbox">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
    
    <?php if(get_option($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; ?> />
    
    	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
     </div>
    <?php break;
    case "section":
    
    $i++;
    
    ?>
    
    <div class="rm_section">
    <div class="rm_title"><h3><img src="<?php bloginfo('template_directory')?>/images/trans.gif" class="inactive" alt="""><?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save" />
    </span><div class="clearfix"></div></div>
    <div class="rm_options">
    
    <?php break;
    
    }
    }
    ?>
    
    <input type="hidden" name="action" value="save" />
    </form>
    <form method="post">
    <p class="submit">
    <input name="reset" type="submit" value="Reset" />
    <input type="hidden" name="action" value="reset" />
    </p>
    </form>
    </div>
    <?php
    }
    ?>
    <?php
    add_action('admin_init', 'mytheme_add_init');
    add_action('admin_menu', 'mytheme_add_admin');
    ?>
  10. Jose Castaneda
    Member
    Posted 1 year ago #

    Weird. I checked and got 30 curly brackets for both opening and closing.
    Is the add_menu_page() hook meant to be in the mytheme_add_admin() or outside?

  11. Frumph
    Member
    Posted 1 year ago #

    What PHP version are you running?

    This bit of code:

    ! empty ( $item->attr_title )
    			// Avoid redundant titles
    			and $item->attr_title !== $item->title
    			and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"';

    Might not be compatible with older versions of PHP. Which is why it worked on one machine and not another.

    My parser is also is reading the proper amount of { and }'s as well

Topic Closed

This topic has been closed to new replies.

About this Topic