Plugin Directory

Changeset 695157


Ignore:
Timestamp:
04/10/2013 10:29:59 AM (13 years ago)
Author:
wp4u.net
Message:

Fixed Error with single wordpress site

Location:
latest-posts-multisite-widget/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • latest-posts-multisite-widget/trunk/latest_posts_multisite.php

    r694125 r695157  
    33 * Plugin Name: Latest Posts MultiSite Widget
    44 * Version: 1.0
    5  * Plugin URI: http://wp4u.net/
     5 * Plugin URI: http://wp4u.net/latest-posts-multisite-widget/
    66 * Description: Latest Posts MultiSite Widget is a wordpress plugin that enables admin to add widgets which display latest posts content from other sites in a wordpress network. The widget supports custom post types, post images, excerpts and also custom fields data. Admin can use default template or make their custom template.
    77 * Author: WP4U
    88 * Author URI: http://wp4u.net/
    99 */
    10 class LatestPostsWidget extends WP_Widget
     10class WP4U_LatestPostsWidget extends WP_Widget
    1111{
    1212    /**
     
    1414    *
    1515    */
    16     function LatestPostsWidget(){
    17         $widget_ops = array('classname' => 'widget_LatestPostsWidget', 'description' => __( "Latest Posts MultiSite Widget is a wp plugin that enables admin to add widgets which display latest post content from other sites in wordpress network, support custom post types .") );
     16    public function WP4U_LatestPostsWidget(){
     17        $widget_ops = array('classname' => 'widget_WP4U_LatestPostsWidget', 'description' => __( "Latest Posts MultiSite Widget is a wp plugin that enables admin to add widgets which display latest post content from other sites in wordpress network, support custom post types .") );
    1818        $control_ops = array('width' => 300, 'height' => 300);
    19         $this->WP_Widget('LatestPostsWidget', __('Latest Posts MultiSite Widget'), $widget_ops, $control_ops);
     19        parent::WP_Widget(false, __('WP4U Latest Posts MultiSite Widget'), $widget_ops, $control_ops);
    2020    }
    2121   
     
    2727        extract($args);
    2828        extract($instance);
    29         switch_to_blog($blog_id);
     29        if(is_multisite())
     30            switch_to_blog($blog_id);
    3031        $output = '';
    3132        global $wpdb;
     
    3334        $request = $wpdb->prepare("SELECT ".$wpdb->prefix."posts.*
    3435                   FROM ".$wpdb->prefix."posts
    35                    WHERE post_type='$post_type' AND post_status = 'publish' ORDER BY post_date DESC LIMIT ".$limit);
     36                   WHERE post_type='$post_type' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 0,%d",(int)$limit);
    3637        $results = $wpdb->get_results($request);
    3738        $results = $wpdb->get_results($request);
     
    6465                             }
    6566                        }
    66                        
     67                        $template = trim($template);
    6768                        if(empty($template))
    6869                        {                       
     
    9293                    $output .= '</ul>';
    9394                }
    94                 restore_current_blog();
     95                if(is_multisite())
     96                    restore_current_blog();
    9597          echo $before_widget . $before_title . $title . $after_title;
    9698          echo $output . $after_widget;
     
    125127        $instance = wp_parse_args( (array) $instance, array('title'=>'', 'limit' => 5,'post_type' => 'post','blog_id' => 1,'template' => '','imagew' => 100,'imageh' => 100,'excerpt_length' => 20));
    126128        extract($instance);
    127        
    128         $blogs = get_blog_list(0,'all');
     129        $blogs = array();
     130        if(is_multisite())
     131            $blogs = get_blog_list(0,'all');
     132        else
     133            $blogs[] = array('blog_id' => 1)
    129134       
    130135       ?>
     
    145150        <select class="widefat" id="<?php echo $this->get_field_id( 'blog_id' ); ?>" name="<?php echo $this->get_field_name( 'blog_id' ); ?>"  >
    146151            <?php foreach($blogs as $bid=>$blog) { 
     152               
     153                if(is_multisite())
     154                    $blog_name = get_blog_option($blog['blog_id'],'blogname');
     155                else
     156                    $blog_name = get_option('blogname');
    147157            ?>
    148                 <option value="<?php echo $blog['blog_id'];?>" <?php if((int)$blog['blog_id'] == (int)$blog_id) echo 'selected="selected"'?>><?php echo get_blog_option($blog['blog_id'],'blogname');?></option>
     158                <option value="<?php echo $blog['blog_id'];?>" <?php if((int)$blog['blog_id'] == (int)$blog_id) echo 'selected="selected"'?>><?php echo $blog_name;?></option>
    149159            <?php }
    150160            ?>
     
    190200    * Calls 'widgets_init' action after widget has been registered.
    191201    */
    192     function LatestPostsWidgetInit() {
    193         register_widget('LatestPostsWidget');
    194     }   
    195     add_action('widgets_init', 'LatestPostsWidgetInit');
     202add_action('widgets_init', create_function('', 'return register_widget(\'WP4U_LatestPostsWidget\');'));
  • latest-posts-multisite-widget/trunk/readme.txt

    r694136 r695157  
    77Requires at least: 3.0
    88Tested up to: 3.5.1
    9 Stable tag: 1.0
     9Stable tag: 1.1
     10
     11Display latest posts from other site in network.
    1012
    1113== Description ==
    12 Latest Posts MultiSite Widget is a wordpress plugin that enables admin to add widgets which display latest posts content from other sites in a wordpress network. The widget supports custom post types, post images, excerpts and also custom fields data. Admin can use default template or make their custom template.
     14
     15###Latest Posts MultiSite Widget
     16
     17
     18[Latest Posts MultiSite Widget](http://wp4u.net/latest-posts-multisite-widget/) is a wordpress plugin that enables admin to add widgets which display latest posts content from other sites in a wordpress network. The widget supports custom post types, post images, excerpts and also custom fields data. Admin can use default template or make their custom template.
     19
     20Support Template Tags :
     21
     22* Post title : **{title}**
     23* Post excerpt : **{excerpt}**
     24* Featured Image : **{image}**
     25* Post Link : **{link}**
     26* Custom fields: **%%custom_field_key%%**
     27* ....
     28
     29And will add more template tags.
    1330
    1431
    1532== Installation ==
     33
     34####Thank you for your interest in [Latest Posts MultiSite Widget](http://wp4u.net/latest-posts-multisite-widget/).
    1635
    1736* Download "latest-posts-multisite.zip" to your computer.
     
    2443* Go to your widget and adjust the settings
    2544* Use template tags to make your custom tempplate : {title}, {link}, {excerpt}, {image}, .. and any custom field data %%custom_field_key%%
     45
     46If any problem occurs with **Latest Posts MultiSite Widget**, please submit tickets in our support page: [WP4U Support](http://wp4u.net/support/). 
    2647
    2748
     
    3960== Changelog ==
    4061
     62= v1.1 04.010.2013 =
     63Fixed error with single wordpress site
     64
    4165= v1.0 04.08.2013 =
    4266initial release
    4367
    44 == Frequently Asked Questions ==
    4568
    46 
    47 == Upgrade Notice ==
    48 
Note: See TracChangeset for help on using the changeset viewer.