-
-
Save hellofromtonya/6b6d18e4ce721f97d1d36ff37b57c4ca to your computer and use it in GitHub Desktop.
Example - Unregistering an object's method callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* OOP Sandbox Plugin | |
* | |
* @package KnowTheCode\OOPSandbox | |
* @author hellofromTonya | |
* @license GPL-2.0+ | |
* | |
* @wordpress-plugin | |
* Plugin Name: OOP Sandbox Plugin | |
* Plugin URI: https://KnowTheCode.io | |
* Description: OOP Sandbox test plugin | |
* Version: 1.0.0 | |
* Author: hellofromTonya | |
* Author URI: https://KnowTheCode.io | |
* Text Domain: journals | |
* License: GPL-2.0+ | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
*/ | |
namespace KnowTheCode\OOPSandbox; | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit( 'Cheatin’ uh?' ); | |
} | |
function autoload() { | |
include( __DIR__ . '/src/class-user.php' ); | |
} | |
autoload(); | |
function new_user( array $user_config ) { | |
return new User( $user_config ); | |
} | |
function get_sally_user_profile() { | |
static $sally; | |
if ( ! $sally ) { | |
$sally = new_user( get_config( 'sally' ) ); | |
} | |
return $sally; | |
} | |
get_sally_user_profile(); | |
//$tonya = new_user( get_config( 'tonya' ) ); | |
//$sally->update_profile(); | |
add_action( 'init', __NAMESPACE__ . '\check_registry_before_object', 1 ); | |
function check_registry_before_object() { | |
global $wp_filter; | |
d( $wp_filter['init'] ); | |
$sally = get_sally_user_profile(); | |
echo '========== removing ============='; | |
remove_action( 'init', array( $sally, 'update_profile' ) ); | |
d( $wp_filter['init'] ); | |
// remove_action( 'init', 'KnowTheCode\OOPSandbox\User::getNumberOfUsers' ); | |
} | |
function get_config( $name ) { | |
$config = array( | |
'tonya' => array( | |
'user_id' => 1, | |
'first_name' => 'Tonya', | |
'last_name' => 'Mork', | |
'email' => 'hellofromtonya@knowthecode.io', | |
'twitter' => '@hellofromtonya', | |
'facebook' => '', | |
), | |
'sally' => array( | |
'user_id' => 2, | |
'first_name' => 'Sally', | |
'last_name' => 'Jones', | |
'email' => 'sally.jones@gmail.com', | |
'twitter' => '@sallyjones', | |
'facebook' => '', | |
), | |
); | |
return $config[ $name ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment