-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.traktivity.php
67 lines (58 loc) · 1.66 KB
/
content.traktivity.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
<?php
/**
* Extra content added to Trakt.tv Event Pages on the front end.
*
* @package Traktivity
*/
defined( 'ABSPATH' ) || die( 'No script kiddies please!' );
/**
* API Calls to get our data, and then store it in our custom post type and taxonomies.
* The core of the plugin's work happens here.
*
* @since 1.1.0
*/
class Traktivity_Content {
/**
* Constructor
*/
function __construct() {
add_filter( 'the_content', array( $this, 'credits' ), 5 );
}
/**
* Display credits at the bottom of each Event page.
*
* @since 1.1.0
*
* @param string $content Post content.
*/
public function credits( $content ) {
// Only add the credits to the detail pages of our post type.
if ( ! is_singular( 'traktivity_event' ) || ! is_main_query() ) {
return $content;
}
// If we have an image in that post, we'll add credits.
if ( false !== strpos( $content, '<img' ) ) {
$credits = '<div class="tmdb_credits"><p><small>';
$credits .= sprintf(
/* Translators: URL to THMDB website. */
__( 'Image source: <a href="%s">themoviedb.org</a>', 'traktivity' ),
esc_url( 'https://www.themoviedb.org/' )
);
$credits .= '</small></p></div>';
/**
* Filter the sentence used in the credits.
* One could then use `add_filter( 'traktivity_event_credits_string', '__return_empty_string' );` to remove the credits.
*
* @since 1.1.0
*
* @param string $credits Credit text.
* @param string $content Post content.
*/
$credits = apply_filters( 'traktivity_event_credits_string', $credits, $content );
return $content . $credits;
}
// Final fallback.
return $content;
}
} // End class.
new Traktivity_Content();