Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Gotta be honest, I’m a GitHub noob so I’ll just cause more issues than it’s worth. If you get a chance to fixing it yourself, great. If not, no worries. The changes are mentioned in my comments above.

    All the best.

    Hi, I did some digging and found the cause – have posted a suggested fix on this post:

    https://ww.wp.xz.cn/support/topic/publish-does-nothing/#post-8423497

    Hope it’ll help 🙂

    • This reply was modified 9 years, 6 months ago by studioscully.

    I think I’ve found the reason here.

    TL;DR: it’s a bug that’s triggered when no pullquote components are set as anchor targets, and is caused by trying to access an array index that doesn’t exist. I’ve pasted a fix at the end.

    CODE

    In class-components.php, within the function add_pullquote_if_needed(), around line 448 is the following code:

    for ( $position = $start; $position < $len; $position++ ) {
    	if ( $components[ $position ]->can_be_anchor_target() ) {
    	break;
    	}
    }
    
    // If none was found, do not add
    if ( ! $components[ $position ]->can_be_anchor_target() ) {
    	return;
    }

    ISSUE

    The issue is that if none of the components return a true value for can_be_anchor_target(), then when the for loop exits, $position is set to $len, not $len-1 (it increments one last time in order to test the $position < $len condition, which fails, ending the for loop).

    $len is set to count( $components ), so the highest index in the $components[] array is $len-1.

    But if we find no matches, $position is set to $len when we then do our final check:

    if ( ! $components[ $position ]->can_be_anchor_target() ) {

    As the max index of $components is $len-1, not $len, $components[$position] is not set, so attempting to access a “can_be_anchor_target()” function throws an exception.

    FIX

    A fix I’ve successfully tested, using a $targetFound flag, is below:

    $targetFound = false;
    
    for ( $position = $start; $position < $len; $position++ ) {
    	if ( $components[ $position ]->can_be_anchor_target() ) {
    		$targetFound = true;
    		break;
    	}
    }
    
    // If none was found, do not add
    if (!$targetFound) {
    	return;
    }
Viewing 3 replies - 1 through 3 (of 3 total)