Create reset filter button in woocommerce - php

I'm using a theme which has an ajax filter for the product category pages, and it works really well.
The only thing is that the button wish is displayed, when someone is selecting filters, don't reset them, it directs the visitor back to the shop page. How can I change the logic of the button, that it would just reset the selected filters? So that the users stay on the page where they are? Because right now the button makes no sense.
Thx so far.
HTML
<div class="nm-shop-results-bar has-filters is-category">
<a href="http://localhost/amaoni/" id="nm-shop-filters-reset" data-shop-url="http://localhost/amaoni/">
<i class="nm-font nm-font-close2"></i>Filters active <span>(1)</span></a>
<a href="http://localhost/amaoni/" id="nm-shop-search-taxonomy-reset" data-shop-url="http://localhost/amaoni/"
<i class="nm-font nm-font-close2"></i>Showing <span>“Hundebetten”</span></a>
</div>
PHP
<?php
/**
* NM: Shop - Results bar/button
*/
defined( 'ABSPATH' ) || exit;
global $nm_theme_options;
$results_bar_class = '';
$results_bar_buttons = array();
// Filters
$filters_count = nm_get_active_filters_count();
if ( $filters_count ) {
$results_bar_class = ' has-filters';
$results_bar_buttons['filters'] = array(
'id' => 'nm-shop-filters-reset',
'title' => sprintf( esc_html__( 'Filters active %s(%s)%s', 'nm-framework' ), '<span>', $filters_count, '</span>' )
);
}
// Search
if ( ! empty( $_REQUEST['s'] ) ) { // Is search query set and not empty?
$results_bar_class .= ' is-search';
$results_bar_buttons['search_taxonomy'] = array(
'id' => 'nm-shop-search-taxonomy-reset',
'title' => sprintf( esc_html__( 'Search results for %s“%s”%s', 'nm-framework' ), '<span>', esc_html( $_REQUEST['s'] ), '</span>' )
);
}
// Taxonomy
else if ( is_product_taxonomy() ) {
$results_bar_buttons['search_taxonomy'] = array(
'id' => 'nm-shop-search-taxonomy-reset'
);
$current_term = $GLOBALS['wp_query']->get_queried_object();
if ( is_product_category() ) {
$results_bar_class .= ' is-category';
$results_bar_buttons['search_taxonomy']['title'] = sprintf( esc_html__( 'Showing %s“%s”%s', 'nm-framework' ), '<span>', esc_html( $current_term->name ), '</span>' );
} else {
$results_bar_class .= ' is-tag';
$results_bar_buttons['search_taxonomy']['title'] = sprintf( esc_html__( 'Products tagged %s“%s”%s', 'nm-framework' ), '<span>', esc_html( $current_term->name ), '</span>' );
}
}
if ( ! empty( $results_bar_buttons ) ) :
?>
<div class="nm-shop-results-bar <?php echo esc_attr( $results_bar_class ); ?>">
<?php
$shop_url = esc_url( get_permalink( wc_get_page_id( 'shop' ) ) );
foreach ( $results_bar_buttons as $button ) {
printf( '<i class="nm-font nm-font-close2"></i>%s',
$nm_theme_options['shop_filters_enable_ajax'] ? '#' : $shop_url,
$button['id'],
$shop_url,
$button['title']
);
}
?>
</div>
<?php endif; ?>
I think that's the code part which directs the users to the shop page, but i don't know how to change it, so that it just reset the selected filters.
<div class="nm-shop-results-bar <?php echo esc_attr( $results_bar_class ); ?>">
<?php
$shop_url = esc_url( get_permalink( wc_get_page_id( 'shop' ) ) );
foreach ( $results_bar_buttons as $button ) {
printf( '<i class="nm-font nm-font-close2"></i>%s',
$nm_theme_options['shop_filters_enable_ajax'] ? '#' : $shop_url,
$button['id'],
$shop_url,
$button['title']
);
}
?>
</div>
<?php endif; ?>
Javascript
if (self.filtersEnableAjax) {
/* Bind: Results bar - Filters reset link */
self.$shopWrap.on('click', '#nm-shop-filters-reset', function(e) {
e.preventDefault();
var resetUrl = location.href.replace(location.search, ''); // Get current URL without query-strings
self.shopGetPage(resetUrl);
});
/* Bind: Results bar - Search/taxonomy reset link */
self.$shopWrap.on('click', '#nm-shop-search-taxonomy-reset', function(e) {
e.preventDefault();
var $resetButton = $(this);
if ($resetButton.closest('.nm-shop-results-bar').hasClass('is-search')) {
// Search
var urlSearchParam = self.urlGetParameter('s'), // Check for the "s" parameter in the current page URL
// Search from external page: Get default/main shop URL (current URL may not be the default shop URL)
// Search from shop page: Get current URL without query-strings (current URL is a shop URL)
resetUrl = (urlSearchParam) ? $resetButton.data('shop-url') : location.href.replace(location.search, '');
} else {
// Category or tag
var resetUrl = $resetButton.data('shop-url'); // Get default/main shop URL
}
self.shopGetPage(resetUrl);
});
}
}

Related

Using the Woocommerce product gallery meta box on other post types

