How to use add_action for multiple instances of the same class

When you call add_meta_box() you must provide a unique ID as the first parameter.

Consider this case:

add_meta_box( 'foobox', 'Foo Title', 'foo_callback' );
add_meta_box( 'foobox', 'Bar Title', 'bar_callback' );

You will just get the Bar Title metabox now, because it will overwrite the first one.

What you need is a new ID for each box:

add_meta_box( 'foobox', 'Foo Title', 'foo_callback' );
add_meta_box( 'barbox', 'Bar Title', 'bar_callback' );

Try to create an ID from $custom_field_name or use a static counter.

Besides that, you should change your code in two other areas:

  1. Get rid of that god class, separate it into multiple classes:

    • one for the output, the metabox markup
    • one for the nonce. Example
    • one to get and to save the data
    • a controller to stick these classes together
  2. Fix your nonce, or your plugin will break badly on multi-site installations.