Changeset 594155
- Timestamp:
- 09/03/2012 07:48:25 PM (14 years ago)
- Location:
- author-post-ratings/trunk
- Files:
-
- 5 edited
-
author-post-ratings.php (modified) (19 diffs)
-
languages/default.mo (modified) (previous)
-
languages/default.po (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
-
screenshot-3.png (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
author-post-ratings/trunk/author-post-ratings.php
r585350 r594155 4 4 Plugin URI: http://philipnewcomer.net/wordpress-plugins/author-post-ratings/ 5 5 Description: Allows a post author to add a simple 5-star rating to posts. 6 Version: 1. 06 Version: 1.1 7 7 Author: Philip Newcomer 8 8 Author URI: http://philipnewcomer.net … … 36 36 { 37 37 $defaults = array( 38 'label_text' => __( 'Rating:', 'author-post-ratings' ), 38 39 '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 41 42 ); 42 43 return $defaults; … … 53 54 54 55 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. */ 56 57 function pn_apr_settings_init() 57 58 { … … 59 60 global $pn_apr_settings; 60 61 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 ); 68 71 } 69 72 } … … 90 93 function the_author_post_rating( $post_id = null, $return = false ) 91 94 { 95 global $pn_apr_settings; 96 92 97 // if no post ID is sent, try to obtain it ourselves. 93 98 if ( $post_id == null ) $post_id = get_the_ID(); … … 97 102 if ( $rating ) { 98 103 99 $settings = get_option( PN_APR_SETTINGS_KEY );100 104 $output = null; 101 105 102 106 $output .= '<div class="author-post-rating">'; 103 107 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> '; 105 109 106 110 $output .= '<span class="author-post-rating-stars" title="' . sprintf( __( '%1$d out of %2$d stars', 'author-post-ratings' ), $rating, 5 ) . '">'; … … 137 141 function pn_apr_the_content_filter( $content ) 138 142 { 139 $settings = get_option( PN_APR_SETTINGS_KEY );143 global $pn_apr_settings; 140 144 $post_type = get_post_type( get_the_ID() ); 141 145 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 142 150 // 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'] ) { 146 154 $content = '[author-post-rating]' . $content; 147 } elseif ( 'bottom' == $ settings['position_on_post'] ) {155 } elseif ( 'bottom' == $pn_apr_settings['position_on_post'] ) { 148 156 $content .= '[author-post-rating]'; 149 157 } … … 168 176 function pn_apr_add_meta_boxes() 169 177 { 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 ) { 173 181 add_meta_box( 174 182 'pn_apr_meta_box', … … 196 204 echo '<option value="unrated"' . selected( $current_post_rating, 0, false ) . '>' . __( 'Unrated', 'author-post-ratings' ) . '</option>'; 197 205 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>'; 199 207 } 200 208 echo '</select>'; … … 236 244 237 245 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' ); 238 247 add_settings_field( 'label_text', __('Label text', 'author-post-ratings'), 'pn_apr_settings_field_label_text', 'pn_apr_settings', 'appearance' ); 239 248 add_settings_field( 'post_types', __('Post types enabled', 'author-post-ratings'), 'pn_apr_settings_field_post_types', 'pn_apr_settings', 'post-types' ); … … 274 283 <?php 275 284 /* 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>'; 277 286 ?> 278 287 … … 283 292 284 293 function pn_apr_settings_validation( $input ) 285 { 294 { 286 295 // Get defaults in case data isn't valid 287 296 $defaults = pn_apr_get_defaults(); 297 298 // label_text: Text area 299 300 $validated['label_text'] = wp_kses_post( (string) $input['label_text'] ); 288 301 289 302 // position_on_post: Radio button … … 307 320 } 308 321 309 // label: Text area310 311 $validated['label_text'] = wp_kses_post( (string) $input['label_text'] );312 313 322 // post_types_enabled: list of checkboxes 314 323 … … 317 326 if ( isset( $input['post_types_enabled'] ) ) { 318 327 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 ) { 320 329 321 if ( $ post_type_value == 'on' ) {330 if ( $current_post_type_value == 'on' ) { 322 331 323 $validated['post_types_enabled'][] = $ post_type_name;332 $validated['post_types_enabled'][] = $current_post_type_name; 324 333 325 334 } … … 329 338 } 330 339 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 331 351 return $validated; 332 352 } … … 336 356 function pn_apr_settings_field_position_on_post() 337 357 { 338 $settings = get_option( PN_APR_SETTINGS_KEY );358 global $pn_apr_settings; 339 359 ?> 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" /> 341 361 <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" /> 343 363 <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" /> 345 365 <label for="pn_apr_settings_position_on_post_shortcode"><?php _e("By shortcode only (don't automatically add to post)", 'author-post-ratings'); ?></label> 346 366 <?php … … 349 369 350 370 371 function 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 351 383 function pn_apr_settings_field_label_text() 352 384 { 353 $settings = get_option( PN_APR_SETTINGS_KEY );385 global $pn_apr_settings; 354 386 ?> 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'] ); ?>" /> 356 388 <?php 357 389 } … … 361 393 function pn_apr_settings_field_post_types() 362 394 { 363 $settings = get_option( PN_APR_SETTINGS_KEY );395 global $pn_apr_settings; 364 396 365 397 $builtin_post_types = array( 'post', 'page' ); … … 368 400 369 401 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="p ost_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 3 3 "Project-Id-Version: Author Post Ratings 1.0\n" 4 4 "Report-Msgid-Bugs-To: \n" 5 "POT-Creation-Date: 2012-0 8-13 15:58-0500\n"6 "PO-Revision-Date: 2012-0 8-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" 7 7 "Last-Translator: Philip Newcomer <filupn@gmail.com>\n" 8 8 "Language-Team: \n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_ e;_n\n"12 "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_n\n" 13 13 "X-Poedit-Basepath: .\n" 14 "X-Poedit-SearchPath-0: . .\n"14 "X-Poedit-SearchPath-0: .\n" 15 15 16 #: ../author-post-ratings.php:3916 #: author-post-ratings.php:38 17 17 msgid "Rating:" 18 18 msgstr "" 19 19 20 #: ../author-post-ratings.php:10620 #: author-post-ratings.php:110 21 21 #, php-format 22 22 msgid "%1$d out of %2$d stars" 23 23 msgstr "" 24 24 25 #: ../author-post-ratings.php:17525 #: author-post-ratings.php:183 26 26 msgid "Post Rating" 27 27 msgstr "" 28 28 29 #: ../author-post-ratings.php:19429 #: author-post-ratings.php:202 30 30 msgid "Choose a rating for this post:" 31 31 msgstr "" 32 32 33 #: ../author-post-ratings.php:19633 #: author-post-ratings.php:204 34 34 msgid "Unrated" 35 35 msgstr "" 36 36 37 #: ../author-post-ratings.php:19837 #: author-post-ratings.php:206 38 38 #, php-format 39 39 msgid "%1s Star" 40 40 msgstr "" 41 41 42 #: ../author-post-ratings.php:23342 #: author-post-ratings.php:241 43 43 msgid "Position" 44 44 msgstr "" 45 45 46 #: ../author-post-ratings.php:23446 #: author-post-ratings.php:242 47 47 msgid "Appearance" 48 48 msgstr "" 49 49 50 #: ../author-post-ratings.php:23550 #: author-post-ratings.php:243 51 51 msgid "Post Types" 52 52 msgstr "" 53 53 54 #: ../author-post-ratings.php:23754 #: author-post-ratings.php:245 55 55 msgid "Rating position on post" 56 56 msgstr "" 57 57 58 #: ../author-post-ratings.php:23858 #: author-post-ratings.php:247 59 59 msgid "Label text" 60 60 msgstr "" 61 61 62 #: ../author-post-ratings.php:23962 #: author-post-ratings.php:248 63 63 msgid "Post types enabled" 64 64 msgstr "" 65 65 66 #: ../author-post-ratings.php:248 ../author-post-ratings.php:25866 #: author-post-ratings.php:257 67 67 msgid "Author Post Ratings Settings" 68 68 msgstr "" 69 69 70 #: ../author-post-ratings.php:24870 #: author-post-ratings.php:257 71 71 msgid "Author Post Ratings" 72 72 msgstr "" 73 73 74 #: ../author-post-ratings.php:26174 #: author-post-ratings.php:270 75 75 #, php-format 76 76 msgid "" … … 82 82 msgstr "" 83 83 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 93 85 #, php-format 94 86 msgid "" … … 98 90 msgstr "" 99 91 100 #: ../author-post-ratings.php:341 101 msgid "Top of post" 92 #: author-post-ratings.php:377 93 #, php-format 94 msgid "" 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." 102 97 msgstr "" 103 104 #: ../author-post-ratings.php:343105 msgid "Bottom of post"106 msgstr ""107 108 #: ../author-post-ratings.php:345109 msgid "By shortcode only (don't automatically add to post)"110 msgstr "" -
author-post-ratings/trunk/readme.txt
r585350 r594155 4 4 Author URI: http://philipnewcomer.net 5 5 Donate link: http://philipnewcomer.net/donate/ 6 Tags: rating, author, stars7 Version: 1. 08 Stable tag: 1. 06 Tags: rating, post, author, stars, custom post type, custom post types, post type 7 Version: 1.1 8 Stable tag: 1.1 9 9 Requires at least: 3.1 10 10 Tested up to: 3.4.1 … … 20 20 == Installation == 21 21 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. 23 23 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 24 If you're not familiar with installing WordPress plugins, follow these steps to install the plugin: 25 26 = Automatic Installation = 27 28 1. Login to your WordPress dashboard, and go to Plugins->Add New. 29 2. In the Search box, type in 'Author Post Ratings', and click 'Search Plugins'. 30 3. *Author Post Ratings* should be the first item in the list. Click on 'Install Now'. 31 4. 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 35 1. Download the plugin to your computer, and unzip it. 36 2. Using an FTP program, upload the 'author-post-ratings' folder to your `/wp-content/plugins/` directory. 37 3. Activate the plugin through the 'Plugins' menu in WordPress. 38 39 = Manual Installation Via WordPress Upload = 40 41 1. Download the plugin ZIP file to your computer. 42 2. In your WordPress dashboard, go to Plugins->Add New. 43 3. Click on the 'Upload' link at the top. 44 4. In the file selection box, select the plugin ZIP file on your computer, and click on 'Install Now'. 45 5. WordPress will upload and install the plugin. Click on the 'Activate Plugin' link, and you're in business! 27 46 28 47 == Frequently Asked Questions == … … 50 69 [plugin homepage URL]: http://philipnewcomer.net/wordpress-plugins/author-post-ratings/ 51 70 71 == Translating the Plugin == 72 73 No 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 52 75 == Screenshots == 53 76
Note: See TracChangeset
for help on using the changeset viewer.