WordPress.org

Plugin Directory

Changeset 588015


Ignore:
Timestamp:
08/20/12 21:34:52 (20 months ago)
Author:
evansolomon
Message:

If the plugin is active, oEmbed in comments is on

  • The oEmbed setting may be going away in 3.5, instead of relying on it or adding our own, just assume that if the plugin is active you want the feature
  • Remove the admin settings
  • Don't load oEmbed media in the admin for possible security reasons, just let make_clickable() turn it into a link
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oembed-in-comments/trunk/oembed-in-comments.php

    r588013 r588015  
    1414     */ 
    1515    function __construct() { 
    16         add_action( 'init',       array( $this, 'init'       ) ); 
    17         add_action( 'admin_init', array( $this, 'admin_init' ) ); 
     16        add_action( 'init', array( $this, 'init' ) ); 
    1817    } 
    1918 
    2019    /** 
    21      * If oEmbed is enabled in comments, keep going 
     20     * If we're not in the admin, keep going 
    2221     */ 
    2322    function init() { 
    24         if ( ! $this->is_enabled() ) 
     23        if ( is_admin() ) 
    2524            return; 
    2625 
     
    2928 
    3029    /** 
    31      * Setup filters to do oEmbed in comments 
     30     * Setup filter to do oEmbed in comments 
    3231     */ 
    3332    function oembed_in_comments() { 
    3433        global $wp_embed; 
    3534 
    36         // wp_kses_post will clobber the markup that oEmbed gave us, make sure we go later 
    37         $kses = has_filter( 'comment_text', 'wp_kses_post' ); 
    38  
    3935        // make_clickable breaks oEmbed regex, make sure we go earlier 
    4036        $clickable = has_filter( 'comment_text', 'make_clickable' ); 
    41  
    42         if ( ! $clickable && ! $kses ) { 
    43             $priority = 10; 
    44         } 
    45         elseif ( ! $kses ) { 
    46             $priority = $clickable - 1; 
    47         } 
    48         elseif ( ! $clickable || $clickable > $kses ) { 
    49             $priority = $kses; 
    50         } 
    51         else { 
    52             // Move make_clickable later 
    53             remove_filter( 'comment_text', 'make_clickable', $clickable ); 
    54             add_filter( 'comment_text', 'make_clickable', $kses + 1 ); 
    55  
    56             $priority = $kses; 
    57         } 
     37        $priority = ( $clickable ) ? $clickable - 1 : 10; 
    5838 
    5939        add_filter( 'comment_text', array( $wp_embed, 'autoembed' ), $priority ); 
    60     } 
    61  
    62     /** 
    63      * Check whether oEmbed is enabled or disabled in comments 
    64      */ 
    65     function is_enabled() { 
    66         $enabled = get_option( $this->get_option_name(), null ); 
    67  
    68         // If there's no option set, default to the option for posts 
    69         if ( is_null( $enabled ) ) 
    70             $enabled = get_option( 'embed_autourls' ); 
    71  
    72         return (bool) $enabled; 
    73     } 
    74  
    75     /** 
    76      * Setup admin area 
    77      */ 
    78     function admin_init() { 
    79         $this->register_setting(); 
    80     } 
    81  
    82     /** 
    83      * Register setting and settings field to allow enabling or disabling 
    84      */ 
    85     function register_setting() { 
    86         add_settings_field( 
    87             $this->get_option_name(), 
    88             __( 'Auto-embeds in comments' ), 
    89             array( $this, 'setting_field' ), 
    90             'media', 
    91             'embeds' 
    92         ); 
    93  
    94         register_setting( 
    95             'media', 
    96             $this->get_option_name(), 
    97             array( $this, 'sanitize_input' ) 
    98         ); 
    99     } 
    100  
    101     /** 
    102      * Check box to turn oEmbed on or off in comments 
    103      */ 
    104     function setting_field() { 
    105         $output  = sprintf( '<label for="%s">', esc_attr( $this->get_option_name() ) ); 
    106         $output .= sprintf( '<input name="%s" type="checkbox" id="%s" %s /> %s', 
    107             esc_attr( $this->get_option_name() ), 
    108             esc_attr( $this->get_option_name() ), 
    109             checked( true, $this->is_enabled(), false ), 
    110             esc_html__( 'When possible, embed the media content from a URL directly into comments.' ) 
    111         ); 
    112         $output .= '</label>'; 
    113  
    114         echo $output; 
    115     } 
    116  
    117     /** 
    118      * Wrapper to generate an option name based on the class name 
    119      */ 
    120     function get_option_name() { 
    121         return strtolower( __CLASS__ ) . '_enabled'; 
    122     } 
    123  
    124     /** 
    125      * Always cast the input as a boolean 
    126      */ 
    127     function sanitize_input( $input ) { 
    128         return (bool) 'on' == $input; 
    12940    } 
    13041} 
Note: See TracChangeset for help on using the changeset viewer.