lesterchan / wp-postratings

Adds an AJAX rating system for your WordPress blog's post/page.
https://wordpress.org/plugins/wp-postratings/
122 stars 82 forks source link

Allow Custom Rating Images To Be Put In Themes Folder #36

Open lesterchan opened 9 years ago

lesterchan commented 9 years ago

https://wordpress.org/support/topic/custom-rating-images-lost-on-plugin-upgrade?replies=1#post-6404160

ramiy commented 8 years ago

Actually, moving the custom images from the plugin folder to the theme folder is not so hard to develop.

The only issue that I see here is backward-compatibility.

ramiy commented 8 years ago

We can do I by introducing a registration mechanism to register images folder:

function add_custom_postratings_images_folder( $folders ) {
    $folders['stars_crystal'] = WP_PLUGIN_DIR.'/wp-postratings/images/stars_crystal';
    $folders['stars_dark']    = WP_PLUGIN_DIR.'/wp-postratings/images/stars_dark';
    return $folders;
} 
add_filter( 'wp_postratings_images', 'add_custom_postratings_images_folder' );

This way, the plugin will register all the default images in a single function and external developers will be able to register custom images located in themes on extended plugins.

ramiy commented 8 years ago

We can also extend this method to deprecate the 'wp_postratings_image_extension' filter and register all kinds of image extensions using an array:

function add_custom_postratings_images_folder( $folders ) {
    $folders['stars(png)']    = array( WP_PLUGIN_DIR.'/wp-postratings/images/stars(png)',    'png' );
    $folders['stars_crystal'] = array( WP_PLUGIN_DIR.'/wp-postratings/images/stars_crystal', 'gif' );
    $folders['stars_dark']    = array( WP_PLUGIN_DIR.'/wp-postratings/images/stars_dark',    'gif' );
    return $folders;
} 
add_filter( 'wp_postratings_images', 'add_custom_postratings_images_folder' );

This way we don't lose backwards compatibility.

lesterchan commented 8 years ago

I like the second idea!

likwrk commented 8 years ago

Why not just define image path

if( ! defined( 'RATINGS_IMG_DIR' ) ) {
    define( 'RATINGS_IMG_DIR', apply_filters( 'wp_postratings_image_dir', plugins_url('wp-postratings/images/') ) );
}
msxpro commented 7 years ago

lesterchan, you have plans to merge this to branch?

lesterchan commented 7 years ago

@msxpro this is not a pull request, so there is nothing to merge.

msxpro commented 7 years ago

Erhhh ... sorry, asking the question better, are there plans to implement this in pluguin? Because this was also a request I made a few times, when I posted that modification on the links in the list of ratings.

lesterchan commented 7 years ago

As of now, I have no plans because I have no time to do it. Feel free to submit a Pull Request =)

aparentMMS commented 5 years ago

ability to upload images would be great, save a step for our administrator to re-ftp images over and over after updates.