Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Fatal error on campaigns_list #91

Closed
etruel opened this issue Mar 29, 2024 · 2 comments
Closed

PHP Fatal error on campaigns_list #91

etruel opened this issue Mar 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@etruel
Copy link
Owner

etruel commented Mar 29, 2024

[29-Mar-2024 05:54:25 UTC] PHP Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-content/plugins/wpematico/app/campaigns_list.php:660
Stack trace: #0 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-content/plugins/wpematico/app/campaigns_list.php(660): implode()

#1 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-includes/class-wp-hook.php(326): WPeMatico_Campaigns::inline_custom_fields()

#2 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters()

#3 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/template.php(323): apply_filters()

#4 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-posts-list-table.php(1175): get_inline_data()

#5 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-posts-list-table.php(1072): WP_Posts_List_Table->column_title()

#6 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-list-table.php(1790): WP_Posts_List_Table->_column_title()

#7 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-posts-list-table.php(1432): WP_List_Table->single_row_columns()

#8 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-posts-list-table.php(834): WP_Posts_List_Table->single_row()

#9 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-posts-list-table.php(810): WP_Posts_List_Table->_display_rows()

#10 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-list-table.php(1709): WP_Posts_List_Table->display_rows()

#11 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/includes/class-wp-list-table.php(1636): WP_List_Table->display_rows_or_placeholder()

#12 /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-admin/edit.php(503): WP_List_Table->display()

#13 {main} thrown in /home/1211698.cloudwaysapps.com/ckncczpwsg/public_html/wp-content/plugins/wpematico/app/campaigns_list.php on line 660

GPT Fix:

static function inline_custom_fields($text) {
global $post, $pagenow;
if (($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'wpematico') || ($pagenow == 'admin-ajax.php' && isset($post) && $post->post_type == 'wpematico')) {
$campaign_data = WPeMatico::get_campaign($post->ID);
// Check if $campaign_data is a WP_Error object
if (is_wp_error($campaign_data)) {
// Handle error appropriately, possibly logging it and/or setting default values
$errorMessage = $campaign_data->get_error_message();
// For simplicity, we'll just return here, but you could handle it differently
return $text . " Error retrieving campaign data: " . $errorMessage;
}

/* Custom inline data for wpematico */
// (initialization of campaign data variables)

// Ensure $campaign_categories is an array
$campaign_categories = (is_array($campaign_data['campaign_categories'])) ? $campaign_data['campaign_categories'] : array();
$campaign_tags = (isset($campaign_data['campaign_tags'])) ? $campaign_data['campaign_tags'] : '';

// (concatenation of the $text variable with HTML elements and campaign data)

$text .= '</div>
<div class="post_id">' . $post->ID . '</div>
// (other div elements)
<div class="campaign_categories">' . implode(',', $campaign_categories) . '</div>
<div class="campaign_tags">' . stripslashes($campaign_tags);
}
return $text;
}
@etruel etruel added bug Something isn't working Prioritise To do it first. Urgent Special Attention labels Mar 29, 2024
@etruel etruel added this to the 2.6.25 milestone Mar 29, 2024
@etruel etruel modified the milestones: 2.6.25, 2.7 Apr 17, 2024
@etruel
Copy link
Owner Author

etruel commented Apr 17, 2024

Related issue #7
Surely the way a campaign could be broken by an unexpected interruption on fetching.

@etruel etruel removed Prioritise To do it first. Urgent Special Attention labels Apr 17, 2024
@etruel etruel assigned etruel and unassigned manuelge and gerarjos14 Apr 19, 2024
@etruel
Copy link
Owner Author

etruel commented Apr 20, 2024

We'll manage this to show a notice of the broken campaign on campaign list and give the chance of trash it.
We should test if it's failing with fatal error on another places, but it is really hard get a broken campaign.

@etruel etruel closed this as completed Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants