Search code examples
phparrayswordpressgenesis

PHP WordPress Error - Catchable fatal error: Object of class WP_Term could not be converted to string


A wordpress website I am working on has a child theme that gives out an error when I try to log in. The main theme is Genesis. Everything used to work a week ago, and I can't figure out what is wrong with this code.

The error reads Catchable fatal error: Object of class WP_Term could not be converted to string in /home/usr234/public_html/wp-content/themes/outreach-pro/lib/cstomize-setting.php on line 408

Is it possible to parse an array into a string?

This is the function in cstomize-setting.php

add_action('admin_init', 'ms_category_images');
function ms_category_images() {
$ms_tags =  get_tags();
$ms_taxonomies = get_taxonomies();

if (is_array($ms_taxonomies)) { 
    foreach ($ms_taxonomies as $ms_taxonomy) {
        add_filter( 'manage_edit-' . $ms_taxonomy . '_columns', 'ms_taxonomy_columns' );
        add_filter( 'manage_' . $ms_taxonomy . '_custom_column', 'ms_taxonomy_column', 10, 3 );
       }
    }
if (is_array($ms_tags)) { 
    foreach ($ms_tags as $ms_taxonomy) {
    **//line no 408 is the one below**
    add_filter( 'manage_edit-' . $ms_taxonomy . '_columns', 'ms_taxonomy_columns' ); //line no 408
    add_filter( 'manage_' . $ms_taxonomy . '_custom_column', 'ms_taxonomy_column', 10, 3 );
    }
}

Solution

  • The error is because $ms_tags is an array of objects not array of names. The code handling $ms_tags should be changed as below:

    if (is_array($ms_tags)) { 
        foreach ($ms_tags as $ms_taxonomy) {
            add_filter( 'manage_edit-' . $ms_taxonomy->slug . '_columns', 'ms_taxonomy_columns' ); //line no 408
            add_filter( 'manage_' . $ms_taxonomy->slug . '_custom_column', 'ms_taxonomy_column', 10, 3 );
        }
    }