| 1635 | * @since 3.3-aortic-dissection |
| 1636 | * |
| 1637 | * It's likely better to call wp_register_pointer() in somewhere in upgrade.php |
| 1638 | * So that this function isn't necassary. Up for discussion |
| 1639 | */ |
| 1640 | function wp_core_pointers() { |
| 1641 | $pointer = 'wp330-admin-bar'; |
| 1642 | |
| 1643 | $done = (array) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); |
| 1644 | |
| 1645 | if ( ! in_array( $pointer, $done ) && apply_filters( 'show_wp_pointer_admin_bar', true ) ) { |
| 1646 | wp_register_pointer( $pointer, '_wp_pointer_print_admin_bar' ); |
| 1647 | $done[] = $pointer; |
| 1648 | update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $done ); |
| 1649 | |
| 1650 | } |
| 1651 | } |
| 1652 | add_action( 'admin_enqueue_scripts', 'wp_core_pointers' ); |
| 1653 | |
| 1654 | /** |
| 1655 | * Register a pointer. |
| 1656 | * |
| 1662 | function wp_register_pointer( $pointer, $callback, $hook_suffix = 'all', $args = array() ) { |
| 1663 | $queued = (array) get_user_meta( get_current_user_id(), 'queued_wp_pointers', true ); |
| 1664 | $queued[ $hook_suffix ][ $pointer ] = array_merge( array( 'callback' => $callback ), $args ); |
| 1665 | update_user_meta( get_current_user_id(), 'queued_wp_pointers', $queued ); |
| 1666 | } |
| 1667 | |
| 1668 | /** |
| 1669 | * Initializes the new feature pointers. |
| 1670 | * |
| 1671 | * @since 3.3.0 |
| 1672 | */ |
1641 | | $enqueue = false; |
1642 | | |
1643 | | $admin_bar = get_user_setting( 'p0', 0 ); |
1644 | | if ( ! $admin_bar && apply_filters( 'show_wp_pointer_admin_bar', true ) ) { |
1645 | | $enqueue = true; |
1646 | | add_action( 'admin_print_footer_scripts', '_wp_pointer_print_admin_bar' ); |
| 1674 | $queued = (array) get_user_meta( get_current_user_id(), 'queued_wp_pointers', true ); |
| 1675 | |
| 1676 | if ( empty( $queued[ 'all' ] ) && empty( $queued[ $hook_suffix] ) ) return; |
| 1677 | |
| 1678 | if ( ! empty( $queued[ 'all' ] ) ) { |
| 1679 | foreach( $queued[ 'all' ] as $pointer ) { |
| 1680 | add_action( 'admin_print_footer_scripts', $pointer[ 'callback' ] ); |
| 1681 | } |
1658 | | $pointer_content = '<h3>' . ('The admin bar has been updated in WordPress 3.3.') . '</h3>'; |
1659 | | $pointer_content .= '<p>' . sprintf( ('Have some feedback? Visit this <a href="%s">ticket</a>.'), 'http://core.trac.wordpress.org/ticket/18197' ) . '</p>'; |
1660 | | $pointer_content .= '<p>' . sprintf( ('P.S. You are looking at a new admin pointer. Chime in <a href="%s">here</a>.'), 'http://core.trac.wordpress.org/ticket/18693' ) . '</p>'; |
| 1700 | $pointer_content = '<h3>' . __('The admin bar has been updated in WordPress 3.3.') . '</h3>'; |
| 1701 | $pointer_content .= '<p>' . sprintf( __('Have some feedback? Visit this <a href="%s">ticket</a>.'), 'http://core.trac.wordpress.org/ticket/18197' ) . '</p>'; |
| 1702 | $pointer_content .= '<p>' . sprintf( __('P.S. You are looking at a new admin pointer. Chime in <a href="%s">here</a>.'), 'http://core.trac.wordpress.org/ticket/18693' ) . '</p>'; |
1662 | | ?> |
1663 | | <script type="text/javascript"> |
1664 | | //<![CDATA[ |
1665 | | jQuery(document).ready( function($) { |
1666 | | $('#wpadminbar').pointer({ |
1667 | | content: '<?php echo $pointer_content; ?>', |
1668 | | position: { |
1669 | | my: 'left top', |
1670 | | at: 'center bottom', |
1671 | | offset: '-25 0' |
1672 | | }, |
| 1704 | ?> |
| 1705 | <script type="text/javascript"> |
| 1706 | //<![CDATA[ |
| 1707 | jQuery(document).ready( function($) { |
| 1708 | $('#wpadminbar').pointer({ |
| 1709 | content: '<?php echo $pointer_content; ?>', |
| 1710 | position: { |
| 1711 | my: 'left top', |
| 1712 | at: 'center bottom', |
| 1713 | offset: '-25 0' |
| 1714 | }, |
| 1728 | |
| 1729 | /** |
| 1730 | * Removes a pointer via AJAX. |
| 1731 | * |
| 1732 | * @since 3.3.0 |
| 1733 | */ |
| 1734 | function dismiss_wp_pointer() { |
| 1735 | $pointer = sanitize_key( $_POST[ 'pointer' ] ); |
| 1736 | |
| 1737 | $hook_suffix = ( isset( $_POST[ 'page' ] ) ) ? sanitize_key( $_POST[ 'page' ] ): 'all'; |
| 1738 | |
| 1739 | // check_ajax_referer( 'dismiss-pointer_' . $pointer ); |
| 1740 | |
| 1741 | $queued = (array) get_user_meta( get_current_user_id(), 'queued_wp_pointers', true ); |
| 1742 | if ( empty( $queued[ $hook_suffix ][ $pointer ] ) ) |
| 1743 | die( '0' ); |
| 1744 | |
| 1745 | unset( $queued[ $hook_suffix ][ $pointer ] ); |
| 1746 | |
| 1747 | update_user_meta( get_current_user_id(), 'queued_wp_pointers', $queued ); |
| 1748 | |
| 1749 | die( '1' ); |
| 1750 | break; |
| 1751 | } |
| 1752 | add_action( 'wp_ajax_dismiss-wp-pointer', 'dismiss_wp_pointer' ); |
| 1753 | |
| 1754 | ?> |