Skip to content

Instantly share code, notes, and snippets.

@malithmcr
Created February 18, 2019 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malithmcr/be9ddee6ef8fb69e78fc13d64eb723c8 to your computer and use it in GitHub Desktop.
Save malithmcr/be9ddee6ef8fb69e78fc13d64eb723c8 to your computer and use it in GitHub Desktop.
Wordpress OOP
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