It always shows authors because you always output the authors column, even if $column
has a different value.
Let’s take the filter and substitute $column
for its string value to demonstrate.
First, WP wants the output for the authors column:
add_action('manage_recipe_posts_custom_column', function ('authors') {
Column::get_columns('authors');
}, 10, 3);
Next, it calls the action again, but for the recipe-types
column:
add_action('manage_recipe_posts_custom_column', function ('recipe-types') {
Column::get_columns('authors');
}, 10, 3);
Notice that even though the action tells you which column it wants to output, that value is ignored. Also, notice that the action gets called multiple times with different column values. Think of actions like events, an event can happen more than once.
What’s more, the static method Column::get_columns
will take an arbitrary column name and generate the correct response, or at least attempt to. The switch statement is fine, but it always receives the same value, this problem has nothing to do with classes, objects, or switch statements, and would have happened even if it was just a function call.
So, instead of hardcoding it to authors
and wondering why it always shows the authors, pass in the column variable instead.
Which brings me to your Column
class. This isn’t OOP, it’s just a single function turned into a static method of a class. I recommend removing the Column
class and just using a function. For it to be object-oriented programming I would expect to be able to create a Column
object, and pass in parameters, and have the object takes care of registering everything on its own, without static methods, or needing inheritance for every column, with a Column
object created for each custom column. Such an implementation would be over-engineering. Just use a function as you do elsewhere.
Additionally, it should echo its output, the return
statements are incorrect.