Black_Studio_TinyMCE_Admin_Pointer

The Black Studio TinyMCE Widget Black Studio TinyMCE Admin Pointer class.

Defined (1)

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

/includes/class-admin-pointer.php  
  1. final class Black_Studio_TinyMCE_Admin_Pointer { 
  2.  
  3. /** 
  4. * The single instance of the class 
  5. * @var object 
  6. * @since 2.1.0 
  7. */ 
  8. protected static $_instance = null; 
  9.  
  10. /** 
  11. * Return the single class instance 
  12. * @return object 
  13. * @since 2.1.0 
  14. */ 
  15. public static function instance() { 
  16. if ( is_null( self::$_instance ) ) { 
  17. self::$_instance = new self(); 
  18. return self::$_instance; 
  19.  
  20. /** 
  21. * Class constructor 
  22. * @uses add_action() 
  23. * @uses add_filter() 
  24. * @uses get_option() 
  25. * @uses get_bloginfo() 
  26. * @global object $wp_embed 
  27. * @since 2.0.0 
  28. */ 
  29. protected function __construct() { 
  30. // Register action and filter hooks 
  31. add_action( 'admin_init', array( $this, 'admin_init' ), 20 ); 
  32.  
  33. /** 
  34. * Prevent the class from being cloned 
  35. * @return void 
  36. * @since 2.1.0 
  37. */ 
  38. protected function __clone() { 
  39. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ uh?' ), '2.0' ); 
  40.  
  41. /** 
  42. * Add actions and filters (only in widgets admin page) 
  43. * @uses add_action() 
  44. * @uses add_filter() 
  45. * @return void 
  46. * @since 2.1.0 
  47. */ 
  48. public function admin_init() { 
  49. global $pagenow; 
  50. if ( 'widgets.php' == $pagenow ) { 
  51. add_action( 'admin_print_scripts', array( $this, 'load' ) ); 
  52. add_filter( 'black_studio_tinymce_admin_pointers-widgets', array( $this, 'register' ), 10 ); 
  53. add_filter( 'black_studio_tinymce_admin_pointers-widgets', array( $this, 'filter_dismissed' ), 20 ); 
  54.  
  55. /** 
  56. * Helper function to enqueue script 
  57. * @uses wp_enqueue_style() 
  58. * @uses wp_enqueue_script() 
  59. * @uses plugins_url() 
  60. * @uses wp_localize_script() 
  61. * @uses SCRIPT_DEBUG 
  62. * @param mixed[] $pointers 
  63. * @return void 
  64. * @since 2.1.0 
  65. */ 
  66. public function enqueue( $pointers ) { 
  67. $script = 'black-studio-tinymce-widget-pointer'; 
  68. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  69. wp_enqueue_style( 'wp-pointer' ); 
  70. wp_enqueue_script( 
  71. $script,  
  72. plugins_url( 'js/' . $script . $suffix . '.js', dirname( __FILE__ ) ),  
  73. array( 'wp-pointer' ),  
  74. bstw()->get_version(),  
  75. true 
  76. ); 
  77. wp_localize_script( 'black-studio-tinymce-widget-pointer', 'bstw_pointers', $pointers ); 
  78.  
  79. /** 
  80. * Load admin pointer(s) 
  81. * @uses get_current_screen() 
  82. * @uses apply_filters() 
  83. * @return void 
  84. * @since 2.1.0 
  85. */ 
  86. public function load() { 
  87. $screen = get_current_screen(); 
  88. $pointers = apply_filters( 'black_studio_tinymce_admin_pointers-' . $screen->id, array() ); 
  89. if ( ! empty( $pointers ) ) { 
  90. $this->enqueue( $pointers ); 
  91.  
  92. /** 
  93. * Remove dismissed pointer(s) 
  94. * @uses get_user_meta() 
  95. * @uses get_current_user_id() 
  96. * @param mixed[] $pointers 
  97. * @return mixed[] 
  98. * @since 2.1.0 
  99. */ 
  100. public function filter_dismissed( $pointers ) { 
  101. $valid_pointers = array(); 
  102. if ( is_array( $pointers ) ) { 
  103. $dismissed = explode( ', ', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); 
  104. foreach ( $pointers as $pointer_id => $pointer ) { 
  105. if ( ! in_array( $pointer_id, $dismissed ) ) { 
  106. $pointer['pointer_id'] = $pointer_id; 
  107. $valid_pointers['pointers'][] = $pointer; 
  108. return $valid_pointers; 
  109.  
  110. /** 
  111. * Register admin pointer(s) 
  112. * @param mixed[] $pointers 
  113. * @return mixed[] 
  114. * @since 2.1.0 
  115. */ 
  116. public function register( $pointers ) { 
  117. $pointers['black_studio_tinymce_widget'] = array( 
  118. 'target' => 'div[id$=black-studio-tinymce-__i__] .widget-top',  
  119. 'options' => array( 
  120. 'content' => sprintf( '<h3>%s</h3> <p>%s</p>',  
  121. /** translators: title for the dismissable admin pointer tooltip (same as plugin name) */ 
  122. __( 'Black Studio TinyMCE Widget', 'black-studio-tinymce-widget' ),  
  123. /** translators: text for the dismissable admin pointer tooltip */ 
  124. __( 'The Visual Editor widget allows you to insert rich text and media objects in your sidebars', 'black-studio-tinymce-widget' ) 
  125. ),  
  126. 'position' => array( 'edge' => 'left', 'align' => 'middle' ) 
  127. ); 
  128. return $pointers; 
  129.  
  130.  
  131. } // END class Black_Studio_TinyMCE_Admin_Pointer