Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There is always danger in thinking your almost there...

The end Goal: A custom page in the admin menus where i can edit a widget I constructed.

Where I am now:

  • I have registered a custom menu
  • I am displaying the active widget controls on my custom page using a function entitled wp_list_widget_controls from wp-admin/includes/widgets.php
  • I have enqued the admin-widgets javascript

The almost there problem
Everything looks like it works. On my custom page, When I edit some of the widget's values and hit the save button I see a console log stating: XHR finished loading: www.example.ca/wp-admin/admin-ajax.php". The new value looks like it has been saved to the widget. But When I reload the page - the old value appears.

Additional Notes

  • The widget exists on appearance > widgets > some registered side bar
  • When I edit the values of the widget using the appearance > widgets > .. the widget works as expected.
  • I have not included the code for the actual widget as the widget works fine when I edit the widget from the correct place.

The code

362 add_action('admin_menu', 'widget_menu');
363 
364 function widget_menu () {
365     add_menu_page( 'News Widget', 'News Widget', 'manage_options', 'news_widget_opt_menu', 'news_widget_options', '', '6' );
366 }   
367 function news_widget_options () {
368 
369     require get_root_path() . '/wp-admin/includes/widgets.php';
370     wp_enqueue_script('admin-widgets');
371     echo wp_list_widget_controls('home_page_widgets');
372 };  

Can anyone help me make the final step (or tell me I have 1000 to go : ) or suggest an alternative approach.

Edit: The XY Problem
(a) I know I can enqueue a stylesheet in the admin widgets page. Therefore I can hide things and make other things bigger ect.

(b) In the html source code of admin/widgets.php, my widget html form code is being duplicated. Therefore the ID's that I am using are useless. I need unique ID's to activate my WMD Pagedown editors..

share|improve this question
1  
If you can make edits from the widget page, why do you need another separate admin page to do the same thing? –  splashingpixels Aug 30 '13 at 14:26
    
This does not seem wise to me (as with most, but not all, things WordPress when you have to include a Core file manually). Mostly though, it does not seem wise because widget options are saved dynamically and part of the information used to save the options is a widget instance ID. You are going to have a hard time keeping your admin page in sync with the saved options and visa versa. Perhaps if you explained why you think you need the additional admin page, there might be another approach. Maybe you have an XY problem. –  s_ha_dum Aug 30 '13 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.