PostMeta.php
991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Favorites\Entities\Post;
use Favorites\Config\SettingsRepository;
use Favorites\Entities\Post\FavoriteCount;
class PostMeta
{
/**
* Settings Repository
*/
private $settings_repo;
public function __construct()
{
$this->settings_repo = new SettingsRepository;
add_action( 'add_meta_boxes', [$this, 'favoriteCountBox']);
}
/**
* Add the Favorite Count Meta Box for enabled Types
*/
public function favoriteCountBox()
{
foreach ( $this->settings_repo->metaEnabled() as $type ){
add_meta_box(
'favorites',
__( 'Favorites', 'favorites' ),
[$this, 'favoriteCount'],
$type,
'side',
'low'
);
}
}
/**
* The favorite count
*/
public function favoriteCount()
{
global $post;
$count = new FavoriteCount;
echo '<strong>' . __('Total Favorites', 'favorites') . ':</strong> ';
echo $count->getCount($post->ID);
echo '<input type="hidden" name="simplefavorites_count" value="' . $count->getCount($post->ID) . '">';
}
}