Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created February 17, 2017 01:44
Embed
What would you like to do?
Example - Unregistering an object's method callback
<?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&#8217; 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