I would like to add a meta box to a custom post type that works like the product gallery meta box that Woocommerce uses. I actually have Woocommerce installed on this project.
I found the code that Woocommerce uses to create the product gallery meta box, and I can get the meta box to display, but the jQuery is not there to pull up the media lightbox that Wordpress uses to add images. I don't know if there is a hook I need to add or if I should enqueue a script?
Here is what I have so far (based on the WooCommerce code but altered for my use)
<?php
function add_mtg_meta_boxes() {
add_meta_box('mtg_hotel_gallery_meta_box', 'Hotel Gallery', 'setup_mtg_hotel_gallery_meta_box', 'meeting', 'side', 'low');
}
add_action('add_meta_boxes', 'add_mtg_meta_boxes');
function setup_mtg_hotel_gallery_meta_box($post) {
echo '<input type="hidden" name="mtg_hotel_gallery_meta_box_nonce" value="'. wp_create_nonce('mtg_hotel_gallery_meta_box'). '" />';
?>
<div id="product_images_container">
<ul class="product_images">
<?php
if ( metadata_exists( 'post', $post->ID, '_product_image_gallery' ) ) {
$product_image_gallery = get_post_meta( $post->ID, '_product_image_gallery', true );
} else {
// Backwards compatibility.
$attachment_ids = get_posts( 'post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids&meta_key=_woocommerce_exclude_image&meta_value=0' );
$attachment_ids = array_diff( $attachment_ids, array( get_post_thumbnail_id() ) );
$product_image_gallery = implode( ',', $attachment_ids );
}
$attachments = array_filter( explode( ',', $product_image_gallery ) );
$update_meta = false;
$updated_gallery_ids = array();
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment_id ) {
$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );
// if attachment is empty skip
if ( empty( $attachment ) ) {
$update_meta = true;
continue;
}
echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
' . $attachment . '
<ul class="actions">
<li>' . __( 'Delete', 'woocommerce' ) . '</li>
</ul>
</li>';
// rebuild ids to be saved
$updated_gallery_ids[] = $attachment_id;
}
// need to update product meta to set new gallery ids
if ( $update_meta ) {
update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) );
}
}
?>
</ul>
<input type="hidden" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( $product_image_gallery ); ?>" />
</div>
<p class="add_product_images hide-if-no-js">
<?php _e( 'Add product gallery images', 'woocommerce' ); ?>
</p>
<?php
}
function save_mtg_hotel_gallery_meta_box($post_id) {
// check nonce
if (!isset($_POST['mtg_gallery_meta_box_nonce']) || !wp_verify_nonce($_POST['mtg_gallery_meta_box_nonce'], 'mtg_gallery_meta_box')) {
return $post_id;
}
// check capabilities
if ('meeting' == $_POST['post_type']) {
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
// exit on autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
$attachment_ids = isset( $_POST['product_image_gallery'] ) ? array_filter( explode( ',', wc_clean( $_POST['product_image_gallery'] ) ) ) : array();
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) );
}
add_action('save_post', 'save_mtg_hotel_gallery_meta_box');
?>
First To Enable the Wordpress Wp Media Uploader you have to enqueue the media js by using wp_enqueue_media(); inside you functions.php admin_enqueue_scripts hook,
function enqueue_media_uploader() {
wp_enqueue_media();
}
add_action( 'admin_enqueue_scripts', 'enqueue_media_uploader' );
and then you have to assign an id to your anchor which clicked media.uploader
will pop up.Like this...
<?php _e( 'Add product gallery images', 'woocommerce' ); ?>
And then to bind the onclick listener to add_product_image id add this line of code to your custom js file...
jQuery('#add_product_image').click(function(e) {
e.preventDefault();
var image = wp.media({
title: 'Upload Image',
multiple: false
}).open()
.on('select', function(e){
var uploaded_image = image.state().get('selection').first();
var image_url = uploaded_image.toJSON().url;
var image_id = uploaded_image.toJSON().id;
});
});
Here image_url var is uploaded or selected image src url and image_id var is id of the image or attachment.

Link Woocommerce Products directly to external site (skip detailpage)

