• Resolved makoun

    (@makoun)


    Is it possible to use custom stars? Or more precisly because we are living 2014, I would like to use font icon or SVG as stars instead of those prebuild images that look bit bad on retina displays. Is this possible? It would be much better way if the plugin would print just divs and then images would be provided via CSS instead of printing images. Then for themers it would very easy to control the look of stars/images.

    https://www.ads-software.com/plugins/wp-postratings/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lester Chan

    (@gamerz)

    That is my plan eventually but unfortunately I have no time to do it since I have a full time job currently and over the past few years

    If you can hire a dev to fork my plugin https://github.com/lesterchan/wp-postratings and implement it there would be great!

    // WP Post Ratings Override plugin images, from plugin source
    	$postratings_max = intval(get_option('postratings_max'));
    	$postratings_ajax_style = get_option('postratings_ajax_style');
    	$postratings_custom = intval(get_option('postratings_customrating'));
    	if($postratings_custom) {
    		for($i = 1; $i <= $postratings_max; $i++) {
    			$postratings_javascript .= 'var ratings_'.$i.'_mouseover_image=new Image();ratings_'.$i.'_mouseover_image.src=ratingsL10n.plugin_url+"/images/"+ratingsL10n.image+"/rating_'.$i.'_over."+ratingsL10n.image_ext;';
    		}
    	} else {
    		$postratings_javascript = 'var ratings_mouseover_image=new Image();ratings_mouseover_image.src=ratingsL10n.plugin_url+"/images/"+ratingsL10n.image+"/rating_over."+ratingsL10n.image_ext;';
    	}
    
    	wp_deregister_script( 'wp-postratings' );
    	wp_enqueue_script('wp-postratings', plugins_url('wp-postratings/postratings-js.js'), array('jquery'), WP_POSTRATINGS_VERSION, true);
    	wp_localize_script('wp-postratings', 'ratingsL10n', array(
    		'plugin_url' => get_bloginfo('stylesheet_directory') . '/images/wp-postratings/',
    		'ajax_url' => admin_url('admin-ajax.php'),
    		'text_wait' => __('Please rate only 1 post at a time.', 'wp-postratings'),
    		'image' => get_option('postratings_image'),
    		'image_ext' => 'gif',
    		'max' => $postratings_max,
    		'show_loading' => intval($postratings_ajax_style['loading']),
    		'show_fading' => intval($postratings_ajax_style['fading']),
    		'custom' => $postratings_custom,
    		'l10n_print_after' => $postratings_javascript
    	));
    add_filter( 'expand_ratings_template', 'prefix_ratings_fix', 999, 1 ); // WP-Ratings Filter
    // Fixing WP-Ratings plugin initial output, to match Design
    function prefix_ratings_fix($html) {
    	$search = plugins_url( '/wp-postratings/images/stars_crystal/' );
    	$replace = get_bloginfo('stylesheet_directory') . '/images/wp-postratings/images/stars_crystal/';
    
    	$html = str_replace($search, $replace, $html);
    
    	return $html;
    }

    Updates the above code to work on the latest version of wordpress.
    Just copy/paste into the functions.php and edit as required.
    Allows the plugin to update as per normal without affecting the custom images used.

    // WP Post Ratings Override plugin images, from plugin source
    	function my_deregister_script() {
    		$postratings_max = intval(get_option('postratings_max'));
    		$postratings_ajax_style = get_option('postratings_ajax_style');
    		$postratings_custom = intval(get_option('postratings_customrating'));
    		if($postratings_custom) {
    			for($i = 1; $i <= $postratings_max; $i++) {
    				$postratings_javascript .= 'var ratings_'.$i.'_mouseover_image=new Image();ratings_'.$i.'_mouseover_image.src=ratingsL10n.plugin_url+"/images/"+ratingsL10n.image+"/rating_'.$i.'_over."+ratingsL10n.image_ext;';
    			}
    		} else {
    			$postratings_javascript = 'var ratings_mouseover_image=new Image();ratings_mouseover_image.src=ratingsL10n.plugin_url+"/images/"+ratingsL10n.image+"/rating_over."+ratingsL10n.image_ext;';
    		}
    		wp_deregister_script( 'wp-postratings' );
    		wp_enqueue_script('wp-postratings', plugins_url('wp-postratings/postratings-js.js'), array('jquery'), WP_POSTRATINGS_VERSION, true);
    		wp_localize_script('wp-postratings', 'ratingsL10n', array(
    			'plugin_url' => get_bloginfo('stylesheet_directory') . '/img/ratings',
    			'ajax_url' => admin_url('admin-ajax.php'),
    			'text_wait' => __('Please rate only 1 post at a time.', 'wp-postratings'),
    			'image' => get_option('postratings_image'),
    			'image_ext' => 'gif',
    			'max' => $postratings_max,
    			'show_loading' => intval($postratings_ajax_style['loading']),
    			'show_fading' => intval($postratings_ajax_style['fading']),
    			'custom' => $postratings_custom,
    			'l10n_print_after' => $postratings_javascript
    		));
    	}
    	add_action( 'wp_print_scripts', 'my_deregister_script', 100 );
    	// Fixing WP-Ratings plugin initial output, to match Design
    	function prefix_ratings_fix($html) {
    		$search = plugins_url( '/wp-postratings/images/stars/' );
    		$replace = get_bloginfo('stylesheet_directory') . '/img/ratings/images/stars/';
    
    		$html = str_replace($search, $replace, $html);
    
    		return $html;
    	}
    	add_filter( 'expand_ratings_template', 'prefix_ratings_fix', 999, 1 ); // WP-Ratings Filter

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom stars images’ is closed to new replies.