/** * Adds the 'sell_media' short code to the editor. [sell_media_item] * * @since 0.1 */ function sell_media_item_shortcode($atts) { extract(shortcode_atts(array('style' => 'default', 'color' => 'blue', 'id' => '', 'attachment' => '', 'text' => 'BUY', 'size' => 'medium', 'align' => 'center'), $atts)); $image = sell_media_item_icon($id, $size, false); $text = apply_filters('sell_media_purchase_text', $text, $id); if (sell_media_has_multiple_attachments($id)) { $button = sell_media_item_buy_button($id, $attachment, 'button', $text, false); } else { $button = ''; } return '<div class="sell-media-item-container sell-media-align' . $align . ' "><a href="' . get_permalink($id) . '">' . $image . '</a>' . $button . '</div>'; }
/** * Get Attachment Meta * * Returns the attachment meta field. * Use to get title, caption, description * Or anything else listed here: * https://codex.wordpress.org/Function_Reference/wp_prepare_attachment_for_js * * @param int $post_id * @param int $field * @uses wp_prepare_attachment_for_js(); * @return string field (id, caption, title, description, etc) * @since 2.0.4 */ function sell_media_get_attachment_meta($post_id = null, $field = 'id') { if (sell_media_has_multiple_attachments($post_id)) { $attachment_id = get_query_var('id'); } else { $attachments = sell_media_get_attachments($post_id); $attachment_id = $attachments[0]; } $attachment_meta = wp_prepare_attachment_for_js($attachment_id); return $attachment_meta[$field]; }
/** * Options meta box */ function sell_media_options_meta_box($post) { $settings = sell_media_get_plugin_options(); $price = get_post_meta($post->ID, 'sell_media_price', true) ? get_post_meta($post->ID, 'sell_media_price', true) : sprintf('%0.2f', $settings->default_price); do_action('sell_media_before_options_meta_box', $post); ?> <div id="sell-media-price-field" class="sell-media-field"> <label for="sell-media-price"><?php _e('Price', 'sell_media'); ?> (<?php echo sell_media_get_currency_symbol(); ?> )</label> <input name="sell_media_price" id="sell-media-price" class="small-text" type="number" step="0.01" min="0" placeholder="<?php echo $price; ?> " value="<?php echo $price; ?> " /> <?php if (sell_media_has_multiple_attachments($post->ID)) { ?> <span class="desc"><?php _e('The price of each original, high-resolution file.', 'sell_media'); ?> </span> <?php } ?> </div> <div id="sell-media-price-group-field" class="sell-media-field"> <label for="sell-media-price-group"><?php _e('Price group for downloads', 'sell_media'); ?> </label> <?php $args = array('show_option_none' => __('None', 'sell_media'), 'option_none_value' => 0, 'name' => 'sell_media_price_group', 'id' => 'sell-media-price-group', 'class' => 'sell-media-price-group', 'taxonomy' => 'price-group', 'hierarchical' => true, 'depth' => 1, 'hide_empty' => false, 'selected' => sell_media_get_item_price_group($post->ID, 'price-group')); wp_dropdown_categories($args); ?> <span class="desc"><?php printf(__('<a href="%1$s">Create new price group</a>', 'sell_media'), admin_url() . 'edit.php?post_type=sell_media_item&page=sell_media_plugin_options&tab=sell_media_size_settings'); ?> </span> </div> <?php do_action('sell_media_after_options_meta_box', $post->ID); }
* So we must set all required tags high * Otherwise, our server-side price validation fails * The item_pgroup class is shared between downloads and reprints, which use different price group taxonomies * Check if terms exist in these price group taxonomies to determine verified prices * Some values below are set via javascript (select options on change event) * .item_usage (license name to be shown on cartColumns) and .item_license are set inline with their select boxes */ ?> <form id="sell-media-cart-items" class="hide"> <input class="item_number" type="text" value="<?php echo $post_id; ?> " /> <input class="item_name" type="text" value="<?php echo get_the_title($post_id); if (sell_media_has_multiple_attachments($post_id)) { echo ', ' . $attachment_id; } ?> " /> <input class="item_type" type="text" value="<?php if ($is_package) { echo 'download'; } else { echo apply_filters('sell_media_set_product_type', 'download'); } ?> " /> <input class="item_image" type="text" value="<?php echo sell_media_item_image_src($post_id, $attachment_id); ?>
/** * Add media (featured image, etc) before the_content * * @since 1.9.2 * @global $post * * @param $content The the_content field of the item object * @return string the content with any additional data attached */ function sell_media_append_media($post_id) { $html = ''; $sell_media_taxonomies = get_object_taxonomies('sell_media_item'); if (is_post_type_archive('sell_media_item') || is_tax($sell_media_taxonomies) || is_search()) { $html .= '<a href="' . get_permalink($post_id) . '" ' . sell_media_link_attributes($post_id) . '>' . sell_media_item_icon($post_id, 'large', false) . '</a>'; } elseif (is_singular('sell_media_item')) { sell_media_set_post_views($post_id); if (sell_media_has_multiple_attachments($post_id)) { $html .= sell_media_gallery($post_id); } else { sell_media_item_icon($post_id, 'large'); $html .= '<p class="sell-media-caption">'; $html .= '<span class="sell-media-title">' . sell_media_get_attachment_meta($post_id, 'title') . '</span>'; if (sell_media_get_attachment_meta($post_id, 'caption')) { $html .= ' — '; $html .= sell_media_get_attachment_meta($post_id, 'caption'); } $html .= '</p>'; } } echo apply_filters('sell_media_append_media_filter', $html, $post_id); }
/** * Extract IPTC info from original source image * Save IPTC data as custom taxonomy terms */ public function parse_iptc_info($original_file = null, $attachment_id = null) { global $post; // Extract IPTC meta info from the uploaded image. $city = sell_media_iptc_parser('city', $original_file); $state = sell_media_iptc_parser('state', $original_file); $creator = sell_media_iptc_parser('creator', $original_file); $keywords = sell_media_iptc_parser('keywords', $original_file); /** * Assign terms to either the post or the attachment. * * In version 2.0, we added the product gallery capabilty. * Since multiple images can be assigned, taxonomy terms (keywords) * should be assigned to the attachments, not the post. */ if (!sell_media_has_multiple_attachments($post->ID)) { $attachment_id = $post->ID; } // Save IPTC info as taxonomies if (!empty($attachment_id)) { if ($city) { sell_media_iptc_save('city', $city, $attachment_id); } if ($state) { sell_media_iptc_save('state', $state, $attachment_id); } if ($creator) { sell_media_iptc_save('creator', $creator, $attachment_id); } if ($keywords) { sell_media_iptc_save('keywords', $keywords, $attachment_id); } } }