WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#16385 closed defect (bug) (wontfix)

Catchable fatal error in WP 3.1 RC3 - echo get_category_link

Reported by: vasylesku Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: General Keywords: reporter-feedback needs-investigating
Focuses: Cc:

Description

I have in index.php the line 6:
<a href="<?php echo get_category_link(get_theme_mod('featured')); ?>"><?php echo cat_id_to_name(get_theme_mod('featured')); ?></a>

In Wordpres 3.0.4 works perfect, but in WordPress 3.1 RC3:
Catchable fatal error: Object of class WP_Error could not be converted to string in C:\wamp\www\wordpress\wp-content\themes\cvasi-magazine\index.php on line 6

Change History (13)

comment:1 dd323 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

comment:2 follow-up: dd323 years ago

Actually, not 100% sure this is a duplicate, but sounds damn close to it..

It sounds like get_theme_mod('featured') is returning either

  • a non-integer
  • an integer, but not the id of a category.

Eitherway, You need to account for the fact that get_category_link MAY return a WP_Error object in the event the input is not correct.

comment:3 in reply to: ↑ 2 vasylesku3 years ago

The input is correct. Like I sad, in wp 3.0.4 is working perfect. I just switch to wp 3.1.
So your comment is shallow. This is a bug. Of course, 3.1.1 comes after 3.1, 3.1.2 comes after 3.1.1 and so.

Last edited 3 years ago by vasylesku (previous) (diff)

comment:4 follow-up: dd323 years ago

so your comment is shallow.

Your bug report is shallow. We can all play that game.

The fact still remains, WP_Error is a valid return from this function, Regardless of if this is a core problem, You'll still need to change that code to prevent it in the future.

What is the return value of get_theme_mod('featured')?

What about the error contents? (var_dump(get_category_link(get_theme_mod('featured')));)

comment:5 in reply to: ↑ 4 vasylesku3 years ago

For get_theme_mod('featured') -
Not name of category, just link "Read more from..." and link goes in the same place (index.php).
Also the category name from top of posts box disappeared.

For (var_dump(get_category_link(get_theme_mod('featured')));) -
array(1) { invalid_term?=> array(1) { [0]=> string(10) "Empty Term" } } error_data?=> array(0) { } }

comment:6 dd323 years ago

So, What's the return value of get_theme_mod('featured')? ie. var_dump(get_theme_mod('featured'));

comment:7 dd323 years ago

Once you've got the return value of that, Hit your themes admin page and re-save it's settings, See if that fixes it.

comment:8 nacin3 years ago

  • Keywords reporter-feedback needs-investigating added; Catchable fatal error echo get_category_link removed
  • Milestone set to 3.1
  • Resolution duplicate deleted
  • Status changed from closed to reopened

Moving to 3.1 as this is concerning. We need feedback here though.

comment:9 westi3 years ago

  • Cc westi added

Unless we have somehow broken get_theme_mod during 3.1 I'm not sure I see a bug here.

Previously get_category_link was slightly more lenient in that it would blindly trust the ID you passed in if pretty permalinks were not enabled.

WP_Error has always been a possible return from get_category_link.

Have you got pretty permalinks enabled or are you using query string style urls?

comment:10 vasylesku3 years ago

The permalinks is set to /%category%/%postname%/. Anyway, I just upgraded to 3.1 from 3.0.4. I installed another wp 3.1 in my wamp and... the same results.
Another example:

<div id="homepageleft">

<div class="hpfeatured">
<h3><?php echo cat_id_to_name(get_theme_mod('featured_top_left')); ?></h3>


<?php $recent = new WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num')); while($recent->have_posts()) : $recent->the_post();?>
<?php if( get_post_meta($post->ID, "thumb", true) ): ?>
<a href="<?php the_permalink() ?>" rel="bookmark"><img class="thumb" src="<?php bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&amp;h=<?php echo get_theme_mod('featured_top_left_thumb_height'); ?>&amp;w=<?php echo get_theme_mod('featured_top_left_thumb_width'); ?>&amp;zc=1" alt="<?php the_title(); ?>" /></a>
<?php else: ?>
<?php endif; ?>


<strong><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></strong>
<?php the_content_limit(80, ""); ?>


<hr/>


<?php endwhile; ?>
<?php $cat = get_category(get_theme_mod('featured_top_left')); ?>

Line 40:
<strong><a href="<?php echo get_category_link(get_theme_mod('featured_top_left')); ?>" rel="bookmark"><?php echo ("Read More Posts From ", 'studiopress')." ".$cat->name; ?></a></strong>

</div>

</div>

Results: "Catchable fatal error: Object of class WP_Error could not be converted to string in C:\wamp\www\wordpress\wp-content\themes\church\home.php on line 40"

Try the Church theme from Studio Press and Fashion Pro from Theme Junkie!

Version 4, edited 3 years ago by vasylesku (previous) (next) (diff)

comment:11 dd323 years ago

3.0.4, When passed invalid data (ie. null/false) when running without rewrite, it'll will create a link as such: 'http://...../?cat='. When running with rewrite it'll Catchable error. As expected, Works with valid data (ie. '1');

Upgrade to 3.1; When presented with valid data, it continues to work, give it invalid data, or a non-set theme mod, and it fails.

I've tested it, get_theme_mod() is persisting on the upgrade, However this was tested with TwentyTen.

vasylesku: As those are both Premium themes, I'm unable to test or confirm if they trigger any bugs.

I'll echo my previous statement:

So, What's the return value of get_theme_mod('featured')? ie. var_dump(get_theme_mod('featured'));

Or in this case, var_dump(get_theme_mod('featured_top_left'));

comment:12 vasylesku3 years ago

For

var_dump(get_theme_mod('featured_top_left'));

returns

string(0) ""


comment:13 markjaquith3 years ago

  • Milestone 3.1 deleted
  • Resolution set to wontfix
  • Status changed from reopened to closed

Passing a blank string:

var_dump( get_category_link("") );

WordPress 3.0.4, default permalinks:

string(21) "http://wp30.dev/?cat="

WordPress 3.0.4, pretty permalinks:

object(WP_Error)#78 (2) { errors?=> array(1) { invalid_term?=> array(1) { [0]=> string(10) "Empty Term" } } error_data?=> array(0) { } }

WordPress 3.1, default permalinks:

object(WP_Error)#181 (2) { errors?=> array(1) { invalid_term?=> array(1) { [0]=> string(10) "Empty Term" } } error_data?=> array(0) { } }

WordPress 3.1, pretty permalinks:

object(WP_Error)#181 (2) { errors?=> array(1) { invalid_term?=> array(1) { [0]=> string(10) "Empty Term" } } error_data?=> array(0) { } }

The only difference is that passing a blank string on a site with default permalinks now generates a WP_Error, whereas before it passed a malformed URL. The new behavior is more consistent with sites that have pretty permalinks enabled.

Note: See TracTickets for help on using tickets.