Skip to:
Content

bbPress.org

Changeset 5506


Ignore:
Timestamp:
09/11/2014 02:52:19 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Preliminary function support for un/approving replies. Props netweb. See #2645.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r5490 r5506  
    11641164 */
    11651165function bbp_get_reply_ancestors( $reply_id = 0 ) {
    1166    
     1166
    11671167    // Validation
    11681168    $reply_id  = bbp_get_reply_id( $reply_id );
     
    14701470
    14711471    // Remove reply_to from moved reply
    1472     delete_post_meta( $move_reply->ID, '_bbp_reply_to' ); 
     1472    delete_post_meta( $move_reply->ID, '_bbp_reply_to' );
    14731473
    14741474    // It is a new topic and we need to set some default metas to make
     
    15831583    $possible_actions = array(
    15841584        'bbp_toggle_reply_spam',
    1585         'bbp_toggle_reply_trash'
     1585        'bbp_toggle_reply_trash',
     1586        'bbp_toggle_reply_approve'
    15861587    );
    15871588
     
    16111612    // What action are we trying to perform?
    16121613    switch ( $action ) {
     1614
     1615        // Toggle approve
     1616        case 'bbp_toggle_reply_approve' :
     1617            check_ajax_referer( 'approve-reply_' . $reply_id );
     1618
     1619            $is_approve = bbp_is_reply_pending( $reply_id );
     1620            $success    = $is_approve ? bbp_approve_reply( $reply_id ) : bbp_unapprove_reply( $reply_id );
     1621            $failure    = $is_approve ? __( '<strong>ERROR</strong>: There was a problem approving the reply!', 'bbpress' ) : __( '<strong>ERROR</strong>: There was a problem unapproving thereply!', 'bbpress' );
     1622            $view_all   = !$is_approve;
     1623
     1624            break;
    16131625
    16141626        // Toggle spam
     
    18101822    // Execute post unspam code
    18111823    do_action( 'bbp_unspammed_reply', $reply_id );
     1824
     1825    // Return reply_id
     1826    return $reply_id;
     1827}
     1828
     1829/**
     1830 * Approves a reply
     1831 *
     1832 * @since bbPress (r5506)
     1833 *
     1834 * @param int $reply_id Reply id
     1835 * @uses bbp_get_reply() To get the reply
     1836 * @uses do_action() Calls 'bbp_approve_reply' with the reply id
     1837 /* @uses add_post_meta() To add the previous status to a meta
     1838 /* @uses delete_post_meta() To delete the previous status meta
     1839 * @uses wp_update_post() To update the reply with the new status
     1840 * @uses do_action() Calls 'bbp_approved_reply' with the reply id
     1841 * @return mixed False or {@link WP_Error} on failure, reply id on success
     1842 */
     1843function bbp_approve_reply( $reply_id = 0 ) {
     1844
     1845    // Get reply
     1846    $reply = bbp_get_reply( $reply_id );
     1847    if ( empty( $reply ) ) {
     1848        return $reply;
     1849    }
     1850
     1851    // Bail if already approved
     1852    if ( bbp_get_pending_status_id() !== $reply->post_status ) {
     1853        return false;
     1854    }
     1855
     1856    // Execute pre pending code
     1857    do_action( 'bbp_approve_reply', $reply_id );
     1858
     1859    // Set publish status
     1860    $reply->post_status = bbp_get_public_status_id();
     1861
     1862    // No revisions
     1863    remove_action( 'pre_post_update', 'wp_save_post_revision' );
     1864
     1865    // Update reply
     1866    $reply_id = wp_update_post( $reply );
     1867
     1868    // Execute post pending code
     1869    do_action( 'bbp_approved_reply', $reply_id );
     1870
     1871    // Return reply_id
     1872    return $reply_id;
     1873}
     1874
     1875/**
     1876 * Unapproves a reply
     1877 *
     1878 * @since bbPress (r5506)
     1879 *
     1880 * @param int $reply_id Reply id
     1881 * @uses bbp_get_reply() To get the reply
     1882 * @uses do_action() Calls 'bbp_unapprove_reply' with the reply id
     1883 /* @uses get_post_meta() To get the previous status
     1884 /* @uses delete_post_meta() To delete the previous status meta
     1885 * @uses wp_update_post() To update the reply with the new status
     1886 * @uses do_action() Calls 'bbp_unapproved_reply' with the reply id
     1887 * @return mixed False or {@link WP_Error} on failure, reply id on success
     1888 */
     1889function bbp_unapprove_reply( $reply_id = 0 ) {
     1890
     1891    // Get reply
     1892    $reply = bbp_get_reply( $reply_id );
     1893    if ( empty( $reply ) ) {
     1894        return $reply;
     1895    }
     1896
     1897    // Bail if already pending
     1898    if ( bbp_get_pending_status_id() === $reply->post_status ) {
     1899        return false;
     1900    }
     1901
     1902    // Execute pre open code
     1903    do_action( 'bbp_unapprove_reply', $reply_id );
     1904
     1905    // Set pending status
     1906    $reply->post_status = bbp_get_pending_status_id();
     1907
     1908    // No revisions
     1909    remove_action( 'pre_post_update', 'wp_save_post_revision' );
     1910
     1911    // Update reply
     1912    $reply_id = wp_update_post( $reply );
     1913
     1914    // Execute post open code
     1915    do_action( 'bbp_unapproved_reply', $reply_id );
    18121916
    18131917    // Return reply_id
     
    23372441/**
    23382442 * Validate a `reply_to` field for hierarchical replies
    2339  * 
     2443 *
    23402444 * Checks for 2 scenarios:
    23412445 * -- The reply to ID is actually a reply
Note: See TracChangeset for help on using the changeset viewer.