: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace NinjaForms\Includes\Admin;
if (!defined('ABSPATH')) exit;
class VersionCompatibilityCheck
* Array construct requirements for compatibility check
const COMPATIBILITY_CHECK_REQUIREMENTS = [
'minVersion' => 'string',
protected $compatiblityCheckCollection;
* Uses NF notices array structure
protected $compatibilityNotices = [];
* Activate checks and notices for plugin's envirnoment compatibility
public function activate(): void
add_action('ninja_forms_loaded', array($this, 'ensureVersionCompatibility'), 0);
* If Authorize.net and NF core versions re incompatible, display user notice
* NOTE: this does not stop functioning of plugin, but warns user that
* functionality may be affected
public function ensureVersionCompatibility(): void
$this->loadCompatibilityConfiguration();
$this->constructCompatiblityNotices();
add_filter('nf_admin_notices', [$this, 'addIncompatibleVersionsNotice']);
* Load compatibility check configuration
protected function loadCompatibilityConfiguration(): void
$this->compatiblityCheckCollection = \Ninja_Forms()->config('VersionCompatibilityCheck');
* Iterate collection, check compatibility, append notices
protected function constructCompatiblityNotices(): void
foreach ($this->compatiblityCheckCollection as $compatiblityCheck) {
if (!$this->isValidConstruct($compatiblityCheck)) {
$versionCompatiblity = $this->checkVersionCompatibility(
$compatiblityCheck['className'],
$compatiblityCheck['minVersion']
if ($versionCompatiblity) {
$compatiblityCheck['className'],
$compatiblityCheck['title'],
$compatiblityCheck['message'],
$compatiblityCheck['int'],
$compatiblityCheck['link']
* Ensure compatibility check construct is valid
* @param array $compatiblityCheck
* @return boolean false on invalid construct
protected function isValidConstruct(array $compatiblityCheck): bool
foreach (self::COMPATIBILITY_CHECK_REQUIREMENTS as $requiredKey => $requiredType) {
!isset($compatiblityCheck[$requiredKey])
|| $requiredType !== \gettype($compatiblityCheck[$requiredKey])
* Check that required versions are installed for proper functionality
* Default is to pass checks; only fail if known version incompatibility
* @return boolean Compatible TRUE, incompatible FALSE
protected function checkVersionCompatibility(string $className, string $requiredVersion): bool
$classVersion = $this->getClassVersion($className);
if ('' != $classVersion && \version_compare($classVersion, $requiredVersion, '<')) {
* Append a notice to the internal collection of notices
* @param string $className
protected function appendNotice(string $className, string $title, string $message, int $int, string $link): void
$this->compatibilityNotices[$className . '_compatibility_notice'] = [
* Determine the version of the request class name
* @param string $className Name of class to check
* @return string Version of the class, empty string if class doesn't exist or
* does not have VERSION constant defined
protected function getClassVersion(string $className): string
if (\class_exists($className) ){
$reflectionClass = new \ReflectionClass($className);
$return = $reflectionClass->getConstant('VERSION')?$reflectionClass->getConstant('VERSION'):'';
* Add NF admin notice for incompatible versions
public function addIncompatibleVersionsNotice($notices): array
foreach($this->compatibilityNotices as $noticeKey=>$newNotice){
'title'=>$newNotice['title'],
'msg'=>$newNotice['msg'],
'int'=>$newNotice['int'],
'link'=>$newNotice['link']