WP: 3.71
Theme: Jupiter (artbees) v.3.02
URL: http://thefastlearners.com/store/
Hi all,
I have some Woocommerce products that are external linking out to amazon or other sites.
My goal is to link these products to their external pages directly from the store page, without the detailpage!
Already tried the visibility option extension which didn’t change a thing.
Here is the original content-product.php excerpt:
`
$mk_add_to_cart = 'id ) ).'" class="add_to_cart_button">'. apply_filters( 'out_of_stock_add_to_cart_text', ( 'READ MORE', 'woocommerce' ) ).'';
$out_of_stock_badge = ''.( 'OUT OF STOCK', 'woocommerce' ).'';
}
else { ?>
switch ( $product->product_type ) {
case "external" :
$link = apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );
$label = apply_filters( 'external_add_to_cart_text', __( 'Read More', 'woocommerce' ) );
$icon_class = 'mk-moon-search-3';
break;
default :
$link = apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );
$label = apply_filters( 'add_to_cart_text', __( 'ADD TO CART', 'woocommerce' ) );
$icon_class = 'mk-moon-cart-plus';
break;
}
if ( $product->product_type != 'external' ) {
$mk_add_to_cart = '<i class="'.$icon_class.'"></i>'. $label.'';
}
else {
$mk_add_to_cart = '';
}
}`
Which I changed to
´<?php
$mk_add_to_cart = &#039**;';
$out_of_stock_badge = '<span class="mk-out-stock">'.__( 'OUT OF STOCK', 'woocommerce' ).'</span>';
}
else { ?>
switch ( $product->product_type ) {
case "external" :
$link = apply_filters( 'external_add_to_cart_url', esc_url( $product_url ) );
$label = apply_filters( 'external_add_to_cart_text', __('Read More', 'woocommerce') );
$icon_class = 'mk-moon-search-3';
break;
default :
$link = apply_filters( 'add_to_cart_url', esc_url( $product_url ) );
$label = apply_filters( 'add_to_cart_text', __( 'ADD TO CART', 'woocommerce' ) );
$icon_class = 'mk-moon-cart-plus';
break;
}
if ( $product->product_type != 'external' ) {
$mk_add_to_cart = '<i class="'.$icon_class.'"></i>'. $label.'';
}
else {
$mk_add_to_cart = '';
}`
Without any results except that I don’t get any button to add anything.
from the external.php template I already figured out that the command should be something like
<?php echo esc_url( $product_url ); ?>
but I don’t get where to put/link it.
Would be wonderful if you can help me out here. Once I got that working I can change the links of the title and image myself.
Thanks,
Mattis
You should try $product->product_url instead of plain $product_url.
That worked for me on the content-product.php page.

Buddypress plugin bug - XML to PHP

It is an external group blogs plugin
It gives group creators and administrators on your BuddyPress install the ability to attach external blog RSS feeds to groups.
Blog posts will appear within the activity stream for the group.
New posts will automatically be pulled every hour, or every 30 minutes if someone specifically visits a group page.
There are so many bugs that I found.
1) it is not fetching feeds automatically
2) if I try to manually updates feeds it is reposting the same entries, I mean it is not fetching new feeds.
3) WordPress admin bar is also not working properly with this plugin.
This plugin contains 2 webpages.
First and the main page is loader.php
<?php
/*
Plugin Name: External Group Blogs
Plugin URI: http://wordpress.org/extend/plugins/external-group-blogs/
Description: Allow group creators to supply external blog RSS feeds that will attach future posts on blogs to a group.
*/
/* Only load the plugin functions if BuddyPress is loaded and initialized. */
function bp_groupblogs_init() {
require( dirname( __FILE__ ) . '/bp-groups-externalblogs.php' );
}
add_action( 'bp_init', 'bp_groupblogs_init' );
/* On activation register the cron to refresh external blog posts. */
function bp_groupblogs_activate() {
wp_schedule_event( time(), 'hourly', 'bp_groupblogs_cron' );
}
register_activation_hook( __FILE__, 'bp_groupblogs_activate' );
/* On deacativation, clear the cron. */
function bp_groupblogs_deactivate() {
wp_clear_scheduled_hook( 'bp_groupblogs_cron' );
/* Remove all external blog activity */
if ( function_exists( 'bp_activity_delete' ) )
bp_activity_delete( array( 'type' => 'exb' ) );
}
register_deactivation_hook( __FILE__, 'bp_groupblogs_deactivate' );
?>
And the 2nd file is bp-groups-externalblogs.php
<?php
/* Group blog extension using the BuddyPress group extension API */
if ( class_exists('BP_Group_Extension' ) ) {
class Group_External_Blogs extends BP_Group_Extension {
function __construct() {
global $bp;
$this->name = __( 'External Blogs', 'bp-groups-externalblogs' );
$this->slug = 'external-blog-feeds';
$this->create_step_position = 21;
$this->enable_nav_item = false;
}
function create_screen() {
global $bp;
if ( !bp_is_group_creation_step( $this->slug ) )
return false;
?>
<p><?php _e(
"Add RSS feeds of blogs you'd like to attach to this group in the box below.
Any future posts on these blogs will show up on the group page and be recorded
in activity streams.", 'bp-groups-externalblogs' ) ?>
</p>
<p class="desc"><?php _e( "Seperate URL's with commas.", 'bp-groups-externalblogs' ) ?></span>
<p>
<label for="blogfeeds"><?php _e( "Feed URL's:", 'bp-groups-externalblogs' ) ?></label>
<textarea name="blogfeeds" id="blogfeeds"><?php echo attribute_escape( implode( ', ', (array)groups_get_groupmeta( $bp->groups->current_group->id, 'blogfeeds' ) ) ) ?></textarea>
</p>
<?php
wp_nonce_field( 'groups_create_save_' . $this->slug );
}
function create_screen_save() {
global $bp;
check_admin_referer( 'groups_create_save_' . $this->slug );
$unfiltered_feeds = explode( ',', $_POST['blogfeeds'] );
foreach( (array) $unfiltered_feeds as $blog_feed ) {
if ( !empty( $blog_feed ) )
$blog_feeds[] = trim( $blog_feed );
}
groups_update_groupmeta( $bp->groups->current_group->id, 'blogfeeds', $blog_feeds );
groups_update_groupmeta( $bp->groups->current_group->id, 'bp_groupblogs_lastupdate', gmdate( "Y-m-d H:i:s" ) );
/* Fetch */
bp_groupblogs_fetch_group_feeds( $bp->groups->current_group->id );
}
function edit_screen() {
global $bp;
if ( !bp_is_group_admin_screen( $this->slug ) )
return false; ?>
<p class="desc"><?php _e( "Enter RSS feed URL's for blogs you would like to attach to this group. Any future posts on these blogs will show on the group activity stream. Seperate URL's with commas.", 'bp-groups-externalblogs' ) ?></span>
<p>
<label for="blogfeeds"><?php _e( "Feed URL's:", 'bp-groups-externalblogs' ) ?></label>
<textarea name="blogfeeds" id="blogfeeds"><?php echo attribute_escape( implode( ', ', (array)groups_get_groupmeta( $bp->groups->current_group->id, 'blogfeeds' ) ) ) ?></textarea>
</p>
<input type="submit" name="save" value="<?php _e( "Update Feed URL's", 'bp-groups-externalblogs' ) ?>" />
<?php
wp_nonce_field( 'groups_edit_save_' . $this->slug );
}
function edit_screen_save() {
global $bp;
if ( !isset( $_POST['save'] ) )
return false;
check_admin_referer( 'groups_edit_save_' . $this->slug );
$existing_feeds = (array)groups_get_groupmeta( $bp->groups->current_group->id, 'blogfeeds' );
$unfiltered_feeds = explode( ',', $_POST['blogfeeds'] );
foreach( (array) $unfiltered_feeds as $blog_feed ) {
if ( !empty( $blog_feed ) )
$blog_feeds[] = trim( $blog_feed );
}
/* Loop and find any feeds that have been removed, so we can delete activity stream items */
if ( !empty( $existing_feeds ) ) {
foreach( (array) $existing_feeds as $feed ) {
if ( !in_array( $feed, (array) $blog_feeds ) )
$removed[] = $feed;
}
}
if ( $removed ) {
/* Remove activity stream items for this feed */
include_once( ABSPATH . WPINC . '/rss.php' );
foreach( (array) $removed as $feed ) {
$rss = fetch_rss( trim( $feed ) );
if ( function_exists( 'bp_activity_delete' ) ) {
bp_activity_delete( array(
'item_id' => $bp->groups->current_group->id,
'secondary_item_id' => wp_hash( $rss->channel['link'] ),
'component' => $bp->groups->id,
'type' => 'exb'
) );
}
}
}
groups_update_groupmeta( $bp->groups->current_group->id, 'blogfeeds', $blog_feeds );
groups_update_groupmeta( $bp->groups->current_group->id, 'bp_groupblogs_lastupdate', gmdate( "Y-m-d H:i:s" ) );
/* Re-fetch */
bp_groupblogs_fetch_group_feeds( $bp->groups->current_group->id );
bp_core_add_message( __( 'External blog feeds updated successfully!', 'bp-groups-externalblogs' ) );
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/admin/' . $this->slug );
}
/* We don't need display functions since the group activity stream handles it all. */
function display() {}
function widget_display() {}
}
bp_register_group_extension( 'Group_External_Blogs' );
function bp_groupblogs_fetch_group_feeds( $group_id = false ) {
global $bp;
include_once( ABSPATH . 'wp-includes/rss.php' );
if ( empty( $group_id ) )
$group_id = $bp->groups->current_group->id;
if ( $group_id == $bp->groups->current_group->id )
$group = $bp->groups->current_group;
else
$group = new BP_Groups_Group( $group_id );
if ( !$group )
return false;
$group_blogs = groups_get_groupmeta( $group_id, 'blogfeeds' );
$group_blogs = explode(";",$group_blogs[0]);
/* Set the visibility */
$hide_sitewide = ( 'public' != $group->status ) ? true : false;
foreach ( (array) $group_blogs as $feed_url ) {
$rss = fetch_feed( trim( $feed_url ) );
if (!is_wp_error($rss) ) {
foreach ( $rss->get_items(0,10) as $item ) {;
$key = $item->get_date( 'U' );
$items[$key]['title'] = $item->get_title();
$items[$key]['subtitle'] = $item->get_title();
//$items[$key]['author'] = $item->get_author()->get_name();
$items[$key]['blogname'] = $item->get_feed()->get_title();
$items[$key]['link'] = $item->get_permalink();
$items[$key]['blogurl'] = $item->get_feed()->get_link();
$items[$key]['description'] = $item->get_description();
$items[$key]['source'] = $item->get_source();
$items[$key]['copyright'] = $item->get_copyright();
}
}
}
if ( $items ) {
ksort($items);
$items = array_reverse($items, true);
} else {
return false;
}
/* Record found blog posts in activity streams */
foreach ( (array) $items as $post_date => $post ) {
//var_dump($post);
if (substr($post['blogname'],0,7) == "Twitter") {
$activity_action = sprintf( __( '%s from %s in the group %s', 'bp-groups-externalblogs' ), '<a class="feed-link" href="' . esc_attr( $post['link'] ) . '">Tweet</a>', '<a class="feed-author" href="' . esc_attr( $post['blogurl'] ) . '">' . attribute_escape( $post['blogname'] ) . '</a>', '' . attribute_escape( $group->name ) . '' );
} else {
$activity_action = sprintf( __( 'Blog: %s from %s in the group %s', 'bp-groups-externalblogs' ), '<a class="feed-link" href="' . esc_attr( $post['link'] ) . '">' . esc_attr( $post['title'] ) . '</a>', '<a class="feed-author" href="' . esc_attr( $post['blogurl'] ) . '">' . attribute_escape( $post['blogname'] ) . '</a>', '' . attribute_escape( $group->name ) . '' );
}
$activity_content = '<div>' . strip_tags( bp_create_excerpt( $post['description'], 175 ) ) . '</div>';
$activity_content = apply_filters( 'bp_groupblogs_activity_content', $activity_content, $post, $group );
/* Fetch an existing activity_id if one exists. */
if ( function_exists( 'bp_activity_get_activity_id' ) )
$id = bp_activity_get_activity_id( array( 'user_id' => false, 'action' => $activity_action, 'component' => $bp->groups->id, 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash( $post['blogurl'] ) ) );
/* Record or update in activity streams. */
groups_record_activity( array(
'id' => $id,
'user_id' => false,
'action' => $activity_action,
'content' => $activity_content,
'primary_link' => $item->get_link(),
'type' => 'exb',
'item_id' => $group_id,
'secondary_item_id' => wp_hash( $post['blogurl'] ),
'recorded_time' => gmdate( "Y-m-d H:i:s", $post_date ),
'hide_sitewide' => $hide_sitewide
) );
}
return $items;
}
/* Add a filter option to the filter select box on group activity pages */
function bp_groupblogs_add_filter() { ?>
<option value="exb"><?php _e( 'External Blogs', 'bp-groups-externalblogs' ) ?></option><?php
}
add_action( 'bp_group_activity_filter_options', 'bp_groupblogs_add_filter' );
add_action( 'bp_activity_filter_options', 'bp_groupblogs_add_filter' );
/* Add a filter option groups avatar */
/* Fetch group twitter posts after 30 mins expires and someone hits the group page */
function bp_groupblogs_refetch() {
global $bp;
$last_refetch = groups_get_groupmeta( $bp->groups->current_group->id, 'bp_groupblogs_lastupdate' );
if ( strtotime( gmdate( "Y-m-d H:i:s" ) ) >= strtotime( '+30 minutes', strtotime( $last_refetch ) ) )
add_action( 'wp_footer', 'bp_groupblogs_refetch' );
/* Refetch the latest group twitter posts via AJAX so we don't stall a page load. */
function _bp_groupblogs_refetch() {
global $bp; ?>
<script type="text/javascript">
jQuery(document).ready( function() {
jQuery.post( ajaxurl, {
action: 'refetch_groupblogs',
'cookie': encodeURIComponent(document.cookie),
'group_id': <?php echo $bp->groups->current_group->id ?>
});
});
</script><?php
groups_update_groupmeta( $bp->groups->current_group->id, 'bp_groupblogs_lastupdate', gmdate( "Y-m-d H:i:s" ) );
}
}
add_action( 'groups_screen_group_home', 'bp_groupblogs_refetch' );
/* Refresh via an AJAX post for the group */
function bp_groupblogs_ajax_refresh() {
bp_groupblogs_fetch_group_feeds( $_POST['group_id'] );
}
add_action( 'wp_ajax_refetch_groupblogs', 'bp_groupblogs_ajax_refresh' );
function bp_groupblogs_cron_refresh() {
global $bp, $wpdb;
$group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM " . $bp->groups->table_name_groupmeta . " WHERE meta_key = 'blogfeeds'" ) );
foreach( $group_ids as $group_id )
bp_groupblogs_fetch_group_feeds( $group_id );
}
add_action( 'bp_groupblogs_cron', 'bp_groupblogs_cron_refresh' );
}
// Add a filter option groups avatar
function bp_groupblogs_avatar_type($var) {
global $activities_template, $bp;
if ( $activities_template->activity->type == "exb" ) {
return 'group';
} else {
return $var;
}
}
add_action( 'bp_get_activity_avatar_object_groups', 'bp_groupblogs_avatar_type');
add_action( 'bp_get_activity_avatar_object_activity', 'bp_groupblogs_avatar_type');
function bp_groupblogs_avatar_id($var) {
global $activities_template, $bp;
if ( $activities_template->activity->type == "exb" ) {
return $activities_template->activity->item_id;
}
return $var;
}
add_action( 'bp_get_activity_avatar_item_id', 'bp_groupblogs_avatar_id');
?>
I have a suggestion for stopping data repeating in activity stream. Maybe use wp-cron api and a current date xml feeds fetching system once in a day. So it will not repeat the same feeds in a group activity stream. We need a criteria by which we can stop data repetition in the bp group activity stream. It is a part of my project. Is there another way of fetching feeds and saving it to the mysql table (in the group activity stream) and then show it as a latest group updates?
Actually IT IS fetching automatically.
I see the cron usage in a plugin. WordPress Cron fires only when any user opens your site. So no users (no pageviews) - no cron activity. On every pageview WP-Cron check whether the time to fire any function came or not.
Perhaps this plugin will help you a bit - display a RSS feed in a separate group tab.

How to get input text from theme options on wordpress?

I just set up a new input text option into my theme-options.php file, which is similar to the twenty eleven theme code.
Here are parts of my theme-options.php code in regards to the input, I'm looking for a way to get the input that users enter into the 'fact' text and show it on the index.php page:
function themename_theme_options_init() {
register_setting(
'themename_options', // Options group, see settings_fields() call in themename_theme_options_render_page()
'themename_theme_options', // Database option, see themename_get_theme_options()
'themename_theme_options_validate' // The sanitization callback, see themename_theme_options_validate()
);
// Register our settings field group
add_settings_section(
'general', // Unique identifier for the settings section
'', // Section title (we don't want one)
'__return_false', // Section callback (we don't want anything)
'theme_options' // Menu slug, used to uniquely identify the page; see themename_theme_options_add_page()
);
// Register our individual settings fields
add_settings_field( 'facts', __( 'Facts', 'themename' ), 'themename_settings_field_facts', 'theme_options', 'general' );
add_settings_field( 'link_color', __( 'Link Color', 'themename' ), 'themename_settings_field_link_color', 'theme_options', 'general' );
}
add_action( 'admin_init', 'themename_theme_options_init' );
Returns the default facts for Theme Name, based on color scheme:
function themename_get_default_facts( $color_scheme = null ) {
if ( null === $color_scheme ) {
$options = themename_get_theme_options();
$color_scheme = $options['color_scheme'];
}
$color_schemes = themename_color_schemes();
if ( ! isset( $color_schemes[ $color_scheme ] ) )
return false;
return $color_schemes[ $color_scheme ]['default_facts'];
}
Renders the Facts setting field.
function themename_settings_field_facts() {
$options = themename_get_theme_options();
?>
<input type="text" name="themename_theme_options[facts]" id="facts" value="<?php echo esc_attr( $options['facts'] ); ?>" />
<br />
<span><?php printf( __( 'Default facts: %s', 'themename' ), '<span id="default-facts">' . themename_get_default_facts ( $options['color_scheme'] ) . '</span>' ); ?></span>
<?php
}
Sanitize and validate form input:
function themename_theme_options_validate( $input ) {
$output = $defaults = themename_get_default_theme_options();
// Color scheme must be in our array of color scheme options
if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], themename_color_schemes() ) )
$output['color_scheme'] = $input['color_scheme'];
// Facts must be characters.
if ( isset( $input['facts'] ) )
$output['facts'] = '' . ( ltrim( $input['facts'], '' ) );
// Our defaults for the link color may have changed, based on the color scheme.
$output['link_color'] = $defaults['link_color'] = themename_get_default_link_color( $output['color_scheme'] );
// Link color must be 3 or 6 hexadecimal characters
if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) )
$output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) );
return apply_filters( 'themename_theme_options_validate', $output, $input, $defaults );
}
Implements theme options into Theme Customizer:
function themename_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$options = themename_get_theme_options();
$defaults = themename_get_default_theme_options();
$wp_customize->add_setting( 'themename_theme_options[facts]', array(
'default' => themename_get_default_facts( $options['color_scheme'] ),
'type' => 'option',
'sanitize_callback' => 'sanitize_text_field',
'capability' => 'edit_theme_options',
) );
}
add_action( 'customize_register', 'themename_customize_register' );
Thank you to anyone that can help :)
Thanks! I got it working :D
----------
<?php
/**
* Theme Options
*
* #package WordPress
*
*/
/* Write the name and the variable_name in which you want to store the data using theme options in the array $options_array */
$options_array = array(
'Facebook URL'=>'facebook_url',
);
function my_theme_options_init() {
// If we have no options in the database, let's add them now.
if ( false === my_theme_options() )
add_option( 'my_theme_options', my_default_theme_options() );
register_setting(
'my_options', // Options group, see settings_fields() call in theme_options_render_page()
'my_theme_options' // Database option, see my_theme_options()
);
global $options_array;
foreach ($options_array as $key=>$option ){
register_setting( 'my_options', $option);
}
}
add_action( 'admin_init', 'my_theme_options_init' );
function my_theme_options_add_page() {
$theme_page = add_theme_page(
'myers themeing', // Name of page
'myers themeing', // Label in menu
'edit_theme_options', // Capability required
'my_options', // Menu slug, used to uniquely identify the page
'my_theme_options_render_page' // Function that renders the options page
);
if ( ! $theme_page )
return;
}
add_action( 'admin_menu', 'my_theme_options_add_page' );
function my_default_schemes() {
$default_array = array('value' => 'Default_theme',
'label' => __( 'Default_theme', 'my' ),
'thumbnail' => get_template_directory_uri() . '/inc/images/my.png'
);
global $options_array;
foreach ($options_array as $key=>$option ){
$default_array[$option] =' ';
}
$default_scheme_options = array(
'Default_theme' => $default_array,
);
return apply_filters( 'my_default_schemes', $default_scheme_options );
}
function my_default_theme_options() {
$default_theme_options = array( 'default_scheme' => 'Default_theme' );
global $options_array;
foreach ($options_array as $key=>$option ){
$default_theme_options[$option] = my_default( $option,'Default_theme' );
}
return apply_filters( 'my_default_theme_options', $default_theme_options );
}
function my_default( $option ,$default_scheme = null ) {
if ( null === $default_scheme ) {
$options = my_theme_options();
$default_scheme = $options['default_scheme'];
}
$default_schemes = my_default_schemes();
if ( ! isset( $default_schemes[ $default_scheme ] ) )
return false;
return $default_schemes[ $default_scheme ][$option];
}
function my_theme_options() {
return get_option( 'my_theme_options', my_default_theme_options() );
}
function my_theme_options_render_page() {
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php printf( __( '%s Theme Options', 'my' ), get_current_theme() ); ?></h2>
<?php settings_errors(); ?>
<hr>
<div id="theme_option_main">
<h2>myers themeing</h2>
<form method="post" enctype="multipart/form-data" action="options.php">
<?php
settings_fields( 'my_options' );
$options = my_theme_options();
$default_options = my_default_theme_options();
global $options_array;
foreach ($options_array as $key=>$option ){
do_settings_sections($option);
}
?>
<table class="form-table">
<tr>
<th scope="row"><?php _e( "(Use ' http:// ' for Hyperlinks)", 'my' ); ?></th>
<td>
<fieldset>
</fieldset>
</td>
</tr>
<?php
foreach ($options_array as $key=>$option ){
?>
<tr>
<th scope="row"><?php _e( $key, 'my' ); ?></th>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( $key, 'my' ); ?></span></legend>
<input type="text" name="<?php echo $option ?>" id="<?php echo $option ?>" class="large-text" value="<?php echo get_option($option); ?>"></input>
</fieldset>
</td>
</tr>
<?php } ?>
</table>
<?php submit_button(); ?>
</form>
</div>
</div>
<?php
}
?>
copy the code and create a new theme options file. Add the name and the variable_name in the options array in the file and you are good to go.
Don't forget to link this file in your functions.php
To link it just add the following code in your functions.php
require( dirname( __FILE__ ) . '/inc/your_file_name.php' );

How to Sharpen Post Thumbnails in WordPress 3

I am using the default thumbnail feature of Wordpress 3 to add thumbnails of various sizes to my posts. Now the problem I face is that the shrinked thumbnails become very blurry.
In .Net I know how to sharpen images and this works really well for thumbnails, so I am now looking for a way to do this for Wordpress (in php obviously).
I really suck at php, so any help is really appreciated!
I use a modified version of ResizeThumbnails. This way you can re-generate all your blurry images and it also takes care of future uploaded images:
<?php
/*
**************************************************************************
Plugin Name: Regenerate Thumbnails
Plugin URI: http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/
Description: Allows you to regenerate all thumbnails after changing the thumbnail sizes.
Version: 2.2.3
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
**************************************************************************
Copyright (C) 2008-2011 Viper007Bond
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
class RegenerateThumbnails {
var $menu_id;
// Plugin initialization
function RegenerateThumbnails() {
// Load up the localization file if we're using WordPress in a different language
// Place it in this plugin's "localization" folder and name it "regenerate-thumbnails-[value in wp-config].mo"
load_plugin_textdomain( 'regenerate-thumbnails', false, '/regenerate-thumbnails/localization' );
add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) );
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueues' ) );
add_action( 'wp_ajax_regeneratethumbnail', array( &$this, 'ajax_process_image' ) );
add_filter( 'media_row_actions', array( &$this, 'add_media_row_action' ), 10, 2 );
//add_filter( 'bulk_actions-upload', array( &$this, 'add_bulk_actions' ), 99 ); // A last minute change to 3.1 makes this no longer work
add_action( 'admin_head-upload.php', array( &$this, 'add_bulk_actions_via_javascript' ) );
add_action( 'admin_action_bulk_regenerate_thumbnails', array( &$this, 'bulk_action_handler' ) ); // Top drowndown
add_action( 'admin_action_-1', array( &$this, 'bulk_action_handler' ) ); // Bottom dropdown (assumes top dropdown = default value)
// Allow people to change what capability is required to use this plugin
$this->capability = apply_filters( 'regenerate_thumbs_cap', 'manage_options' );
}
// Register the management page
function add_admin_menu() {
$this->menu_id = add_management_page( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ), __( 'Regen. Thumbnails', 'regenerate-thumbnails' ), $this->capability, 'regenerate-thumbnails', array(&$this, 'regenerate_interface') );
}
// Enqueue the needed Javascript and CSS
function admin_enqueues( $hook_suffix ) {
if ( $hook_suffix != $this->menu_id )
return;
// WordPress 3.1 vs older version compatibility
if ( wp_script_is( 'jquery-ui-widget', 'registered' ) )
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/jquery.ui.progressbar.min.js', __FILE__ ), array( 'jquery-ui-core', 'jquery-ui-widget' ), '1.8.6' );
else
wp_enqueue_script( 'jquery-ui-progressbar', plugins_url( 'jquery-ui/jquery.ui.progressbar.min.1.7.2.js', __FILE__ ), array( 'jquery-ui-core' ), '1.7.2' );
wp_enqueue_style( 'jquery-ui-regenthumbs', plugins_url( 'jquery-ui/redmond/jquery-ui-1.7.2.custom.css', __FILE__ ), array(), '1.7.2' );
}
// Add a "Regenerate Thumbnails" link to the media row actions
function add_media_row_action( $actions, $post ) {
if ( 'image/' != substr( $post->post_mime_type, 0, 6 ) || ! current_user_can( $this->capability ) )
return $actions;
$url = wp_nonce_url( admin_url( 'tools.php?page=regenerate-thumbnails&goback=1&ids=' . $post->ID ), 'regenerate-thumbnails' );
$actions['regenerate_thumbnails'] = '' . __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ) . '';
return $actions;
}
// Add "Regenerate Thumbnails" to the Bulk Actions media dropdown
function add_bulk_actions( $actions ) {
$delete = false;
if ( ! empty( $actions['delete'] ) ) {
$delete = $actions['delete'];
unset( $actions['delete'] );
}
$actions['bulk_regenerate_thumbnails'] = __( 'Regenerate Thumbnails', 'regenerate-thumbnails' );
if ( $delete )
$actions['delete'] = $delete;
return $actions;
}
// Add new items to the Bulk Actions using Javascript
// A last minute change to the "bulk_actions-xxxxx" filter in 3.1 made it not possible to add items using that
function add_bulk_actions_via_javascript() {
if ( ! current_user_can( $this->capability ) )
return;
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('select[name^="action"] option:last-child').before('<option value="bulk_regenerate_thumbnails"><?php echo esc_attr( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ) ); ?></option>');
});
</script>
<?php
}
// Handles the bulk actions POST
function bulk_action_handler() {
if ( empty( $_REQUEST['action'] ) || ( 'bulk_regenerate_thumbnails' != $_REQUEST['action'] && 'bulk_regenerate_thumbnails' != $_REQUEST['action2'] ) )
return;
if ( empty( $_REQUEST['media'] ) || ! is_array( $_REQUEST['media'] ) )
return;
check_admin_referer( 'bulk-media' );
$ids = implode( ',', array_map( 'intval', $_REQUEST['media'] ) );
// Can't use wp_nonce_url() as it escapes HTML entities
wp_redirect( add_query_arg( '_wpnonce', wp_create_nonce( 'regenerate-thumbnails' ), admin_url( 'tools.php?page=regenerate-thumbnails&goback=1&ids=' . $ids ) ) );
exit();
}
// The user interface plus thumbnail regenerator
function regenerate_interface() {
global $wpdb;
?>
<div id="message" class="updated fade" style="display:none"></div>
<div class="wrap regenthumbs">
<h2><?php _e('Regenerate Thumbnails', 'regenerate-thumbnails'); ?></h2>
<?php
// If the button was clicked
if ( ! empty( $_POST['regenerate-thumbnails'] ) || ! empty( $_REQUEST['ids'] ) ) {
// Capability check
if ( ! current_user_can( $this->capability ) )
wp_die( __( 'Cheatin’ uh?' ) );
// Form nonce check
check_admin_referer( 'regenerate-thumbnails' );
// Create the list of image IDs
if ( ! empty( $_REQUEST['ids'] ) ) {
$images = array_map( 'intval', explode( ',', trim( $_REQUEST['ids'], ',' ) ) );
$ids = implode( ',', $images );
} else {
// Directly querying the database is normally frowned upon, but all
// of the API functions will return the full post objects which will
// suck up lots of memory. This is best, just not as future proof.
if ( ! $images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC" ) ) {
echo ' <p>' . sprintf( __( "Unable to find any images. Are you sure <a href='%s'>some exist</a>?", 'regenerate-thumbnails' ), admin_url( 'upload.php?post_mime_type=image' ) ) . "</p></div>";
return;
}
// Generate the list of IDs
$ids = array();
foreach ( $images as $image )
$ids[] = $image->ID;
$ids = implode( ',', $ids );
}
echo ' <p>' . __( "Please be patient while the thumbnails are regenerated. This can take a while if your server is slow (inexpensive hosting) or if you have many images. Do not navigate away from this page until this script is done or the thumbnails will not be resized. You will be notified via this page when the regenerating is completed.", 'regenerate-thumbnails' ) . '</p>';
$count = count( $images );
$text_goback = ( ! empty( $_GET['goback'] ) ) ? sprintf( __( 'To go back to the previous page, click here.', 'regenerate-thumbnails' ), 'javascript:history.go(-1)' ) : '';
$text_failures = sprintf( __( 'All done! %1$s image(s) were successfully resized in %2$s seconds and there were %3$s failure(s). To try regenerating the failed images again, click here. %5$s', 'regenerate-thumbnails' ), "' + rt_successes + '", "' + rt_totaltime + '", "' + rt_errors + '", esc_url( wp_nonce_url( admin_url( 'tools.php?page=regenerate-thumbnails&goback=1' ), 'regenerate-thumbnails' ) . '&ids=' ) . "' + rt_failedlist + '", $text_goback );
$text_nofailures = sprintf( __( 'All done! %1$s image(s) were successfully resized in %2$s seconds and there were 0 failures. %3$s', 'regenerate-thumbnails' ), "' + rt_successes + '", "' + rt_totaltime + '", $text_goback );
?>
<noscript><p><em><?php _e( 'You must enable Javascript in order to proceed!', 'regenerate-thumbnails' ) ?></em></p></noscript>
<div id="regenthumbs-bar" style="position:relative;height:25px;">
<div id="regenthumbs-bar-percent" style="position:absolute;left:50%;top:50%;width:300px;margin-left:-150px;height:25px;margin-top:-9px;font-weight:bold;text-align:center;"></div>
</div>
<p><input type="button" class="button hide-if-no-js" name="regenthumbs-stop" id="regenthumbs-stop" value="<?php _e( 'Abort Resizing Images', 'regenerate-thumbnails' ) ?>" /></p>
<h3 class="title"><?php _e( 'Debugging Information', 'regenerate-thumbnails' ) ?></h3>
<p>
<?php printf( __( 'Total Images: %s', 'regenerate-thumbnails' ), $count ); ?><br />
<?php printf( __( 'Images Resized: %s', 'regenerate-thumbnails' ), '<span id="regenthumbs-debug-successcount">0</span>' ); ?><br />
<?php printf( __( 'Resize Failures: %s', 'regenerate-thumbnails' ), '<span id="regenthumbs-debug-failurecount">0</span>' ); ?>
</p>
<ol id="regenthumbs-debuglist">
<li style="display:none"></li>
</ol>
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function($){
var i;
var rt_images = [<?php echo $ids; ?>];
var rt_total = rt_images.length;
var rt_count = 1;
var rt_percent = 0;
var rt_successes = 0;
var rt_errors = 0;
var rt_failedlist = '';
var rt_resulttext = '';
var rt_timestart = new Date().getTime();
var rt_timeend = 0;
var rt_totaltime = 0;
var rt_continue = true;
// Create the progress bar
$("#regenthumbs-bar").progressbar();
$("#regenthumbs-bar-percent").html( "0%" );
// Stop button
$("#regenthumbs-stop").click(function() {
rt_continue = false;
$('#regenthumbs-stop').val("<?php echo $this->esc_quotes( __( 'Stopping...', 'regenerate-thumbnails' ) ); ?>");
});
// Clear out the empty list element that's there for HTML validation purposes
$("#regenthumbs-debuglist li").remove();
// Called after each resize. Updates debug information and the progress bar.
function RegenThumbsUpdateStatus( id, success, response ) {
$("#regenthumbs-bar").progressbar( "value", ( rt_count / rt_total ) * 100 );
$("#regenthumbs-bar-percent").html( Math.round( ( rt_count / rt_total ) * 1000 ) / 10 + "%" );
rt_count = rt_count + 1;
if ( success ) {
rt_successes = rt_successes + 1;
$("#regenthumbs-debug-successcount").html(rt_successes);
$("#regenthumbs-debuglist").append("<li>" + response.success + "</li>");
}
else {
rt_errors = rt_errors + 1;
rt_failedlist = rt_failedlist + ',' + id;
$("#regenthumbs-debug-failurecount").html(rt_errors);
$("#regenthumbs-debuglist").append("<li>" + response.error + "</li>");
}
}
// Called when all images have been processed. Shows the results and cleans up.
function RegenThumbsFinishUp() {
rt_timeend = new Date().getTime();
rt_totaltime = Math.round( ( rt_timeend - rt_timestart ) / 1000 );
$('#regenthumbs-stop').hide();
if ( rt_errors > 0 ) {
rt_resulttext = '<?php echo $text_failures; ?>';
} else {
rt_resulttext = '<?php echo $text_nofailures; ?>';
}
$("#message").html("<p><strong>" + rt_resulttext + "</strong></p>");
$("#message").show();
}
// Regenerate a specified image via AJAX
function RegenThumbs( id ) {
$.ajax({
type: 'POST',
url: ajaxurl,
data: { action: "regeneratethumbnail", id: id },
success: function( response ) {
if ( response.success ) {
RegenThumbsUpdateStatus( id, true, response );
}
else {
RegenThumbsUpdateStatus( id, false, response );
}
if ( rt_images.length && rt_continue ) {
RegenThumbs( rt_images.shift() );
}
else {
RegenThumbsFinishUp();
}
},
error: function( response ) {
RegenThumbsUpdateStatus( id, false, response );
if ( rt_images.length && rt_continue ) {
RegenThumbs( rt_images.shift() );
}
else {
RegenThumbsFinishUp();
}
}
});
}
RegenThumbs( rt_images.shift() );
});
// ]]>
</script>
<?php
}
// No button click? Display the form.
else {
?>
<form method="post" action="">
<?php wp_nonce_field('regenerate-thumbnails') ?>
<p><?php printf( __( "Use this tool to regenerate thumbnails for all images that you have uploaded to your blog. This is useful if you've changed any of the thumbnail dimensions on the <a href='%s'>media settings page</a>. Old thumbnails will be kept to avoid any broken images due to hard-coded URLs.", 'regenerate-thumbnails' ), admin_url( 'options-media.php' ) ); ?></p>
<p><?php printf( __( "You can regenerate specific images (rather than all images) from the <a href='%s'>Media</a> page. Hover over an image's row and click the link to resize just that one image or use the checkboxes and the "Bulk Actions" dropdown to resize multiple images (WordPress 3.1+ only).", 'regenerate-thumbnails '), admin_url( 'upload.php' ) ); ?></p>
<p><?php _e( "Thumbnail regeneration is not reversible, but you can just change your thumbnail dimensions back to the old values and click the button again if you don't like the results.", 'regenerate-thumbnails' ); ?></p>
<p><?php _e( 'To begin, just press the button below.', 'regenerate-thumbnails '); ?></p>
<p><input type="submit" class="button hide-if-no-js" name="regenerate-thumbnails" id="regenerate-thumbnails" value="<?php _e( 'Regenerate All Thumbnails', 'regenerate-thumbnails' ) ?>" /></p>
<noscript><p><em><?php _e( 'You must enable Javascript in order to proceed!', 'regenerate-thumbnails' ) ?></em></p></noscript>
</form>
<?php
} // End if button
?>
</div>
<?php
}
// Process a single image ID (this is an AJAX handler)
function ajax_process_image() {
#error_reporting( 0 ); // Don't break the JSON result
header( 'Content-type: application/json' );
$id = (int) $_REQUEST['id'];
$image = get_post( $id );
if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) )
die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'regenerate-thumbnails' ), esc_html( $_REQUEST['id'] ) ) ) ) );
if ( ! current_user_can( $this->capability ) )
$this->die_json_error_msg( $image->ID, __( "Your user account doesn't have permission to resize images", 'regenerate-thumbnails' ) );
$fullsizepath = get_attached_file( $image->ID );
if ( false === $fullsizepath || ! file_exists( $fullsizepath ) )
$this->die_json_error_msg( $image->ID, sprintf( __( 'The originally uploaded image file cannot be found at %s', 'regenerate-thumbnails' ), '<code>' . esc_html( $fullsizepath ) . '</code>' ) );
#set_time_limit( 900 ); // 5 minutes per image should be PLENTY
$metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath );
if ( is_wp_error( $metadata ) )
$this->die_json_error_msg( $image->ID, $metadata->get_error_message() );
if ( empty( $metadata ) )
$this->die_json_error_msg( $image->ID, __( 'Unknown failure reason.', 'regenerate-thumbnails' ) );
// If this fails, then it just means that nothing was changed (old value == new value)
wp_update_attachment_metadata( $image->ID, $metadata );
die( json_encode( array( 'success' => sprintf( __( '"%1$s" (ID %2$s) was successfully resized in %3$s seconds.', 'regenerate-thumbnails' ), esc_html( get_the_title( $image->ID ) ), $image->ID, timer_stop() ) ) ) );
}
// Helper to make a JSON error message
function die_json_error_msg( $id, $message ) {
die( json_encode( array( 'error' => sprintf( __( '"%1$s" (ID %2$s) failed to resize. The error message was: %3$s', 'regenerate-thumbnails' ), esc_html( get_the_title( $id ) ), $id, $message ) ) ) );
}
// Helper function to escape quotes in strings for use in Javascript
function esc_quotes( $string ) {
return str_replace( '"', '\"', $string );
}
}
// Start up this plugin
add_action( 'init', 'RegenerateThumbnails' );
function RegenerateThumbnails() {
global $RegenerateThumbnails;
$RegenerateThumbnails = new RegenerateThumbnails();
}
// sharpen uploaded images
function ajx_sharpen_resized_files( $resized_file ) {
$image = wp_load_image( $resized_file );
if ( !is_resource( $image ) )
return new WP_Error( 'error_loading_image', $image, $file );
$size = #getimagesize( $resized_file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
switch ( $orig_type ) {
case IMAGETYPE_JPEG:
$matrix = array(
array(apply_filters('sharpen_resized_corner',-1.2), apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_corner',-1.2)),
array(apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_center',20), apply_filters('sharpen_resized_side',-1)),
array(apply_filters('sharpen_resized_corner',-1.2), apply_filters('sharpen_resized_side',-1), apply_filters('sharpen_resized_corner',-1.2)),
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imageconvolution($image, $matrix, $divisor, $offset);
imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 100, 'edit_image' ));
break;
case IMAGETYPE_PNG:
return $resized_file;
case IMAGETYPE_GIF:
return $resized_file;
}
// we don't need images in memory anymore
imagedestroy( $image );
return $resized_file;
}
add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files', 900);
?>
i think this is your answer: http://vikjavev.no/computing/ump.php ,
however you'll need to change the thumbnailer creator script in wp.
Here is the solution if your wordpress post thumbnail blurry, go to your theme CSS , get the code :
.secondary-posts .post-thumbnail
width: 100%;
background-color: #666;
height: 150px;
padding: 0;
box-shadow: 0 0px 5px #888;
background-repeat: no-repeat;
background-position:center;
background-size: 150px auto;
( CHANGE THIS BACKGROUND SIZE TO YOUR THUMBNAIL BOX SIZE( example 150px )
I have used it for our web and its works ,the thumbnail sharp now,here is the result
: http://kresnatourjogja.com/category/jogjakarta-temple/

Categories