Skip to:
Content

BuddyPress.org

Changeset 8667


Ignore:
Timestamp:
07/22/2014 08:44:11 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Introduce helper functions to build nonced URL's when marking single notifications as read/unread, for more easily making custom notification links.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/bp-notifications-template.php

    r8666 r8667  
    725725    function bp_get_the_notification_mark_read_link() {
    726726
    727         // Get the URL with nonce, action, and id
    728         $url = wp_nonce_url( add_query_arg( array( 'action' => 'read', 'notification_id' => bp_get_the_notification_id() ), bp_get_notifications_unread_permalink() ), 'bp_notification_mark_read_' . bp_get_the_notification_id() );
    729 
    730727        // Start the output buffer
    731728        ob_start(); ?>
    732729
    733         <a href="<?php echo esc_url( $url ); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a>
     730        <a href="<?php bp_the_notification_mark_read_url(); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a>
    734731
    735732        <?php $retval = ob_get_clean();
    736733
    737734        return apply_filters( 'bp_get_the_notification_mark_read_link', $retval );
     735    }
     736
     737/**
     738 * Output the URL used for marking a single notification as read
     739 *
     740 * Since this function directly outputs a URL, it is escaped.
     741 *
     742 * @since BuddyPress (2.1.0)
     743 *
     744 * @uses bp_get_the_notification_mark_read_url()
     745 */
     746function bp_the_notification_mark_read_url() {
     747    echo esc_url( bp_get_the_notification_mark_read_url() );
     748}
     749    /**
     750     * Return the URL used for marking a single notification as read
     751     *
     752     * @since BuddyPress (2.1.0)
     753     */
     754    function bp_get_the_notification_mark_read_url() {
     755
     756        // Get the notification ID
     757        $id   = bp_get_the_notification_id();
     758
     759        // Get the args to add to the URL
     760        $args = array(
     761            'action'          => 'read',
     762            'notification_id' => $id
     763        );
     764
     765        // Add the args to the URL
     766        $url = add_query_arg( $args, bp_get_notifications_unread_permalink() );
     767
     768        // Add the nonce
     769        $url = wp_nonce_url( $url, 'bp_notification_mark_read_' . $id );
     770
     771        // Filter and return
     772        return apply_filters( 'bp_get_the_notification_mark_read_url', $url );
    738773    }
    739774
     
    755790    function bp_get_the_notification_mark_unread_link() {
    756791
    757         // Get the URL with nonce, action, and id
    758         $url = wp_nonce_url( add_query_arg( array( 'action' => 'unread', 'notification_id' => bp_get_the_notification_id() ), bp_get_notifications_read_permalink() ), 'bp_notification_mark_unread_' . bp_get_the_notification_id() );
    759 
    760792        // Start the output buffer
    761793        ob_start(); ?>
    762794
    763         <a href="<?php echo esc_url( $url ); ?>" class="mark-unread primary"><?php _e( 'Unread', 'buddypress' ); ?></a>
     795        <a href="<?php bp_the_notification_mark_unread_url(); ?>" class="mark-unread primary"><?php _e( 'Unread', 'buddypress' ); ?></a>
    764796
    765797        <?php $retval = ob_get_clean();
    766798
    767799        return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval );
     800    }
     801
     802/**
     803 * Output the URL used for marking a single notification as unread
     804 *
     805 * Since this function directly outputs a URL, it is escaped.
     806 *
     807 * @since BuddyPress (2.1.0)
     808 *
     809 * @uses bp_get_the_notification_mark_unread_url()
     810 */
     811function bp_the_notification_mark_unread_url() {
     812    echo esc_url( bp_get_the_notification_mark_unread_url() );
     813}
     814    /**
     815     * Return the URL used for marking a single notification as unread
     816     *
     817     * @since BuddyPress (2.1.0)
     818     */
     819    function bp_get_the_notification_mark_unread_url() {
     820
     821        // Get the notification ID
     822        $id   = bp_get_the_notification_id();
     823
     824        // Get the args to add to the URL
     825        $args = array(
     826            'action'          => 'unread',
     827            'notification_id' => $id
     828        );
     829
     830        // Add the args to the URL
     831        $url = add_query_arg( $args, bp_get_notifications_read_permalink() );
     832
     833        // Add the nonce
     834        $url = wp_nonce_url( $url, 'bp_notification_mark_unread_' . $id );
     835
     836        // Filter and return
     837        return apply_filters( 'bp_get_the_notification_mark_unread_url', $url );
    768838    }
    769839
     
    850920        }
    851921
    852         // Args to add to the link
     922        // Get the ID
     923        $id = bp_get_the_notification_id();
     924
     925        // Get the args to add to the URL
    853926        $args = array(
    854927            'action'          => 'delete',
    855             'notification_id' => bp_get_the_notification_id()
     928            'notification_id' => $id
    856929        );
    857930
     
    860933
    861934        // Add the nonce
    862         $url = wp_nonce_url( $url, 'bp_notification_delete_' . bp_get_the_notification_id() );
     935        $url = wp_nonce_url( $url, 'bp_notification_delete_' . $id );
    863936
    864937        // Filter and return
Note: See TracChangeset for help on using the changeset viewer.