dmhendricks / wordpress-base-plugin

A starter template for WordPress plugins, with autoloading, namespaces and object caching (where available).
GNU General Public License v2.0
83 stars 21 forks source link

plugin prefix on multiple plugin installation #7

Open mmaturan opened 5 years ago

mmaturan commented 5 years ago

Hi , I don't know if im doing something wrong, but I edit and installed the pluggin twice, in the same wordpress installation. I did all the steps in the Documentation, Installing carbon field with composer in both of them. both have a custom posttype with custom fields created with carbon fields. but the fields in the second plugin are saved with a wrong prefix . Both custom posts, from two different plugins, get the same prefix for theirs metas. if I deactivate the first plugin, the other plugin gets fixed, and its custom fields are saved right.

Thanks!

dmhendricks commented 5 years ago

I have verified and you are correct. This is, indeed, a bug that surfaced at some point. I will have to look into it (it is located in one of my dependencies, not this code).

In the mean time, you can fix it by adding the following function to your app/Plugin.php files:

/**
  * Append a field prefix as defined in $config
  *
  * @param string $field_name The string/field to prefix
  * @param string $before String to add before the prefix
  * @param string $after String to add after the prefix
  * @return string Prefixed string/field value
  */
public static function prefix( $field_name = null, $before = '', $after = '_' ) {

  $prefix = $before . self::$config->get( 'prefix' ) . $after;
  return $field_name !== null ? $prefix . $field_name : $prefix;

}

Thank you for the report! This is a major bug that needs to be fixed properly.

mvargasmoran commented 5 years ago

@dmhendricks Whoa, that was a really quick answer, thanks man. Good Guy Hendricks!

dmhendricks commented 5 years ago

No problem, thanks!