Make WordPress Core

Changeset 43157


Ignore:
Timestamp:
05/03/2018 07:37:32 PM (7 years ago)
Author:
azaozz
Message:

Privacy: Store plugin callbacks in associative array for flexibility.

The personal data export and erasure tools allow plugins to register their own callbacks, in order to add additional data to the export and erasure processes. Previously, these were registered without specifying a constant identifier in the array of callbacks. Using mutable integers makes it difficult for plugins to modify the callbacks of other plugins, though.

Using associative array keys instead provides a covenient and reliable way to identify and interact with another plugin's callbacks.

Props desrosj, allendav, ocean90.
Merges [43154] to the 4.9 branch.
Fixes #43931.

Location:
branches/4.9
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/admin-filters.php

    r43101 r43157  
    134134
    135135// Privacy hooks
    136 add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 6 );
     136add_filter( 'wp_privacy_personal_data_export_page', 'wp_privacy_process_personal_data_export_page', 10, 7 );
    137137add_action( 'wp_privacy_personal_data_export_file', 'wp_privacy_generate_personal_data_export_file', 10 );
    138138
  • branches/4.9/src/wp-admin/includes/ajax-actions.php

    r43111 r43157  
    41004100        }
    41014101
    4102         $index = $exporter_index - 1;
    4103 
    41044102        if ( $page < 1 ) {
    41054103            wp_send_json_error( __( 'Page index cannot be less than one.' ) );
    41064104        }
    41074105
    4108         $exporter = $exporters[ $index ];
     4106        $exporter_keys = array_keys( $exporters );
     4107        $exporter_key  = $exporter_keys[ $exporter_index - 1 ];
     4108        $exporter      = $exporters[ $exporter_key ];
    41094109
    41104110        if ( ! is_array( $exporter ) ) {
    41114111            wp_send_json_error(
    4112                 /* translators: %d: array index */
    4113                 sprintf( __( 'Expected an array describing the exporter at index %d.' ), $exporter_index )
     4112                /* translators: %s: array index */
     4113                sprintf( __( 'Expected an array describing the exporter at index %s.' ), $exporter_key )
    41144114            );
    41154115        }
    41164116        if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
    41174117            wp_send_json_error(
    4118                 /* translators: %d: array index */
    4119                 sprintf( __( 'Exporter array at index %d does not include a friendly name.' ), $exporter_index )
     4118                /* translators: %s: array index */
     4119                sprintf( __( 'Exporter array at index %s does not include a friendly name.' ), $exporter_key )
    41204120            );
    41214121        }
     
    41334133        }
    41344134
    4135         $callback = $exporters[ $index ]['callback'];
    4136         $exporter_friendly_name = $exporters[ $index ]['exporter_friendly_name'];
     4135        $callback               = $exporter['callback'];
     4136        $exporter_friendly_name = $exporter['exporter_friendly_name'];
    41374137
    41384138        $response = call_user_func( $callback, $email_address, $page );
     
    41864186     * @param int    $request_id      The privacy request post ID associated with this request.
    41874187     * @param bool   $send_as_email   Whether the final results of the export should be emailed to the user.
     4188     * @param int    $exporter_key    The key (slug) of the exporter that provided this data.
    41884189     */
    4189     $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email );
     4190    $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key );
    41904191
    41914192    if ( is_wp_error( $response ) ) {
     
    42824283        }
    42834284
    4284         $index  = $eraser_index - 1; // Convert to zero based for eraser index.
    4285         $eraser = $erasers[ $index ];
     4285        $eraser_keys = array_keys( $erasers );
     4286        $eraser_key  = $eraser_keys[ $eraser_index - 1 ];
     4287        $eraser      = $erasers[ $eraser_key ];
    42864288
    42874289        if ( ! is_array( $eraser ) ) {
     
    43054307        }
    43064308
    4307         $callback             = $erasers[ $index ]['callback'];
    4308         $eraser_friendly_name = $erasers[ $index ]['eraser_friendly_name'];
     4309        $callback             = $eraser['callback'];
     4310        $eraser_friendly_name = $eraser['eraser_friendly_name'];
    43094311
    43104312        $response = call_user_func( $callback, $email_address, $page );
     
    43974399     *
    43984400     * @param array  $response        The personal data for the given exporter and page.
    4399      * @param int    $exporter_index  The index of the exporter that provided this data.
     4401     * @param int    $eraser_index    The index of the eraser that provided this data.
    44004402     * @param string $email_address   The email address associated with this personal data.
    44014403     * @param int    $page            The page for this response.
    44024404     * @param int    $request_id      The privacy request post ID associated with this request.
     4405     * @param int    $eraser_key      The key (slug) of the eraser that provided this data.
    44034406     */
    4404     $response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id );
     4407    $response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id, $eraser_key );
    44054408
    44064409    if ( is_wp_error( $response ) ) {
  • branches/4.9/src/wp-admin/includes/file.php

    r43119 r43157  
    21262126 * @param int    $request_id      The request ID for this personal data export.
    21272127 * @param bool   $send_as_email   Whether the final results of the export should be emailed to the user.
     2128 * @param string $exporter_key    The slug (key) of the exporter.
    21282129 * @return array The filtered response.
    21292130 */
    2130 function wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email ) {
     2131function wp_privacy_process_personal_data_export_page( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key ) {
    21312132    /* Do some simple checks on the shape of the response from the exporter.
    21322133     * If the exporter response is malformed, don't attempt to consume it - let it
  • branches/4.9/src/wp-includes/comment.php

    r43127 r43157  
    31703170 */
    31713171function wp_register_comment_personal_data_exporter( $exporters ) {
    3172     $exporters[] = array(
     3172    $exporters['wordpress-comments'] = array(
    31733173        'exporter_friendly_name' => __( 'WordPress Comments' ),
    31743174        'callback'               => 'wp_comments_personal_data_exporter',
     
    32753275 */
    32763276function wp_register_comment_personal_data_eraser( $erasers ) {
    3277     $erasers[] = array(
     3277    $erasers['wordpress-comments'] = array(
    32783278        'eraser_friendly_name' => __( 'WordPress Comments' ),
    32793279        'callback'             => 'wp_comments_personal_data_eraser',
     
    33833383    );
    33843384}
    3385 
  • branches/4.9/src/wp-includes/media.php

    r43108 r43157  
    39663966 */
    39673967function wp_register_media_personal_data_exporter( $exporters ) {
    3968     $exporters[] = array(
     3968    $exporters['wordpress-media'] = array(
    39693969        'exporter_friendly_name' => __( 'WordPress Media' ),
    39703970        'callback'               => 'wp_media_personal_data_exporter',
  • branches/4.9/src/wp-includes/user.php

    r43119 r43157  
    27572757 */
    27582758function wp_register_user_personal_data_exporter( $exporters ) {
    2759     $exporters[] = array(
     2759    $exporters['wordpress-user'] = array(
    27602760        'exporter_friendly_name' => __( 'WordPress User' ),
    27612761        'callback'               => 'wp_user_personal_data_exporter',
Note: See TracChangeset for help on using the changeset viewer.