WordPress.org

Make WordPress Core

Changeset 21144


Ignore:
Timestamp:
06/26/2012 08:59:13 PM (6 years ago)
Author:
nacin
Message:

Deprecate wp_explain_nonce(). see #21076 for 3.3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/wp-includes/functions.php

    r19636 r21144  
    26292629 * Retrieve nonce action "Are you sure" message.
    26302630 *
    2631  * The action is split by verb and noun. The action format is as follows:
    2632  * verb-action_extra. The verb is before the first dash and has the format of
    2633  * letters and no spaces and numbers. The noun is after the dash and before the
    2634  * underscore, if an underscore exists. The noun is also only letters.
    2635  *
    2636  * The filter will be called for any action, which is not defined by WordPress.
    2637  * You may use the filter for your plugin to explain nonce actions to the user,
    2638  * when they get the "Are you sure?" message. The filter is in the format of
    2639  * 'explain_nonce_$verb-$noun' with the $verb replaced by the found verb and the
    2640  * $noun replaced by the found noun. The two parameters that are given to the
    2641  * hook are the localized "Are you sure you want to do this?" message with the
    2642  * extra text (the text after the underscore).
     2631 * @since 2.0.4
     2632 * @deprecated 3.4.1
     2633 * @deprecated Use wp_nonce_ays()
     2634 * @see wp_nonce_ays()
     2635 *
     2636 * @param string $action Nonce action.
     2637 * @return string Are you sure message.
     2638 */
     2639function wp_explain_nonce( $action ) {
     2640    _deprecated_function( __FUNCTION__, '3.4', 'wp_nonce_ays()' );
     2641    return __( 'Are you sure you want to do this?' );
     2642}
     2643
     2644/**
     2645 * Display "Are You Sure" message to confirm the action being taken.
     2646 *
     2647 * If the action has the nonce explain message, then it will be displayed along
     2648 * with the "Are you sure?" message.
    26432649 *
    26442650 * @package WordPress
     
    26462652 * @since 2.0.4
    26472653 *
    2648  * @param string $action Nonce action.
    2649  * @return string Are you sure message.
    2650  */
    2651 function wp_explain_nonce( $action ) {
    2652     if ( $action !== -1 && preg_match( '/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches ) ) {
    2653         $verb = $matches[1];
    2654         $noun = $matches[2];
    2655 
    2656         $trans = array();
    2657         $trans['update']['attachment'] = array( __( 'Your attempt to edit this attachment: “%s” has failed.' ), 'get_the_title' );
    2658 
    2659         $trans['add']['category']      = array( __( 'Your attempt to add this category has failed.' ), false );
    2660         $trans['delete']['category']   = array( __( 'Your attempt to delete this category: “%s” has failed.' ), 'get_cat_name' );
    2661         $trans['update']['category']   = array( __( 'Your attempt to edit this category: “%s” has failed.' ), 'get_cat_name' );
    2662 
    2663         $trans['delete']['comment']    = array( __( 'Your attempt to delete this comment: “%s” has failed.' ), 'use_id' );
    2664         $trans['unapprove']['comment'] = array( __( 'Your attempt to unapprove this comment: “%s” has failed.' ), 'use_id' );
    2665         $trans['approve']['comment']   = array( __( 'Your attempt to approve this comment: “%s” has failed.' ), 'use_id' );
    2666         $trans['update']['comment']    = array( __( 'Your attempt to edit this comment: “%s” has failed.' ), 'use_id' );
    2667         $trans['bulk']['comments']     = array( __( 'Your attempt to bulk modify comments has failed.' ), false );
    2668         $trans['moderate']['comments'] = array( __( 'Your attempt to moderate comments has failed.' ), false );
    2669 
    2670         $trans['add']['bookmark']      = array( __( 'Your attempt to add this link has failed.' ), false );
    2671         $trans['delete']['bookmark']   = array( __( 'Your attempt to delete this link: “%s” has failed.' ), 'use_id' );
    2672         $trans['update']['bookmark']   = array( __( 'Your attempt to edit this link: “%s” has failed.' ), 'use_id' );
    2673         $trans['bulk']['bookmarks']    = array( __( 'Your attempt to bulk modify links has failed.' ), false );
    2674 
    2675         $trans['add']['page']          = array( __( 'Your attempt to add this page has failed.' ), false );
    2676         $trans['delete']['page']       = array( __( 'Your attempt to delete this page: “%s” has failed.' ), 'get_the_title' );
    2677         $trans['update']['page']       = array( __( 'Your attempt to edit this page: “%s” has failed.' ), 'get_the_title' );
    2678 
    2679         $trans['edit']['plugin']       = array( __( 'Your attempt to edit this plugin file: “%s” has failed.' ), 'use_id' );
    2680         $trans['activate']['plugin']   = array( __( 'Your attempt to activate this plugin: “%s” has failed.' ), 'use_id' );
    2681         $trans['deactivate']['plugin'] = array( __( 'Your attempt to deactivate this plugin: “%s” has failed.' ), 'use_id' );
    2682         $trans['upgrade']['plugin']    = array( __( 'Your attempt to update this plugin: “%s” has failed.' ), 'use_id' );
    2683 
    2684         $trans['add']['post']          = array( __( 'Your attempt to add this post has failed.' ), false );
    2685         $trans['delete']['post']       = array( __( 'Your attempt to delete this post: “%s” has failed.' ), 'get_the_title' );
    2686         $trans['update']['post']       = array( __( 'Your attempt to edit this post: “%s” has failed.' ), 'get_the_title' );
    2687 
    2688         $trans['add']['user']          = array( __( 'Your attempt to add this user has failed.' ), false );
    2689         $trans['delete']['users']      = array( __( 'Your attempt to delete users has failed.' ), false );
    2690         $trans['bulk']['users']        = array( __( 'Your attempt to bulk modify users has failed.' ), false );
    2691         $trans['update']['user']       = array( __( 'Your attempt to edit this user: “%s” has failed.' ), 'get_the_author_meta', 'display_name' );
    2692         $trans['update']['profile']    = array( __( 'Your attempt to modify the profile for: “%s” has failed.' ), 'get_the_author_meta', 'display_name' );
    2693 
    2694         $trans['update']['options']    = array( __( 'Your attempt to edit your settings has failed.' ), false );
    2695         $trans['update']['permalink']  = array( __( 'Your attempt to change your permalink structure to: %s has failed.' ), 'use_id' );
    2696         $trans['edit']['file']         = array( __( 'Your attempt to edit this file: “%s” has failed.' ), 'use_id' );
    2697         $trans['edit']['theme']        = array( __( 'Your attempt to edit this theme file: “%s” has failed.' ), 'use_id' );
    2698         $trans['switch']['theme']      = array( __( 'Your attempt to switch to this theme: “%s” has failed.' ), 'use_id' );
    2699 
    2700         $trans['log']['out']           = array( sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'sitename' ) ), false );
    2701 
    2702         if ( isset( $trans[$verb][$noun] ) ) {
    2703             if ( !empty( $trans[$verb][$noun][1] ) ) {
    2704                 $lookup = $trans[$verb][$noun][1];
    2705                 if ( isset($trans[$verb][$noun][2]) )
    2706                     $lookup_value = $trans[$verb][$noun][2];
    2707                 $object = $matches[4];
    2708                 if ( 'use_id' != $lookup ) {
    2709                     if ( isset( $lookup_value ) )
    2710                         $object = call_user_func( $lookup, $lookup_value, $object );
    2711                     else
    2712                         $object = call_user_func( $lookup, $object );
    2713                 }
    2714                 return sprintf( $trans[$verb][$noun][0], esc_html($object) );
    2715             } else {
    2716                 return $trans[$verb][$noun][0];
    2717             }
    2718         }
    2719 
    2720         return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __( 'Are you sure you want to do this?' ), isset($matches[4]) ? $matches[4] : '' );
    2721     } else {
    2722         return apply_filters( 'explain_nonce_' . $action, __( 'Are you sure you want to do this?' ) );
    2723     }
    2724 }
    2725 
    2726 /**
    2727  * Display "Are You Sure" message to confirm the action being taken.
    2728  *
    2729  * If the action has the nonce explain message, then it will be displayed along
    2730  * with the "Are you sure?" message.
    2731  *
    2732  * @package WordPress
    2733  * @subpackage Security
    2734  * @since 2.0.4
    2735  *
    27362654 * @param string $action The nonce action.
    27372655 */
    27382656function wp_nonce_ays( $action ) {
    27392657    $title = __( 'WordPress Failure Notice' );
    2740     $html = esc_html( wp_explain_nonce( $action ) );
    2741     if ( 'log-out' == $action )
    2742         $html .= "</p><p>" . sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() );
    2743     elseif ( wp_get_referer() )
    2744         $html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
     2658    if ( 'log-out' == $action ) {
     2659        $html = sprintf( __( 'You are attempting to log out of %s' ), get_bloginfo( 'name' ) ) . '</p><p>';
     2660        $html .= sprintf( __( "Do you really want to <a href='%s'>log out</a>?"), wp_logout_url() );
     2661    } else {
     2662        $html = __( 'Are you sure you want to do this?' );
     2663        if ( wp_get_referer() )
     2664            $html .= "</p><p><a href='" . esc_url( remove_query_arg( 'updated', wp_get_referer() ) ) . "'>" . __( 'Please try again.' ) . "</a>";
     2665    }
    27452666
    27462667    wp_die( $html, $title, array('response' => 403) );
Note: See TracChangeset for help on using the changeset viewer.