Created
February 18, 2019 13:08
-
-
Save malithmcr/be9ddee6ef8fb69e78fc13d64eb723c8 to your computer and use it in GitHub Desktop.
Wordpress OOP
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
namespace Wpse240042\Type; | |
use WP_Post; | |
interface Book { | |
/** | |
* @return string | |
*/ | |
public function title(); | |
/** | |
* @return string | |
*/ | |
public function publisher(); | |
/** | |
* @return int | |
*/ | |
public function year(); | |
} | |
class WpPostBook implements Book { | |
/** | |
* @var WP_Post | |
*/ | |
private $post; | |
/** | |
* @param WP_Post $post | |
*/ | |
public function __construct( WP_Post $post ) { | |
$this->post = $post; | |
} | |
/** | |
* @return string | |
*/ | |
public function title() { | |
return $this->post->post_title; | |
} | |
/** | |
* @return string | |
*/ | |
public function publisher() { | |
return get_post_meta( $this->post->ID, '_book_publisher', TRUE ); | |
} | |
/** | |
* @return int | |
*/ | |
public function year() { | |
return get_post_meta( $this->post->ID, '_book_publisher', TRUE ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment