Skip to content

Instantly share code, notes, and snippets.

@dingo-d
Last active December 13, 2018 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dingo-d/211d24517cc0b1b47025e77c71c2bad7 to your computer and use it in GitHub Desktop.
Save dingo-d/211d24517cc0b1b47025e77c71c2bad7 to your computer and use it in GitHub Desktop.
<?php
/**
* Pointers manger file
*
* @since 1.0.0
* @package Plugin
*/
namespace Plugin;
/**
* Pointers class
*
* Adds the various tooltip pointers that will be used in the admin UI
*/
class Pointers {
/**
* List of available pointers and their locations
*
* Returns list of tooltips to appear on certain places at the certain time.
*
* Example:
* array(
* array(
* 'title' => Name of the tooltio,
* 'content' => Content of the tooltip,
* 'anchorId' => ID of anchor where tooltip will be shown,
* 'id' => ID of the tooltip,
* 'edge' => 'top|bottom|left|right' relative to the parent wrapper,
* 'align' => 'left|right' relative to the anchor placement,
* 'initialOrder' => In what order do tooltips appear,
* 'context' => What is the screen ID where tooltips should appear,
* 'dismissable' => If the tooltip should be dissmissable <true|false>
* ),
* );
*
* @return array List of all pointers registered on the admin UI.
* @since 1.0.0
*/
public static function get_all_pointers() : array {
return array(
'show-yaml-upload-tooltip' => array(
'title' => sprintf( '<h3>%s</h3>', esc_html__( 'Include security definitions', 'developer-portal' ) ),
'content' => sprintf( '<p>%s</p>', esc_html__( 'If you want to enable automatic authorization and \'try it out\' on the frontend you should add the \'securityDefinitions\' in your YAML file.', 'developer-portal' ) ),
'anchorId' => '#upload-documentation',
'id' => 'show-yaml-upload-tooltip',
'edge' => 'top',
'align' => 'left',
'initialOrder' => '0',
'context' => 'documentation-type',
'dismissable' => false,
),
'test-tooltip' => array(
'title' => sprintf( '<h3>%s</h3>', esc_html__( 'Testing', 'developer-portal' ) ),
'content' => sprintf( '<p>%s</p>', esc_html__( 'This is a test', 'developer-portal' ) ),
'anchorId' => '#acf-field_8a82f50sca8du',
'id' => 'test-tooltip',
'edge' => 'top',
'align' => 'left',
'initialOrder' => '1',
'context' => 'documentation-type',
'dismissable' => true,
),
'test-tooltip-3' => array(
'title' => sprintf( '<h3>%s</h3>', esc_html__( 'Testing third tooltip', 'developer-portal' ) ),
'content' => sprintf( '<p>%s</p>', esc_html__( 'third tooltip test!!!', 'developer-portal' ) ),
'anchorId' => '.acf-field-5a82f50c9d06b',
'id' => 'test-tooltip-3',
'edge' => 'top',
'align' => 'right',
'initialOrder' => '3',
'context' => 'documentation-type',
'dismissable' => false,
),
'add-new-post' => array(
'title' => sprintf( '<h3>%s</h3>', esc_html__( 'Testing context', 'developer-portal' ) ),
'content' => sprintf( '<p>%s</p>', esc_html__( 'This is a test of context', 'developer-portal' ) ),
'anchorId' => '#wp-admin-bar-new-content',
'id' => 'add-new-post',
'edge' => 'top',
'align' => 'left',
'initialOrder' => '1',
'context' => 'dashboard',
'dismissable' => true,
),
);
}
}
// This needs to be set somewhere and hooked to admin_enqueue_scripts!!
//
// public function enqueue_scripts() : void {
// global $current_screen;
// // Tooltip scripts.
// if ( in_array( $current_screen->id, array( 'post_type_slug' ), true ) ) {
// $pointer_script = // path to 'pointer.js'
// $pointer_handle = 'pointer-scripts'
// wp_register_script( $pointer_handle, $pointer_script, array( 'wp-pointer' ), '1.0.0' );
// wp_enqueue_script( $pointer_handle );
// wp_localize_script(
// $pointer_handle,
// 'pointerLocalization',
// array(
// 'pointers' => Pointers::get_all_pointers(),
// 'nextLabel' => esc_html__( 'Next', 'developer-portal' ),
// 'closeLabel' => esc_html__( 'Close', 'developer-portal' ),
// 'currentScreen' => $current_screen->id,
// )
// );
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment