Open utterances-bot opened 3 years ago
Hi all! Warning: Illegal string offset 'checkbox' in C:..........\functions.php on line 176. Can someone help me fix this? Thank you!
Hi bataa21, I am not associated to this tutorial in any way, but I just happened to come across it when I noticed your question. The "illegal string offset" is the 'checkbox' part in $meta['checkbox']. For a new form (not submitted yet) $meta is an emtpy array. There is an "Edit 2018" at the very end of the tutorial, but that is insufficient.
Please note that this tutorial is far from complete. It is not up to WordPress (or any other) coding standards. To start, input id's should not contain brackets [ ]. If you are further along and make the field required, browsers will fail with "ID your_fields['checkbox'] is not focusable."
What is even more more important is that there is no validation nor sanititation when the form has been submiited and before it is sent to your database. Especially the textarea can easily contain dangerous content, like javascript. The simple rule is: Always sanitize! On input and output. Because this tutorial stores your metabox field values in an array, you would need to loop through the $_POST['your_fields'] to sanitize the input.
The tutorial also deletes all fields if one field has not been filled out. Please note that a checkbox only saves any value if it has been checked. So if you have saved the from and later uncheck the checkbox and click "Update" your form will be blank.
This tutorial should only be used for your very first steps in coding. Please do not use it on your live website.
Thanks for the advice!
how can i enable Wysiwyg field WordPress content editor as seen in Posts and Pages.
function setting_facebook1() { ?>
<?php }
PHP:
wp_enqueue_script( 'wp-tinymce' );
$args = array(
'wpautop' => true,
'media_buttons' => true,
'textarea_name' => 'your_fields[facebook]',
'textarea_rows' => 4,
'editor_css' => false,
'editor_class' => false,
'teeny' => false,
'dfw' => true,
'tinymce' => true,
'quicktags' => true
);
$value = isset( $meta['facebook'] ) ? wp_kses_post( $meta['facebook'] ) : null;
wp_editor( $value, 'facebook_editor', $args );
jQuery:
jQuery( '#facebook_editor' ).on( 'focusout' , function() {
tinymce.triggerSave();
});
where i put this code
This is the best, custom theme development i have seen.
WordPress Tutorial: Custom Fields and Meta Boxes | Tania Rascia
In the first part of my WordPress tutorial series, we learned what WordPress is and how to create and use a basic theme. In part two, we…
https://www.taniarascia.com/wordpress-part-three-custom-fields-and-metaboxes/