Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created March 28, 2014 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pippinsplugins/9842051 to your computer and use it in GitHub Desktop.
Save pippinsplugins/9842051 to your computer and use it in GitHub Desktop.
Sample of how to extend a class in PHP
<?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