$_POST field value gets altered after “init”

Yes, it’s the expected behaviour. There’s information on why it works like this here, and this function which can help in removing slashes from larger data structures: https://developer.wordpress.org/reference/functions/stripslashes_deep/ In the short term, if you can live without JSON for this field, why not just remove it, and if you need multiple hidden fields add them … Read more

Custom Post Type Meta Box Text Input Field Won’t Save When Blank

The problematic line is this one: if (isset($_POST[“book_title”]) && $_POST[“book_title”] <> ”) update_post_meta($post->ID, “book_title”, $_POST[“book_title”]); That logic says: If the submitted form contains a field called ‘book_title’ and if the content of the ‘book_title’ field does not equal an empty string, then save it. In your situation, the first condition should be met (HTML input … Read more

Display random image url from list of input values

Instead of echoing out these images, just store them as strings inside an array and choose one of the array items at random. <?php $headerimage_options = get_option(‘headerimage_options’ ); $images = array(); $images[] = ‘<img title=”‘.get_bloginfo(‘name’).'” src=”‘.esc_url( $headerimage_options[‘image’] ).'”/>’; $images[] = ‘<img title=”‘.get_bloginfo(‘name’).'” src=”‘.esc_url( $headerimage_options[‘image2′] ).'”/>’; $images[] = ‘<img title=”‘.get_bloginfo(‘name’).'” src=”‘.esc_url( $headerimage_options[‘image3′] ).'”/>’; $v = array_rand($images); … Read more

Adding a single text input field to a custom Dashboard widget

You need a set of functions to : process datas sanitize options allow datas to be updated output the form I like to proceed this way. I set also a function to grab datas so I can call them the simpliest way : add_action(‘wp_dashboard_setup’, ‘wpse_106458_add_widget’); function wpse_106458_add_widget() { $title = my_function_get_options(); $title = $title[‘title’]; wp_add_dashboard_widget(‘widget_id’, … Read more