Skip to content

Instantly share code, notes, and snippets.

@beezee
Created May 5, 2013 14:57
Show Gist options
  • Save beezee/5521040 to your computer and use it in GitHub Desktop.
Save beezee/5521040 to your computer and use it in GitHub Desktop.
cpt extended class of post with virtual attributes based on meta
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