Make WordPress Core

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

File 18693.more-pointers.2.patch, 6.2 KB (added by ocean90, 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.
    16741672 */
    16751673function wp_pointer_enqueue( $hook_suffix ) {
    1676         $enqueue = false;
    1677 
     1674        /*
     1675         * Pointers to show
     1676         * Format:
     1677         * array( hook_suffix => pointer_id )
     1678         * You can use 'all' as hook_suffix to diplay the pointer on all screens.
     1679         */
     1680        $pointers = apply_filters( 'wp_pointers', array(
     1681                'index.php' => array(
     1682                                'wp330-toolbar',
     1683                                'wp330-flyout-menus'
     1684                        ),
     1685                'post-new.php' => 'wp330-media-uploader',
     1686                'themes.php' => 'wp330-saving-widgets',
     1687                'all' => ''
     1688        ) );
     1689       
     1690        // Get screen relevant pointers
     1691        $pointers = array_merge( (array) $pointers[$hook_suffix], (array) $pointers['all'] ) ;
     1692       
     1693        // No pointers to show
     1694        if ( empty( $pointers ) )
     1695                return;
     1696       
     1697        // Get pointers which are dismissed
    16781698        $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    16791699
    1680         if ( ! in_array( 'wp330-admin-bar', $dismissed ) ) {
    1681                 $enqueue = true;
    1682                 add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' );
    1683         }
     1700        // Sort dismissed pointers out
     1701        $pointers = array_diff( $pointers, $dismissed );
    16841702
    1685         if ( $enqueue ) {
    1686                 wp_enqueue_style( 'wp-pointer' );
    1687                 wp_enqueue_script( 'wp-pointer' );
    1688         }
     1703        // All pointers were already shown
     1704        if ( empty( $pointers ) )
     1705                return;
     1706
     1707        // Print pointers
     1708        foreach ( $pointers as $pointer )
     1709                        add_action( 'admin_print_footer_scripts', '_wp_pointer_print_' . str_replace( '-', '_', $pointer ) );
     1710
     1711        // Load pointers script and style
     1712        wp_enqueue_style( 'wp-pointer' );
     1713        wp_enqueue_script( 'wp-pointer' );
     1714
    16891715}
    16901716add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
    16911717
    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>';
     1718/**
     1719 * Print the pointer javascript data.
     1720 *
     1721 * @since 3.3.0
     1722 *
     1723 * @param string $pointer_id The pointer ID
     1724 * @param string $selector The HTML elements, on which the pointer should be attached.
     1725 * @param string $content The pointer content
     1726 * @param array|string $position The pointer position. Defaults to edge = top and align = center
     1727 */
     1728function _wp_pointer_javascript( $pointer_id, $selector, $content, $position ) {
     1729        if ( empty( $pointer_id ) || empty( $selector ) || empty( $content ) )
     1730                return;
    16961731
     1732        /* TODO: Match wp-pointers.js defaults */
     1733        $_position = '';
     1734        if ( is_string( $position ) )
     1735                $_position = "position: '{$position}',";
     1736        elseif( is_array( $position ) ) {
     1737                if ( ! empty( $position['edge'] ) && ! empty( $position['align'] ) ) {
     1738                        $_position = "position: { edge: '{$position['edge']}', align: '{$position['align']}' },";
     1739                } elseif ( ! empty( $position['edge'] ) ) {
     1740                        $_position = "position: { edge: '{$position['edge']}' },";
     1741                } elseif ( ! empty( $position['align'] ) ) {
     1742                        $_position = "position: { align: '{$position['align']}' },";
     1743                }
     1744        }
     1745
     1746
    16971747?>
    16981748<script type="text/javascript">
    16991749//<![CDATA[
    17001750jQuery(document).ready( function($) {
    1701         $('#wpadminbar').pointer({
    1702                 content: '<?php echo $pointer_content; ?>',
    1703                 position: {
    1704                         edge:  'top',
    1705                         align: 'center'
    1706                 },
     1751        $('<?php echo $selector; ?>').pointer({
     1752                content: '<?php echo $content; ?>',
     1753                <?php if ( !empty( $_position) ) echo $_position; ?>
    17071754                close: function() {
    17081755                        $.post( ajaxurl, {
    1709                                         pointer: 'wp330-admin-bar',
    1710                                 //      _ajax_nonce: $('#_ajax_nonce').val(),
     1756                                        pointer: '<?php echo $pointer_id; ?>',
    17111757                                        action: 'dismiss-wp-pointer'
    17121758                        });
    17131759                }
     
    17171763</script>
    17181764<?php
    17191765}
     1766
     1767
     1768/**
     1769 * Print 'New Feature: Toolbar' for 3.3.0.
     1770 *
     1771 * @since 3.3.0
     1772 */
     1773function _wp_pointer_print_wp330_toolbar() {
     1774        $content  = '<h3>' . esc_js( __( 'New Feature: Toolbar' ) ). '</h3>';
     1775        $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>';
     1776
     1777        if ( is_multisite() && is_super_admin() )
     1778                $content .= '<p>' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '</p>';
     1779
     1780        $position['align'] = 'right';
     1781        $position['edge'] = 'top';
     1782
     1783        _wp_pointer_javascript( 'wp330-toolbar', '#wpadminbar', $content, $position );
     1784}
     1785
     1786/**
     1787 * Print 'New Feature: Flyout Menus' for 3.3.0.
     1788 *
     1789 * @since 3.3.0
     1790 */
     1791function _wp_pointer_print_wp330_flyout_menus() {
     1792        $content  = '<h3>' .  esc_js( __( 'New Feature: Flyout Menus' ) ) . '</h3>';
     1793        $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>';
     1794
     1795        $position['edge'] = 'left';
     1796        $position['align'] = 'bottom';
     1797
     1798        _wp_pointer_javascript( 'wp330-flyout-menus', '#adminmenu', $content, $position );
     1799}
     1800
     1801/**
     1802 * Print 'Updated Media Uploader' for 3.3.0.
     1803 *
     1804 * @since 3.3.0
     1805 */
     1806function _wp_pointer_print_wp330_media_uploader() {
     1807        $content  = '<h3>' . esc_js( __( 'Updated Media Uploader' ) ) . '</h3>';
     1808        $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>';
     1809
     1810        $position['align'] = 'right';
     1811        $position['edge'] = 'top';
     1812
     1813        _wp_pointer_javascript( 'wp330-media-uploader', '#content-add_media', $content, $position );
     1814}
     1815
     1816/**
     1817 * Print 'New Feature: Saving Widgets' for 3.3.0.
     1818 *
     1819 * @since 3.3.0
     1820 */
     1821function _wp_pointer_print_wp330_saving_widgets() {
     1822        $content  = '<h3>' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '</h3>';
     1823        $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>';
     1824
     1825        $position['align'] = 'left';
     1826        $position['edge'] = 'top';
     1827
     1828        _wp_pointer_javascript( 'wp330-saving-widgets', '#message2', $content, $position );
     1829}