Skip to:
Content

bbPress.org

Changeset 3753


Ignore:
Timestamp:
02/22/2012 07:32:48 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Add autoembed to topics and replies.

  • Includes admin setting to toggle on/off (default on)
  • Introduce option function to get the setting globally
  • Hooked into bbp_init so can be overridden as needed
  • Fixes #1752
  • Props jaredatch for original patch
Location:
branches/plugin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-admin.php

    r3731 r3753  
    268268        }
    269269
    270         // Allow global access setting
    271         add_settings_field( '_bbp_use_wp_editor', __( 'Fancy Editor',  'bbpress' ), 'bbp_admin_setting_callback_use_wp_editor', 'bbpress', 'bbp_main' );
    272         register_setting  ( 'bbpress',            '_bbp_use_wp_editor',             'intval'                                                          );
     270        // Allow Fancy editor setting
     271        add_settings_field( '_bbp_use_wp_editor', __( 'Fancy Editor',     'bbpress' ), 'bbp_admin_setting_callback_use_wp_editor', 'bbpress', 'bbp_main' );
     272        register_setting  ( 'bbpress',            '_bbp_use_wp_editor',                'intval'                                                          );
     273       
     274        // Allow oEmbeds setting
     275        add_settings_field( '_bbp_use_autoembed', __( 'Auto-embed Links', 'bbpress' ), 'bbp_admin_setting_callback_use_autoembed', 'bbpress', 'bbp_main' );
     276        register_setting  ( 'bbpress',           '_bbp_use_autoembed',                 'intval'                                                          );
    273277
    274278        /** Per Page Section **************************************************/
  • branches/plugin/bbp-admin/bbp-settings.php

    r3719 r3753  
    150150    <input id="_bbp_use_wp_editor" name="_bbp_use_wp_editor" type="checkbox" id="_bbp_use_wp_editor" value="1" <?php checked( bbp_use_wp_editor( true ) ); ?> />
    151151    <label for="_bbp_use_wp_editor"><?php _e( 'Use the fancy WordPress editor to create and edit topics and replies', 'bbpress' ); ?></label>
     152
     153<?php
     154}
     155
     156/**
     157 * Allow oEmbed in replies
     158 *
     159 * @since bbPress (r3752)
     160 *
     161 * @uses checked() To display the checked attribute
     162 */
     163function bbp_admin_setting_callback_use_autoembed() {
     164?>
     165
     166    <input id="_bbp_use_autoembed" name="bbp_use_autoembed" type="checkbox" id="_bbp_use_autoembed" value="1" <?php checked( bbp_use_autoembed( true ) ); ?> />
     167    <label for="_bbp_use_autoembed"><?php _e( 'Embed media (YouTube, Twitter, Flickr, etc...) directly into topics and replies.', 'bbpress' ); ?></label>
    152168
    153169<?php
     
    594610                            '<li>' . __( '"Anonymous Posting" allows guest users who do not have accounts on your site to both create topics as well as replies.',                                                             'bbpress' ) . '</li>' .
    595611                            '<li>' . __( 'The Fancy Editor brings the luxury of the Visual editor and HTML editor from the traditional WordPress dashboard into your theme.',                                                  'bbpress' ) . '</li>' .
     612                            '<li>' . __( 'Auto-embed will embed the media content from a URL directly into the replies. For example: links to Flickr and YouTube.',                                                            'bbpress' ) . '</li>' .
    596613                        '</ul>' .
    597614                    '</p>' .
  • branches/plugin/bbp-includes/bbp-core-hooks.php

    r3744 r3753  
    7171 *                                                    v---Load order
    7272 */
    73 add_action( 'bbp_init', 'bbp_load_textdomain',        2   );
    74 add_action( 'bbp_init', 'bbp_setup_option_filters',   4   );
    75 add_action( 'bbp_init', 'bbp_register_post_types',    10  );
    76 add_action( 'bbp_init', 'bbp_register_post_statuses', 12  );
    77 add_action( 'bbp_init', 'bbp_register_taxonomies',    14  );
    78 add_action( 'bbp_init', 'bbp_register_views',         16  );
    79 add_action( 'bbp_init', 'bbp_register_shortcodes',    18  );
    80 add_action( 'bbp_init', 'bbp_add_rewrite_tags',       20  );
    81 add_action( 'bbp_init', 'bbp_ready',                  999 );
     73add_action( 'bbp_init', 'bbp_load_textdomain',         2   );
     74add_action( 'bbp_init', 'bbp_setup_option_filters',    4   );
     75add_action( 'bbp_init', 'bbp_register_post_types',     10  );
     76add_action( 'bbp_init', 'bbp_register_post_statuses',  12  );
     77add_action( 'bbp_init', 'bbp_register_taxonomies',     14  );
     78add_action( 'bbp_init', 'bbp_register_views',          16  );
     79add_action( 'bbp_init', 'bbp_register_shortcodes',     18  );
     80add_action( 'bbp_init', 'bbp_add_rewrite_tags',        20  );
     81add_action( 'bbp_init', 'bbp_ready',                   999 );
     82
     83// Autoembeds
     84add_filter( 'bbp_init', 'bbp_reply_content_autoembed', 8   );
     85add_filter( 'bbp_init', 'bbp_topic_content_autoembed', 8   );
    8286
    8387/**
  • branches/plugin/bbp-includes/bbp-core-options.php

    r3586 r3753  
    4949        // Use the WordPress editor if available
    5050        '_bbp_use_wp_editor'        => true,
     51       
     52        // Use the WordPress editor if available
     53        '_bbp_use_wp_editor'        => true,
     54       
     55        // Allow oEmbed in topics and replies
     56        '_bbp_allow_oembed'         => false,
    5157
    5258        /** Per Page **********************************************************/
     
    329335function bbp_use_wp_editor( $default = true ) {
    330336    return (bool) apply_filters( 'bbp_use_wp_editor', (bool) get_option( '_bbp_use_wp_editor', $default ) );
     337}
     338
     339/**
     340 * Use WordPress's oEmbed API
     341 *
     342 * @since bbPress (r3752)
     343 *
     344 * @param $default bool Optional. Default value true
     345 *
     346 * @uses get_option() To get the oEmbed option
     347 * @return bool Use oEmbed?
     348 */
     349function bbp_use_autoembed( $default = true ) {
     350    return (bool) apply_filters( 'bbp_use_autoembed', (bool) get_option( '_bbp_use_autoembed', $default ) );
    331351}
    332352
  • branches/plugin/bbp-includes/bbp-reply-functions.php

    r3715 r3753  
    13411341}
    13421342
     1343/** Autoembed *****************************************************************/
     1344
     1345/**
     1346 * Check if autoembeds are enabled and hook them in if so
     1347 *
     1348 * @since bbPress (r3752)
     1349 * @global WP_Embed $wp_embed
     1350 */
     1351function bbp_reply_content_autoembed() {
     1352    global $wp_embed;
     1353
     1354    if ( bbp_use_autoembed() && is_a( $wp_embed, 'WP_Embed' ) ) {
     1355        add_filter( 'bbp_get_reply_content', array( $wp_embed, 'autoembed' ), 8 );     
     1356    }
     1357}
     1358
    13431359/** Feeds *********************************************************************/
    13441360
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r3714 r3753  
    29602960}
    29612961
     2962/** Autoembed *****************************************************************/
     2963
     2964/**
     2965 * Check if autoembeds are enabled and hook them in if so
     2966 *
     2967 * @since bbPress (r3752)
     2968 * @global WP_Embed $wp_embed
     2969 */
     2970function bbp_topic_content_autoembed() {
     2971    global $wp_embed;
     2972
     2973    if ( bbp_use_autoembed() && is_a( $wp_embed, 'WP_Embed' ) ) {
     2974        add_filter( 'bbp_get_topic_content', array( $wp_embed, 'autoembed' ), 8 );     
     2975    }
     2976}
     2977
    29622978/** Feeds *********************************************************************/
    29632979
Note: See TracChangeset for help on using the changeset viewer.