Make WordPress Core

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

File 18693.more-pointers.5.patch, 6.0 KB (added by koopersmith, 14 years ago)
  • wp-admin/includes/template.php

     
    16691669 *
    16701670 * @since 3.3.0
    16711671 *
    1672  * Pointer user settings:
    1673  *    p0 - Admin bar pointer, added 3.3.
     1672 * All pointers can be disabled using the following:
     1673 *     remove_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
     1674 *
     1675 * Individual pointers (e.g. wp330-toolbar) can be disabled using the following:
     1676 *     remove_action( 'admin_print_footer_scripts', '_wp_pointer_print_wp330_toolbar' );
    16741677 */
    16751678function wp_pointer_enqueue( $hook_suffix ) {
    1676         $enqueue = false;
     1679        /*
     1680         * Register feature pointers
     1681         * Format: array( hook_suffix => pointer_id )
     1682         */
     1683        $registered_pointers = array(
     1684                'index.php'    => array( 'wp330-toolbar', 'wp330-flyout-menus' ),
     1685                'post-new.php' => 'wp330-media-uploader',
     1686                'themes.php'   => 'wp330-saving-widgets',
     1687        );
    16771688
     1689        // Check if screen related pointers are registered
     1690        if ( empty( $registered_pointers[$hook_suffix] ) )
     1691                return;
     1692
     1693        // Get dismissed pointers
    16781694        $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    16791695
    1680         if ( ! in_array( 'wp330-admin-bar', $dismissed ) ) {
    1681                 $enqueue = true;
    1682                 add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' );
    1683         }
     1696        // Sort dismissed pointers out
     1697        $pointers = array_diff( (array) $registered_pointers[$hook_suffix], $dismissed );
    16841698
    1685         if ( $enqueue ) {
    1686                 wp_enqueue_style( 'wp-pointer' );
    1687                 wp_enqueue_script( 'wp-pointer' );
    1688         }
     1699        // Pointers were already shown
     1700        if ( empty( $pointers ) )
     1701                return;
     1702
     1703        // Init pointers print functions
     1704        foreach ( $pointers as $pointer )
     1705                add_action( 'admin_print_footer_scripts', '_wp_pointer_print_' . str_replace( '-', '_', $pointer ) );
     1706
     1707        // Add pointers script and style to queue
     1708        wp_enqueue_style( 'wp-pointer' );
     1709        wp_enqueue_script( 'wp-pointer' );
    16891710}
    16901711add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
    16911712
    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>';
     1713/**
     1714 * Print the pointer javascript data.
     1715 *
     1716 * @since 3.3.0
     1717 *
     1718 * @param string $pointer_id The pointer ID.
     1719 * @param string $selector The HTML elements, on which the pointer should be attached.
     1720 * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.dev.js).
     1721 */
     1722function _wp_pointer_print_js_data( $pointer_id, $selector, $args ) {
     1723        if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
     1724                return;
    16961725
    16971726?>
    16981727<script type="text/javascript">
    16991728//<![CDATA[
    17001729jQuery(document).ready( function($) {
    1701         $('#wpadminbar').pointer({
    1702                 content: '<?php echo $pointer_content; ?>',
    1703                 position: {
    1704                         edge:  'top',
    1705                         align: 'center'
    1706                 },
     1730        var options = <?php echo json_encode( $args ); ?>;
     1731
     1732        if ( ! options )
     1733                return;
     1734
     1735        options = $.extend( options, {
    17071736                close: function() {
    17081737                        $.post( ajaxurl, {
    1709                                         pointer: 'wp330-admin-bar',
    1710                                 //      _ajax_nonce: $('#_ajax_nonce').val(),
    1711                                         action: 'dismiss-wp-pointer'
     1738                                pointer: '<?php echo $pointer_id; ?>',
     1739                                action: 'dismiss-wp-pointer'
    17121740                        });
    17131741                }
    1714         }).pointer('open');
     1742        });
     1743
     1744        $('<?php echo $selector; ?>').pointer( options ).pointer('open');
    17151745});
    17161746//]]>
    17171747</script>
    17181748<?php
    17191749}
     1750
     1751/**
     1752 * Print 'New Feature: Toolbar' for 3.3.0.
     1753 *
     1754 * @since 3.3.0
     1755 */
     1756function _wp_pointer_print_wp330_toolbar() {
     1757        $content  = '<h3>' . esc_js( __( 'New Feature: Toolbar' ) ). '</h3>';
     1758        $content .= '<p>' . esc_js( __( 'We&#8217;ve combined the admin bar and the old Dashboard header into one persistent toolbar. Hover over the toolbar items to see what&#8217;s new.' ) ) . '</p>';
     1759
     1760        if ( is_multisite() && is_super_admin() )
     1761                $content .= '<p>' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '</p>';
     1762
     1763        _wp_pointer_print_js_data( 'wp330-toolbar', '#wpadminbar', array(
     1764                'content'  => $content,
     1765                'position' => array( 'edge' => 'top', 'align' => 'right' ),
     1766        ) );
     1767}
     1768
     1769/**
     1770 * Print 'New Feature: Flyout Menus' for 3.3.0.
     1771 *
     1772 * @since 3.3.0
     1773 */
     1774function _wp_pointer_print_wp330_flyout_menus() {
     1775        $content  = '<h3>' .  esc_js( __( 'New Feature: Flyout Menus' ) ) . '</h3>';
     1776        $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>';
     1777
     1778        _wp_pointer_print_js_data( 'wp330-flyout-menus', '#menu-users', array(
     1779                'content'  => $content,
     1780                'position' => array( 'edge' => 'left', 'align' => 'center' ),
     1781        ) );
     1782}
     1783
     1784/**
     1785 * Print 'Updated Media Uploader' for 3.3.0.
     1786 *
     1787 * @since 3.3.0
     1788 */
     1789function _wp_pointer_print_wp330_media_uploader() {
     1790        $content  = '<h3>' . esc_js( __( 'Updated Media Uploader' ) ) . '</h3>';
     1791        $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>';
     1792
     1793        _wp_pointer_print_js_data( 'wp330-media-uploader', '#content-add_media', array(
     1794                'content'  => $content,
     1795                'position' => array( 'edge' => 'left', 'align' => 'center' ),
     1796        ) );
     1797}
     1798
     1799/**
     1800 * Print 'New Feature: Saving Widgets' for 3.3.0.
     1801 *
     1802 * @since 3.3.0
     1803 */
     1804function _wp_pointer_print_wp330_saving_widgets() {
     1805        $content  = '<h3>' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '</h3>';
     1806        $content .= '<p>' . esc_js( __( 'If you change your mind and revert to your previous theme, we&#8217;ll put the widgets back the way you had them.' ) ) . '</p>';
     1807
     1808        _wp_pointer_print_js_data( 'wp330-saving-widgets', '#message2', array(
     1809                'content'  => $content,
     1810                'position' => array( 'edge' => 'top', 'align' => 'left' ),
     1811        ) );
     1812
     1813}