Skip to content

Commit

Permalink
Add option to allow on select pages or posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHartnell committed Aug 6, 2015
1 parent 31b2f58 commit eb56706
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions hypothesis.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* @package Hypothesis
* @version 0.2.0
* @version 0.2.1
*/
/*
Plugin Name: Hypothesis
Plugin URI: http://hypothes.is/
Description: Hypothesis is an open platform for the collaborative evaluation of knowledge. This plugin embeds the necessary scripts in your Wordpress site to enable any user to use Hypothesis without installing any extensions.
Author: The Hypothesis Project and contributors
Version: 0.2.0
Version: 0.2.1
Author URI: http://hypothes.is/
*/

Expand Down Expand Up @@ -119,6 +119,22 @@ public function page_init()
'setting_section_id'
);

add_settings_field(
'post_ids_show_h', // ID
'Allow on posts (list of comma-separated post ids, no spaces)', // Title
array( $this, 'post_ids_show_h_callback' ), // Callback
'hypothesis-setting-admin', // Page
'setting_section_id' // Section
);

add_settings_field(
'page_ids_show_h', // ID
'Allow on pages (list of comma-separated page ids, no spaces)', // Title
array( $this, 'page_ids_show_h_callback' ), // Callback
'hypothesis-setting-admin', // Page
'setting_section_id' // Section
);

add_settings_field(
'post_ids_override', // ID
'Disallow on posts (list of comma-separated post ids, no spaces)', // Title
Expand Down Expand Up @@ -164,6 +180,12 @@ public function sanitize( $input )
if( isset( $input['allow-on-pages'] ) )
$new_input['allow-on-pages'] = absint($input['allow-on-pages']);

if( isset( $input['post_ids_show_h'] ) )
$new_input['post_ids_show_h'] = explode(',', esc_attr($input['post_ids_show_h']));

if( isset( $input['page_ids_show_h'] ) )
$new_input['page_ids_show_h'] = explode(',', esc_attr($input['page_ids_show_h']));

if( isset( $input['post_ids_override'] ) )
$new_input['post_ids_override'] = explode(',', esc_attr($input['post_ids_override']));

Expand Down Expand Up @@ -231,6 +253,29 @@ public function allow_on_pages_callback()
);
}

/**
* Get the settings option array and print one of its values
*/
public function page_ids_show_h_callback()
{
printf(
'<input type="text" id="page_ids_show_h" name="wp_hypothesis_options[page_ids_show_h]" value="%s" />',
isset( $this->options['page_ids_show_h'] ) ? esc_attr( implode(',', $this->options['page_ids_show_h'])) : ''
);
}

/**
* Get the settings option array and print one of its values
*/
public function post_ids_show_h_callback()
{
printf(
'<input type="text" id="post_ids_show_h" name="wp_hypothesis_options[post_ids_show_h]" value="%s" />',
isset( $this->options['post_ids_show_h'] ) ? esc_attr( implode(',', $this->options['post_ids_show_h'])) : ''
);
}


/**
* Get the settings option array and print one of its values
*/
Expand Down Expand Up @@ -276,17 +321,27 @@ public function category_ids_override_callback()

function add_hypothesis($param) {
$options = get_option( 'wp_hypothesis_options' );

if (isset($options['allow-on-blog-page']) && is_home()):
wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true );

elseif (isset($options['allow-on-front-page']) && is_front_page()):
wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true );

elseif (isset($options['post_ids_show_h']) && is_single($options['post_ids_show_h'])):
wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true );

elseif (isset($options['page_ids_show_h']) && is_page($options['page_ids_show_h'])):
wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true );

elseif (isset($options['allow-on-posts']) && is_single()):
if (isset($options['post_ids_override']) && is_single($options['post_ids_override']));
elseif (isset($options['category_ids_override']) && in_category($options['category_ids_override']));
else
wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true );

elseif (isset($options['allow-on-pages']) && is_page() && !is_front_page() && !is_home()):
if (isset($options['page_ids_override']) && is_page($options['page_ids_override']));
if (isset($options['page_ids_override']) && is_page($options['page_ids_override']));
else
wp_enqueue_script( 'hypothesis', '//hypothes.is/embed.js', '', false, true );
endif;
Expand Down

0 comments on commit eb56706

Please sign in to comment.