Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class MetaChecker {
public function checkMeta( WP_Post $post ) {
$value = get_post_meta($post->ID, 'key_of_value_store', true);
// @TODO: Do magic with $value
}
}
<?php
class MetaChecker {
/** @var MetaRepository */
public $metaRepository;
public function __construct( MetaRepository $metaRepository ) {
$this->metaRepository = $metaRepository;
}
public function checkMeta( WP_Post $post ) {
$value = $this->metaRepository->getMeta($post, 'key_of_value_store', true);
// @TODO: Do magic with $value
}
}
<?php
interface MetaRepository {
public function getMeta( WP_Post $post, $key, $single );
}
class WordPressMetaRepository implements MetaRepository {
public function getMeta( WP_Post $post, $key, $single ) {
return get_post_meta($post->ID, $key, $single);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment