Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a4ef7e8
Remove php4 constructor
Sephster Jul 17, 2018
2e59bb6
Change to use yoda condition
Sephster Jul 17, 2018
4ba2f2b
Fix coding standard issues
Sephster Jul 17, 2018
ac7da19
Removed excess blank lines
Sephster Jul 17, 2018
65210bb
Code tidyup
Sephster Jul 18, 2018
3c07fd3
Reinstate openattribute from master
Sephster Jul 18, 2018
b52d8e3
Change include file to match open-attribute-widget class
Sephster Jul 18, 2018
7c38860
Fix class name
Sephster Jul 18, 2018
a3f5bd8
Apply coding standard fixes
Sephster Jul 18, 2018
efe0096
Fix calling of old constructor
Sephster Jul 18, 2018
846b69f
Fix a bug where we were accessing an undefined index
Sephster Jul 18, 2018
3c3edfe
Fix access of undefined index bug
Sephster Jul 18, 2018
0b56227
Fix access to non-existent post value
Sephster Jul 18, 2018
28fe355
Change plugin directory to be openattribute
Sephster Jul 18, 2018
6c52253
Fix issue with undefined variable being called
Sephster Jul 19, 2018
1cc64c7
Initialise the site license URL
Sephster Jul 19, 2018
33be017
Fix checkbox for widget which return on, not true
Sephster Jul 19, 2018
072a993
Change incorrect constant to a string
Sephster Jul 19, 2018
ff4b08b
Fix accessing of undefined indexes
Sephster Jul 19, 2018
0b6b377
Fix access to undefined index
Sephster Jul 19, 2018
0e71207
Fix access to undefined post variables
Sephster Jul 19, 2018
a1dacbe
Fixing blank spaces added to form fields
Sephster Jul 19, 2018
3164520
Fix accessing undefined index
Sephster Jul 19, 2018
4784f82
Fix incorrect escaping of html elements
Sephster Jul 19, 2018
2aae892
Added support for the customizer
Sephster Jul 19, 2018
d763dd4
Update version number
Sephster Jul 19, 2018
0155a1d
Updates to the readme and version number
Sephster Jul 19, 2018
226aa0d
Further updates to readme to clarify changes
Sephster Jul 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions class-open-attribute-widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
Loading