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:
<?php
/**
* @package FirstPlugin
*/
/*
Plugin Name: FirstPlugin
Plugin URI: https://example.com
Description: This is the first plugin.
Version: 1.0.0
Author: First Lastname
Author URI: http://www.example.com
*/
Second Plugin:
<?php
/**
* @package SecongPlugin
*/
/*
Plugin Name: SecondPlugin
Plugin URI: https://example.com
Description: This is the second plugin
Version: 1.0.1
Author: Brad Ahrens
Author URI: http://www.example.com
*/
The file names are exactly the same (other than the main folder name and the initial first-plugin.php / second-plugin.php files).
$this
? What class do you use in these plugins?