Created
September 16, 2016 17:58
-
-
Save greatislander/44be523d8badf59035a02e5af0723dd3 to your computer and use it in GitHub Desktop.
Hypothesis support for custom post types (rough draft)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$posttypes = apply_filters('hypothesis_supported_posttypes', array( | |
'post' => 'posts', | |
'page' => 'pages' | |
) ); | |
foreach ( $posttypes as $posttype => $name ) { | |
add_settings_field( | |
"allow-on-$posttype", | |
"Allow on $name", | |
array( $this, 'allow_on_posttype_callback' ), | |
'hypothesis-setting-admin', | |
'setting_section_id', | |
array( | |
$posttype, | |
$name | |
) | |
); | |
} | |
// then in sanitize… | |
foreach ( $posttypes as $posttype => $name ) { | |
if( isset( $input["allow-on-$name"] ) ) | |
$new_input["allow-on-$name"] = absint($input["allow-on-$name"]); | |
} | |
// callback… | |
public function allow_on_posttype_callback( $args ) | |
{ | |
$slug = sanitize_title($args[1]); | |
printf( | |
'<input type="checkbox" id="allow-on-' . $slug . '" name="wp_hypothesis_options[allow-on-' . $slug . ']" value="1" | |
'.checked( isset($this->options["allow-on-" . $slug]) ? $this->options["allow-on-" . $slug]: null, 1, false ).' />', | |
isset( $this->options['allow-on-' . $slug] ) ? esc_attr( $this->options['allow-on-' . $slug]) : 0 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment