Make WordPress Core


Ignore:
Timestamp:
11/21/2011 10:39:48 PM (13 years ago)
Author:
koopersmith
Message:

Add new 3.3 pointer content, encapsulate 3.3 internal pointers in a final class. props ocean90, see #18693.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r19321 r19388  
    16651665}
    16661666
    1667 /**
    1668  * Initializes the new feature pointers.
    1669  *
    1670  * @since 3.3.0
    1671  *
    1672  * Pointer user settings:
    1673  *    p0 - Admin bar pointer, added 3.3.
    1674  */
    1675 function wp_pointer_enqueue( $hook_suffix ) {
    1676     $enqueue = false;
    1677 
    1678     $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
    1679 
    1680     if ( ! in_array( 'wp330-admin-bar', $dismissed ) ) {
    1681         $enqueue = true;
    1682         add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' );
    1683     }
    1684 
    1685     if ( $enqueue ) {
     1667final class WP_Internal_Pointers {
     1668    /**
     1669     * Initializes the new feature pointers.
     1670     *
     1671     * @since 3.3.0
     1672     *
     1673     * All pointers can be disabled using the following:
     1674     *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
     1675     *
     1676     * Individual pointers (e.g. wp330-toolbar) can be disabled using the following:
     1677     *     remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp330_toolbar' ) );
     1678     */
     1679    public static function enqueue_scripts( $hook_suffix ) {
     1680        /*
     1681         * Register feature pointers
     1682         * Format: array( hook_suffix => pointer_id )
     1683         */
     1684        $registered_pointers = array(
     1685            'index.php'    => 'wp330-toolbar',
     1686            'post-new.php' => 'wp330-media-uploader',
     1687            'themes.php'   => 'wp330-saving-widgets',
     1688        );
     1689
     1690        // Check if screen related pointer is registered
     1691        if ( empty( $registered_pointers[ $hook_suffix ] ) )
     1692            return;
     1693
     1694        $pointer = $registered_pointers[ $hook_suffix ];
     1695
     1696        // Get dismissed pointers
     1697        $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
     1698
     1699        // Pointer has been dismissed
     1700        if ( in_array( $pointer, $dismissed ) )
     1701            return;
     1702
     1703        // Bind pointer print function
     1704        add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . str_replace( '-', '_', $pointer ) ) );
     1705
     1706        // Add pointers script and style to queue
    16861707        wp_enqueue_style( 'wp-pointer' );
    16871708        wp_enqueue_script( 'wp-pointer' );
    16881709    }
    1689 }
    1690 add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
    1691 
    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>';
    1696 
    1697 ?>
    1698 <script type="text/javascript">
    1699 //<![CDATA[
    1700 jQuery(document).ready( function($) {
    1701     $('#wpadminbar').pointer({
    1702         content: '<?php echo $pointer_content; ?>',
    1703         position: {
    1704             edge:  'top',
    1705             align: 'center'
    1706         },
    1707         close: function() {
    1708             $.post( ajaxurl, {
    1709                     pointer: 'wp330-admin-bar',
    1710                 //  _ajax_nonce: $('#_ajax_nonce').val(),
    1711                     action: 'dismiss-wp-pointer'
     1710
     1711    /**
     1712     * Print the pointer javascript data.
     1713     *
     1714     * @since 3.3.0
     1715     *
     1716     * @param string $pointer_id The pointer ID.
     1717     * @param string $selector The HTML elements, on which the pointer should be attached.
     1718     * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.dev.js).
     1719     */
     1720    private static function print_js( $pointer_id, $selector, $args ) {
     1721        if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
     1722            return;
     1723
     1724        ?>
     1725        <script type="text/javascript">
     1726        //<![CDATA[
     1727        jQuery(document).ready( function($) {
     1728            var options = <?php echo json_encode( $args ); ?>;
     1729
     1730            if ( ! options )
     1731                return;
     1732
     1733            options = $.extend( options, {
     1734                close: function() {
     1735                    $.post( ajaxurl, {
     1736                        pointer: '<?php echo $pointer_id; ?>',
     1737                        action: 'dismiss-wp-pointer'
     1738                    });
     1739                }
    17121740            });
    1713         }
    1714     }).pointer('open');
    1715 });
    1716 //]]>
    1717 </script>
    1718 <?php
    1719 }
     1741
     1742            $('<?php echo $selector; ?>').pointer( options ).pointer('open');
     1743        });
     1744        //]]>
     1745        </script>
     1746        <?php
     1747    }
     1748
     1749    public static function pointer_wp330_toolbar() {
     1750        $content  = '<h3>' . esc_js( __( 'New Feature: Toolbar' ) ). '</h3>';
     1751        $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>';
     1752
     1753        if ( is_multisite() && is_super_admin() )
     1754            $content .= '<p>' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '</p>';
     1755
     1756        WP_Internal_Pointers::print_js( 'wp330-toolbar', '#wpadminbar', array(
     1757            'content'  => $content,
     1758            'position' => array( 'edge' => 'top', 'align' => 'center' ),
     1759        ) );
     1760    }
     1761
     1762    /**
     1763     * Print 'Updated Media Uploader' for 3.3.0.
     1764     *
     1765     * @since 3.3.0
     1766     */
     1767    public static function pointer_wp330_media_uploader() {
     1768        $content  = '<h3>' . esc_js( __( 'Updated Media Uploader' ) ) . '</h3>';
     1769        $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>';
     1770
     1771        WP_Internal_Pointers::print_js( 'wp330-media-uploader', '#content-add_media', array(
     1772            'content'  => $content,
     1773            'position' => array( 'edge' => 'left', 'align' => 'center' ),
     1774        ) );
     1775    }
     1776
     1777    /**
     1778     * Print 'New Feature: Saving Widgets' for 3.3.0.
     1779     *
     1780     * @since 3.3.0
     1781     */
     1782    public static function pointer_wp330_saving_widgets() {
     1783        $content  = '<h3>' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '</h3>';
     1784        $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>';
     1785
     1786        WP_Internal_Pointers::print_js( 'wp330-saving-widgets', '#message2', array(
     1787            'content'  => $content,
     1788            'position' => array( 'edge' => 'top', 'align' => 'left' ),
     1789        ) );
     1790    }
     1791}
     1792
     1793add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
Note: See TracChangeset for help on using the changeset viewer.