Skip to content

Instantly share code, notes, and snippets.

View sunshinephotocart's full-sized avatar

Sunshine Photo Cart sunshinephotocart

View GitHub Profile
@sunshinephotocart
sunshinephotocart / image-keywords.php
Created October 5, 2023 18:55
Show keywords for an image
add_action( 'sunshine_after_image', 'sunshine_show_image_keywords' );
function sunshine_show_image_keywords( $image ) {
$metadata = $image->get_meta_value( '_wp_attachment_metadata' );
if ( ! empty( $metadata['image_meta']['keywords'] ) ) {
echo join( ', ', $metadata['image_meta']['keywords'] );
}
}
@sunshinephotocart
sunshinephotocart / entire-gallery-download-before-add-cart.php
Created June 5, 2023 17:35
Entire Gallery Download add to cart link before add to cart form
@sunshinephotocart
sunshinephotocart / sunshine-checkout-redirect.php
Last active May 31, 2023 18:18
Redirect to login or registration if not logged in at checkout
// Redirects to Login page.
add_action( 'template_redirect', function() {
global $sunshine;
if ( ! is_user_logged_in() && is_page( $sunshine->options['page_checkout'] ) ) {
wp_redirect( wp_login_url( get_permalink( $sunshine->options['page_checkout'] ) ) );
exit;
}
});
// Redirects to Registration page.
// Add this to your theme's functions.php file
// Or use this plugin https://wordpress.org/plugins/insert-headers-and-footers/
add_filter( 'sunshine_allowed_css', 'sunshine_custom_allowed_css' );
function sunshine_custom_allowed_css( $allowed ) {
$allowed[] = 'cookie'; // This must contain a keyword from the wp_enqueue_style from your plugin/theme
return $allowed;
}
// Add this to your theme's functions.php file
// Or use this plugin https://wordpress.org/plugins/my-custom-functions/
add_filter( 'sunshine_currencies', 'my_custom_sunshine_currencies' );
function my_custom_sunshine_currencies( $currencies ) {
$currencies['TND'] = 'Tunisian Dinar'; // TND = Currency code and then name
return $currencies;
}
@sunshinephotocart
sunshinephotocart / sunshine-custom-action-menu.php
Created September 20, 2021 17:24
Add menu item to action menu
// Add this to your theme's functions.php file
// Or use this plugin https://wordpress.org/plugins/my-custom-functions/
add_filter( 'sunshine_action_menu', 'my_custom_sunshine_action_menu' );
function my_custom_sunshine_action_menu( $menu ) {
$menu[97] = array(
'name' => 'PAGE_NAME',
'url' => "PAGE_URL',
);
return $menu;
}
@sunshinephotocart
sunshinephotocart / sunshine-single-image-exif.php
Last active October 5, 2023 18:59
Show all EXIF/image meta on single image view (Sunshine 3)
add_action( 'sunshine_after_image', 'sunshine_exif_data' );
function sunshine_exif_data( $image ) {
$meta = wp_get_attachment_metadata( $image->get_id() );
$image_meta = $meta['image_meta']; // Get the meta data/EXIF from the image upload
foreach ( $image_meta as $key => $value ) {
if ( !empty( $value ) ) {
echo ucwords( $key ) . ': '; // Display key as label
if ( is_array( $value ) ) {
echo join( ', ', $value ); // Display array values comma separated, likely keywords
} else {
@sunshinephotocart
sunshinephotocart / sunshine-related-images.php
Last active May 7, 2021 19:49
Show related images in single image view
@sunshinephotocart
sunshinephotocart / sunshine-stop-view-tracking.php
Created December 6, 2019 17:37
Stops image view tracking to keep database small
<?php
/*
Plugin Name: Sunshine Photo Cart - Analytics (Stop image view tracking)
Plugin URI: http://www.sunshinephotocart.com/addon/analytics
Description: Stops image view tracking to keep database small
Version: 0.1
Author: Sunshine Photo Cart
Author URI: http://www.sunshinephotocart.com
*/
@sunshinephotocart
sunshinephotocart / sunshine-galleries-by-date
Created November 13, 2019 22:47
Order galleries in admin by date
// Add this to your theme's functions.php file
// Or use this plugin https://wordpress.org/plugins/my-custom-functions/
add_filter( 'pre_get_posts', 'sunshine_order_galleries_by_date_in_admin' );
function sunshine_order_galleries_by_date_in_admin( $wp_query ) {
global $pagenow;
if ( is_admin() && $_GET['post_type'] == 'sunshine-gallery' && 'edit.php' == $pagenow && !isset( $_GET['orderby'] ) ) {
$wp_query->set( 'orderby', 'date' );
$wp_query->set( 'order', 'DESC' );
}
}