Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@coenjacobs
Last active May 30, 2018 08:42
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 coenjacobs/274095c1bc6a88b94e94952f68c5722f to your computer and use it in GitHub Desktop.
Save coenjacobs/274095c1bc6a88b94e94952f68c5722f to your computer and use it in GitHub Desktop.
<?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