-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.php
67 lines (56 loc) · 1.78 KB
/
post.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
class PostBackgroundPluginPost {
public static $singleton = null;
public static function singleton() {
if ( is_null( self::$singleton ) ) {
self::$singleton = new self;
}
return self::$singleton;
}
public function __construct() {
add_action( 'wp_head', array( $this, 'header' ) );
}
protected function rule( $selector, $rule ) {
if ( empty( $rule ) ) {
return;
}
echo "$selector {\n";
if ( @$rule['color'] ) {
echo " background-color: " . @$rule['color'] . ";\n";
}
if ( @$rule['image'] ) {
echo " background-image: url('" . @$rule['image'] . "');\n";
}
if ( @$rule['repeat-x'] && @$rule['repeat-y'] ) {
echo " background-repeat: repeat;\n";
} elseif ( @$rule['repeat-x'] ) {
echo " background-repeat: repeat-x;\n";
} elseif ( @$rule['repeat-y'] ) {
echo " background-repeat: repeat-y;\n";
} else {
echo " background-repeat: no-repeat;\n";
}
if ( @$rule['position'] ) {
echo " background-position: " . @$rule['position'] . ";\n";
}
echo "}\n";
}
public function header() {
global $wp_query;
$options = PostBackgroundPluginOptions::singleton();
echo "<style type=\"text/css\">\n";
if ( $wp_query->is_single() || $wp_query->is_page() ) {
$postbackground = get_post_meta( get_the_ID(), 'postbackground', true );
$this->rule( 'body', isset( $postbackground['body'] ) ? $postbackground['body'] : array() );
}
while ( $wp_query->have_posts() ) {
$post = $wp_query->next_post();
$postbackground = get_post_meta( $post->ID, 'postbackground', true );
$selector = $options->get_content_selector( $post );
$this->rule( $selector, isset( $postbackground['content'] ) ? $postbackground['content'] : array() );
}
$wp_query->rewind_posts();
echo "</style>";
}
}
return PostBackgroundPluginPost::singleton();