I’m updating one of my plugins and I’m a little stuck with deprecating functions.
Originally, my plugin had a global variable and the plugin’s main class was instantiated and stored in the global variable. This way users could use the global to access functions in the plugin class.
$GLOBALS['my_custom_plugin'] = new my_custom_plugin();
Then, for example, in my FAQ I had code that showed how to remove one of my class’ functions from a specific hook and add to to a different hook:
function move_input(){
global $my_custom_plugin;
remove_action( 'before_main_content', array( $my_custom_plugin, 'display_input') );
add_action( 'after_main_content', array( $my_custom_plugin, 'display_input' ) );
}
add_action( 'wp_head' , 'move_input' );
Now, in my update the display_input()
function has been moved to another class and I want to let people know how to access it. I tried replacing the original function (in the main plugin class) with the following deprecation notice:
public function display_input() {
_deprecated_function( 'display_price', '2.0', 'my_custom_plugin()->display->display_input' );
return $this->display->display_input();
}
However, the add_action
and remove_action
functions don’t seem to trigger the deprecation notice. Weirdly, completely removing the function doesn’t cause an error either even though array( $my_custom_plugin, 'display_input')
doesn’t exist.
If someone tries to access the function directly:
$my_custom_plugin->display_input();
Then I do see the debug notices. Is this the expected outcome for _deprecated_function()
? or am I missing something? Is it possible to show a debug notice when someone tries to remove or add an action using a deprecated function?
Update
I realized that I was simply not seeing the debug message for the add_action
as I was adding it pretty low on the page. #facepalm! However, I am still not seeing any debug notice for the remove_action
.