Plugin Directory

Changeset 1604073


Ignore:
Timestamp:
02/26/2017 11:11:01 PM (9 years ago)
Author:
lgteamwork
Message:

v1.6

Location:
real-time-crowd/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • real-time-crowd/trunk/readme.txt

    r1292667 r1604073  
    33Tags: realtime, real time, real-time, realtime crowd, real time crowd, real-time crowd, woocommerce
    44Requires at least: 3.6
    5 Tested up to: 4.3.1
    6 Stable tag: 1.5
     5Tested up to: 4.7.2
     6Stable tag: 1.6
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3030
    3131== Changelog ==
     32
     33= 1.6 =
     34* Set default homepage title and image.
     35* Get picture of the first product in category if category image is not available, otherwise fallback to default image if exists on filesystem.
     36* set Display=none for iframe when the widget "Display" checkbox is not checked.
    3237
    3338= 1.5 =
  • real-time-crowd/trunk/real-time-crowd.php

    r1292668 r1604073  
    44Plugin URI: http://www.realtimecrowd.net/
    55Description: Enables Real-Time Crowd tracking and generation on your WordPress site.
    6 Version: 1.5
     6Version: 1.6
    77Author: RealTimeCrowd.net
    88Author URI: http://www.realtimecrowd.net/
     
    8888        <td>
    8989          <input name="rtc_display_widget" type="checkbox" value="1" <?php checked( '1', get_option( 'rtc_display_widget' ) ); ?> />
    90           <span class="description">Checking this will display the widget on every post and page of the site. (The widget also contains a small icon linking to RealTimeCrowd.net)</span>
     90          <span class="description">Checking this will display the widget on every post and page of the site.</span>
    9191        </td>
    9292      </tr>
     
    162162                {
    163163                    $pageTitle = $cat->name;
    164                     $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
    165                     $pageImageUrl = wp_get_attachment_url( $thumbnail_id );
    166                    
    167                     $icon = plugin_dir_path(__FILE__)."category-icon.png";
    168                     $icon = str_replace("/","\\",$icon);
    169                     if (empty($pageImageUrl) && file_exists($icon))
    170                     {
    171                         $pageImageUrl = plugin_dir_url( __FILE__ ) . "category-icon.png";
    172                     }
    173                 }
     164                }
     165                $pageImageUrl = getCategoryImageUrl($postId, $cat);
    174166            }
    175167            else if (is_product())
     
    179171                {
    180172                    $pageTitle = html_entity_decode(get_the_title($postId),ENT_QUOTES,'UTF-8');
    181                     if (has_post_thumbnail($postId))
    182                     {
    183                         $images = wp_get_attachment_image_src(get_post_thumbnail_id($postId), array(100, 100));
    184                         if (count($images)>0)
    185                         {
    186                             $pageImageUrl = $images[0];
    187                         }
    188                     }
    189                     else
    190                     {
    191                         $attachment_ids = $product->get_gallery_attachment_ids();
    192                         if (count($attachment_ids)>0)
    193                         {
    194                             $pageImageUrl = wp_get_attachment_url($attachment_ids[0]);
    195                         }
    196                     }
    197                    
    198                     $icon = plugin_dir_path(__FILE__)."product-icon.png";
    199                     $icon = str_replace("/","\\",$icon);
    200                     if (empty($pageImageUrl) && file_exists($icon))
    201                     {
    202                         $pageImageUrl = plugin_dir_url( __FILE__ ) . "product-icon.png";
    203                     }
    204                 }
     173                }
     174                $pageImageUrl = getProductImageUrl($postId, $product);
    205175            }
    206176        }
     
    224194        else if (is_front_page() || is_home())
    225195        {
    226             $pageTitle = get_bloginfo('name');
     196            //$pageTitle = get_bloginfo('name');
     197            $pageTitle = "Homepage";
    227198            $icon = plugin_dir_path(__FILE__)."home-icon.png";
    228             $icon = str_replace("/","\\",$icon);
    229199            if (empty($pageImageUrl) && file_exists($icon))
    230200            {
     
    234204    }
    235205
    236     if (!empty($pageTitle) && !empty($accountAlias) && !is_admin())
     206    if (!empty($pageTitle) && !is_admin())
    237207    {
    238208        echo "<!--rtc code-->
     
    263233    }
    264234}
     235function getProductImageUrl($postId, $product)
     236{
     237    $pageImageUrl = "";
     238    if ($product)
     239    {
     240        if (has_post_thumbnail($postId))
     241        {
     242            $images = wp_get_attachment_image_src(get_post_thumbnail_id($postId), array(100, 100));
     243            if (count($images)>0)
     244            {
     245                $pageImageUrl = $images[0];
     246            }
     247        }
     248        else
     249        {
     250            $attachment_ids = $product->get_gallery_attachment_ids();
     251            if (count($attachment_ids)>0)
     252            {
     253                $pageImageUrl = wp_get_attachment_url($attachment_ids[0]);
     254            }
     255        }
     256    }
     257
     258    //if product didnt have image, try to set default image
     259    $icon = plugin_dir_path(__FILE__)."product-icon.png";
     260    if (empty($pageImageUrl) && file_exists($icon))
     261    {
     262        $pageImageUrl = plugin_dir_url( __FILE__ ) . "product-icon.png";
     263    }
     264    return $pageImageUrl;
     265}
     266function getCategoryImageUrl($postId, $category)
     267{
     268    $pageImageUrl = "";
     269    if ($category)
     270    {
     271        //try to get image of the category
     272        $thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
     273        if ($thumbnail_id)
     274        {
     275            $pageImageUrl = wp_get_attachment_url( $thumbnail_id );
     276        }
     277       
     278        //if category didnt have image try to get thumbnail of first product in this category
     279        if (empty($pageImageUrl))
     280        {
     281            //build our query
     282            $query_args = array(
     283                'meta_query' => array(
     284                    array(
     285                        'key' => '_visibility',
     286                        'value' => array( 'catalog', 'visible' ),
     287                        'compare' => 'IN'
     288                    )
     289                ),
     290                'post_status' => 'publish',
     291                'post_type' => 'product',
     292                'posts_per_page' => 1,
     293                'tax_query' => array(
     294                    array(
     295                        'field' => 'id',
     296                        'taxonomy' => 'product_cat',
     297                        'terms' => $category->term_id
     298                    )
     299                ),
     300                'orderby'    => 'date',
     301                'sort_order' => 'desc'
     302            );
     303            //Query DB
     304            $products = get_posts( $query_args );
     305            //If matching products found
     306            if($products && count($products)>0)
     307            {
     308                if (has_post_thumbnail($products[0]->ID))
     309                {
     310                    // check for a thumbnail
     311                    $images = wp_get_attachment_image_src(get_post_thumbnail_id($products[0]->ID), array(100, 100));
     312                    if (count($images)>0)
     313                    {
     314                        $pageImageUrl = $images[0];
     315                    }
     316                }
     317                else
     318                {
     319                    //check for image of product
     320                    $attachment_ids = $products[0]->get_gallery_attachment_ids();
     321                    if (count($attachment_ids)>0)
     322                    {
     323                        $pageImageUrl = wp_get_attachment_url($attachment_ids[0]);
     324                    }
     325                }
     326            }
     327        }
     328    }
     329           
     330    //if category still doesnt have image, try to set default image
     331    $icon = plugin_dir_path(__FILE__)."category-icon.png";
     332    if (empty($pageImageUrl) && file_exists($icon))
     333    {
     334        $pageImageUrl = plugin_dir_url( __FILE__ ) . "category-icon.png";
     335    }
     336    return $pageImageUrl;
     337}
    265338/* Puts code on Wordpress pages */
    266339add_action('wp_footer', 'rtc_tracking_code');
Note: See TracChangeset for help on using the changeset viewer.