I built a WordPress plugin following Alessandro Castellani's tutorials with no problem.
However, when I built a second plugin and activate it, for some reason it overwrites the first one. In the sidebar, I get two links for the same (the second) plugin, whereas the first one does not appear. Even if I deactivate the first one, the second plugin appears as double.
Desired Behaviour:
The two plugins work and act as separate units.
Current Behaviour:
They seem to be overlapping and taking settings from each other and the second one removes the first one from the sidebar. What appears is the second plugin twice.
I have a different name for the plugin and reference this throughout
/**
* @package PluginNumberTwo
*/
Could the problem be because my __construct function within the BaseController is nearly identical?
First Plugin:
namespace Inc\Base;
class BaseController
{
public $plugin_path;
public $plugin_url;
public $plugin;
public function __construct(){
$this->plugin_path = plugin_dir_path( dirname( __DIR__ ) );
$this->plugin_url = plugin_dir_url( dirname( __DIR__ ) );
$this->plugin = plugin_basename(dirname(dirname(__DIR__))) .'/first-plugin.php';
...
}
}
Second Plugin:
namespace Inc\Base;
class BaseController
{
public $plugin_path;
public $plugin_url;
public $plugin;
public function __construct(){
$this->plugin_path = plugin_dir_path( dirname( __DIR__ ) );
$this->plugin_url = plugin_dir_url( dirname( __DIR__ ) );
$this->plugin = plugin_basename(dirname(dirname(__DIR__))) .'/second-plugin.php';
...
}
}
One potential problem is that some of the functions have the same names.
public function register()
public function addPages( array $pages )
public function addAdminMenu()
public function setSettings( array $settings )
public function setSections( array $sections )
public function setFields( array $fields )
public function registerCustomFields()
Would this potentially cause the problem?
Also, here are the comments at the beginning of each plugin file:
First plugin: