treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Help With Checkboxes in Wordpress Plugin

  • I'm writing a plugin for my site that preserves html tags in the excerpt. I got it to work with a textfield. Where I manually put in the html tags, but I want to use checkbox's instead.

    I have an array of the html tags called $excerpt_tags and a foreach loop that outputs the array list with checkbox's.

    I just don't know how to set the checkbox's to my preserve html option

    Here's the code for the texfield


    public function lz_excerpt($lz_text) {

    $get_lz_funSettings = new FunctionSettings();
    $lz_values = $get_lz_funSettings->lz_funcSettings();

    $raw_excerpt = $lz_text;
    if ( '' == $lz_text ) {
    //Retrieve the post content.
    $lz_text = get_the_content('');

    //Delete all shortcode tags from the content.
    $lz_text = strip_shortcodes( $lz_text );

    $lz_text = apply_filters('the_content', $lz_text);
    $lz_text = str_replace(']]>', ']]>', $lz_text);

    $lz_allowed_tags = $lz_values['set_allowed_tags'];

    $lz_text = strip_tags($lz_text, $lz_allowed_tags);

    if ($lz_values['ena_expLength'] == 'true') {
    $lz_excerptlength = $lz_values['set_expLength'];
    $lz_set_excerpt_length = apply_filters('excerpt_length', $lz_excerptlength);
    }

    if ($lz_values['ena_expMoreLink'] == 'true') {
    $lz_excerptMoreLink = $lz_values['set_expMoreLink'];
    $lz_excerpt_more_link = apply_filters('excerpt_more', '&nbsp;<a href="'. get_permalink() . '">'. $lz_excerptMoreLink.' </a>');
    }

    $words = preg_split("/[\n\r\t ]+/", $lz_text, $lz_set_excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
    if ( count($words) > $lz_set_excerpt_length ) {
    array_pop($words);
    $lz_text = implode(' ', $words);
    $lz_text = $lz_text . $lz_excerpt_more_link;
    } else {
    $lz_text = implode(' ', $words);
    }
    }
    return apply_filters('wp_trim_excerpt', $lz_text, $raw_excerpt);
    }
    }


    if (!class_exists("functionSettings")) {
    class functionSettings {
    public $lz_adminOptionsName = "HeadCleanUpAdminOptions";
    public function lz_funcSettings(){
    $lz_adminOptions = array(
    'ena_expLength' => 'false',
    'set_expLength' => '10',
    'ena_expMoreLink' => 'false',
    'set_expMoreLink' => '',
    'set_allowed_tags' => ''
    );
    $lz_settings = get_option($this->lz_adminOptionsName);
    if (!empty($lz_settings)) {
    foreach ($lz_settings as $key => $option)
    $lz_adminOptions[$key] = $option;
    }
    update_option($this->lz_adminOptionsName, $lz_adminOptions);
    return $lz_settings;
    }
    }

    <p>
    <h3>Preserved Tags</h3>
    <label for="setAllowedTags">
    <textarea id="setAllowedTags" name="setAllowedTags" style="width: 300px; height: 100px;" value="<?php echo $lz_adminOptions['set_allowed_tags'] ?>"/> <?php _e(apply_filters('format_to_edit',htmlentities($lz_adminOptions['set_allowed_tags'])), 'layzeeFunctions') ?></textarea>
    </label>
    </p>

    <input type="submit" name="update_layzeeFunctionsAdminOptions" value="<?php _e('Update Settings', 'layzeeFunctions') ?>" />


    Like I said this works, so how can I do this but with checkbox's?