WordPress.org

Ready to get started?Download WordPress

Forums

ThreeWP Broadcast
[PATCH] undefined variable warning (8 posts)

  1. flynsarmy
    Member
    Posted 8 months ago #

    Notice: Undefined property: stdClass::$id in /path/to/wp-content/plugins/threewp-broadcast/include/threewp_broadcast/BroadcastData.php on line 54

    In the sql() method change

    $bcd->id = $result->id;

    to

    if ( !empty($result->id) )
    	$bcd->id = $result->id;

    A bit of background on this issue: The method is called by sql_get_broadcast_datas() in ThreeWP_Broadcast.php with:

    $query = sprintf( "SELECT * FROM<code>%s</code>WHERE<code>blog_id</code>= '%s' AND<code>post_id</code> IN ('%s')",
    	$this->broadcast_data_table(),
    	$blog_id,
    	implode( "', '", $post_ids )
    );
    $results = $this->query( $query );
    foreach( $results as $index => $result )
    	$results[ $index ][ 'data' ] = BroadcastData::sql( $result );

    Problem is that the broadcast_data_table doesn't have an ID column, so in your sql() method the line $bcd->id = $result->id; will never actually work.

    http://wordpress.org/plugins/threewp-broadcast/

  2. flynsarmy
    Member
    Posted 8 months ago #

    Another. This time when broadcasting:

    Undefined property: threewp_broadcast\broadcasting_data::$attachment_id in /path/to/wp-content/plugins/threewp-broadcast/ThreeWP_Broadcast.php on line 2131

    This line is the culprit:

    $a->new = get_post( $o->attachment_id );

    in this block:

    foreach( $bcd->attachment_data as $key => $attachment )
    {
    	if ( $key != 'thumbnail' )
    	{
    		$o = clone( $bcd );
    		$o->attachment_data = $attachment;
    		if ( $o->attachment_data->post->post_parent > 0 )
    			$o->attachment_data->post->post_parent = $bcd->new_post[ 'ID' ];
    		$this->maybe_copy_attachment( $o );
    		$a = new \stdClass();
    		$a->old = $attachment;
    		if ( !empty($o->attachment_id) )
    			$a->new = get_post( $o->attachment_id );
    		else
    			$a->new = null;
    		$bcd->copied_attachments[] = $a;
    	}
    }

    Now I haven't dug deep enough to figure out exactly what's going on here. But I guess your options are to either it to:

    if ( !empty($o->attachment_id) )
    	$a->new = get_post( $o->attachment_id );
    else
    	$a->new = null;

    which then presents a problem in that it leads to a few more issues where you're calling ->new->guid which doesn't exist...

    Line 2148 change

    foreach( $bcd->copied_attachments as $a )
    {
    	// Replace the GUID with the new one.
    	$modified_post->post_content = str_replace( $a->old->guid, $a->new->guid, $modified_post->post_content );
    	// And replace the IDs present in any image captions.
    	$modified_post->post_content = str_replace( 'id="attachment_' . $a->old->id . '"', 'id="attachment_' . $a->new->id . '"', $modified_post->post_content );
    }

    to

    foreach( $bcd->copied_attachments as $a )
    {
    	if ( !$a->new )
    		continue;
    
    	// Replace the GUID with the new one.
    	$modified_post->post_content = str_replace( $a->old->guid, $a->new->guid, $modified_post->post_content );
    	// And replace the IDs present in any image captions.
    	$modified_post->post_content = str_replace( 'id="attachment_' . $a->old->id . '"', 'id="attachment_' . $a->new->id . '"', $modified_post->post_content );
    }

    and line 2171ish change

    foreach( $bcd->copied_attachments as $ca )
    {
    	if ( $ca->old->id != $id )
    		continue;
    	$new_ids[] = $ca->new->ID;
    }

    to

    foreach( $bcd->copied_attachments as $ca )
    {
    	if ( $ca->new && $ca->old->id != $id )
    		continue;
    	$new_ids[] = $ca->new->ID;
    }

    ----------

    Alternatively you could simply not add $a to the copied_attachments list if it doesn't exist. Back up at line 2120 change

    $bcd->copied_attachments[] = $a;

    to

    if ( $a->new )
    	$bcd->copied_attachments[] = $a;

    Please enable WP_DEBUG to see these errors.

  3. flynsarmy
    Member
    Posted 8 months ago #

    Finally when redirecting after submitting a broadcasted post, I get an error about _POST not existing (in /wp-admin/post.php). This is probably caused by you unsetting it. You shouldnt' do that. Around line 1965 instead of

    // POST is no longer needed. Remove it so that other plugins don't use it.
    unset( $_POST );

    use

    $_POST = array();
  4. edward_plainview
    Member
    Plugin Author

    Posted 8 months ago #

    The first error is because the plugin wasn't properly upgraded. Deactivate and reactivate it and the wp__3wp_broadcast_broadcastdata table should receive an ID column.

    I would love to figure out why WordPress' upgrade function doesn't call the plugin activation method...

    The second error should never occur, since all attachments that exist in the first post must also exist in the new post. What would be far more interesting to find it would be why the new attachment isn't being copied as it should. THAT is the problem.

    The third error I've now fixed. Will release a new version in a day or two.

    Thank you for your help. Keep it coming.

  5. flynsarmy
    Member
    Posted 7 months ago #

    Thanks for the fix for issues 1 and 3. I deleted and re-added the plugin just to make sure all code is synched 100% with yours and there was a fresh activation so the table has the id column.

    As for issue two though, I don't know what to tell you but it IS happening. I have a post with two attachments (both 404ing but I doubt that'd affect attachment_id property). I edited around line 2130 to dump the object just before you attempt to grab its attachment_id property:

    if ( $key != 'thumbnail' )
    {
    	$o = clone( $bcd );
    	$o->attachment_data = $attachment;
    	if ( $o->attachment_data->post->post_parent > 0 )
    		$o->attachment_data->post->post_parent = $bcd->new_post[ 'ID' ];
    	$this->maybe_copy_attachment( $o );
    	$a = new \stdClass();
    	$a->old = $attachment;
    	if ( empty($o->attachment_id) )
    	{
    		var_dump($o);
    		exit;
    	}
    	$a->new = get_post( $o->attachment_id );
    	$bcd->copied_attachments[] = $a;
    }

    Here is the output: http://pastebin.com/BspmvRLt

    EDIT: Just added var_dump($key) above the var_dump($o) just incase it helps. The result was int 23406.

  6. edward_plainview
    Member
    Plugin Author

    Posted 7 months ago #

    > I have a post with two attachments (both 404ing but I doubt that'd affect attachment_id property).

    Actually, I'm figuring it would. :)

    Attachments, according to WordPress, must exist. It makes no sense to attach files (posts) that don't exist in the media library.

    If you test a post with attachments that exist, do you still get the errors?

  7. flynsarmy
    Member
    Posted 7 months ago #

    No, they exist fine in the database. It's just the files on disk that don't exist. I coudl throw in dummy files with the correct filenames and get the exact same error.

  8. edward_plainview
    Member
    Plugin Author

    Posted 7 months ago #

    In copy_attachment( $o ), at around line 2390 you'll find:

    if ( ! file_exists( $o->attachment_data->filename_path ) )
    return false;

    Meaning that the files must exist on disk. Dummy files would prevent the error from happening, I figure.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.