Plugin Directory

Changeset 3217050


Ignore:
Timestamp:
01/05/2025 02:03:37 AM (12 months ago)
Author:
bhubbard
Message:

Update to 0.2.0

Location:
image-flip-for-woocommerce/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • image-flip-for-woocommerce/trunk

    • Property svn:ignore set to
      vendor
  • image-flip-for-woocommerce/trunk/image-flip-for-woocommerce.php

    r2603897 r3217050  
    88 * Text Domain:     image-flip-for-woocommerce
    99 * Domain Path:     /languages
    10  * Version:         0.1.9
     10 * Version:         0.2.0
     11 * Tested up to: 6.7.1
    1112 * License: GNU General Public License v3.0
    1213 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
    1314 * Based on plugin by jameskoster (https://jameskoster.co.uk)
    1415 *
    15  * @package         Image_Flip_For_Woocommerce
     16 * @package Image_Flip_For_Woocommerce
    1617 */
    1718
     
    1920 * Check if WooCommerce is active
    2021 */
    21 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
     22if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')), true) ) {
    2223
    23     /**
    24     * Image Flipper class exists.
    25     */
    26     if ( ! class_exists( 'Image_Flip_WooCommerce' ) ) {
     24    /**
     25    * Image Flipper class exists.
     26    */
     27    if (! class_exists('Image_Flip_WooCommerce') ) {
    2728
    28         /**
    29          * Image_Flip_WooCommerce class.
    30          */
    31         class Image_Flip_WooCommerce {
     29        /**
     30         * Image_Flip_WooCommerce class.
     31         */
     32        class Image_Flip_WooCommerce
     33        {
    3234
    33             /**
    34              * __construct function.
    35              *
    36              * @access public
    37              * @return void
    38              */
    39             public function __construct() {
    40                 add_action( 'init', array( $this, 'init' ) );
    41                 add_action( 'wp_enqueue_scripts', array( $this, 'image_flip_styles' ) );
    42                 add_action( 'woocommerce_before_shop_loop_item_title', array( $this, 'woocommerce_template_loop_second_product_thumbnail' ), 11 );
    43                 add_filter( 'post_class', array( $this, 'product_has_gallery' ) );
    44             }
     35            /**
     36             * __construct function.
     37             *
     38             * @access public
     39             * @return void
     40             */
     41            public function __construct()
     42            {
     43                add_action('init', array( $this, 'init' ));
     44                add_action('wp_enqueue_scripts', array( $this, 'image_flip_styles' ));
     45                add_action('woocommerce_before_shop_loop_item_title', array( $this, 'woocommerce_template_loop_second_product_thumbnail' ), 11);
     46                add_filter('post_class', array( $this, 'product_has_gallery' ));
     47            }
    4548
    46             /**
    47              * Init.
    48              *
    49              * @access public
    50              */
    51             public function init() {
    52                 load_plugin_textdomain( 'image-flip-for-woocommerce', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
    53             }
     49            /**
     50             * Init.
     51             *
     52             * @access public
     53             */
     54            public function init()
     55            {
     56                load_plugin_textdomain('image-flip-for-woocommerce', false, dirname(plugin_basename(__FILE__)) . '/languages');
     57            }
    5458
    55             /**
    56              * Styles.
    57              *
    58              * @access public
    59              */
    60             public function image_flip_styles() {
    61                 if( is_product_category() ) {
    62                     if ( apply_filters( 'image_flip_styles', true ) ) {
    63                         wp_enqueue_style( 'image-flip-styles', plugins_url( '/assets/css/image-flip.min.css', __FILE__ ), array(), '0.0.1', 'all' );
    64                     }
    65                 }
    66             }
     59            /**
     60             * Styles.
     61             *
     62             * @access public
     63             */
     64            public function image_flip_styles()
     65            {
     66                if(is_product_category() ) {
     67                    if (apply_filters('image_flip_styles', true) ) {
     68                        wp_enqueue_style('image-flip-styles', plugins_url('/assets/css/image-flip.min.css', __FILE__), array(), '0.0.1', 'all');
     69                    }
     70                }
     71            }
    6772
    68             /**
    69              * Add class if Product has Gallery.
    70              *
    71              * @access public
    72              * @param mixed $classes Classes.
    73              */
    74             public function product_has_gallery( $classes ) {
     73            /**
     74             * Add class if Product has Gallery.
     75             *
     76             * @access public
     77             * @param  mixed $classes Classes.
     78             */
     79            public function product_has_gallery( $classes )
     80            {
    7581
    76                     global $product;
     82                global $product;
    7783
    78                     $post_type = get_post_type( get_the_ID() );
     84                $post_type = get_post_type(get_the_ID());
    7985
    80                     if ( ! is_admin() ) {
     86                if (! is_admin() ) {
    8187
    82                         if ( 'product' === $post_type && is_product_category() ) {
     88                    if ('product' === $post_type && is_product_category() ) {
    8389
    84                             $attachment_ids = $this->get_gallery_image_ids( $product );
     90                            $attachment_ids = $this->get_gallery_image_ids($product);
    8591
    86                             if ( $attachment_ids ) {
    87                                 $classes[] = 'pif-has-gallery';
    88                             }
    89                         }
    90                     }
     92                        if ($attachment_ids ) {
     93                            $classes[] = 'pif-has-gallery';
     94                        }
     95                    }
     96                }
    9197
    92                     return $classes;
     98                return $classes;
    9399
    94             }
     100            }
    95101
    96             /**
    97              * Loop Second Product Thumbnail.
    98              *
    99              * @access public
    100              */
    101             public function woocommerce_template_loop_second_product_thumbnail() {
     102            /**
     103             * Loop Second Product Thumbnail.
     104             *
     105             * @access public
     106             */
     107            public function woocommerce_template_loop_second_product_thumbnail()
     108            {
    102109
    103                 if( is_product_category() ) {
     110                if(is_product_category() ) {
    104111
    105                     global $product, $woocommerce;
     112                    global $product, $woocommerce;
    106113
    107                     $attachment_ids = $this->get_gallery_image_ids( $product );
     114                    $attachment_ids = $this->get_gallery_image_ids($product);
    108115
    109                     if ( $attachment_ids ) {
    110                         $attachment_ids     = array_values( $attachment_ids );
    111                         $secondary_image_id = $attachment_ids['0'];
     116                    if ($attachment_ids ) {
     117                        $attachment_ids     = array_values($attachment_ids);
     118                        $secondary_image_id = $attachment_ids['0'];
    112119
    113                         $secondary_image_alt   = get_post_meta( $secondary_image_id, '_wp_attachment_image_alt', true );
    114                         $secondary_image_title = get_the_title( $secondary_image_id );
     120                        $secondary_image_alt   = get_post_meta($secondary_image_id, '_wp_attachment_image_alt', true);
     121                        $secondary_image_title = get_the_title($secondary_image_id);
    115122
    116                         echo wp_get_attachment_image(
    117                             $secondary_image_id,
    118                             'shop_catalog',
    119                             '',
    120                             array(
    121                                 'class' => 'secondary-image attachment-shop-catalog wp-post-image wp-post-image--secondary',
    122                                 'alt'   => $secondary_image_alt,
    123                                 'title' => $secondary_image_title,
    124                             )
    125                         );
    126                     }
     123                        echo wp_get_attachment_image(
     124                            $secondary_image_id,
     125                            'shop_catalog',
     126                            '',
     127                            array(
     128                            'class' => 'secondary-image attachment-shop-catalog wp-post-image wp-post-image--secondary',
     129                            'alt'   => $secondary_image_alt,
     130                            'title' => $secondary_image_title,
     131                            )
     132                        );
     133                    }
    127134
    128                 }
    129             }
     135                }
     136            }
    130137
    131             /**
    132              * Get Gallery Image IDs.
    133              *
    134              * @access public
    135              * @param mixed $product Product.
    136              */
    137             public function get_gallery_image_ids( $product ) {
     138            /**
     139             * Get Gallery Image IDs.
     140             *
     141             * @access public
     142             * @param  mixed $product Product.
     143             */
     144            public function get_gallery_image_ids( $product )
     145            {
    138146
    139                 if( is_product_category() ) {
     147                if(is_product_category() ) {
    140148
    141                     if ( ! is_a( $product, 'WC_Product' ) ) {
    142                         return;
    143                     }
     149                    if (! is_a($product, 'WC_Product') ) {
     150                        return;
     151                    }
    144152
    145                     if ( is_callable( 'WC_Product::get_gallery_image_ids' ) ) {
    146                         return $product->get_gallery_image_ids();
    147                     } else {
    148                         return $product->get_gallery_attachment_ids();
    149                     }
     153                    if (is_callable('WC_Product::get_gallery_image_ids') ) {
     154                        return $product->get_gallery_image_ids();
     155                    } else {
     156                        return $product->get_gallery_attachment_ids();
     157                    }
    150158
    151                 }
    152             }
     159                }
     160            }
    153161
    154         }
     162        }
    155163
    156         $image_flip_woocommerce = new Image_Flip_WooCommerce();
    157     }
     164        $image_flip_woocommerce = new Image_Flip_WooCommerce();
     165    }
    158166}
  • image-flip-for-woocommerce/trunk/uninstall.php

    r2121753 r3217050  
    77
    88// Exit if accessed directly.
    9 defined( 'ABSPATH' ) || exit;
     9defined('ABSPATH') || exit;
    1010
    11 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    12     exit();
     11if (! defined('WP_UNINSTALL_PLUGIN') ) {
     12    exit();
    1313}
    1414
Note: See TracChangeset for help on using the changeset viewer.