<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[19388] trunk/wp-admin/includes/template.php: Add new 3.3 pointer content, encapsulate 3.3 internal pointers in a final class.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/19388">19388</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2011-11-21 22:39:48 +0000 (Mon, 21 Nov 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add new 3.3 pointer content, encapsulate 3.3 internal pointers in a final class. props ocean90, see <a href="http://core.trac.wordpress.org/ticket/18693">#18693</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (19387 => 19388)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2011-11-21 22:23:39 UTC (rev 19387)
+++ trunk/wp-admin/includes/template.php        2011-11-21 22:39:48 UTC (rev 19388)
</span><span class="lines">@@ -1664,56 +1664,130 @@
</span><span class="cx"> &lt;?php
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-/**
- * Initializes the new feature pointers.
- *
- * @since 3.3.0
- *
- * Pointer user settings:
- *    p0 - Admin bar pointer, added 3.3.
- */
-function wp_pointer_enqueue( $hook_suffix ) {
-        $enqueue = false;
</del><ins>+final class WP_Internal_Pointers {
+        /**
+         * Initializes the new feature pointers.
+         *
+         * @since 3.3.0
+         *
+         * All pointers can be disabled using the following:
+         *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
+         *
+         * Individual pointers (e.g. wp330-toolbar) can be disabled using the following:
+         *     remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp330_toolbar' ) );
+         */
+        public static function enqueue_scripts( $hook_suffix ) {
+                /*
+                 * Register feature pointers
+                 * Format: array( hook_suffix =&gt; pointer_id )
+                 */
+                $registered_pointers = array(
+                        'index.php'    =&gt; 'wp330-toolbar',
+                        'post-new.php' =&gt; 'wp330-media-uploader',
+                        'themes.php'   =&gt; 'wp330-saving-widgets',
+                );
</ins><span class="cx"> 
</span><del>-        $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
</del><ins>+                // Check if screen related pointer is registered
+                if ( empty( $registered_pointers[ $hook_suffix ] ) )
+                        return;
</ins><span class="cx"> 
</span><del>-        if ( ! in_array( 'wp330-admin-bar', $dismissed ) ) {
-                $enqueue = true;
-                add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' );
-        }
</del><ins>+                $pointer = $registered_pointers[ $hook_suffix ];
</ins><span class="cx"> 
</span><del>-        if ( $enqueue ) {
</del><ins>+                // Get dismissed pointers
+                $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
+
+                // Pointer has been dismissed
+                if ( in_array( $pointer, $dismissed ) )
+                        return;
+
+                // Bind pointer print function
+                add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . str_replace( '-', '_', $pointer ) ) );
+
+                // Add pointers script and style to queue
</ins><span class="cx">                 wp_enqueue_style( 'wp-pointer' );
</span><span class="cx">                 wp_enqueue_script( 'wp-pointer' );
</span><span class="cx">         }
</span><del>-}
-add_action( 'admin_enqueue_scripts', 'wp_pointer_enqueue' );
</del><span class="cx"> 
</span><del>-function _wp_pointer_print_admin_bar() {
-        $pointer_content  = '&lt;h3&gt;' . 'The admin bar has been updated in WordPress 3.3.' . '&lt;/h3&gt;';
-        $pointer_content .= '&lt;p&gt;' . sprintf( 'Have some feedback? Visit the &lt;a href=&quot;%s&quot;&gt;forum&lt;/a&gt;.', 'http://wordpress.org/support/forum/alphabeta' ) . '&lt;/p&gt;';
-        $pointer_content .= '&lt;p&gt;' . 'P.S. You are looking at a new admin pointer.' . '&lt;/p&gt;';
</del><ins>+        /**
+         * Print the pointer javascript data.
+         *
+         * @since 3.3.0
+         *
+         * @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.dev.js).
+         */
+        private static function print_js( $pointer_id, $selector, $args ) {
+                if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
+                        return;
</ins><span class="cx"> 
</span><del>-?&gt;
-&lt;script type=&quot;text/javascript&quot;&gt;
-//&lt;![CDATA[
-jQuery(document).ready( function($) {
-        $('#wpadminbar').pointer({
-                content: '&lt;?php echo $pointer_content; ?&gt;',
-                position: {
-                        edge:  'top',
-                        align: 'center'
-                },
-                close: function() {
-                        $.post( ajaxurl, {
-                                        pointer: 'wp330-admin-bar',
-                                //        _ajax_nonce: $('#_ajax_nonce').val(),
-                                        action: 'dismiss-wp-pointer'
</del><ins>+                ?&gt;
+                &lt;script type=&quot;text/javascript&quot;&gt;
+                //&lt;![CDATA[
+                jQuery(document).ready( function($) {
+                        var options = &lt;?php echo json_encode( $args ); ?&gt;;
+
+                        if ( ! options )
+                                return;
+
+                        options = $.extend( options, {
+                                close: function() {
+                                        $.post( ajaxurl, {
+                                                pointer: '&lt;?php echo $pointer_id; ?&gt;',
+                                                action: 'dismiss-wp-pointer'
+                                        });
+                                }
</ins><span class="cx">                         });
</span><del>-                }
-        }).pointer('open');
-});
-//]]&gt;
-&lt;/script&gt;
-&lt;?php
</del><ins>+
+                        $('&lt;?php echo $selector; ?&gt;').pointer( options ).pointer('open');
+                });
+                //]]&gt;
+                &lt;/script&gt;
+                &lt;?php
+        }
+
+        public static function pointer_wp330_toolbar() {
+                $content  = '&lt;h3&gt;' . esc_js( __( 'New Feature: Toolbar' ) ). '&lt;/h3&gt;';
+                $content .= '&lt;p&gt;' . esc_js( __( 'We&amp;#8217;ve combined the admin bar and the old Dashboard header into one persistent toolbar. Hover over the toolbar items to see what&amp;#8217;s new.' ) ) . '&lt;/p&gt;';
+
+                if ( is_multisite() &amp;&amp; is_super_admin() )
+                        $content .= '&lt;p&gt;' .esc_js( __( 'Network Admin is now located in the My Sites menu.' ) ) . '&lt;/p&gt;';
+
+                WP_Internal_Pointers::print_js( 'wp330-toolbar', '#wpadminbar', array(
+                        'content'  =&gt; $content,
+                        'position' =&gt; array( 'edge' =&gt; 'top', 'align' =&gt; 'center' ),
+                ) );
+        }
+
+        /**
+         * Print 'Updated Media Uploader' for 3.3.0.
+         *
+         * @since 3.3.0
+         */
+        public static function pointer_wp330_media_uploader() {
+                $content  = '&lt;h3&gt;' . esc_js( __( 'Updated Media Uploader' ) ) . '&lt;/h3&gt;';
+                $content .= '&lt;p&gt;' . 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.' ) ) . '&lt;/p&gt;';
+
+                WP_Internal_Pointers::print_js( 'wp330-media-uploader', '#content-add_media', array(
+                        'content'  =&gt; $content,
+                        'position' =&gt; array( 'edge' =&gt; 'left', 'align' =&gt; 'center' ),
+                ) );
+        }
+
+        /**
+         * Print 'New Feature: Saving Widgets' for 3.3.0.
+         *
+         * @since 3.3.0
+         */
+        public static function pointer_wp330_saving_widgets() {
+                $content  = '&lt;h3&gt;' . esc_js( __( 'New Feature: Saving Widgets' ) ) . '&lt;/h3&gt;';
+                $content .= '&lt;p&gt;' . esc_js( __( 'If you change your mind and revert to your previous theme, we&amp;#8217;ll put the widgets back the way you had them.' ) ) . '&lt;/p&gt;';
+
+                WP_Internal_Pointers::print_js( 'wp330-saving-widgets', '#message2', array(
+                        'content'  =&gt; $content,
+                        'position' =&gt; array( 'edge' =&gt; 'top', 'align' =&gt; 'left' ),
+                ) );
+        }
</ins><span class="cx"> }
</span><ins>+
+add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>