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.
Related
Hello guys i got new WP theme and i cant install im getting this error on website
Parse error: syntax error, unexpected '}', expecting end of file in
/storage/h3/665/790665/public_html/wp-content/themes/gameaddict/post_templates.php
on line 1
<?php
class Single_Post_Template_Plugin {
function __construct() {
add_action( 'admin_menu', array( $this, 'add_metabox' ) );
add_action( 'save_post', array( $this, 'metabox_save' ), 1, 2 );
add_filter( 'single_template', array( $this, 'get_post_template' ) );
}
function get_post_template( $template ) {
global $post;
$custom_field = get_post_meta( $post->ID, '_wp_post_template', true );
if( !$custom_field )
return $template;
/** Prevent directory traversal */
$custom_field = str_replace( '..', '', $custom_field );
if( file_exists( get_stylesheet_directory() . "/{$custom_field}" ) )
$template = get_stylesheet_directory() . "/{$custom_field}";
elseif( file_exists( get_template_directory() . "/{$custom_field}" ) )
$template = get_template_directory() . "/{$custom_field}";
return $template;
}
function get_post_templates() {
$templates = wp_get_theme()->get_files( 'php', 1 );
$post_templates = array();
$base = array( trailingslashit( get_template_directory()), trailingslashit( get_stylesheet_directory()) );
foreach ( (array) $templates as $file => $full_path ) {
if( $full_path == get_theme_root().'/gameaddict/post_templates.php'){continue;}else{
if ( !preg_match( '|Single Post Template:(.*)$|mi', file_get_contents( $full_path ), $header ))
continue;
$post_templates[ $file ] = _cleanup_header_comment( $header[1] );
}}
return $post_templates;
}
function post_templates_dropdown() {
global $post;
$post_templates = $this->get_post_templates();
/** Loop through templates, make them options */
foreach ( (array) $post_templates as $template_file => $template_name ) {
$selected = ( $template_file == get_post_meta( $post->ID, '_wp_post_template', true ) ) ? ' selected="selected"' : '';
$opt = '<option value="' . esc_attr( $template_file ) . '"' . $selected . '>' . esc_html( $template_name ) . '</option>';
echo $opt;
}
}
function add_metabox() {
$screens = array( 'post', 'portfolio' );
foreach ( $screens as $screen ) {
add_meta_box(
'pt_post_templates',
__( 'Sidebar position', 'addict' ),
array( $this, 'metabox' ),
$screen,'normal', 'high'
);
}
}
function metabox( $post ) {
?>
<input type="hidden" name="pt_noncename" id="pt_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
<label class="hidden" for="post_template"><?php _e( 'Post Template', 'addict' ); ?></label><br />
<select name="_wp_post_template" id="post_template" class="dropdown">
<?php $this->post_templates_dropdown(); ?>
</select>
<?php
}
function metabox_save( $post_id, $post ) {
/*
* Verify this came from the our screen and with proper authorization,
* because save_post can be triggered at other times
*/
if(isset($_POST['pt_noncename'])){
if ( !wp_verify_nonce( $_POST['pt_noncename'], plugin_basename( __FILE__ ) ) )
return $post->ID;
}
/** Is the user allowed to edit the post or page? */
if(isset($_POST['post_type'])){
if ( 'page' == $_POST['post_type'] )
if ( !current_user_can( 'edit_page', $post->ID ) )
return $post->ID;
else
if ( !current_user_can( 'edit_post', $post->ID ) )
return $post->ID;
}
/** OK, we're authenticated: we need to find and save the data */
/** Put the data into an array to make it easier to loop though and save */
if(isset($_POST['_wp_post_template'])){
$mydata['_wp_post_template'] = $_POST['_wp_post_template'];
}
/** Add values of $mydata as custom fields */
if(isset($mydata)){
foreach ( $mydata as $key => $value ) {
/** Don't store custom data twice */
if( 'revision' == $post->post_type )
return;
/** If $value is an array, make it a CSV (unlikely) */
$value = implode( ',', (array) $value );
/** Update the data if it exists, or add it if it doesn't */
if( get_post_meta( $post->ID, $key, false ) )
update_post_meta( $post->ID, $key, $value );
else
add_post_meta( $post->ID, $key, $value );
/** Delete if blank */
if( !$value )
delete_post_meta( $post->ID, $key );
}}
}
}
add_action( 'init', 'post_templates_plugin_init' );
/**
* Instantiate the class after theme has been set up.
*/
function post_templates_plugin_init() {
new Single_Post_Template_Plugin;
}
Assuming the theme is this one https://themeforest.net/item/game-addict-clan-war-gaming-theme/6771881 and it's purchased from themeforest, it should work right out of the box. Try downloading it again, make sure to check if there is not a zipped file inside of the zip you are downloading to make sure you are uploading the right file, sometimes the zip you download has a lot of files like documentation and demos, but the actual theme file is another zip inside.
If nothing of the above helps, write to their customer support.
Basically, it's complaining that wp-content/themes/gameaddict/post_templates.php has a } on line 1, while PHP was expecting end of a file. The code you've included seems fine. The issue is most likely about the developer closing a bracket without opening it, somewhere in the code. It seems like you're using a pre-made theme, in that case contacting the developer would be the best option.
i'm searching for a way to display the modified date of a custom field / meta box. until now, i only know how to echo
the_modified_date('l, j.n.Y');
but this one only works with the entire post.
i'am using a meta_box for additional pdf files uploading, code:
<?php class PDF_Metabox_id1 {
function __construct() {
add_action( 'post_mime_types', array( $this, 'pdf_mime_type_id1' ) );
add_action( 'add_meta_boxes', array( $this, 'admin_scripts_id1' ), 5 );
add_action( 'add_meta_boxes', array( $this, 'metabox_add_id1' ) );
add_action( 'save_post', array( $this, 'pdf_save_postdata_id1') );
add_action( 'wp_ajax_refresh_pdf', array( $this, 'refresh_pdf_id1' ) ); }
function pdf_mime_type_id1() {
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) );
return $post_mime_types;
}
function admin_scripts_id1() {
wp_register_script( 'pdf_metabox_js', get_stylesheet_directory_uri() . '/js/pdf_metabox.js' );
}
function metabox_add_id1() {
$post_types = array( 'myposttype','anotherposttype' );
$context = 'normal'; $priority = 'low';
foreach( $post_types as $post_type ) {
add_meta_box( 'pdf_metabox_id1', __( 'PDF Box 1', 'pdf_metabox_id1' ), array( $this, 'pdf_metabox_id1' ), $post_type, $context, $priority );
wp_enqueue_media();
wp_enqueue_script( 'pdf_metabox_js' );
}
}
function pdf_metabox_id1( $post ) {
$original_post = $post; echo $this->pdf_metabox_html_id1( $post->ID ); $post = $original_post;
}
function pdf_item_id1( $id ) {
if(!$id) return; $pdf_url = esc_url_raw(wp_get_attachment_url($id)); $pdf = $pdf_url; return $pdf;
}
function pdf_metabox_html_id1( $post_id ) {
$current_value = ''; $post_meta = get_post_custom($post_id);
if( isset($post_meta['pdf_id_id1'][0] ) ) $current_value = $post_meta['pdf_id_id1'][0];
$return = ''; wp_nonce_field( plugin_basename( __FILE__ ), 'pdf_noncename' );
$return .= '<p>';
$return .= '<a title="'.__( 'PDF', 'pdf_metabox_id1' ).'" class="button button-primary insert-pdf-button" id="insert_pdf_button_id1" href="#" style="float:left">'.__( 'Upload / editiere PDF', 'pdf_metabox_id1' ).'</a><span id="pdf_spinner_id1" class="spinner" style="float:left"></span></p>';
$return .= '<div style="clear:both"></div>';
$return .= '<input type="hidden" name="pdf_id_id1" id="pdf_id_id1" value="'.$current_value.'">';
$return .= '<div style="clear:both"></div>';
$return .= '<div id="pdf_wrapper_id1">';
$pdf = $this->pdf_item_id1( $current_value ); if( empty( $pdf ) ) {
$return .= '<p>Diesem Feld ist kein PDF hinterlegt.</p>'; } else {
$return .= '<br />URL des PDF:<br /> ';
$return .= $pdf; }
$return .= '</div>';
return $return;
}
function pdf_save_postdata_id1($post_id){
if ( isset($_POST['post_type']) && 'post' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_post', $post_id ) ) return; } if ( !isset( $_POST['pdf_noncename'] ) || ! wp_verify_nonce( $_POST['pdf_noncename'], plugin_basename( __FILE__ ) ) ) return;
if(isset($_POST['pdf_id_id1']) ): update_post_meta($post_id, 'pdf_id_id1', sanitize_text_field( $_POST['pdf_id_id1'] ) );
else: if (isset($post_id)) {
delete_post_meta($post_id, 'pdf_id_id1'); }
endif;
}
function refresh_pdf_id1() {
if(isset($_POST['id'])){
$item = $_POST['id'];
if($item != '' && $item !=0){
$pdf = $this->pdf_item_id1( $item );
$ret = array();
if( !empty( $pdf ) ) {$ret['success'] = true;
$ret['pdf'] = $pdf; } else {
$ret['success'] = false; } } else {
$ret['success'] = true; $ret['pdf'] = ''; } } else {
$ret['success'] = false; } echo json_encode( $ret ); die();
}
}
$PDF_Metabox_id1 = new PDF_Metabox_id1();
in my theme i'm using:
$post_meta_id1 = get_post_custom(get_the_ID());
$pdf_id_id1 = $post_meta_id1['pdf_id_id1'][0];
$pdf_url_id1 = wp_get_attachment_url($pdf_id_id1);
...and now i want to display the modified date of this field. any ideas?
As per the comment
how do i save the modified date of this custom field and how do i get it?
You may need to check every custom field in loop one by one if any of custom fields doesnot matched with the current post data then save a new custom field to post_meta. then retrieve in your template/page.
Just an idea:
<?php
function attributes_save_postdata( $post_id ) {
$postcustom = get_post_custom( $post_id );
$is_modified = false;
foreach ( $postcustom as $key => $val ) {
var_dump( $val );
// check your post custom values and
$getpostmeta = get_post_meta( $post_id, 'your_meta_key', true );
// if database value ($getpostmeta) not equal to current post value($_POST['your_meta_key'])
if ( $getpostmeta != $_POST['your_meta_key'] ) {
$is_modified = true;
// if found any custom field updated set $modified = true
}
}
// if found any custom field updated add or update new date and time
if ( $is_modified ) {
$date = date( 'Y-m-d h:i:s' ); // example : 2016-02-02 12:00:00 current date and time
update_post_meta( $post_id, '_modifieddate', $date );
}
}
add_action( 'save_post', 'attributes_save_postdata' );
Then in your theme. get modified date.
$post_id = get_the_ID();
$getpostmeta = get_post_meta( $post_id, 'your_meta_key', true );
I think that wordpress built-in function about this would help you out even for the custom fields.
<p>Last modified: <?php the_modified_time(); ?></p>
I made a plugin that converts any uri to a hyperlink, if it finds hyper-link it will ignore it and only convert the no hyper-links uri.
In the plugin admin page I set two options, first to convert links only for the front-end, and the second option is to convert uri when ever a post/comment saved to database.
// permanently means before save to database
if ( $this->plugin_options['uri2links_convert_method'] == 'permanently' ) {
add_action( 'wp_insert_post_data', array($this, 'make_post_url_clickable' ) );
//add_action( 'preprocess_comment', array($this, 'make_comment_url_clickable' ) );
}
else {
add_filter( 'the_content', array($this, 'make_post_url_clickable' ) );
//add_filter( 'preprocess_comment', array($this, 'make_comment_url_clickable' ) );
}
My problem here if I set the plugin option to convert uri for front-end it will ignore hyper-links and convert the other uri, but if I set it to convert before save to database it 'll not ignore hyper-links and treat them as normal uri witch make the results look like this:
<a class="sdf" href=" <a href="http://test.test-75.1474.stackoverflow.com/" >http://test.test-75.1474.stackoverflow.com/ </a>
<a class="sdf" href=" <a href="https://www.stackoverflow.com" >https://www.stackoverflow.com </a>
The complete plugin source code:
<?php
/*
Plugin name: URIs to a click-able links
Plugin URI:
Description: Convert URI's to a click-able links
Author: h Abdou
Author URI: habdou.me
Version: 1.0
*/
// The admin page for the plugin
require_once( 'uri2links-menu.php' );
class Uri2Links {
protected $css = '';
protected $rel = '';
protected $target = '';
protected $convert_links = '';
protected $convert_emails = '';
protected $plugin_options = array();
protected $url_match_pattern = '/[a-zA-Z0-9\.\/\?\:#\-_=#]+\.([a-zA-Z0-9\.\/\?\:#\-_=#])+/';
protected $email_match_pattern = '/^[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/';
//protected $links_match_pattern = '/<a(?:"[^"]*"[\'"]*|\'[^\']*\'[\'"]*|[^\'">])+>^[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$<\/a>/';
protected $links_match_pattern = '/<a[^>]*>(.*?)<\/a>/';
protected $links_matched = array();
public function __construct() {
//$this->plugin_options = get_option( 'uri2links_plugin_options' );
$this->plugin_options = array( 'uri2links_convertLinksEmails' => array( 'Links', 'Emails' ), 'uri2links_convert_method' => 'permanently' );
$this->css = isset( $this->plugin_options['uri2links_custom_css'] ) ? ' class="' . $this->plugin_options['uri2links_custom_css'] . '"' : '';
$this->rel = isset( $this->plugin_options['uri2links_rel_attr'] ) ? ' rel="' . $this->plugin_options['uri2links_rel_attr'] . '"' : '';
if ( isset( $this->plugin_options['uri2links_open_links_method'] ) && $this->plugin_options['uri2links_open_links_method'] == 'new')
$this->target = ' target="_blank"';
$this->convert_links = isset( $this->plugin_options['uri2links_convertLinksEmails'][0] ) ? $this->plugin_options['uri2links_convertLinksEmails'][0] : '';
$this->convert_emails = isset( $this->plugin_options['uri2links_convertLinksEmails'][1] ) ? $this->plugin_options['uri2links_convertLinksEmails'][1] : '';
if ( $this->plugin_options['uri2links_convert_method'] == 'permanently' ) {
add_action( 'wp_insert_post_data', array($this, 'make_post_url_clickable' ) );
//add_action( 'preprocess_comment', array($this, 'make_comment_url_clickable' ) );
}
else {
add_filter( 'the_content', array($this, 'make_post_url_clickable' ) );
//add_filter( 'preprocess_comment', array($this, 'make_comment_url_clickable' ) );
}
// The admin page for the plugin
new Uri2LinksMenu;
}
// Convert all URI in a post to hyper-links.
public function make_post_url_clickable( $content ) {
$links = $this->hash_links( $content );
if ( $this->convert_links == 'Links' ) {
$content = preg_replace($this->url_match_pattern, ' <a href="\\0"' . $this->css . $this->rel . $this->target . ' >\\0</a> ', $content);
}
if ( $this->convert_emails == 'Emails' ) {
$content = preg_replace($this->email_match_pattern, ' <a href="mailto:\\0"' . $this->css . $this->rel . $this->target . ' >\\0</a> ', $content);
}
// Replace back the hashed 'a' tags to the original status.
foreach ( $links as $link_hash => $link_text ) {
$content = str_replace( $link_hash, $link_text, $content );
}
return $content;
}
// Same as 'make_post_url_clickable' but this for comments
public function make_comment_url_clickable( $content ) {
$links = hash_links( $content['comment_content']['comment_content'] );
if ( $this->convert_links == 'Links' ) {
$content['comment_content'] = preg_replace($this->url_match_pattern, ' <a href="\\0"' . $this->css . $this->rel . $this->target . ' >\\0</a> ', $content['comment_content']);
}
if ( $this->convert_emails == 'Emails' ) {
$content['comment_content'] = preg_replace($this->email_match_pattern, ' <a href="mailto:\\0"' . $this->css . $this->rel . $this->target . ' >\\0</a> ', $content['comment_content']);
}
foreach ( $links as $link_hash => $link_text ) {
$content['comment_content'] = str_replace( $link_hash, $link_text, $content['comment_content'] );
}
return $content;
}
// hash all 'a' tags so 'make_*_url_clickable' will ignore them.
public function hash_links( &$content ) {
$links = array();
if ( preg_match_all( $this->links_match_pattern, $content, $matches ) ) {
$array_size = sizeof( $matches[0] );
for ( $i = 0; $i < $array_size; ++$i ) {
$link_hash = md5( $matches[0][$i] );
$links[$link_hash] = $matches[0][$i];
$content = str_replace( $matches[0][$i], $link_hash, $content );
}
}
//die('hash_links called!');
return $links;
}
}
new Uri2Links;
?>
I just want to mention that WordPress already got the make_clickable() function that takes text uri to HTML links.
To activate it for the post content we only need this simple plugin:
<?php
/** Plugin Name: Make text uri to HTML links in the post content **/
add_filter( 'the_content', 'make_clickable', 9 );
By default this function runs on the comment text:
add_filter( 'comment_text', 'make_clickable', 9 );
I have this question on the Wordpress stack exchange as well, but not having any luck there. So, as my solution probably involves me hard-coding php and css, It may be better to have it here.
I'm using 'Flex Slider' plugin - that works on top of 'WP rotator' plug-in on my Wordpress 3.2 website. I have it implemented fine, and beginning to look at inserting my content - but I need to add a caption to be on top of the slider. As are present on most sliders on the web, within the documentation of the non-Wordpress plugin of the tool it suggests I can do something like;
<div class="flex-container">
<div class="flexslider">
<ul class="slides">
<li>
<img src="slide1.jpg" />
<p class="flex-caption">Captions and cupcakes. Winning combination.</p>
</li>
<li>
<img src="slide2.jpg" />
<p class="flex-caption">This image is wrapped in a link!</p>
</li>
<li>
<img src="slide3.jpg" />
</li>
</ul>
</div>
</div>
Problem is; with the Wordpress plug-in version, I can't find that markup to work inside.
Here's the only non-css non-js file in the plug-ins directory, so I assume I have to work in there.
I've tried inserting the mark-up that was suggested non-Wordpress above, but not sure where to insert it as it's broke it with my attempts thus far.
<?php
/*
Plugin Name: Flex Slider for WP Rotator
Plugin URI: http://wordpress.org/extend/plugins/flex-slider-for-wp-rotator/
Description: Turns WP Rotator into FlexSlider, a fully responsive jQuery slider.
Version: 1.1
Author: Bill Erickson
Author URI: http://www.billerickson.net/blog/wordpress-guide
*/
class BE_Flex_Slider {
var $instance;
function __construct() {
$this->instance =& $this;
register_activation_hook( __FILE__, array( $this, 'activation_hook' ) );
add_action( 'plugins_loaded', array( $this, 'init' ) );
}
/**
* Activation Hook
* Confirm WP Rotator is currently active
*/
function activation_hook() {
if( !function_exists( 'wp_rotator_option' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( sprintf( __( 'Sorry, you can’t activate unless you have installed WP Rotator', 'flex-slider-for-wp-rotator'), 'http://wordpress.org/extend/plugins/wp-rotator/' ) );
}
}
function init() {
// Remove original scripts and styles
remove_action('wp_head','wp_rotator_css');
remove_action('admin_head','wp_rotator_css');
remove_action('wp_head','wp_rotator_javascript');
remove_action('admin_head','wp_rotator_javascript');
remove_action('init','wp_rotator_add_jquery');
remove_action('admin_init','wp_rotator_add_jquery');
// Enqueue Scripts and Styles
add_action( 'init', array( $this, 'enqueue_scripts_and_styles' ) );
// Remove original outer markup
remove_action( 'wp_rotator', 'wp_rotator' );
// Add new markup
add_action( 'wp_rotator', array( $this, 'flex_slider' ) );
remove_shortcode( 'wp_rotator' );
add_shortcode( 'wp_rotator', array( $this, 'flex_slider_markup' ) );
}
function enqueue_scripts_and_styles() {
// Use this filter to limit where the scripts are enqueued.
$show = apply_filters( 'be_flex_slider_show_scripts', true );
if ( true === $show ) {
wp_enqueue_style( 'flex-slider', plugins_url( 'flexslider.css', __FILE__ ) );
wp_enqueue_script( 'jquery ');
wp_enqueue_script( 'flex-slider', plugins_url( 'jquery.flexslider-min.js', __FILE__ ), array( 'jquery' ) );
add_action( 'wp_head', array( $this, 'flex_slider_settings' ) );
}
}
function flex_slider_settings() {
?>
<script type="text/javascript" charset="utf-8">
jQuery(window).load(function() {
jQuery('.flexslider').flexslider({
<?php
$flex_settings = array(
'animation' => '"' . wp_rotator_option( 'animate_style' ) . '"',
'slideshowSpeed' => wp_rotator_option( 'rest_ms' ),
'animationDuration' => wp_rotator_option( 'animate_ms' ),
);
$flex_slide_settings = array(
'controlsContainer' => '".flex-container"'
);
if( 'slide' == wp_rotator_option( 'animate_style' ) )
$flex_settings = array_merge( $flex_settings, $flex_slide_settings );
$flex_settings = apply_filters( 'be_flex_slider_settings', $flex_settings );
foreach ( $flex_settings as $field => $value ) {
echo $field . ': ' . $value . ', ';
}
?>
});
});
</script>
<?php
}
function flex_slider_markup() {
$output = '';
if( 'slide' == wp_rotator_option( 'animate_style' ) )
$output .= '<div class="flex-container">';
$output .= '<div class="flexslider"><ul class="slides">';
$loop = new WP_Query( esc_attr( wp_rotator_option('query_vars') ) );
while ( $loop->have_posts() ): $loop->the_post(); global $post;
$url = esc_url ( get_post_meta( $post->ID, 'wp_rotator_url', true ) );
if ( empty( $url ) ) $url = get_permalink($post->ID);
$show_info = esc_attr( get_post_meta( $post->ID, 'wp_rotator_show_info', true ) );
if ( true == $show_info ) {
$title = get_the_title();
if ( get_the_excerpt() ) $excerpt = get_the_excerpt();
else $excerpt = '';
$caption = $title . ' <span class="excerpt">' . $excerpt . '</span>';
$info = '<p class="flex-caption">' . apply_filters( 'be_flex_slider_caption', $caption, $title, $excerpt ) . '</p>';
} else {
$info = '';
}
$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'wp_rotator' );
$slide = '<li><img src="' . $image[0] . '" />' . $info . '</li>';
$output .= apply_filters( 'be_flex_slider_slide', $slide );
endwhile; wp_reset_query();
$output .= '</ul></div>';
if( 'slide' == wp_rotator_option( 'animate_style' ) )
$output .= '</div>';
return $output;
}
function flex_slider() {
echo $this->flex_slider_markup();
}
}
new BE_Flex_Slider;
?>
I have contacted the plug-in developer, he's not responding so I assume hes not going to support my question - so I'm left to handcode.
http://wordpress.org/extend/plugins/wp-rotator/
http://flex.madebymufffin.com/
http://wordpress.org/extend/plugins/flex-slider-for-wp-rotator/
Thanks for any pointers!
It looks like captions are automatically added to the slider as long as you set the post to show rotator info (wp_rotator_show_info... probably on the plugin settings page or on your individual post page). The automatic caption is made up of the title of the post plus the excerpt. Here's the key part in the plugin above:
$show_info = esc_attr( get_post_meta( $post->ID, 'wp_rotator_show_info', true ) );
if ( true == $show_info ) {
$title = get_the_title();
if ( get_the_excerpt() ) $excerpt = get_the_excerpt();
else $excerpt = '';
$caption = $title . ' <span class="excerpt">' . $excerpt . '</span>';
$info = '<p class="flex-caption">' . apply_filters( 'be_flex_slider_caption', $caption, $title, $excerpt ) . '</p>';
} else {
$info = '';
}
UPDATE: If you want the caption to show no matter what, replace the above portion with this:
$title = get_the_title();
if ( get_the_excerpt() ) $excerpt = get_the_excerpt();
else $excerpt = '';
$caption = $title . ' <span class="excerpt">' . $excerpt . '</span>';
$info = '<p class="flex-caption">' . apply_filters( 'be_flex_slider_caption', $caption, $title, $excerpt ) . '</p>';
Note that I merely deleted the part that checks for wp_rotator_show_info.
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/