display-screen-options.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. function ninja_forms_load_screen_options_tab() {
  3. global $ninja_forms_help_screen_tabs, $ninja_forms_screen_options;
  4. $current_tab = ninja_forms_get_current_tab();
  5. $current_page = esc_html( $_REQUEST['page'] );
  6. $screen = get_current_screen();
  7. if(isset($ninja_forms_help_screen_tabs['_universal_'])){
  8. foreach($ninja_forms_help_screen_tabs['_universal_'] as $key => $tab){
  9. $screen->add_help_tab( array(
  10. 'id' => $key, // This should be unique for the screen.
  11. 'title' => $tab['title'],
  12. 'callback' => $tab['content'],
  13. // Use 'callback' instead of 'content' for a function callback that renders the tab content.
  14. ) );
  15. }
  16. }
  17. if(isset($ninja_forms_help_screen_tabs[$current_page]['_universal_'])){
  18. foreach($ninja_forms_help_screen_tabs[$current_page]['_universal_'] as $key => $tab){
  19. $screen->add_help_tab( array(
  20. 'id' => $key, // This should be unique for the screen.
  21. 'title' => $tab['title'],
  22. 'callback' => $tab['content'],
  23. // Use 'callback' instead of 'content' for a function callback that renders the tab content.
  24. ) );
  25. }
  26. }
  27. if(isset($ninja_forms_help_screen_tabs[$current_page][$current_tab])){
  28. foreach($ninja_forms_help_screen_tabs[$current_page][$current_tab] as $key => $tab){
  29. $screen->add_help_tab( array(
  30. 'id' => $key, // This should be unique for the screen.
  31. 'title' => $tab['title'],
  32. 'callback' => $tab['content'],
  33. // Use 'callback' instead of 'content' for a function callback that renders the tab content.
  34. ) );
  35. }
  36. }
  37. if(isset($ninja_forms_screen_options['_universal_']) OR isset($ninja_forms_screen_options[$current_page]['_universal_']) OR isset($ninja_forms_screen_options[$current_page][$current_tab]) ){
  38. add_filter('screen_layout_columns', 'ninja_forms_display_screen_options');
  39. $screen->add_option('ninja_forms', '');
  40. }
  41. }
  42. function ninja_forms_display_screen_options($content){
  43. global $ninja_forms_help_screen_tabs, $ninja_forms_screen_options;
  44. $current_page = esc_html( $_REQUEST['page'] );
  45. $current_tab = ninja_forms_get_current_tab();
  46. ninja_forms_update_screen_options();
  47. if(isset($ninja_forms_screen_options['_universal_']) OR isset($ninja_forms_screen_options[$current_page]['_universal_']) OR isset($ninja_forms_screen_options[$current_page][$current_tab])){
  48. if(isset($ninja_forms_screen_options['_universal_'])){
  49. foreach($ninja_forms_screen_options['_universal_'] as $option){
  50. $display_function = $option['display_function'];
  51. $arguments = func_get_args();
  52. array_shift($arguments); // We need to remove the first arg ($function_name)
  53. call_user_func_array($display_function, $arguments);
  54. }
  55. }
  56. if(isset($ninja_forms_screen_options[$current_page]['_universal_'])){
  57. foreach($ninja_forms_screen_options[$current_page]['_universal_'] as $option){
  58. $display_function = $option['display_function'];
  59. $arguments = func_get_args();
  60. array_shift($arguments); // We need to remove the first arg ($function_name)
  61. call_user_func_array($display_function, $arguments);
  62. }
  63. }
  64. if(isset($ninja_forms_screen_options[$current_page][$current_tab])){
  65. foreach($ninja_forms_screen_options[$current_page][$current_tab] as $option){
  66. $display_function = $option['display_function'];
  67. $arguments = func_get_args();
  68. array_shift($arguments); // We need to remove the first arg ($function_name)
  69. call_user_func_array($display_function, $arguments);
  70. }
  71. }
  72. ?>
  73. <br class="clear">
  74. <input type="hidden" name="ninja_forms_save_screen_options" value="1">
  75. <?php wp_nonce_field('ninja_forms_update_options'); ?>
  76. <input name="Submit" type="submit" class="button-primary" value="<?php _e( 'Save Options', 'ninja-forms' ); ?>">
  77. <?php
  78. }
  79. }
  80. function ninja_forms_update_screen_options(){
  81. global $ninja_forms_screen_options;
  82. $current_tab = ninja_forms_get_current_tab();
  83. if(isset($_POST['_wpnonce'])){
  84. $nonce = $_POST['_wpnonce'];
  85. }else{
  86. $nonce = '';
  87. }
  88. if(!empty($_POST) AND $_POST['ninja_forms_save_screen_options'] == 1 AND wp_verify_nonce($nonce, 'ninja_forms_update_options') AND check_admin_referer( 'ninja_forms_update_options', '_wpnonce' )){
  89. if(!empty($ninja_forms_screen_options) AND is_array($ninja_forms_screen_options)){
  90. //print_r($ninja_forms_screen_options);
  91. if(isset($ninja_forms_screen_options['_universal_']) AND is_array($ninja_forms_screen_options['_universal_'])){
  92. foreach($ninja_forms_screen_options['_universal_'] as $slug => $option){
  93. $save_function = $option['save_function'];
  94. $arguments = func_get_args();
  95. array_shift($arguments); // We need to remove the first arg ($function_name)
  96. call_user_func_array($save_function, $arguments);
  97. }
  98. }
  99. if(isset($ninja_forms_screen_options[$current_tab]) AND is_array($ninja_forms_screen_options[$current_tab])){
  100. foreach($ninja_forms_screen_options[$current_tab] as $slug => $option){
  101. $save_function = $option['save_function'];
  102. $arguments = func_get_args();
  103. array_shift($arguments); // We need to remove the first arg ($function_name)
  104. call_user_func_array($save_function, $arguments);
  105. }
  106. }
  107. }
  108. }
  109. }