/** * According to the stored settings, maybe adds filters for appending the votes HTML to the content and/or excerpt. * * @return void */ private function maybe_add_filters() { $option = Models\Option::get(); if (!empty($option['append_to_content'])) { $key = 'append_to_content_priority'; $priority = isset($option[$key]) ? (int) $option[$key] : 10; add_filter('the_content', array($this->view, 'append'), $priority); } if (!empty($option['append_to_excerpt'])) { $key = 'append_to_excerpt_priority'; $priority = isset($option[$key]) ? (int) $option[$key] : 10; add_filter('the_excerpt', array($this->view, 'append'), $priority); } }
/** * Renders the HTML. * * @return void */ public function render() { $option_name = Models\Option::get_name(); $option = Models\Option::get(); ?> <div class="wrap"> <h2> <?php echo $this->title; ?> </h2> <form action="<?php echo admin_url('options.php'); ?> " method="post"> <?php settings_fields($option_name); ?> <table class="form-table"> <tbody> <tr> <th scope="row"> <?php esc_html_e('Automatic Appending', 'that-was-helpful'); ?> </th> <td> <fieldset> <?php $id = 'append-to-content'; $name = 'append_to_content'; ?> <label for="<?php echo $id; ?> "> <input name="<?php echo "{$option_name}[{$name}]"; ?> " type="checkbox" value="1" id="<?php echo $id; ?> " <?php checked(!empty($option[$name])); ?> > <?php /* translators: %s: Priority input element HTML */ $string = esc_html__('Automatically append to content with priority %s', 'that-was-helpful'); $id .= '-priority'; $name .= '_priority'; $value = isset($option[$name]) ? (int) $option[$name] : 10; $input = '</label>' . '<label for="' . $id . '">' . '<input name="' . "{$option_name}[{$name}]" . '" type="number" step="1" value="' . $value . '" id="' . $id . '" class="small-text">'; printf($string, $input); ?> </label> <br> <?php $id = 'append-to-excerpt'; $name = 'append_to_excerpt'; ?> <label for="<?php echo $id; ?> "> <input name="<?php echo "{$option_name}[{$name}]"; ?> " type="checkbox" value="1" id="<?php echo $id; ?> " <?php checked(!empty($option[$name])); ?> > <?php /* translators: %s: Priority input element HTML */ $string = esc_html__('Automatically append to excerpt with priority %s', 'that-was-helpful'); $id .= '-priority'; $name .= '_priority'; $value = isset($option[$name]) ? (int) $option[$name] : 10; $input = '</label>' . '<label for="' . $id . '">' . '<input name="' . "{$option_name}[{$name}]" . '" type="number" step="1" value="' . $value . '" id="' . $id . '" class="small-text">'; printf($string, $input); ?> </label> </fieldset> </td> </tr> </tbody> </table> <?php submit_button(); ?> </form> </div> <?php }