Checkbox `checked()` function echo's checked='checked'

Interactive

I'm writing a WordPress plugin and have a checkbox in a form.

If the checkbox is checked it saves the value to the database and shows up checked in the form. However if the checkbox is checked it outputs checked='checked' in the form.

So the checkbox works like it needs to work but I cant see why it outputs checked='checked' to the form

public function display() {

    $html = '';
    // Add an nonce field so we can check for it later.
    wp_nonce_field( basename( __FILE__ ), 'nonce_check_value' );
    $html .= '<label for="CMBUserBoxName">Name metabox: </label>';
    $html .= '<input type="text" name="CMBUserBoxName" value="' . get_post_meta( get_the_ID(), 'CMBUserBoxName', true ). '">';
    $html .= '<h1>What do you need?</h1>';
    $html .= '<label for="CMBUserCheckbox">Checkbox: </label>';
    $checkedByUser = get_post_meta( get_the_ID(), 'CMBUserCheckbox', true );
    $html .= '<input type="checkbox" name="CMBUserCheckbox" value="1" '.checked( $checkedByUser, 1 ).' />';

    echo $html;
}

The output on screen is as followed
enter image description here

Syscall

The checked() function echos by default. Use false in the last parameter to return the string instead of echo.

$html .= '<input type="checkbox" name="CMBUserCheckbox" value="1" '.checked( $checkedByUser, 1, false).' />';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Function if checkbox checked and a different function if not checked?

From Dev

Checkbox not checked

From Dev

Execute function when the checkbox is checked

From Dev

ID of non checked checkbox's

From Dev

How to echo <div> content when a checkbox is checked?

From Dev

PHP checkbox validation checked or not checked

From Dev

Get checkbox values on checked and not checked

From Dev

Checkbox - Fire one function when checked and fire another when not checked

From Dev

Checkbox null means it's not, checkbox checked is 1

From Dev

javascript laravel - call a function when the checkbox is checked

From Dev

Execute if function if checkbox is checked angular.js

From Dev

calling js function in php when checkbox is checked

From Dev

How to call function on android checkbox checked?

From Dev

Is it possible to style ::before of a checked checkbox's label?

From Dev

Checkbox's checked property binding - Polymer

From Dev

checked and unchecked Checkbox with another Activiti's Listview

From Dev

If checkbox is checked add class to it's label

From Dev

react: get custom checkbox's checked attribute

From Dev

Checkbox have to display in the TABLE YES/NO if it's checked or not

From Java

Check if checkbox is checked with jQuery

From Dev

checkbox is not checked in javascript?

From Dev

angularjs checkbox not getting checked

From Dev

Angularjs checkbox not checked at start

From Dev

Programmatically change checked of a checkbox

From Dev

Toggle element on checkbox checked

From Java

Testing if a checkbox is checked with jQuery

From Java

jQuery if checkbox is checked

From Java

Setting "checked" for a checkbox with jQuery

From Dev

check if qtreewidgetitem checkbox is checked

Related Related

HotTag

Archive