-
Notifications
You must be signed in to change notification settings - Fork 4
/
FeaturedMedia.php
72 lines (48 loc) · 1.7 KB
/
FeaturedMedia.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
Copyright © 2014 Code for the People Ltd
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
namespace FeaturedMedia;
class FeaturedMedia extends Plugin {
protected function __construct( $file ) {
# Actions
add_action( 'plugins_loaded', array( $this, 'action_plugins_loaded' ) );
# Filters
add_filter( 'post_class', array( $this, 'filter_post_class' ), 10, 3 );
# languages
add_action( 'after_theme_setup', array( $this, 'load_language_files' ) );
# Parent setup:
parent::__construct( $file );
}
public static function init( $file = null ) {
static $instance = null;
if ( !$instance )
$instance = new FeaturedMedia( $file );
return $instance;
}
public function load_language_files() {
//
load_plugin_textdomain( 'featured-media', false, dirname(__FILE__) . '/assets/languages/');
}
public function filter_post_class( $classes, $class, $post_id ) {
if ( has_featured_media_video( $post_id ) )
$classes[] = 'has-featured-media-video';
if ( has_featured_media_thumbnail( $post_id ) )
$classes[] = 'has-featured-media-thumbnail';
if ( has_featured_media_gallery( $post_id ) )
$classes[] = 'has-featured-media-gallery';
return $classes;
}
public function action_plugins_loaded() {
if ( is_admin() )
$this->admin = new Admin;
}
}