WordPress.org

Plugin Directory

Changeset 548720


Ignore:
Timestamp:
05/24/12 22:25:44 (2 years ago)
Author:
goldenapples
Message:

Version 0.4.2, fixes some bugs where the plugin widgets would be interfered with by a comments query running on the archive page or a post. Also introduces an option to allow unregistered users to post.

Location:
recommended-links
Files:
12 edited
9 copied

Legend:

Unmodified
Added
Removed
  • recommended-links/tags/0.4.2/admin-functions.php

    r534560 r548720  
    1616    $page = ( isset($_GET['tab']) && in_array( $_GET['tab'], array_keys( $tabs ) ) ) ? $_GET['tab'] : 'general'; 
    1717 
    18     $current_settings = get_option( 'reclinks_options' ); 
    1918    if ( !empty( $_POST ) && check_admin_referer( 'gad-reclinks-settings', '_wpnonce') ) 
    2019        update_reclinks_settings( $page ); 
     
    5352    switch ( $page ) : 
    5453        case 'general': 
    55             $settings['page_for_reclinks'] = intval( $_POST['page_id'] ); 
     54            $settings['page_for_reclinks'] = intval( $_POST['page_for_reclinks'] ); 
    5655            $settings['sort_order'] = $_POST['sort_order']; 
    5756            $settings['tax'] = ( isset( $_POST['tax'] ) ) ? $_POST['tax'] : array(); 
    5857            $settings['allow-unregistered-vote'] = (isset($_POST['allow-unregistered-vote']) && true == $_POST['allow-unregistered-vote']); 
    5958            $settings['allow-unregistered-post'] = (isset($_POST['allow-unregistered-post']) && true == $_POST['allow-unregistered-post']); 
     59            $settings['anonymous-links-author'] = intval($_POST['anonymous-links-author']);  
    6060            $settings['vote-on-comments'] = (isset($_POST['vote-on-comments']) && true == $_POST['vote-on-comments']); 
    6161 
  • recommended-links/tags/0.4.2/admin/options-archives.php

    r509618 r548720  
    99 
    1010?> 
     11<tr> 
     12    <th scope="row"></th> 
     13    <td></td> 
     14</tr> 
     15<tr> 
     16    <th scope="row"></th> 
     17    <td></td> 
     18</tr> 
     19<tr> 
     20    <th scope="row"></th> 
     21    <td></td> 
     22</tr> 
     23<tr> 
     24    <th scope="row"></th> 
     25    <td></td> 
     26</tr> 
    1127<p>This is a placeholder for more options to come.</p> 
  • recommended-links/tags/0.4.2/admin/options-general.php

    r509618 r548720  
    1616            <?php wp_dropdown_pages( 
    1717                array( 
     18                    'name' => 'page_for_reclinks', 
    1819                    'show_option_none' => __('None (use default archive)', 'gad_reclinks'), 
    1920                    'exclude' => array( get_option('page_for_posts') ), 
     
    2627    <tr> 
    2728        <th scope="row"> 
    28             <label for="page_for_reclinks"><?php _e( 'Default Sort Order:', 'gad_reclinks' ); ?></label> 
     29            <label for="sort_order"><?php _e( 'Default Sort Order:', 'gad_reclinks' ); ?></label> 
    2930        </th> 
    3031        <td> 
     
    6465                <br><span class="description"><?php _e('(Votes will be logged by IP address.)', 'gad_reclinks' ); ?></span> 
    6566            </p> 
    66     <!--- 
    6767            <p> 
    6868                <input type="checkbox" name="allow-unregistered-post" <?php checked( $current_settings['allow-unregistered-post'] ); ?>/> 
    6969                <label for="allow-unregistered-post"><?php _e( 'Allow unregistered users to post new links?', 'gad_reclinks' ); ?></label> 
    7070            </p> 
    71     --> 
     71            <p class="description"><?php _e( 'If unregistered users are allowed to post links, choose an author to assign to those links:', 'gad_reclinks' ); ?></p> 
     72            <?php wp_dropdown_users( array( 
     73                'name' => 'anonymous-links-author', 
     74                'selected' => ( isset( $current_settings['anonymous-links-author'] ) ) ? $current_settings['anonymous-links-author'] : null, 
     75                ) 
     76            ); ?> 
    7277        </td> 
    7378    </tr> 
  • recommended-links/tags/0.4.2/ajax-functions.php

    r509618 r548720  
    4949 
    5050 
     51add_action( 'wp_ajax_nopriv_add_reclink', 'gad_reclinks_ajax_add' ); 
    5152add_action( 'wp_ajax_add_reclink', 'gad_reclinks_ajax_add' ); 
    5253 
    5354function gad_reclinks_ajax_add() { 
    54     $plugin_settings = get_option( 'reclinks_plugin_settings' ); 
     55    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
    5556 
    5657    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
     
    6364        'reclink_taxes' => isset( $_POST['reclink_taxes'] ) ? $_POST['reclink_taxes'] : null 
    6465    ); 
    65  
     66     
    6667    $link = gad_add_reclink( $reclink ); 
    6768    echo json_encode( get_post( $link ) ); 
  • recommended-links/tags/0.4.2/display-filters.php

    r534560 r548720  
    88 
    99 
    10 add_filter('query_vars', 'gad_reclinks_add_query_vars'); 
    11  
    12 function gad_reclinks_add_query_vars( $query_vars ) { 
    13     $query_vars[] = "reclinks_sort"; 
    14     return $query_vars; 
     10add_filter( 'query_vars', 'gad_reclinks_add_query_vars' ); 
     11 
     12function gad_reclinks_add_query_vars( $vars ) { 
     13    array_push( $vars, 'reclinks_sort' ); 
     14    return $vars; 
     15} 
     16 
     17// flush_rules() if our rules are not yet included 
     18add_action( 'wp_loaded','gad_reclinks_flush_rules' ); 
     19 
     20function gad_reclinks_flush_rules() { 
     21    global $wp_rewrite; 
     22 
     23    if ( !$wp_rewrite->using_permalinks() ) 
     24        return; 
     25 
     26    $rules = get_option( 'rewrite_rules' ); 
     27    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     28    $archive_page = $plugin_settings['page_for_reclinks']; 
     29    if ( !$archive_page ) 
     30        return; 
     31 
     32    $archive_page_name = get_post( $archive_page )->post_name; 
     33    if ( !isset( $rules["({$archive_page_name})/(newest|hot|current|score|controversial)/?"] ) ) { 
     34        $wp_rewrite->flush_rules(); 
     35    } 
     36} 
     37 
     38add_filter( 'rewrite_rules_array', 'gad_reclinks_sortorder_rewrite' ); 
     39 
     40function gad_reclinks_sortorder_rewrite( $rules ) { 
     41 
     42    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     43 
     44    if ( $archive_page = $plugin_settings['page_for_reclinks'] ) { 
     45 
     46        $archive_page_name = get_post( $archive_page )->post_name; 
     47        $new_rules = array(  
     48            "({$archive_page_name})/(newest|hot|current|score|controversial)/page/([0-9]+)/?" => 'index.php?pagename=$matches[1]&reclinks_sort=$matches[2]&paged=$matches[3]', 
     49            "({$archive_page_name})/(newest|hot|current|score|controversial)/?" => 'index.php?pagename=$matches[1]&reclinks_sort=$matches[2]' 
     50        ); 
     51        $rules = $new_rules + $rules; 
     52 
     53        return $rules; 
     54    } 
    1555} 
    1656 
     
    263303 
    264304    $links_paged = ( isset( $wp_query->query['paged'] ) ) ? $wp_query->query['paged'] : 1; 
     305    $links_sort = ( isset( $wp_query->query_vars['reclinks_sort'] ) ) ? $wp_query->query_vars['reclinks_sort'] : $plugin_settings['sort_order']; 
    265306    $posts_per_page = ( isset( $plugin_settings['posts_per_page'] ) ) ? $plugin_settings['posts_per_page'] : 25; 
    266307 
     
    271312    $wp_query = new WP_Query( array( 
    272313        'post_type' => 'reclink', 
    273         'reclinks_sort' => $plugin_settings['sort_order'], 
     314        'reclinks_sort' => $links_sort, 
    274315        'posts_per_page' => $posts_per_page, 
    275316        'paged' => $links_paged 
  • recommended-links/tags/0.4.2/readme.txt

    r534560 r548720  
    55Requires at least: 3.2.1 
    66Tested up to: 3.4 
    7 Stable tag: 0.4.1 
     7Stable tag: 0.4.2 
    88 
    99A sort of "Reddit clone" that allows users to post links, up- or down-vote them, and comment on them. 
     
    2020 
    2121== Changelog == 
     22 
     23= 0.4.2 = 
     24 
     25Fixes a couple of bugs relating to displaying the plugin's widgets on a page that includes a comments query (the author and the score of all links in the widget would be taken from the last comment displayed on the page. 
     26 
     27Also, includes an option to allow unregistered users to post for the the first time. 
    2228 
    2329= 0.4.1 = 
     
    7783== Upgrade Notice == 
    7884 
    79 = 0.4 = 
    80 This update introduces a bookmarklet that can be used for easier submission of links, and some other features. 
     85= 0.4.2 
     86Mostly bugfixes; also includes an option to allow unregistered users to post links. 
  • recommended-links/tags/0.4.2/recommended-links.php

    r534565 r548720  
    55Description: A "reddit clone" that runs in Wordpress. 
    66Author: Nathaniel Taintor 
    7 Version: 0.4.1 
     7Version: 0.4.2 
    88Author URI: http://goldenapplesdesign.com 
    99*/ 
     
    135135    // Check to see that user is authorized to add link 
    136136    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
    137         return false; 
     137        { 
     138            error_log ( 'unauthorixed user tried to post link: ' . print_r( $reclink, true ) ); 
     139            return false; 
     140        } 
    138141 
    139142    // Check to see if that link already exists 
     
    155158    } 
    156159 
     160    $author = ( is_user_logged_in() ) ? $current_user->ID : $plugin_settings['anonymous-links-author']; 
     161 
    157162    $link_ID = wp_insert_post( array( 
    158163        'post_type'     => 'reclink', 
    159         'post_author'   => $current_user->ID, 
     164        'post_author'   => $author, 
    160165        'post_title'    => $reclink['reclink_title'], 
    161166        'post_content'  => $reclink['reclink_description'], 
  • recommended-links/tags/0.4.2/widgets.php

    r509618 r548720  
    2323        function widget($args, $instance) { 
    2424        // prints the widget 
    25             if ( !current_user_can('add_reclink') ) 
     25            $plugin_settings = get_option('reclinks_plugin_options'); 
     26 
     27            if ( !$plugin_settings['allow-unregistered-vote'] && !current_user_can('add_reclink') ) 
    2628                return; 
    2729            extract($args, EXTR_SKIP); 
     
    8688 
    8789 
    88             global $wp_query; 
     90            global $wp_query, $comment; 
    8991            $old_query = $wp_query; 
     92            $old_comment_query = $GLOBALS['comment'] = $comment; 
     93            unset( $comment, $GLOBALS['comment'] ); 
    9094 
    9195            $wp_query = new WP_Query( array( 
     
    99103 
    100104            $wp_query = $old_query; 
     105            $GLOBALS['comment'] = $old_comment_query; 
    101106 
    102107            if ( $instance['links'] !== 'none' ): 
  • recommended-links/trunk/admin-functions.php

    r534560 r548720  
    1616    $page = ( isset($_GET['tab']) && in_array( $_GET['tab'], array_keys( $tabs ) ) ) ? $_GET['tab'] : 'general'; 
    1717 
    18     $current_settings = get_option( 'reclinks_options' ); 
    1918    if ( !empty( $_POST ) && check_admin_referer( 'gad-reclinks-settings', '_wpnonce') ) 
    2019        update_reclinks_settings( $page ); 
     
    5352    switch ( $page ) : 
    5453        case 'general': 
    55             $settings['page_for_reclinks'] = intval( $_POST['page_id'] ); 
     54            $settings['page_for_reclinks'] = intval( $_POST['page_for_reclinks'] ); 
    5655            $settings['sort_order'] = $_POST['sort_order']; 
    5756            $settings['tax'] = ( isset( $_POST['tax'] ) ) ? $_POST['tax'] : array(); 
    5857            $settings['allow-unregistered-vote'] = (isset($_POST['allow-unregistered-vote']) && true == $_POST['allow-unregistered-vote']); 
    5958            $settings['allow-unregistered-post'] = (isset($_POST['allow-unregistered-post']) && true == $_POST['allow-unregistered-post']); 
     59            $settings['anonymous-links-author'] = intval($_POST['anonymous-links-author']);  
    6060            $settings['vote-on-comments'] = (isset($_POST['vote-on-comments']) && true == $_POST['vote-on-comments']); 
    6161 
  • recommended-links/trunk/admin/options-archives.php

    r509618 r548720  
    99 
    1010?> 
     11<tr> 
     12    <th scope="row"></th> 
     13    <td></td> 
     14</tr> 
     15<tr> 
     16    <th scope="row"></th> 
     17    <td></td> 
     18</tr> 
     19<tr> 
     20    <th scope="row"></th> 
     21    <td></td> 
     22</tr> 
     23<tr> 
     24    <th scope="row"></th> 
     25    <td></td> 
     26</tr> 
    1127<p>This is a placeholder for more options to come.</p> 
  • recommended-links/trunk/admin/options-general.php

    r509618 r548720  
    1616            <?php wp_dropdown_pages( 
    1717                array( 
     18                    'name' => 'page_for_reclinks', 
    1819                    'show_option_none' => __('None (use default archive)', 'gad_reclinks'), 
    1920                    'exclude' => array( get_option('page_for_posts') ), 
     
    2627    <tr> 
    2728        <th scope="row"> 
    28             <label for="page_for_reclinks"><?php _e( 'Default Sort Order:', 'gad_reclinks' ); ?></label> 
     29            <label for="sort_order"><?php _e( 'Default Sort Order:', 'gad_reclinks' ); ?></label> 
    2930        </th> 
    3031        <td> 
     
    6465                <br><span class="description"><?php _e('(Votes will be logged by IP address.)', 'gad_reclinks' ); ?></span> 
    6566            </p> 
    66     <!--- 
    6767            <p> 
    6868                <input type="checkbox" name="allow-unregistered-post" <?php checked( $current_settings['allow-unregistered-post'] ); ?>/> 
    6969                <label for="allow-unregistered-post"><?php _e( 'Allow unregistered users to post new links?', 'gad_reclinks' ); ?></label> 
    7070            </p> 
    71     --> 
     71            <p class="description"><?php _e( 'If unregistered users are allowed to post links, choose an author to assign to those links:', 'gad_reclinks' ); ?></p> 
     72            <?php wp_dropdown_users( array( 
     73                'name' => 'anonymous-links-author', 
     74                'selected' => ( isset( $current_settings['anonymous-links-author'] ) ) ? $current_settings['anonymous-links-author'] : null, 
     75                ) 
     76            ); ?> 
    7277        </td> 
    7378    </tr> 
  • recommended-links/trunk/ajax-functions.php

    r509618 r548720  
    4949 
    5050 
     51add_action( 'wp_ajax_nopriv_add_reclink', 'gad_reclinks_ajax_add' ); 
    5152add_action( 'wp_ajax_add_reclink', 'gad_reclinks_ajax_add' ); 
    5253 
    5354function gad_reclinks_ajax_add() { 
    54     $plugin_settings = get_option( 'reclinks_plugin_settings' ); 
     55    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
    5556 
    5657    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
     
    6364        'reclink_taxes' => isset( $_POST['reclink_taxes'] ) ? $_POST['reclink_taxes'] : null 
    6465    ); 
    65  
     66     
    6667    $link = gad_add_reclink( $reclink ); 
    6768    echo json_encode( get_post( $link ) ); 
  • recommended-links/trunk/display-filters.php

    r534560 r548720  
    88 
    99 
    10 add_filter('query_vars', 'gad_reclinks_add_query_vars'); 
    11  
    12 function gad_reclinks_add_query_vars( $query_vars ) { 
    13     $query_vars[] = "reclinks_sort"; 
    14     return $query_vars; 
     10add_filter( 'query_vars', 'gad_reclinks_add_query_vars' ); 
     11 
     12function gad_reclinks_add_query_vars( $vars ) { 
     13    array_push( $vars, 'reclinks_sort' ); 
     14    return $vars; 
     15} 
     16 
     17// flush_rules() if our rules are not yet included 
     18add_action( 'wp_loaded','gad_reclinks_flush_rules' ); 
     19 
     20function gad_reclinks_flush_rules() { 
     21    global $wp_rewrite; 
     22 
     23    if ( !$wp_rewrite->using_permalinks() ) 
     24        return; 
     25 
     26    $rules = get_option( 'rewrite_rules' ); 
     27    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     28    $archive_page = $plugin_settings['page_for_reclinks']; 
     29    if ( !$archive_page ) 
     30        return; 
     31 
     32    $archive_page_name = get_post( $archive_page )->post_name; 
     33    if ( !isset( $rules["({$archive_page_name})/(newest|hot|current|score|controversial)/?"] ) ) { 
     34        $wp_rewrite->flush_rules(); 
     35    } 
     36} 
     37 
     38add_filter( 'rewrite_rules_array', 'gad_reclinks_sortorder_rewrite' ); 
     39 
     40function gad_reclinks_sortorder_rewrite( $rules ) { 
     41 
     42    $plugin_settings = get_option( 'reclinks_plugin_options' ); 
     43 
     44    if ( $archive_page = $plugin_settings['page_for_reclinks'] ) { 
     45 
     46        $archive_page_name = get_post( $archive_page )->post_name; 
     47        $new_rules = array(  
     48            "({$archive_page_name})/(newest|hot|current|score|controversial)/page/([0-9]+)/?" => 'index.php?pagename=$matches[1]&reclinks_sort=$matches[2]&paged=$matches[3]', 
     49            "({$archive_page_name})/(newest|hot|current|score|controversial)/?" => 'index.php?pagename=$matches[1]&reclinks_sort=$matches[2]' 
     50        ); 
     51        $rules = $new_rules + $rules; 
     52 
     53        return $rules; 
     54    } 
    1555} 
    1656 
     
    263303 
    264304    $links_paged = ( isset( $wp_query->query['paged'] ) ) ? $wp_query->query['paged'] : 1; 
     305    $links_sort = ( isset( $wp_query->query_vars['reclinks_sort'] ) ) ? $wp_query->query_vars['reclinks_sort'] : $plugin_settings['sort_order']; 
    265306    $posts_per_page = ( isset( $plugin_settings['posts_per_page'] ) ) ? $plugin_settings['posts_per_page'] : 25; 
    266307 
     
    271312    $wp_query = new WP_Query( array( 
    272313        'post_type' => 'reclink', 
    273         'reclinks_sort' => $plugin_settings['sort_order'], 
     314        'reclinks_sort' => $links_sort, 
    274315        'posts_per_page' => $posts_per_page, 
    275316        'paged' => $links_paged 
  • recommended-links/trunk/readme.txt

    r534560 r548720  
    55Requires at least: 3.2.1 
    66Tested up to: 3.4 
    7 Stable tag: 0.4.1 
     7Stable tag: 0.4.2 
    88 
    99A sort of "Reddit clone" that allows users to post links, up- or down-vote them, and comment on them. 
     
    2020 
    2121== Changelog == 
     22 
     23= 0.4.2 = 
     24 
     25Fixes a couple of bugs relating to displaying the plugin's widgets on a page that includes a comments query (the author and the score of all links in the widget would be taken from the last comment displayed on the page. 
     26 
     27Also, includes an option to allow unregistered users to post for the the first time. 
    2228 
    2329= 0.4.1 = 
     
    7783== Upgrade Notice == 
    7884 
    79 = 0.4 = 
    80 This update introduces a bookmarklet that can be used for easier submission of links, and some other features. 
     85= 0.4.2 
     86Mostly bugfixes; also includes an option to allow unregistered users to post links. 
  • recommended-links/trunk/recommended-links.php

    r534565 r548720  
    55Description: A "reddit clone" that runs in Wordpress. 
    66Author: Nathaniel Taintor 
    7 Version: 0.4.1 
     7Version: 0.4.2 
    88Author URI: http://goldenapplesdesign.com 
    99*/ 
     
    135135    // Check to see that user is authorized to add link 
    136136    if ( !$plugin_settings['allow-unregistered-post'] && !current_user_can( 'add_reclink' ) ) 
    137         return false; 
     137        { 
     138            error_log ( 'unauthorixed user tried to post link: ' . print_r( $reclink, true ) ); 
     139            return false; 
     140        } 
    138141 
    139142    // Check to see if that link already exists 
     
    155158    } 
    156159 
     160    $author = ( is_user_logged_in() ) ? $current_user->ID : $plugin_settings['anonymous-links-author']; 
     161 
    157162    $link_ID = wp_insert_post( array( 
    158163        'post_type'     => 'reclink', 
    159         'post_author'   => $current_user->ID, 
     164        'post_author'   => $author, 
    160165        'post_title'    => $reclink['reclink_title'], 
    161166        'post_content'  => $reclink['reclink_description'], 
  • recommended-links/trunk/widgets.php

    r509618 r548720  
    2323        function widget($args, $instance) { 
    2424        // prints the widget 
    25             if ( !current_user_can('add_reclink') ) 
     25            $plugin_settings = get_option('reclinks_plugin_options'); 
     26 
     27            if ( !$plugin_settings['allow-unregistered-vote'] && !current_user_can('add_reclink') ) 
    2628                return; 
    2729            extract($args, EXTR_SKIP); 
     
    8688 
    8789 
    88             global $wp_query; 
     90            global $wp_query, $comment; 
    8991            $old_query = $wp_query; 
     92            $old_comment_query = $GLOBALS['comment'] = $comment; 
     93            unset( $comment, $GLOBALS['comment'] ); 
    9094 
    9195            $wp_query = new WP_Query( array( 
     
    99103 
    100104            $wp_query = $old_query; 
     105            $GLOBALS['comment'] = $old_comment_query; 
    101106 
    102107            if ( $instance['links'] !== 'none' ): 
Note: See TracChangeset for help on using the changeset viewer.