<?php $wp_version = '6.2.0'; // WP Core code. class Foo { public function __call( $name, $arguments ) { if ( 'new_method_A' === $name || 'new_method_B' === $name || 'new_method_C' === $name ) { return $this->$name( ...$arguments ); } $class = get_class( $this ); $trace = debug_backtrace(); $file = $trace[0]['file']; $line = $trace[0]['line']; trigger_error( "Call to undefined method $class::$name() in $file on line $line", E_USER_ERROR ); } private function new_method_A() { echo __FUNCTION__, ' called!', PHP_EOL; } private function new_method_B() { echo __FUNCTION__, ' called!', PHP_EOL; } public function new_method_C() { echo __FUNCTION__, ' called!', PHP_EOL; } } // Plugin code. $obj = new Foo(); if (method_exists($obj, 'new_method_A')) { $obj->new_method_A(); } else { // Do it some other way to support older WP versions. } if (method_exists('Foo', 'new_method_A')) { $obj->new_method_A(); } else { // Do it some other way to support older WP versions. } if (is_callable($obj, 'new_method_B')) { $obj->new_method_B(); // NOTE: doesn't work as method is private. } else { // Do it some other way to support older WP versions. } if (version_compare($wp_version, '6.2.0', '>=') === true) { $obj->new_method_C(); } else { // Do it some other way to support older WP versions. }
You have javascript disabled. You will not be able to edit any code.