diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-admin/includes/class-wp-internal-pointers.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wp/wp-admin/includes/class-wp-internal-pointers.php Mon Oct 14 17:39:30 2019 +0200 @@ -0,0 +1,203 @@ + pointer callback + * ) + * + * Example: + * array( + * 'themes.php' => 'wp390_widgets' + * ) + */ + $registered_pointers = array( + 'index.php' => 'wp496_privacy', + ); + + // Check if screen related pointer is registered + if ( empty( $registered_pointers[ $hook_suffix ] ) ) + return; + + $pointers = (array) $registered_pointers[ $hook_suffix ]; + + /* + * Specify required capabilities for feature pointers + * + * Format: + * array( + * pointer callback => Array of required capabilities + * ) + * + * Example: + * array( + * 'wp390_widgets' => array( 'edit_theme_options' ) + * ) + */ + $caps_required = array( + 'wp496_privacy' => array( + 'manage_privacy_options', + 'export_others_personal_data', + 'erase_others_personal_data', + ), + ); + + // Get dismissed pointers + $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); + + $got_pointers = false; + foreach ( array_diff( $pointers, $dismissed ) as $pointer ) { + if ( isset( $caps_required[ $pointer ] ) ) { + foreach ( $caps_required[ $pointer ] as $cap ) { + if ( ! current_user_can( $cap ) ) + continue 2; + } + } + + // Bind pointer print function + add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); + $got_pointers = true; + } + + if ( ! $got_pointers ) + return; + + // Add pointers script and style to queue + wp_enqueue_style( 'wp-pointer' ); + wp_enqueue_script( 'wp-pointer' ); + } + + /** + * Print the pointer JavaScript data. + * + * @since 3.3.0 + * + * @static + * + * @param string $pointer_id The pointer ID. + * @param string $selector The HTML elements, on which the pointer should be attached. + * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js). + */ + private static function print_js( $pointer_id, $selector, $args ) { + if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) + return; + + ?> + + ' . __( 'Personal Data and Privacy' ) . ''; + $content .= '
' . __( 'New Tools have been added to help you with personal data export and erasure requests.' ) . '
'; + $content .= '' . __( 'Create or select your site’s privacy policy page under Settings > Privacy to keep your users informed and aware.' ) . '
'; + + if ( is_rtl() ) { + $position = array( + 'edge' => 'right', + 'align' => 'bottom', + ); + } else { + $position = array( + 'edge' => 'left', + 'align' => 'bottom', + ); + } + + $js_args = array( + 'content' => $content, + 'position' => $position, + 'pointerClass' => 'wp-pointer arrow-bottom', + 'pointerWidth' => 420, + ); + self::print_js( 'wp496_privacy', '#menu-tools', $js_args ); + } + + /** + * Prevents new users from seeing existing 'new feature' pointers. + * + * @since 3.3.0 + * + * @static + * + * @param int $user_id User ID. + */ + public static function dismiss_pointers_for_new_users( $user_id ) { + add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp496_privacy' ); + } +}