Created
May 5, 2013 14:57
-
-
Save beezee/5521040 to your computer and use it in GitHub Desktop.
cpt extended class of post with virtual attributes based on meta
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
class Player extends Post | |
{ | |
private $_points = false; | |
public static $after_save = array('update_points'); | |
public function set_points($points) | |
{ | |
$this->_points = $points; | |
} | |
public function get_points() | |
{ | |
return $this->_points ?: $this->meta('points', false, true); | |
} | |
public function update_points() | |
{ | |
if (!$this->_points) return; | |
$points_meta = $this->meta('points', true, true); | |
$points_meta->meta_value = $this->_points; | |
$points_meta->save(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment