WordPress.org

Make WordPress Core

Ticket #18693: 18693.more-pointers.4.patch

File 18693.more-pointers.4.patch, 6.1 KB (added by ocean90, 7 years ago)

Don't allow to set pointers onto all screens.

  • wp-admin/includes/template.php

     
    16691669 *
    16701670 * @since 3.3.0
    16711671 *
    1672  * Pointer user settings:
    1673  *    p0 - Admin bar pointer, added 3.3.
    16741672 */
    16751673function wp_pointer_enqueue( $hook_suffix ) {
    1676         $enqueue = false;
     1674        /*
     1675         * Register feature pointers
     1676         * Format: array( hook_suffix => pointer_id )
     1677         */
     1678        $registered_pointers = apply_filters( 'wp_pointers', array(
     1679                'index.php' => array( 'wp330-toolbar', 'wp330-flyout-menus' ),
     1680                'post-new.php' => 'wp330-media-uploader',
     1681                'themes.php' => 'wp330-saving-widgets'
     1682        ) );
    16771683
     1684        // Check if screen related pointers are registered
     1685        if ( empty( $registered_pointers[$hook_suffix] ) )
     1686                return;
     1687
     1688        // Get dismissed pointers
    16781689        $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    16791690
    1680         if ( ! in_array( 'wp330-admin-bar', $dismissed ) ) {
    1681                 $enqueue = true;
    1682                 add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' );
    1683         }
     1691        // Sort dismissed pointers out
     1692        $pointers = array_diff( (array) $registered_pointers[$hook_suffix], $dismissed );
    16841693
    1685         if ( $enqueue ) {
    1686                 wp_enqueue_style( 'wp-pointer' );
    1687                 wp_enqueue_script( 'wp-pointer' );
    1688         }
     1694        // Pointers were already shown
     1695        if ( empty( $pointers ) )
     1696                return;
     1697
     1698        // Init pointers print functions
     1699        foreach ( $pointers as $pointer )
     1700                add_action( 'admin_print_footer_scripts', '_wp_pointer_print_' . str_replace( '-', '_', $pointer ) );
     1701
     1702        // Add pointers script and style to queue
     1703        wp_enqueue_style( 'wp-pointer' );
     1704        wp_enqueue_script( 'wp-pointer' );
    16891705}
    16901706add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
    16911707
    1692 function _wp_pointer_print_admin_bar() {
    1693         $pointer_content  = '<h3>' . 'The admin bar has been updated in WordPress 3.3.' . '</h3>';
    1694         $pointer_content .= '<p>' . sprintf( 'Have some feedback? Visit the <a href="%s">forum</a>.', 'http://wordpress.org/support/forum/alphabeta' ) . '</p>';
    1695         $pointer_content .= '<p>' . 'P.S. You are looking at a new admin pointer.' . '</p>';
     1708/**
     1709 * Print the pointer javascript data.
     1710 *
     1711 * @since 3.3.0
     1712 *
     1713 * @param string $pointer_id The pointer ID
     1714 * @param string $selector The HTML elements, on which the pointer should be attached
     1715 * @param string $content The pointer content
     1716 * @param array|string $position The pointer position, see wp-pointer.dev.js
     1717 */
     1718function _wp_pointer_print_js_data( $pointer_id, $selector, $content, $position ) {
     1719        if ( empty( $pointer_id ) || empty( $selector ) || empty( $content ) )
     1720                return;
    16961721
     1722        // Set arrow and pointer position
     1723        $_position = '';
     1724        if ( is_string( $position ) )
     1725                $_position = "position: '{$position}',";
     1726        elseif( is_array( $position ) ) {
     1727                if ( ! empty( $position['edge'] ) && ! empty( $position['align'] ) ) {
     1728                        $_position = "position: { edge: '{$position['edge']}', align: '{$position['align']}' },";
     1729                } elseif ( ! empty( $position['edge'] ) ) {
     1730                        $_position = "position: { edge: '{$position['edge']}' },";
     1731                } elseif ( ! empty( $position['align'] ) ) {
     1732                        $_position = "position: { align: '{$position['align']}' },";
     1733                }
     1734        }
    16971735?>
    16981736<script type="text/javascript">
    16991737//<![CDATA[
    17001738jQuery(document).ready( function($) {
    1701         $('#wpadminbar').pointer({
    1702                 content: '<?php echo $pointer_content; ?>',
    1703                 position: {
    1704                         edge:  'top',
    1705                         align: 'center'
    1706                 },
     1739        $('<?php echo $selector; ?>').pointer({
     1740                content: '<?php echo $content; ?>',
     1741                <?php if ( ! empty( $_position) ) echo $_position; ?>
    17071742                close: function() {
    17081743                        $.post( ajaxurl, {
    1709                                         pointer: 'wp330-admin-bar',
    1710                                 //      _ajax_nonce: $('#_ajax_nonce').val(),
     1744                                        pointer: '<?php echo $pointer_id; ?>',
    17111745                                        action: 'dismiss-wp-pointer'
    17121746                        });
    17131747                }
     
    17171751</script>
    17181752<?php
    17191753}
     1754
     1755/**
     1756 * Print 'New Feature: Toolbar' for 3.3.0.
     1757 *
     1758 * @since 3.3.0
     1759 */
     1760function _wp_pointer_print_wp330_toolbar() {
     1761        $content  = '<h3>' . esc_js( __( 'New Feature: Toolbar' ) ). '</h3>';
     1762        $content .= '<p>' . esc_js( __( "We've combined the admin bar and the old Dashboard header into one persistent toolbar. Hover over the toolbar items to see what's new." ) ) . '</p>';
     1763
     1764        if ( is_multisite() && is_super_admin() )
     1765                $content .= '<p>' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '</p>';
     1766
     1767        $position['edge'] = 'top';
     1768        $position['align'] = 'right';
     1769
     1770        _wp_pointer_print_js_data( 'wp330-toolbar', '#wpadminbar', $content, $position );
     1771}
     1772
     1773/**
     1774 * Print 'New Feature: Flyout Menus' for 3.3.0.
     1775 *
     1776 * @since 3.3.0
     1777 */
     1778function _wp_pointer_print_wp330_flyout_menus() {
     1779        $content  = '<h3>' .  esc_js( __( 'New Feature: Flyout Menus' ) ) . '</h3>';
     1780        $content .= '<p>' .  esc_js( __( 'Instead of clicking to open and close navigation sections, just hover over a menu item and the submenu will "fly out" to the side, allowing single-click access to any screen.' ) ) . '</p>';
     1781
     1782        $position['edge'] = 'left';
     1783        $position['align'] = 'center';
     1784
     1785        _wp_pointer_print_js_data( 'wp330-flyout-menus', '#menu-users', $content, $position );
     1786}
     1787
     1788/**
     1789 * Print 'Updated Media Uploader' for 3.3.0.
     1790 *
     1791 * @since 3.3.0
     1792 */
     1793function _wp_pointer_print_wp330_media_uploader() {
     1794        $content  = '<h3>' . esc_js( __( 'Updated Media Uploader' ) ) . '</h3>';
     1795        $content .= '<p>' . esc_js( __( 'The single media icon now launches the uploader for all file types, and the new drag and drop interface makes uploading a breeze.' ) ) . '</p>';
     1796
     1797        $position['edge'] = 'left';
     1798        $position['align'] = 'center';
     1799
     1800        _wp_pointer_print_js_data( 'wp330-media-uploader', '#content-add_media', $content, $position );
     1801}
     1802
     1803/**
     1804 * Print 'New Feature: Saving Widgets' for 3.3.0.
     1805 *
     1806 * @since 3.3.0
     1807 */
     1808function _wp_pointer_print_wp330_saving_widgets() {
     1809        $content  = '<h3>' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '</h3>';
     1810        $content .= '<p>' . esc_js( __( "If you change your mind and revert to your previous theme, we'll put the widgets back the way you had them." ) ) . '</p>';
     1811
     1812        $position['edge'] = 'top';
     1813        $position['align'] = 'left';
     1814
     1815        _wp_pointer_print_js_data( 'wp330-saving-widgets', '#message2', $content, $position );
     1816}