-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclass-open-attribute-widget.php
More file actions
117 lines (100 loc) · 3.21 KB
/
class-open-attribute-widget.php
File metadata and controls
117 lines (100 loc) · 3.21 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
class Open_Attribute_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'openattribute_widget',
'OpenAttribute Widget',
[
'classname' => 'OpenAttribute Widget',
'description' => 'Display a a license for your blog post or entire site in a widget',
'customize_selective_refresh' => true,
],
''
);
}
/**
* Echoes the widget content
*
* @return void
*/
public function widget( $args, $instance ) {
if ( ( $instance['openattribute_link'] ) || $instance['openattribute_image'] ) {
global $wp_query;
if ( is_single() ) {
if ( get_option( 'openattribute_widgetset' ) === '1' ) {
$disable = get_post_meta( $wp_query->posts[0]->ID, 'disable_license' );
if ( 'off' === $disable[0] || '' === $disable[0] ) {
$display = true;
if ( get_option( 'openattribute_blogoverride' ) === '1' ) {
$content = $wp_query->posts[0]->post_content;
$author = explode( 'oaauthor', $content );
$title = explode( 'oatitle', $content );
$oashorthand = explode( 'oashorthand', $content );
if ( count( $author ) !== 1 ) {
$display = false;
}
if ( count( $title ) !== 1 ) {
$display = false;
}
if ( count( $oashorthand ) !== 1 ) {
$display = false;
}
}
if ( $display ) {
echo $args['before_widget'];
echo $args['before_title'];
echo 'Attribute me';
echo $args['after_title'];
if ( $instance['openattribute_image'] ) {
echo '<a onclick="attribute_button(event)" style="cursor:hand; cursor:pointer"><img src="' . esc_url( WP_PLUGIN_URL . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) ) . 'attrib_button.png' ) . '" /></a>';
}
if ( $instance['openattribute_link'] ) {
echo '<a onclick="attribute_button(event)" style="cursor:hand; cursor:pointer">Attribute this resource</a>';
}
echo $args['after_widget'];
}
}
}
}
}
}
/**
* Updates a particular instance of a widget
*
* @return array
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['openattribute_link'] = strip_tags( $new_instance['openattribute_link'] );
$instance['openattribute_image'] = strip_tags( $new_instance['openattribute_image'] );
return $instance;
}
/**
* Outputs the settings update form
*
* @return void
*/
public function form( $instance ) {
?>
<p>Tick the respective box if you wish the following to appear in this widget:</p>
<input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'openattribute_link' ) ); ?>"
<?php
if ( isset( $instance['openattribute_link'] ) && 'on' === $instance['openattribute_link'] ) {
echo ' checked />';
} else {
echo ' />';
}
?>
<label>"Attribute this resource"</label> <br />
<input type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'openattribute_image' ) ); ?>"
<?php
if ( isset( $instance['openattribute_link'] ) && 'on' === $instance['openattribute_image'] ) {
echo ' checked />';
} else {
echo ' />';
}
?>
<label>OpenAttribute image</label>
<?php
}
}