Skip to:
Content

bbPress.org

Changeset 2768


Ignore:
Timestamp:
01/07/2011 09:43:40 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Introduce tag management utilities. Fixes #1424. Props GautamGupta via Google Code-in

Location:
branches/plugin
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-functions.php

    r2763 r2768  
    13101310
    13111311/**
     1312 * Handles the front end tag management (renaming, merging, destroying)
     1313 *
     1314 * @since bbPress (r2768)
     1315 *
     1316 * @uses check_admin_referer() To verify the nonce and check the referer
     1317 * @uses current_user_can() To check if the current user can edit/delete tags
     1318 * @uses bbPress::errors::add() To log the error messages
     1319 * @uses wp_update_term() To update the topic tag
     1320 * @uses get_term_link() To get the topic tag url
     1321 * @uses term_exists() To check if the topic tag already exists
     1322 * @uses wp_insert_term() To insert a topic tag
     1323 * @uses wp_delete_term() To delete the topic tag
     1324 * @uses home_url() To get the blog's home page url
     1325 * @uses do_action() Calls actions based on the actions with associated args
     1326 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
     1327 * @uses wp_redirect() To redirect to the url
     1328 */
     1329function bbp_manage_topic_tag_handler() {
     1330
     1331    if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && in_array( $_POST['action'], array( 'bbp-update-topic-tag', 'bbp-merge-topic-tag', 'bbp-delete-topic-tag' ) ) && !empty( $_POST['tag-id'] ) ) {
     1332
     1333        global $bbp;
     1334
     1335        $action = $_POST['action'];
     1336        $tag_id = (int) $_POST['tag-id'];
     1337        $tag    = get_term( $tag_id, $bbp->topic_tag_id );
     1338
     1339        if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
     1340            $append_error = $tag->get_error_message() . ' ';
     1341            $bbp->errors->add( 'bbp_manage_topic_invalid_tag', __( '<strong>ERROR</strong>: The following problem(s) have been found while getting the tag:' . $append_error . 'Please try again.', 'bbpress' ) );
     1342            return;
     1343        }
     1344
     1345        switch ( $action ) {
     1346            case 'bbp-update-topic-tag' :
     1347                check_admin_referer( 'update-tag_' . $tag_id );
     1348
     1349                if ( !current_user_can( 'edit_topic_tags' ) ) {
     1350                    $bbp->errors->add( 'bbp_manage_topic_tag_update_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to edit the topic tags!', 'bbpress' ) );
     1351                    return;
     1352                }
     1353
     1354                if ( empty( $_POST['tag-name'] ) || !$name = $_POST['tag-name'] ) {
     1355                    $bbp->errors->add( 'bbp_manage_topic_tag_update_name', __( '<strong>ERROR</strong>: You need to enter a tag name!', 'bbpress' ) );
     1356                    return;
     1357                }
     1358
     1359                $slug = !empty( $_POST['tag-slug'] ) ? $_POST['tag-slug'] : '';
     1360
     1361                $tag = wp_update_term( $tag_id, $bbp->topic_tag_id, array( 'name' => $name, 'slug' => $slug ) );
     1362
     1363                if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
     1364                    $append_error = $tag->get_error_message() . ' ';
     1365                    $bbp->errors->add( 'bbp_manage_topic_tag_update_error', __( '<strong>ERROR</strong>: The following problem(s) have been found while updating the tag:' . $append_error . 'Please try again.', 'bbpress' ) );
     1366                    return;
     1367                }
     1368
     1369                $redirect = get_term_link( $tag_id, $bbp->topic_tag_id );
     1370
     1371                // Update counts, etc...
     1372                do_action( 'bbp_update_topic_tag', $tag_id, $tag, $name, $slug );
     1373
     1374                break;
     1375
     1376            case 'bbp-merge-topic-tag'  :
     1377                check_admin_referer( 'merge-tag_' . $tag_id );
     1378
     1379                if ( !current_user_can( 'edit_topic_tags' ) ) {
     1380                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to edit the topic tags!', 'bbpress' ) );
     1381                    return;
     1382                }
     1383
     1384                if ( empty( $_POST['tag-name'] ) || !$name = $_POST['tag-name'] ) {
     1385                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_name', __( '<strong>ERROR</strong>: You need to enter a tag name!', 'bbpress' ) );
     1386                    return;
     1387                }
     1388
     1389                // Much part of merge tags functionality taken from Scribu's Term Management Tools WordPress Plugin
     1390
     1391                if ( !$tag = term_exists( $name, $bbp->topic_tag_id ) )
     1392                    $tag = wp_insert_term( $name, $bbp->topic_tag_id );
     1393
     1394                if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
     1395                    $append_error = $tag->get_error_message() . ' ';
     1396                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_error', __( '<strong>ERROR</strong>: The following problem(s) have been found while merging the tags:' . $append_error . 'Please try again.', 'bbpress' ) );
     1397                    return;
     1398                }
     1399
     1400                $to_tag = $tag['term_id'];
     1401
     1402                if ( $tag_id == $to_tag ) {
     1403                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_same', __( '<strong>ERROR</strong>: The tags which are being merged can not be the same.', 'bbpress' ) );
     1404                    return;
     1405                }
     1406
     1407                $tag = wp_delete_term( $tag_id, $bbp->topic_tag_id, array( 'default' => $to_tag, 'force_default' => true ) );
     1408
     1409                if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
     1410                    $append_error = $tag->get_error_message() . ' ';
     1411                    $bbp->errors->add( 'bbp_manage_topic_tag_merge_error', __( '<strong>ERROR</strong>: The following problem(s) have been found while merging the tags:' . $append_error . 'Please try again.', 'bbpress' ) );
     1412                    return;
     1413                }
     1414
     1415                $redirect = get_term_link( (int) $to_tag, $bbp->topic_tag_id );
     1416
     1417                // Update counts, etc...
     1418                do_action( 'bbp_merge_topic_tag', $tag_id, $to_tag, $tag );
     1419
     1420                break;
     1421
     1422            case 'bbp-delete-topic-tag' :
     1423                check_admin_referer( 'delete-tag_' . $tag_id );
     1424
     1425                if ( !current_user_can( 'delete_topic_tags' ) ) {
     1426                    $bbp->errors->add( 'bbp_manage_topic_tag_delete_permissions', __( '<strong>ERROR</strong>: You do not have the permissions to delete the topic tags!', 'bbpress' ) );
     1427                    return;
     1428                }
     1429
     1430                $tag = wp_delete_term( $tag_id, $bbp->topic_tag_id );
     1431
     1432                if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
     1433                    $append_error = $tag->get_error_message() . ' ';
     1434                    $bbp->errors->add( 'bbp_manage_topic_tag_delete_error', __( '<strong>ERROR</strong>: The following problem(s) have been found while deleting the tag:' . $append_error . 'Please try again.', 'bbpress' ) );
     1435                    return;
     1436                }
     1437
     1438                // We don't have any other place to go other than home! Or we may die because of the 404 disease
     1439                $redirect = home_url();
     1440
     1441                // Update counts, etc...
     1442                do_action( 'bbp_delete_topic_tag', $tag_id, $tag );
     1443
     1444                break;
     1445        }
     1446
     1447        // Redirect back
     1448        $redirect = ( !empty( $redirect ) && !is_wp_error( $redirect ) ) ? $redirect : home_url();
     1449        wp_redirect( $redirect );
     1450
     1451        // For good measure
     1452        exit();
     1453
     1454    }
     1455}
     1456
     1457/**
    13121458 * Handles the front end user editing
    13131459 *
  • branches/plugin/bbp-includes/bbp-hooks.php

    r2758 r2768  
    8484add_action( 'bbp_deactivation', 'bbp_remove_caps',   1     );
    8585add_action( 'bbp_deactivation', 'bbp_remove_roles',  2     );
     86
     87// Topic Tag Page
     88add_action( 'template_redirect', 'bbp_manage_topic_tag_handler', 1 );
    8689
    8790// Profile Page
  • branches/plugin/bbp-includes/bbp-topic-template.php

    r2767 r2768  
    16741674            return;
    16751675
    1676         $uri = esc_url( add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->id ) ) );
     1676        $uri = esc_url( add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) ) );
    16771677
    16781678        return apply_filters( 'bbp_get_topic_merge_link', $link_before . '<a href="' . $uri . '">' . $merge_text . '</a>' . $link_after, $args );
  • branches/plugin/bbp-themes/bbp-twentyten/css/bbpress.css

    r2758 r2768  
    203203
    204204.bbp-topic-form,
    205 .bbp-reply-form {
     205.bbp-reply-form,
     206.bbp-topic-tag-form {
    206207    clear: left;
    207208}
    208209
    209 p#bbp_topic_submit_container {
     210#merge_tag,
     211#delete_tag {
     212    display: inline;
     213}
     214
     215p#bbp_topic_submit_container,
     216p#bbp_reply_submit_container {
    210217    float: right;
    211218}
     
    294301        background-color: #fffbcc;
    295302    }
    296     div.bbp-template-notice.error {
     303    div.bbp-template-notice.error,
     304    div.bbp-template-notice.warning {
    297305        background-color: #ffebe8;
    298306        border-color: #c00;
    299307    }
    300     div.bbp-template-notice.error a {
     308    div.bbp-template-notice.error a,
     309    div.bbp-template-notice.warning a {
    301310        color: #c00;
    302311    }
     
    307316        line-height: 140%;
    308317    }
     318    fieldset div.bbp-template-notice {
     319        margin-top: -10px;
     320    }
    309321
    310322/* =Stickies
  • branches/plugin/bbp-themes/bbp-twentyten/form-bbp_reply.php

    r2763 r2768  
    6262                        <?php endif; ?>
    6363
    64                         <p id="bbp_topic_submit_container">
     64                        <p id="bbp_reply_submit_container">
    6565                            <button type="submit" tabindex="14" id="bbp_reply_submit" name="bbp_reply_submit"><?php _e( 'Submit', 'bbpress' ); ?></button>
    6666                        </p>
  • branches/plugin/bbp-themes/bbp-twentyten/taxonomy-bbp_topic_tag.php

    r2758 r2768  
    2929                        <?php get_template_part( 'loop', 'bbp_topics' ); ?>
    3030
     31                        <?php get_template_part( 'form', 'bbp_topic_tag' ); ?>
     32
    3133                    </div>
    3234                </div><!-- #topic-tag -->
  • branches/plugin/bbpress.php

    r2753 r2768  
    641641        // Register the topic tag taxonomy
    642642        register_taxonomy(
    643             $this->topic_tag_id, // The topic tag ID
    644             $this->topic_id,     // The topic content type
     643            $this->topic_tag_id, // The topic tag id
     644            $this->topic_id,     // The topic post type
    645645            $bbp_tt
    646646        );
Note: See TracChangeset for help on using the changeset viewer.