Warn user that data may be lost for custom pages

you have to make a javascript code similar to this… jQuery(function ($) { name = $(‘#name’).val(); $(‘#name’).data(‘old_value’,name); window.onbeforeunload = function () { if ($(‘#name’).data(‘old_value’) !== $(‘#name’).val()) return ‘You have unsaved changes!’; } }); here’s a demo page… try closing the page after changing the value of the textbox there…

Save and user submitted data from a form and display them in the wp backend

Can you just tell me how I can grab the input value for “name” and add the entry to custom_post_type? Sure thing: if ( isset( $_POST[‘name’] ) ) { $name = sanitize_text_field( wp_unslash( $_POST[‘name’] ) ); if ( $name ) { wp_insert_post( array( ‘post_title’ => $name, ‘post_type’ => ‘my_post_type’, ‘post_status’ => ‘publish’, /* Or “draft”, … Read more

How to get options of all active widgets ?

This actually seems like a quite plausible approach – to me. There is nothing wrong with looping through it, sometimes it is the only/fastest way anyway. I don’t know how you get your sidebars, but for this $sidebars_widgets = get_option( ‘sidebars_widgets’ ); can be used. Which gives you an associative array containing a list of … Read more

update_option_{$option} not showing old value

You should use pre_update_option_{option_name} filter. Example:- function system_save_number( $new_value, $old_value ) { mail(‘[email protected]’,’here’,print_r($old_value ,true) . “\n\n” . print_r($new_value,true)); return $new_value; } function system_init_actions() { add_filter( ‘pre_update_option_system_number’, ‘system_save_number’, 10, 2 ); } add_action( ‘init’, ‘system_init_actions’ );

WP_OPTIONS table, active_plugins entry [closed]

That entry is a PHP serialized array. The serialize method takes an array and stores it’s value as a string so it can be stored elsewhere – like a database. In the above example, the “s:” entries stand for “string:”. With a serialized array, each element’s data type is represented by a letter (a, s, … Read more

wp-options keep crashing please help

It sounds like you may be running a plugin that stores too many transient options. If you can’t currently access wp-admin, try FTP’ing in and renaming your /plugins folder to disable all plugins. Then you should be able to log in to wp-admin. Next, back in FTP rename your /plugins folder back to the normal … Read more

Is a series of update_option calls safe, performance wise?

Using separate option names for a bunch of related options is not ideal. Instead, store options in a single key as a serialized array unless there is a specific reason not too. This way, you’ll only need the one call to add_option(), update_option(), and get_option() which will mean fewer queries being generated overall, particularly (as … Read more

Custom plugin admin page issues

The last parameter of add_submenu_page expects a function callback, not a file include – hence the error as that is not a valid callback. (See add_submenu_page in the codex.) You can include the file in the function if you prefer: add_submenu_page( “???”, “Add / Edit Price Options in Kilometers”, “Add / Edit Price Options in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)