Created
August 27, 2015 13:57
-
-
Save mattheu/f3cc89f09e28b95257f2 to your computer and use it in GitHub Desktop.
Post Objects Example
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 | |
namespace Post_Objects; | |
class Post { | |
private $_post; | |
public function get_id() { | |
return $this->data->id; | |
} | |
public function get_title() { | |
return $this->data->title; | |
} | |
} |
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 | |
namespace USAT_Post_Objects; | |
class Post extends PostObjects\Post { | |
public function is_sponsored() { | |
$sponsored = lawrence_get_sponsored_post(); | |
return $sponsored && $sponsored->ID === $this->get_id(); | |
} | |
} |
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 $post = USAT\Post::get_by_id( 1 ); ?> | |
<h2><?php echo esc_html( $post->get_title() ); ?></h2> | |
<?php if ( $post->is_sponsored() ) : ?> | |
<p>Sponsored!</p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment