Created
March 28, 2014 20:15
-
-
Save pippinsplugins/9842051 to your computer and use it in GitHub Desktop.
Sample of how to extend a class in PHP
This file contains hidden or 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 | |
/* | |
* Plugin Name: PD101 Extending Classes Example | |
* Description: An example of how to extend a class | |
* Author: Pippin Williamson | |
*/ | |
class PD101_Base { | |
public function __construct() { | |
add_action( 'wp_footer', array( $this, 'footer_text' ) ); | |
} | |
public function footer_text() { | |
echo $this->get_footer_text(); | |
} | |
public function get_footer_text() { | |
return '<p>Hello! I am in the footer!</p>'; | |
} | |
} | |
class PD101_Extension extends PD101_base { | |
public function get_footer_text() { | |
return '<p><strong>Oh hey!</strong> This is cool</p>'; | |
} | |
} | |
new PD101_Extension; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment