Plugin Directory

Changeset 594155


Ignore:
Timestamp:
09/03/2012 07:48:25 PM (14 years ago)
Author:
philip.newcomer
Message:

Updating files to version 1.1

Location:
author-post-ratings/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • author-post-ratings/trunk/author-post-ratings.php

    r585350 r594155  
    44Plugin URI: http://philipnewcomer.net/wordpress-plugins/author-post-ratings/
    55Description: Allows a post author to add a simple 5-star rating to posts.
    6 Version: 1.0
     6Version: 1.1
    77Author: Philip Newcomer
    88Author URI: http://philipnewcomer.net
     
    3636{
    3737    $defaults = array(
     38        'label_text' => __( 'Rating:', 'author-post-ratings' ),
    3839        'position_on_post' => 'top', // Options: top, bottom, or shortcode
    39         'label_text' => __( 'Rating:', 'author-post-ratings' ),
    40         'post_types_enabled' => array( 'post' )
     40        'post_types_enabled' => array( 'post' ),
     41        'show_only_on_singular' => false
    4142    );
    4243    return $defaults;
     
    5354
    5455
    55 /* Load settings from database; If no settings have been saved, use default settings and update database. */
     56/* Load settings from database; If no settings have been saved, use default settings. */
    5657function pn_apr_settings_init()
    5758{
     
    5960    global $pn_apr_settings;
    6061   
    61     // Load saved settings from the database, if they exist
    62     $pn_apr_settings = get_option( PN_APR_SETTINGS_KEY );
    63    
    64     // If there were no settings saved, get defaults and save them.
    65     if ( false == $pn_apr_settings ) {
    66         $pn_apr_settings = pn_apr_get_defaults();
    67         update_option( PN_APR_SETTINGS_KEY, $pn_apr_settings );
     62    // Load settings defaults
     63    $pn_apr_default_settings = pn_apr_get_defaults();
     64   
     65    // Load saved settings from the database. If there are no saved settings, save and use defaults
     66    if ( ! $pn_apr_settings = get_option( PN_APR_SETTINGS_KEY ) ) {
     67        update_option( PN_APR_SETTINGS_KEY, $pn_apr_default_settings );
     68        $pn_apr_settings = $pn_apr_default_settings;
     69    } else {
     70        $pn_apr_settings = array_merge( $pn_apr_default_settings, $pn_apr_settings );
    6871    }
    6972}
     
    9093function the_author_post_rating( $post_id = null, $return = false )
    9194{
     95    global $pn_apr_settings;
     96   
    9297    // if no post ID is sent, try to obtain it ourselves.
    9398    if ( $post_id == null ) $post_id = get_the_ID();
     
    97102    if ( $rating ) {
    98103       
    99         $settings = get_option( PN_APR_SETTINGS_KEY );
    100104        $output = null;
    101105       
    102106        $output .= '<div class="author-post-rating">';
    103107   
    104         $output .= '<span class="author-post-rating-label">' . esc_attr( $settings['label_text'] ) . '</span> ';
     108        $output .= '<span class="author-post-rating-label">' . esc_attr( $pn_apr_settings['label_text'] ) . '</span> ';
    105109       
    106110        $output .= '<span class="author-post-rating-stars" title="' . sprintf( __( '%1$d out of %2$d stars', 'author-post-ratings' ), $rating, 5 ) . '">';
     
    137141function pn_apr_the_content_filter( $content )
    138142{   
    139     $settings = get_option( PN_APR_SETTINGS_KEY );
     143    global $pn_apr_settings;
    140144    $post_type = get_post_type( get_the_ID() );
    141145   
     146    // If the 'show only on single post' setting is turned on, respect that
     147    if ( $pn_apr_settings['show_only_on_singular'] == true && ! is_singular() )
     148        return $content;
     149   
    142150    // Only add the rating shortcode if this post type is enabled in the settings. A user may have added a rating to a post, and then turned off the rating for that post type.
    143     if ( in_array( $post_type, $settings['post_types_enabled'] ) ) {
    144    
    145         if ( 'top' == $settings['position_on_post'] ) {
     151    if ( in_array( $post_type, $pn_apr_settings['post_types_enabled'] ) ) {
     152   
     153        if ( 'top' == $pn_apr_settings['position_on_post'] ) {
    146154            $content = '[author-post-rating]' . $content;
    147         } elseif ( 'bottom' == $settings['position_on_post'] ) {
     155        } elseif ( 'bottom' == $pn_apr_settings['position_on_post'] ) {
    148156            $content .= '[author-post-rating]';
    149157        }
     
    168176function pn_apr_add_meta_boxes()
    169177{
    170     $settings = get_option( PN_APR_SETTINGS_KEY );
    171    
    172     foreach ( $settings['post_types_enabled'] as $post_type_name ) {
     178    global $pn_apr_settings;
     179   
     180    foreach ( $pn_apr_settings['post_types_enabled'] as $post_type_name ) {
    173181        add_meta_box(
    174182            'pn_apr_meta_box',
     
    196204    echo '<option value="unrated"' . selected( $current_post_rating, 0, false ) . '>' . __( 'Unrated', 'author-post-ratings' ) . '</option>';
    197205    for ( $i = 1; $i <= 5; $i++ ) {
    198         echo '<option value="' . $i . '"' . selected( $current_post_rating, $i, false ) . '>' . sprintf( _n( '%1s Star', '%1s Stars', $i, 'pn_apr' ), $i ) . '</option>';
     206        echo '<option value="' . $i . '"' . selected( $current_post_rating, $i, false ) . '>' . sprintf( _n( '%1s Star', '%1s Stars', $i, 'author-post-ratings' ), $i ) . '</option>';
    199207    }
    200208    echo '</select>';
     
    236244
    237245    add_settings_field( 'position_on_post', __('Rating position on post', 'author-post-ratings'), 'pn_apr_settings_field_position_on_post', 'pn_apr_settings', 'position' );
     246    add_settings_field( 'show_only_on_singular', null, 'pn_apr_settings_field_show_only_on_singular', 'pn_apr_settings', 'position' );
    238247    add_settings_field( 'label_text', __('Label text', 'author-post-ratings'), 'pn_apr_settings_field_label_text', 'pn_apr_settings', 'appearance' );
    239248    add_settings_field( 'post_types', __('Post types enabled', 'author-post-ratings'), 'pn_apr_settings_field_post_types', 'pn_apr_settings', 'post-types' );
     
    274283    <?php
    275284    /* For debugging: */
    276     //echo '<h3>Settings Debugging Info</h3><pre>'; print_r( get_option( PN_APR_SETTINGS_KEY ) ); echo '</pre>';
     285    //global $pn_apr_settings; echo '<h2>Settings Debugging Info</h2><h3>Current settings</h3><pre>'; print_r( $pn_apr_settings ); echo '</pre><h3>Saved settings</h3><pre>'; print_r( get_option( PN_APR_SETTINGS_KEY ) ); echo '</pre><h3>Default settings</h3><pre>'; print_r( pn_apr_get_defaults() ); echo '</pre>';
    277286    ?>
    278287   
     
    283292
    284293function pn_apr_settings_validation( $input )
    285 {   
     294{
    286295    // Get defaults in case data isn't valid
    287296    $defaults = pn_apr_get_defaults();
     297   
     298    // label_text: Text area
     299   
     300        $validated['label_text'] = wp_kses_post( (string) $input['label_text'] );
    288301   
    289302    // position_on_post: Radio button
     
    307320        }
    308321   
    309     // label: Text area
    310    
    311         $validated['label_text'] = wp_kses_post( (string) $input['label_text'] );
    312    
    313322    // post_types_enabled: list of checkboxes
    314323       
     
    317326        if ( isset( $input['post_types_enabled'] ) ) {
    318327           
    319             foreach ( $input['post_types_enabled'] as $post_type_name => $post_type_value ) {
     328            foreach ( $input['post_types_enabled'] as $current_post_type_name => $current_post_type_value ) {
    320329               
    321                 if ( $post_type_value == 'on' ) {
     330                if ( $current_post_type_value == 'on' ) {
    322331                   
    323                     $validated['post_types_enabled'][] = $post_type_name;
     332                    $validated['post_types_enabled'][] = $current_post_type_name;
    324333                   
    325334                }
     
    329338        }
    330339   
     340    // show_only_on_singular: Checkbox
     341
     342        if ( isset( $input['show_only_on_singular'] ) && $input['show_only_on_singular'] == 'on' ) {
     343            $validated['show_only_on_singular'] = true;
     344        } else {
     345            $validated['show_only_on_singular'] = false;
     346        }
     347   
     348    // For debugging:
     349    //echo '<h3>Input</h3><pre>'; print_r( $input ); echo '</pre><h3>Validated</h3><pre>'; print_r( $validated ); echo '</pre><h3>Defaults</h3><pre>'; print_r( pn_apr_get_defaults() ); echo '</pre>'; die();
     350   
    331351    return $validated;
    332352}
     
    336356function pn_apr_settings_field_position_on_post()
    337357{
    338     $settings = get_option( PN_APR_SETTINGS_KEY );
     358    global $pn_apr_settings;
    339359?>
    340 <input type="radio" name="pn_apr_settings[position_on_post]" value="top" id="pn_apr_settings_position_on_post_top"<?php checked( 'top', $settings['position_on_post'] ); ?>></input>
     360<input type="radio" name="pn_apr_settings[position_on_post]" id="pn_apr_settings_position_on_post_top"<?php checked( 'top', $pn_apr_settings['position_on_post'] ); ?> value="top" />
    341361    <label for="pn_apr_settings_position_on_post_top"><?php _e('Top of post', 'author-post-ratings'); ?></label><br />
    342 <input type="radio" name="pn_apr_settings[position_on_post]" value="bottom" id="pn_apr_settings_position_on_post_bottom"<?php checked( 'bottom', $settings['position_on_post'] ); ?>></input>
     362<input type="radio" name="pn_apr_settings[position_on_post]" id="pn_apr_settings_position_on_post_bottom"<?php checked( 'bottom', $pn_apr_settings['position_on_post'] ); ?> value="bottom" />
    343363    <label for="pn_apr_settings_position_on_post_bottom"><?php _e('Bottom of post', 'author-post-ratings'); ?></label><br />
    344 <input type="radio" name="pn_apr_settings[position_on_post]" value="shortcode" id="pn_apr_settings_position_on_post_shortcode"<?php checked( 'shortcode', $settings['position_on_post'] ); ?>></input>
     364<input type="radio" name="pn_apr_settings[position_on_post]" id="pn_apr_settings_position_on_post_shortcode"<?php checked( 'shortcode', $pn_apr_settings['position_on_post'] ); ?> value="shortcode" />
    345365    <label for="pn_apr_settings_position_on_post_shortcode"><?php _e("By shortcode only (don't automatically add to post)", 'author-post-ratings'); ?></label>
    346366<?php
     
    349369
    350370
     371function pn_apr_settings_field_show_only_on_singular()
     372{
     373    global $pn_apr_settings;
     374?>
     375<input type="checkbox" name="pn_apr_settings[show_only_on_singular]" id="pn_apr_settings_show_only_on_singular" <?php checked( $pn_apr_settings['show_only_on_singular'] ); ?> />
     376<label for="pn_apr_settings_show_only_on_singular"><?php _e('Show only in singular post view', 'author-post-ratings'); ?></label>
     377<p class="description"><?php printf( __('Turn this on if you want to hide the post rating on archive pages, and your theme uses the %1$s quicktag for post excerpts instead of true excerpts.', 'author-post-ratings'), '<code>' . htmlentities('<!--more-->') . '</code>' ); ?></p>
     378<?php
     379}
     380
     381
     382
    351383function pn_apr_settings_field_label_text()
    352384{
    353     $settings = get_option( PN_APR_SETTINGS_KEY );
     385    global $pn_apr_settings;
    354386?>
    355 <input type="text" name="pn_apr_settings[label_text]" id="pn_apr_settings_description_text" value="<?php echo esc_attr( $settings['label_text'] ); ?>" />
     387<input type="text" name="pn_apr_settings[label_text]" id="pn_apr_settings_description_text" value="<?php echo esc_attr( $pn_apr_settings['label_text'] ); ?>" />
    356388<?php
    357389}
     
    361393function pn_apr_settings_field_post_types()
    362394{
    363     $settings = get_option( PN_APR_SETTINGS_KEY );
     395    global $pn_apr_settings;
    364396   
    365397    $builtin_post_types = array( 'post', 'page' );
     
    368400   
    369401    foreach ( $post_types_available as $post_type ) {
    370         echo '<div><input type="checkbox" id="post_types_enabled-' . $post_type . '" name="pn_apr_settings[post_types_enabled][' . $post_type . ']" ' . checked( in_array( $post_type, $settings['post_types_enabled'] ), true, false) . ' />';
    371         echo ' <label for="post_types_enabled-' . $post_type . '">' . $post_type . '</label></div>';
    372     }
    373 }
     402        echo '<div><input type="checkbox" name="pn_apr_settings[post_types_enabled][' . $post_type . ']" ' . checked( in_array( $post_type, $pn_apr_settings['post_types_enabled'] ), true, false) . ' id="pn_apr_settings_post_types_enabled-' . $post_type . '" />';
     403        echo ' <label for="pn_apr_settings_post_types_enabled-' . $post_type . '">' . $post_type . '</label></div>';
     404    }
     405}
  • author-post-ratings/trunk/languages/default.po

    r585350 r594155  
    33"Project-Id-Version: Author Post Ratings 1.0\n"
    44"Report-Msgid-Bugs-To: \n"
    5 "POT-Creation-Date: 2012-08-13 15:58-0500\n"
    6 "PO-Revision-Date: 2012-08-13 15:58-0500\n"
     5"POT-Creation-Date: 2012-09-03 15:41-0500\n"
     6"PO-Revision-Date: 2012-09-03 15:42-0500\n"
    77"Last-Translator: Philip Newcomer <filupn@gmail.com>\n"
    88"Language-Team: \n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e;_n\n"
     12"X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_n\n"
    1313"X-Poedit-Basepath: .\n"
    14 "X-Poedit-SearchPath-0: ..\n"
     14"X-Poedit-SearchPath-0: .\n"
    1515
    16 #: ../author-post-ratings.php:39
     16#: author-post-ratings.php:38
    1717msgid "Rating:"
    1818msgstr ""
    1919
    20 #: ../author-post-ratings.php:106
     20#: author-post-ratings.php:110
    2121#, php-format
    2222msgid "%1$d out of %2$d stars"
    2323msgstr ""
    2424
    25 #: ../author-post-ratings.php:175
     25#: author-post-ratings.php:183
    2626msgid "Post Rating"
    2727msgstr ""
    2828
    29 #: ../author-post-ratings.php:194
     29#: author-post-ratings.php:202
    3030msgid "Choose a rating for this post:"
    3131msgstr ""
    3232
    33 #: ../author-post-ratings.php:196
     33#: author-post-ratings.php:204
    3434msgid "Unrated"
    3535msgstr ""
    3636
    37 #: ../author-post-ratings.php:198
     37#: author-post-ratings.php:206
    3838#, php-format
    3939msgid "%1s Star"
    4040msgstr ""
    4141
    42 #: ../author-post-ratings.php:233
     42#: author-post-ratings.php:241
    4343msgid "Position"
    4444msgstr ""
    4545
    46 #: ../author-post-ratings.php:234
     46#: author-post-ratings.php:242
    4747msgid "Appearance"
    4848msgstr ""
    4949
    50 #: ../author-post-ratings.php:235
     50#: author-post-ratings.php:243
    5151msgid "Post Types"
    5252msgstr ""
    5353
    54 #: ../author-post-ratings.php:237
     54#: author-post-ratings.php:245
    5555msgid "Rating position on post"
    5656msgstr ""
    5757
    58 #: ../author-post-ratings.php:238
     58#: author-post-ratings.php:247
    5959msgid "Label text"
    6060msgstr ""
    6161
    62 #: ../author-post-ratings.php:239
     62#: author-post-ratings.php:248
    6363msgid "Post types enabled"
    6464msgstr ""
    6565
    66 #: ../author-post-ratings.php:248 ../author-post-ratings.php:258
     66#: author-post-ratings.php:257
    6767msgid "Author Post Ratings Settings"
    6868msgstr ""
    6969
    70 #: ../author-post-ratings.php:248
     70#: author-post-ratings.php:257
    7171msgid "Author Post Ratings"
    7272msgstr ""
    7373
    74 #: ../author-post-ratings.php:261
     74#: author-post-ratings.php:270
    7575#, php-format
    7676msgid ""
     
    8282msgstr ""
    8383
    84 #: ../author-post-ratings.php:262
    85 msgid "Donate Now!"
    86 msgstr ""
    87 
    88 #: ../author-post-ratings.php:271
    89 msgid "Usage"
    90 msgstr ""
    91 
    92 #: ../author-post-ratings.php:272
     84#: author-post-ratings.php:281
    9385#, php-format
    9486msgid ""
     
    9890msgstr ""
    9991
    100 #: ../author-post-ratings.php:341
    101 msgid "Top of post"
     92#: author-post-ratings.php:377
     93#, php-format
     94msgid ""
     95"Turn this on if you want to hide the post rating on archive pages, and your "
     96"theme uses the %1$s quicktag for post excerpts instead of true excerpts."
    10297msgstr ""
    103 
    104 #: ../author-post-ratings.php:343
    105 msgid "Bottom of post"
    106 msgstr ""
    107 
    108 #: ../author-post-ratings.php:345
    109 msgid "By shortcode only (don't automatically add to post)"
    110 msgstr ""
  • author-post-ratings/trunk/readme.txt

    r585350 r594155  
    44Author URI: http://philipnewcomer.net
    55Donate link: http://philipnewcomer.net/donate/
    6 Tags: rating, author, stars
    7 Version: 1.0
    8 Stable tag: 1.0
     6Tags: rating, post, author, stars, custom post type, custom post types, post type
     7Version: 1.1
     8Stable tag: 1.1
    99Requires at least: 3.1
    1010Tested up to: 3.4.1
     
    2020== Installation ==
    2121
    22 To manually install the plugin, follow these steps:
     22*Author Post Ratings* is installed just like any other WordPress plugin. No configuration is required, but if you wish, you may change the plugin settings at Settings->Author Post Ratings.
    2323
    24 1. Unzip the plugin, and upload the 'author-post-ratings' folder to your `/wp-content/plugins/` directory
    25 2. Activate the plugin through the 'Plugins' menu in WordPress
    26 3. Optional: Go to Settings->Author Post Ratings and configure the plugin settings
     24If you're not familiar with installing WordPress plugins, follow these steps to install the plugin:
     25
     26= Automatic Installation =
     27
     281. Login to your WordPress dashboard, and go to Plugins->Add New.
     292. In the Search box, type in 'Author Post Ratings', and click 'Search Plugins'.
     303. *Author Post Ratings* should be the first item in the list. Click on 'Install Now'.
     314. WordPress will download and install the plugin. Click on the 'Activate Plugin' link, and you're in business!
     32
     33= Manual Installation Via FTP =
     34
     351. Download the plugin to your computer, and unzip it.
     362. Using an FTP program, upload the 'author-post-ratings' folder to your `/wp-content/plugins/` directory.
     373. Activate the plugin through the 'Plugins' menu in WordPress.
     38
     39= Manual Installation Via WordPress Upload =
     40
     411. Download the plugin ZIP file to your computer.
     422. In your WordPress dashboard, go to Plugins->Add New.
     433. Click on the 'Upload' link at the top.
     444. In the file selection box, select the plugin ZIP file on your computer, and click on 'Install Now'.
     455. WordPress will upload and install the plugin. Click on the 'Activate Plugin' link, and you're in business!
    2746
    2847== Frequently Asked Questions ==
     
    5069[plugin homepage URL]: http://philipnewcomer.net/wordpress-plugins/author-post-ratings/
    5170
     71== Translating the Plugin ==
     72
     73No translation is needed for most sites. The post rating label text can be changed in the plugin settings. However, if someone wishes to translate the settings interface, the plugin is fully internationalized and ready for translation. There is a .po and a .mo file included in the plugin's 'languages' directory for your convenience.
     74
    5275== Screenshots ==
    5376
Note: See TracChangeset for help on using the changeset viewer.