BWS_admin_tooltip

The Google Sitemap by BestWebSoft BWS admin tooltip class.

Defined (1)

The class is defined in the following location(s).

/bws_menu/bws_functions.php  
  1. class BWS_admin_tooltip { 
  2. private $tooltip_args; 
  3.  
  4. public function __construct( $tooltip_args ) { 
  5. global $wp_version; 
  6. if ( 3.3 > $wp_version ) 
  7. return; 
  8. /** Default arguments */ 
  9. $tooltip_args_default = array(  
  10. 'tooltip_id' => false,  
  11. 'css_selector' => false,  
  12. 'actions' => array( 
  13. 'click' => true,  
  14. 'onload' => false,  
  15. ),  
  16. 'buttons' => array( 
  17. 'close' => array( 
  18. 'type' => 'dismiss',  
  19. 'text' => __( 'Close', 'bestwebsoft' ),  
  20. ),  
  21. ),  
  22. 'position' => array( 
  23. 'edge' => 'top',  
  24. 'align' => 'center',  
  25. 'pos-left' => 0,  
  26. 'pos-top' => 0,  
  27. 'zindex' => 10000  
  28. ),  
  29. 'set_timeout' => 0 
  30. ); 
  31. $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args ); 
  32. /** Check that our merged array has default values */ 
  33. foreach ( $tooltip_args_default as $arg_key => $arg_value ) { 
  34. if ( is_array( $arg_value ) ) { 
  35. foreach ( $arg_value as $key => $value) { 
  36. if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) { 
  37. $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ]; 
  38. /** Check if tooltip is dismissed */ 
  39. if ( true === $tooltip_args['actions']['onload'] ) { 
  40. if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ', ', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) { 
  41. $tooltip_args['actions']['onload'] = false; 
  42. /** Check entered data */ 
  43. if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) { 
  44. /** if not enough data to output a tooltip or both actions (click, onload) are false */ 
  45. return; 
  46. } else { 
  47. /** check position */ 
  48. if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) { 
  49. $tooltip_args['position']['edge'] = 'top'; 
  50. if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center', ) ) ) { 
  51. $tooltip_args['position']['align'] = 'center'; 
  52. /** fix position */ 
  53. switch ( $tooltip_args['position']['edge'] ) { 
  54. case 'left': 
  55. case 'right': 
  56. switch ( $tooltip_args['position']['align'] ) { 
  57. case 'top': 
  58. case 'bottom': 
  59. $tooltip_args['position']['align'] = 'center'; 
  60. break; 
  61. break; 
  62. case 'top': 
  63. case 'bottom': 
  64. if ( $tooltip_args['position']['align'] == 'left' ) { 
  65. $tooltip_args['position']['pos-left'] -= 65; 
  66. break; 
  67. $this->tooltip_args = $tooltip_args; 
  68. /** add styles and scripts */ 
  69. wp_enqueue_style( 'wp-pointer' ); 
  70. wp_enqueue_script( 'wp-pointer' ); 
  71. /** add script that displays our tooltip */ 
  72. add_action( 'admin_print_footer_scripts', array( $this, 'add_scripts' ) ); 
  73.  
  74. /** 
  75. * Display tooltip 
  76. */ 
  77. public function add_scripts() { 
  78. global $bstwbsftwppdtplgns_tooltip_script_add; 
  79. if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) { 
  80. echo '<script type="text/javascript" src="' . plugins_url( 'js/bws_tooltip.js', __FILE__ ) . '"></script>'; 
  81. $bstwbsftwppdtplgns_tooltip_script_add = true; 
  82. $tooltip_args = $this->tooltip_args; ?> 
  83. <script type="text/javascript"> 
  84. (function($) { 
  85. $(document).ready( function() { 
  86. $.bwsTooltip( <?php echo json_encode( $tooltip_args ); ?> ); 
  87. }) 
  88. })(jQuery); 
  89. </script> 
  90. <?php }