/** * Scripts * * Enqueues all necessary scripts in the WP Admin to run Sell Media * * @since 1.8.5 * @return void */ function sell_media_scripts($hook) { $settings = sell_media_get_plugin_options(); // enqueue wp_enqueue_script('sell_media_jquery_cookie', SELL_MEDIA_PLUGIN_URL . 'js/jquery.cookie.js', array('jquery'), SELL_MEDIA_VERSION); wp_enqueue_script('sell_media', SELL_MEDIA_PLUGIN_URL . 'js/sell_media.js', array('jquery', 'sell_media_jquery_cookie'), SELL_MEDIA_VERSION); wp_enqueue_script('sellMediaCart', SELL_MEDIA_PLUGIN_URL . 'js/sell_media_cart.js', array('jquery'), SELL_MEDIA_VERSION); wp_enqueue_style('sell_media', SELL_MEDIA_PLUGIN_URL . 'css/sell_media.css', array('dashicons'), SELL_MEDIA_VERSION); if (isset($settings->style) && '' != $settings->style) { wp_enqueue_style('sell-media-style', SELL_MEDIA_PLUGIN_URL . 'css/sell_media-' . $settings->style . '.css'); } else { wp_enqueue_style('sell-media-style', SELL_MEDIA_PLUGIN_URL . 'css/sell_media-light.css'); } wp_localize_script('sell_media', 'sell_media', array('ajaxurl' => esc_url(admin_url('admin-ajax.php')), 'pluginurl' => esc_url(SELL_MEDIA_PLUGIN_URL . 'sell-media.php'), 'site_name' => esc_html(get_bloginfo('name')), 'site_url' => esc_url(site_url()), 'checkout_url' => empty($settings->checkout_page) ? null : esc_url(get_permalink($settings->checkout_page)), 'currency_symbol' => $settings->currency, 'dashboard_page' => esc_url(get_permalink($settings->dashboard_page)), 'error' => array('email_exists' => __('Sorry that email already exists or is invalid', 'sell_media')), 'sandbox' => $settings->test_mode == 1 ? true : false, 'paypal_email' => empty($settings->paypal_email) ? null : $settings->paypal_email, 'thanks_page' => esc_url(get_permalink($settings->thanks_page)), 'listener_url' => esc_url(add_query_arg('sell_media-listener', 'IPN', home_url('index.php'))), 'added_to_cart' => sprintf("%s! <a href='" . esc_url(get_permalink($settings->checkout_page)) . "' class='cart'>%s</a>!", __('Added', 'sell_media'), __('Checkout now', 'sell_media')), 'cart_labels' => array('name' => __('Name', 'sell_media'), 'size' => __('Size', 'sell_media'), 'license' => __('License', 'sell_media'), 'price' => __('Price', 'sell_media'), 'qty' => __('Qty', 'sell_media'), 'sub_total' => __('Subtotal', 'sell_media')), 'cart_style' => apply_filters('sell_media_cart_style', 'table'), 'tax' => empty($settings->tax) ? 0 : $settings->tax_rate, 'shipping' => apply_filters('sell_media_shipping', 0), 'cart_error' => __('There was an error loading the cart data. Please contact the site owner.', 'sell_media'), 'checkout_text' => __('Checkout Now', 'sell_media'), 'checkout_wait_text' => __('Please wait...', 'sell_media'), 'remove_text' => __('Remove from Lightbox', 'sell_media'), 'save_text' => __('Save to Lightbox', 'sell_media'))); do_action('sell_media_scripts_hook'); }
/** * Verify prices of products * * @return $prices (array) */ public function verify_the_price($product_id = null, $price_id = null) { // price group price $price_group_price = sell_media_get_term_meta($price_id, 'price', true); $custom_price = get_post_meta($product_id, 'sell_media_price', true); // check that the price_id exists and that the price meta is set if (!empty($price_group_price)) { $price = $price_group_price; } elseif (!empty($custom_price)) { $price = get_post_meta($product_id, 'sell_media_price', true); } else { // set the default price from settings $settings = sell_media_get_plugin_options(); $price = $settings->default_price; } return $price; }
/** * Lightbox link * * @param int $post_id * @return html * @since 1.9.2 */ function sell_media_lightbox_link($post_id = null, $attachment_id = null) { $item = array(); $item['post_id'] = $post_id; $item['attachment_id'] = !empty($attachment_id) ? $attachment_id : sell_media_get_attachment_id($post_id); $html = '<a href="javascript:void(0);" title="' . sell_media_get_lightbox_text($item) . '" id="lightbox-' . $post_id . '" class="add-to-lightbox" data-id="' . $post_id . '" data-attachment-id="' . $item['attachment_id'] . '">' . sell_media_get_lightbox_text($item) . '</a>'; // display lightbox notice on single posts if (is_single()) { $settings = sell_media_get_plugin_options(); // show a link if lightbox page is assigned in settings $link = !empty($settings->lightbox_page) ? '<a href="' . get_the_permalink($settings->lightbox_page) . '" title="' . __('Go to lightbox', 'sell_media') . '">' . __('lightbox', 'sell_media') . '</a>' : __('lightbox', 'sell_media'); // set css class based on item status $class = sell_media_get_lightbox_state($item) ? 'in-lightbox' : 'not-in-lightbox'; // lightbox notice $html .= '<div class="lightbox-notice ' . $class . '">'; $html .= '<p>' . sprintf(__('This item was saved to your %1$s.', 'sell_media'), $link) . '</p>'; $html .= '</div>'; } return apply_filters('sell_media_lightbox_link', $html, $post_id); }
/** * Email the user after registration to request a new password * * @param $user_id * @return (bool) * */ public function email_details($user_id = null) { $settings = sell_media_get_plugin_options(); $user = get_user_by('id', $user_id); $email = $user->user_email; $site_name = esc_attr(get_bloginfo('name')); $message['subject'] = __('Account registration at', 'sell_media') . ' ' . get_bloginfo('name'); $message['body'] = __('Welcome', 'sell_media') . ' ' . $user->first_name . '!' . "\n\n"; $message['body'] .= __('Here are your login credentials', 'sell_media') . ':' . "\n\n"; $message['body'] .= __('Username', 'sell_media') . ': ' . $user->user_login . "\n\n"; $message['body'] .= __('Create a password if you want to login to our dashboard to download any of your purchases in the future.', 'sell_media') . ':' . "\n\n"; $message['body'] .= esc_url(site_url('wp-login.php?action=lostpassword')) . "\n\n"; $message['body'] .= __('Any purchases your make will be available on your account dashboard.', 'sell_media') . "\n\n"; $message['body'] .= esc_url(get_permalink($settings->dashboard_page)) . "\n\n"; $message['body'] .= __('Thanks', 'sell_media') . ',' . "\n"; $message['body'] .= $site_name; $message['headers'] = "From: " . $site_name . "\r\n"; $message['headers'] .= "Reply-To: " . $settings->from_email . "\r\n"; $message['headers'] .= "MIME-Version: 1.0\r\n"; $message['headers'] .= "Content-Type: text/html; charset=utf-8\r\n"; // Send the email to buyer $r = wp_mail($email, $message['subject'], nl2br($message['body']), $message['headers']); return $r ? "Sent to: {$email}" : "Failed to send to: {$email}"; }
/** * Constructor */ public function __construct() { $this->settings = sell_media_get_plugin_options(); add_action('admin_notices', array(&$this, 'admin_notices')); add_action('set_site_transient_update_plugins', array(&$this, 'delete_transients')); }
/** * Filter custom column content on the edit media table. * * @since 0.1 */ function sell_media_item_content($column, $post_id) { switch ($column) { case "icon": $html = '<a href="' . site_url() . '/wp-admin/post.php?post=' . $post_id . '&action=edit">'; $html .= sell_media_item_icon($post_id, 'thumbnail', false); $html .= '</a>'; echo $html; break; case "sell_media_price": $price = get_post_meta($post_id, 'sell_media_price', true); $settings = sell_media_get_plugin_options(); if ($price) { echo sell_media_get_currency_symbol() . number_format($price, 2, '.', ''); } elseif ($settings->default_price) { echo sell_media_get_currency_symbol() . number_format($settings->default_price, 2, '.', ''); } else { echo __('No price set', 'sell_media'); } break; default: break; } }
/** * Custom login form * * @since 1.5.5 */ function sell_media_login_form_shortcode() { $settings = sell_media_get_plugin_options(); if (is_user_logged_in()) { return '<p class="sell-media-login-out">' . sprintf(__('You are logged in. %1$s or %2$s.', 'sell_media'), '<a href="' . apply_filters('sell_media_logout_redirect_url', wp_logout_url(site_url())) . '">' . __('Logout', 'sell_media') . '</a>', '<a href="' . get_post_type_archive_link('sell_media_item') . '">' . __('continue shopping', 'sell_media') . '</a>') . '</p>'; } else { if (isset($_GET['login']) && "failed" == $_GET['login']) { echo '<span class="error">' . __('Login failed', 'sell_media') . '</span>'; } $args = array('redirect' => get_permalink($settings->checkout_page), 'label_username' => __('Username', 'sell_media'), 'label_password' => __('Password', 'sell_media'), 'label_remember' => __('Remember Me', 'sell_media'), 'label_log_in' => __('Log In', 'sell_media')); wp_login_form($args); echo '<a href="' . wp_lostpassword_url(get_permalink()) . '" title="' . __('Forgot Password', 'sell_media') . '">' . __('Forgot Password', 'sell_media') . '</a>'; } }
<?php /** * Template for Cart dialog */ /** * If this attachment has a price use it, if not * fall back on the default price set in the * plugin settings */ $settings = sell_media_get_plugin_options(); $post_id = $_POST['product_id']; $attachment_id = $_POST['attachment_id']; // check if is package $is_package = Sell_Media()->products->is_package($post_id); // check if has assigned price group $has_price_group = Sell_Media()->products->has_price_group($post_id); // assign price $price = $has_price_group ? 0 : Sell_Media()->products->get_original_price($post_id); // assign licenses $licenses = wp_get_post_terms($post_id, 'licenses'); // featured image id $image_id = sell_media_has_multiple_attachments($post_id) ? $attachment_id : $post_id; ?> <div class="main-container sellMediaCart_shelfItem"> <span class="close">×</span> <div class="content"> <header> <figure><?php sell_media_item_icon($image_id); ?>
/** * Determine the price of all items in the cart that is being sent during checkout and set it. */ public function sell_media_verify_callback() { ini_set('display_errors', 0); check_ajax_referer('validate_cart', 'security'); $settings = sell_media_get_plugin_options(); // Our PayPal settings $args = array('currency_code' => $settings->currency, 'business' => $settings->paypal_email, 'return' => get_permalink($settings->thanks_page), 'notify_url' => site_url('?sell_media-listener=IPN')); $cart = $_POST['cart']; // Set discount code id to 0 if it isn't in cart array if (empty($cart['custom'])) { $cart['custom'] = 0; } // Count the number of keys that match the pattern "item_number_" $cart_count = count(preg_grep('/^item_number_/', array_keys($cart))); $cnt = 0; for ($i = 1; $i <= $cart_count; $i++) { $cnt += $cart['quantity_' . $i]; } $sub_total = 0; $shipping_flag = false; for ($i = 1; $i <= $cart_count; $i++) { $product_id = $cart['item_number_' . $i]; $type = empty($cart['os0_' . $i]) ? null : $cart['os0_' . $i]; $cart['os1_' . $i] = null; // Remove image url from the paypal checkout page $price_id = empty($cart['os2_' . $i]) ? null : $cart['os2_' . $i]; $license_id = empty($cart['os5_' . $i]) ? null : $cart['os5_' . $i]; // this is a download with an assigned license, so add license markup if (!empty($license_id) || $license_id != "undefined") { $price = Sell_Media()->products->verify_the_price($product_id, $price_id); $markup = Sell_Media()->products->markup_amount($product_id, $price_id, $license_id); $amount = $price + $markup; } else { // this is either a download without a license or a print, so just verify the price $amount = Sell_Media()->products->verify_the_price($product_id, $price_id); } $cart['amount_' . $i] = number_format(apply_filters('sell_media_price_filter', $amount, $cart['custom'], $cnt), 2, '.', ''); $sub_total += $cart['amount_' . $i] * $cart['quantity_' . $i]; } // Add shipping if ($shipping_flag) { switch ($settings->reprints_shipping) { case 'shippingFlatRate': $shipping_amount = $settings->reprints_shipping_flat_rate; break; case 'shippingQuantityRate': $shipping_amount = $settings->reprints_shipping_quantity_rate; break; case 'shippingTotalRate': $shipping_amount = $settings->reprints_shipping_total_rate; break; default: $shipping_amount = 0; break; } } else { $shipping_amount = 0; } $cart['handling'] = number_format($shipping_amount, 2, '.', ''); // If tax is enabled, tax the order if ($settings->tax) { // Cannot validate taxes because of qty // So just get the tax rate from local storage //$cart['tax_cart'] = $cart['tax_cart']; // If we could validate taxes, we could start here: $tax_amount = $settings->tax_rate * $sub_total; $cart['tax_cart'] = number_format($tax_amount, 2, '.', ''); } wp_send_json(array('cart' => $cart)); }
/** * Get system info * * @since 1.9.14 * @access public * @global object $wpdb Used to query the database using the WordPress Database API * @return string $return A string containing the info to output */ function sell_media_get_system_info() { global $wpdb; // Sell Media Settings $settings = sell_media_get_plugin_options(); if (!class_exists('Browser')) { require_once dirname(__FILE__) . '/libraries/browser.php'; } $browser = new Browser(); // Get theme info if (get_bloginfo('version') < '3.4') { $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css'); $theme = $theme_data['Name'] . ' ' . $theme_data['Version']; } else { $theme_data = wp_get_theme(); $theme = $theme_data->Name . ' ' . $theme_data->Version; } $return = '### Begin System Info ###' . "\n\n"; // Start with the basics... $return .= '-- Site Info' . "\n\n"; $return .= 'Site URL: ' . site_url() . "\n"; $return .= 'Home URL: ' . home_url() . "\n"; $return .= 'Multisite: ' . (is_multisite() ? 'Yes' : 'No') . "\n"; // The local users' browser information, handled by the Browser class $return .= "\n" . '-- User Browser' . "\n\n"; $return .= $browser; // WordPress configuration $return .= "\n" . '-- WordPress Configuration' . "\n\n"; $return .= 'Version: ' . get_bloginfo('version') . "\n"; $return .= 'Language: ' . (defined('WPLANG') && WPLANG ? WPLANG : 'en_US') . "\n"; $return .= 'Permalink Structure: ' . (get_option('permalink_structure') ? get_option('permalink_structure') : 'Default') . "\n"; $return .= 'Active Theme: ' . $theme . "\n"; $return .= 'Show On Front: ' . get_option('show_on_front') . "\n"; // Only show page specs if frontpage is set to 'page' if (get_option('show_on_front') == 'page') { $front_page_id = get_option('page_on_front'); $blog_page_id = get_option('page_for_posts'); $return .= 'Page On Front: ' . ($front_page_id != 0 ? get_the_title($front_page_id) . ' (#' . $front_page_id . ')' : 'Unset') . "\n"; $return .= 'Page For Posts: ' . ($blog_page_id != 0 ? get_the_title($blog_page_id) . ' (#' . $blog_page_id . ')' : 'Unset') . "\n"; } // Make sure wp_remote_post() is working $request['cmd'] = '_notify-validate'; $params = array('sslverify' => false, 'timeout' => 60, 'user-agent' => 'SellMedia/' . SELL_MEDIA_VERSION, 'body' => $request); $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { $WP_REMOTE_POST = 'wp_remote_post() works'; } else { $WP_REMOTE_POST = 'wp_remote_post() does not work'; } $return .= 'Remote Post: ' . $WP_REMOTE_POST . "\n"; $return .= 'Table Prefix: ' . 'Length: ' . strlen($wpdb->prefix) . ' Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable') . "\n"; $return .= 'WP_DEBUG: ' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set') . "\n"; $return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; $return .= 'Registered Post Stati: ' . implode(', ', get_post_stati()) . "\n"; // Sell Media settings $return .= "\n" . '-- Sell Media Configuration' . "\n\n"; $return .= 'Version: ' . SELL_MEDIA_VERSION . "\n"; if ($settings) { foreach ($settings as $k => $v) { if (is_array($v)) { $return .= $k . ': '; $vv_array = array(); foreach ($v as $kk => $vv) { $vv_array[] .= $vv; } $return .= implode(', ', $vv_array); $return .= "\n"; } else { $return .= $k . ': ' . $v . "\n"; } } } // Must-use plugins $muplugins = get_mu_plugins(); if (count($muplugins > 0)) { $return .= "\n" . '-- Must-Use Plugins' . "\n\n"; foreach ($muplugins as $plugin => $plugin_data) { $return .= $plugin_data['Name'] . ': ' . $plugin_data['Version'] . "\n"; } } // WordPress active plugins $return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; $plugins = get_plugins(); $active_plugins = get_option('active_plugins', array()); foreach ($plugins as $plugin_path => $plugin) { if (!in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } // WordPress inactive plugins $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; foreach ($plugins as $plugin_path => $plugin) { if (in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } if (is_multisite()) { // WordPress Multisite active plugins $return .= "\n" . '-- Network Active Plugins' . "\n\n"; $plugins = wp_get_active_network_plugins(); $active_plugins = get_site_option('active_sitewide_plugins', array()); foreach ($plugins as $plugin_path) { $plugin_base = plugin_basename($plugin_path); if (!array_key_exists($plugin_base, $active_plugins)) { continue; } $plugin = get_plugin_data($plugin_path); $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } } // Server configuration $return .= "\n" . '-- Webserver Configuration' . "\n\n"; $return .= 'PHP Version: ' . PHP_VERSION . "\n"; $return .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; $return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; // PHP config $return .= "\n" . '-- PHP Configuration' . "\n\n"; $return .= 'Safe Mode: ' . (ini_get('safe_mode') ? 'Enabled' : 'Disabled' . "\n"); $return .= 'Memory Limit: ' . ini_get('memory_limit') . "\n"; $return .= 'Upload Max Size: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Post Max Size: ' . ini_get('post_max_size') . "\n"; $return .= 'Upload Max Filesize: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Time Limit: ' . ini_get('max_execution_time') . "\n"; $return .= 'Max Input Vars: ' . ini_get('max_input_vars') . "\n"; $return .= 'Display Errors: ' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A') . "\n"; // PHP extensions etc $return .= "\n" . '-- PHP Extensions' . "\n\n"; $return .= 'GD: ' . (function_exists('gd_info') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'cURL: ' . (function_exists('curl_init') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'fsockopen: ' . (function_exists('fsockopen') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'SOAP Client: ' . (class_exists('SoapClient') ? 'Installed' : 'Not Installed') . "\n"; $return .= 'Suhosin: ' . (extension_loaded('suhosin') ? 'Installed' : 'Not Installed') . "\n"; $return .= "\n" . '### End System Info ###'; return $return; }
/** * Function for building the slider on Add/Edit License admin page * * @since 0.1 */ function sell_media_the_markup_slider($tag) { if (isset($_GET['tag_ID'])) { $term_id = $_GET['tag_ID']; } else { $term_id = null; } if (sell_media_get_term_meta($term_id, 'markup', true)) { $initial_markup = str_replace("%", "", sell_media_get_term_meta($term_id, 'markup', true)); } else { $initial_markup = 0; } $settings = sell_media_get_plugin_options(); ?> <script> jQuery(document).ready(function($){ if ( ! jQuery().slider ) return; function calc_price( markUp ){ var price = <?php echo $settings->default_price; ?> ; if ( markUp == undefined ) var markUp = <?php print $initial_markup; ?> ; finalPrice = ( +price + ( +markUp * .01 ) * price ); finalPrice = finalPrice.toFixed(2); return finalPrice; } $( ".menu-cart-total" ).html( calc_price() ); $( "#markup_slider" ).slider({ range: "min", value: <?php print $initial_markup; ?> , min: 0, step: .1, max: 1000, slide: function( event, ui ) { var markUp = ui.value; $( ".markup-target" ).val( markUp + "%" ); $( ".markup-target" ).html( markUp + "%" ); $( ".menu-cart-total" ).html( calc_price( markUp ) ); } }); $( ".markup-target" ).val( $( "#markup_slider" ).slider( "value" ) + "%" ); }); </script> <div class="sell_media-slider-container"> <div id="markup_slider"></div> <div class="sell_media-price-container"> <input name="meta_value[markup]" class="markup-target" type="text" value="<?php echo sell_media_get_term_meta($term_id, 'markup', true); ?> " size="40" /> </div> <p class="description"> <?php _e('Increase the price of a item if a buyer selects this license by dragging the slider above.', 'sell_media'); ?> <?php if (sell_media_get_term_meta($term_id, 'markup', true)) { $default_markup = sell_media_get_term_meta($term_id, 'markup', true); } else { $default_markup = '0%'; } if ($settings->default_price) { $price = sell_media_get_currency_symbol() . $settings->default_price; } else { $price = __('you have not set a default price', 'sell_media'); } printf(__(' The %1$s of %2$s with %3$s markup is %4$s', 'sell_media'), '<a href="' . admin_url() . 'edit.php?post_type=sell_media_item&page=sell_media_plugin_options&tab=sell_media_general_settings ">default item price</a>', '<strong>' . $price . '</strong>', '<strong><span class="markup-target">' . $default_markup . '</span></strong>', '<strong>' . sell_media_get_currency_symbol() . '<span class="menu-cart-total"></span></strong>'); ?> </p> </div> <?php }
/** * Callback for get_settings_field() */ function sell_media_plugin_setting_callback($option) { $sell_media_options = (array) sell_media_get_plugin_options(); $option_parameters = sell_media_get_plugin_option_parameters(); $optionname = $option['name']; $optiontitle = $option['title']; $optiondescription = $option['description']; $fieldtype = $option['type']; $fieldname = sell_media_get_current_plugin_id() . "_options[ { {$optionname} } ]"; $attr = $option_parameters[$option['name']]; $value = $sell_media_options[$optionname]; //Determine the type of input field switch ($fieldtype) { //Render Text Input case 'text': sell_media_plugin_field_text($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render Password Input //Render Password Input case 'password': sell_media_plugin_field_password($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render textarea options //Render textarea options case 'textarea': sell_media_plugin_field_textarea($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render select dropdowns //Render select dropdowns case 'select': sell_media_plugin_field_select($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render radio dropdowns //Render radio dropdowns case 'radio': sell_media_plugin_field_radio($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render radio image dropdowns //Render radio image dropdowns case 'radio_image': sell_media_plugin_field_radio_image($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render checkboxes //Render checkboxes case 'checkbox': sell_media_plugin_field_checkbox($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render color picker //Render color picker case 'color': sell_media_plugin_field_color($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render uploaded image //Render uploaded image case 'image': sell_media_plugin_field_image($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render uploaded gallery //Render uploaded gallery case 'gallery': sell_media_plugin_field_gallery($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render uploaded gallery //Render uploaded gallery case 'html': sell_media_plugin_field_html($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; default: break; } }
/** * Register Custom Taxonomies * @since 1.8.5 */ function sell_media_register_taxonomies() { $settings = sell_media_get_plugin_options(); $admin_columns = empty($settings->admin_columns) ? null : $settings->admin_columns; /** * Register Price Group */ $price_group_labels = array('name' => __('Price Groups', 'sell_media'), 'singular_name' => __('Price Groups', 'sell_media'), 'search_items' => __('Search Price Groups', 'sell_media'), 'popular_items' => __('Popular Price Groups', 'sell_media'), 'all_items' => __('All Price Groups', 'sell_media'), 'parent_item' => __('Parent Price Groups', 'sell_media'), 'parent_item_colon' => __('Parent Price Groups:', 'sell_media'), 'edit_item' => __('Edit Price Group', 'sell_media'), 'update_item' => __('Update Price Group', 'sell_media'), 'add_new_item' => __('Add New Price Group', 'sell_media'), 'new_item_name' => __('New Price Group', 'sell_media'), 'separate_items_with_commas' => __('Separate Price Groups with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove Price Groups', 'sell_media'), 'choose_from_most_used' => __('Choose from most used Price Groups', 'sell_media'), 'menu_name' => __('Price Groups', 'sell_media')); $price_group_args = array('labels' => $price_group_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'show_ui' => false, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true); register_taxonomy('price-group', array('sell_media_item'), $price_group_args); /** * Register Collection */ $collection_labels = array('name' => __('Product Collections', 'sell_media'), 'singular_name' => __('Collection', 'sell_media'), 'search_items' => __('Search Collection', 'sell_media'), 'popular_items' => __('Popular Collection', 'sell_media'), 'all_items' => __('All Collections', 'sell_media'), 'parent_item' => __('Parent Collection', 'sell_media'), 'parent_item_colon' => __('Parent Collection:', 'sell_media'), 'edit_item' => __('Edit Collection', 'sell_media'), 'update_item' => __('Update Collection', 'sell_media'), 'add_new_item' => __('Add New Collection', 'sell_media'), 'new_item_name' => __('New Collection', 'sell_media'), 'separate_items_with_commas' => __('Separate collection with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove Collection', 'sell_media'), 'choose_from_most_used' => __('Choose from most used Collection', 'sell_media'), 'menu_name' => __('Collections', 'sell_media')); $collection_args = array('labels' => $collection_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => !empty($admin_columns) && in_array('show_collection', $admin_columns) ? true : false, 'show_ui' => true, 'show_tagcloud' => true, 'hierarchical' => true, 'rewrite' => array('hierarchical' => true), 'query_var' => true); register_taxonomy('collection', array('sell_media_item'), $collection_args); /** * Register Licenses */ $licenses_labels = array('name' => __('Licenses', 'sell_media'), 'singular_name' => __('License', 'sell_media'), 'search_items' => __('Search Licenses', 'sell_media'), 'popular_items' => __('Popular Licenses', 'sell_media'), 'all_items' => __('All Licenses', 'sell_media'), 'parent_item' => __('Parent License', 'sell_media'), 'parent_item_colon' => __('Parent License:', 'sell_media'), 'edit_item' => __('Edit License', 'sell_media'), 'update_item' => __('Update License', 'sell_media'), 'add_new_item' => __('Add New License', 'sell_media'), 'new_item_name' => __('New License', 'sell_media'), 'separate_items_with_commas' => __('Separate licenses with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove Licenses', 'sell_media'), 'choose_from_most_used' => __('Choose from most used Licenses', 'sell_media'), 'menu_name' => __('Licenses', 'sell_media')); $licenses_args = array('labels' => $licenses_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => !empty($admin_columns) && in_array('show_license', $admin_columns) ? true : false, 'show_ui' => true, 'show_tagcloud' => true, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true); register_taxonomy('licenses', array('sell_media_item'), $licenses_args); /** * Register Keywords */ $keywords_labels = array('name' => __('Keywords', 'sell_media'), 'singular_name' => __('Keyword', 'sell_media'), 'search_items' => __('Search Keywords', 'sell_media'), 'popular_items' => __('Popular Keywords', 'sell_media'), 'all_items' => __('All Keywords', 'sell_media'), 'parent_item' => __('Parent Keyword', 'sell_media'), 'parent_item_colon' => __('Parent Keyword:', 'sell_media'), 'edit_item' => __('Edit Keyword', 'sell_media'), 'update_item' => __('Update Keyword', 'sell_media'), 'add_new_item' => __('Add New Keyword', 'sell_media'), 'new_item_name' => __('New Keyword', 'sell_media'), 'separate_items_with_commas' => __('Separate keywords with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove Keywords', 'sell_media'), 'choose_from_most_used' => __('Choose from most used Keywords', 'sell_media'), 'menu_name' => __('Keywords', 'sell_media')); $keywords_args = array('labels' => $keywords_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => !empty($admin_columns) && in_array('show_keywords', $admin_columns) ? true : false, 'show_ui' => true, 'show_tagcloud' => true, 'hierarchical' => false, 'rewrite' => true, 'query_var' => true); register_taxonomy('keywords', array('sell_media_item', 'attachment'), $keywords_args); /** * Register Creator */ $creator_labels = array('name' => __('Creators', 'sell_media'), 'singular_name' => __('Creator', 'sell_media'), 'search_items' => __('Search Creator', 'sell_media'), 'popular_items' => __('Popular Creator', 'sell_media'), 'all_items' => __('All Creator', 'sell_media'), 'parent_item' => __('Parent Creator', 'sell_media'), 'parent_item_colon' => __('Parent Creator:', 'sell_media'), 'edit_item' => __('Edit Creator', 'sell_media'), 'update_item' => __('Update Creator', 'sell_media'), 'add_new_item' => __('Add New Creator', 'sell_media'), 'new_item_name' => __('New Creator', 'sell_media'), 'separate_items_with_commas' => __('Separate creator with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove Creator', 'sell_media'), 'choose_from_most_used' => __('Choose from most used Creator', 'sell_media'), 'menu_name' => __('Creators', 'sell_media')); $creator_args = array('labels' => $creator_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_admin_column' => !empty($admin_columns) && in_array('show_creators', $admin_columns) ? true : false, 'show_tagcloud' => true, 'hierarchical' => false, 'rewrite' => true, 'query_var' => true); register_taxonomy('creator', array('sell_media_item', 'attachment'), $creator_args); /** * Register City */ $city_labels = array('name' => __('City', 'sell_media'), 'singular_name' => __('Keyword', 'sell_media'), 'search_items' => __('Search City', 'sell_media'), 'popular_items' => __('Popular City', 'sell_media'), 'all_items' => __('All City', 'sell_media'), 'parent_item' => __('Parent Keyword', 'sell_media'), 'parent_item_colon' => __('Parent Keyword:', 'sell_media'), 'edit_item' => __('Edit Keyword', 'sell_media'), 'update_item' => __('Update Keyword', 'sell_media'), 'add_new_item' => __('Add New Keyword', 'sell_media'), 'new_item_name' => __('New Keyword', 'sell_media'), 'separate_items_with_commas' => __('Separate city with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove City', 'sell_media'), 'choose_from_most_used' => __('Choose from most used City', 'sell_media'), 'menu_name' => __('City', 'sell_media')); $city_args = array('labels' => $city_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => false, 'show_tagcloud' => true, 'hierarchical' => false, 'rewrite' => true, 'query_var' => true); register_taxonomy('city', array('sell_media_item', 'attachment'), $city_args); /** * Register State */ $state_labels = array('name' => __('State', 'sell_media'), 'singular_name' => __('Keyword', 'sell_media'), 'search_items' => __('Search State', 'sell_media'), 'popular_items' => __('Popular State', 'sell_media'), 'all_items' => __('All State', 'sell_media'), 'parent_item' => __('Parent Keyword', 'sell_media'), 'parent_item_colon' => __('Parent Keyword:', 'sell_media'), 'edit_item' => __('Edit Keyword', 'sell_media'), 'update_item' => __('Update Keyword', 'sell_media'), 'add_new_item' => __('Add New Keyword', 'sell_media'), 'new_item_name' => __('New Keyword', 'sell_media'), 'separate_items_with_commas' => __('Separate state with commas', 'sell_media'), 'add_or_remove_items' => __('Add or remove State', 'sell_media'), 'choose_from_most_used' => __('Choose from most used State', 'sell_media'), 'menu_name' => __('State', 'sell_media')); $state_args = array('labels' => $state_labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => false, 'show_tagcloud' => true, 'hierarchical' => false, 'rewrite' => true, 'query_var' => true); register_taxonomy('state', array('sell_media_item', 'attachment'), $state_args); }
/** * Search form * * @since 1.8.7 */ public function form($url = null, $used = null) { $settings = sell_media_get_plugin_options(); // only use this method if it hasn't already been used on the page static $used; if (!isset($used)) { $used = true; $query = get_search_query() ? get_search_query() : ''; $html = ''; $html .= '<div class="sell-media-search">'; $html .= '<form role="search" method="get" id="sell-media-search-form" class="sell-media-search-form" action="' . site_url() . '">'; $html .= '<div class="sell-media-search-inner cf">'; // Visible search options wrapper $html .= '<div id="sell-media-search-visible" class="sell-media-search-visible cf">'; // Input field $html .= '<div id="sell-media-search-query" class="sell-media-search-field sell-media-search-query">'; $html .= '<input type="text" value="' . $query . '" name="s" id="sell-media-search-text" class="sell-media-search-text" placeholder="' . apply_filters('sell_media_search_placeholder', sprintf(__('Search for %1$s', 'sell_media'), empty($settings->post_type_slug) ? 'items' : $settings->post_type_slug)) . '"/>'; $html .= '</div>'; // Submit button $html .= '<div id="sell-media-search-submit" class="sell-media-search-field sell-media-search-submit">'; $html .= '<input type="hidden" name="post_type" value="sell_media_item" />'; $html .= '<input type="submit" id="sell-media-search-submit-button" class="sell-media-search-submit-button" value="' . apply_filters('sell_media_search_button', __('Search', 'sell_media')) . '" />'; $html .= '</div>'; $html .= '</div>'; // Hidden search options wrapper $html .= '<div id="sell-media-search-hidden" class="sell-media-search-hidden cf">'; // Exact match field $html .= '<div id="sell-media-search-exact-match" class="sell-media-search-field sell-media-search-exact-match">'; $html .= '<label for="sentence" id="sell-media-search-exact-match-desc" class="sell-media-search-exact-match-desc sell-media-tooltip" data-tooltip="Check to limit search results to exact phrase matches. Without exact phrase match checked, a search for \'New York Yankees\' would return results containing any of the three words \'New\', \'York\' and \'Yankees\'.">' . __('Exact phrase match (?)', 'sell_media') . '</label>'; $html .= '<input type="checkbox" value="1" name="sentence" id="sentence" />'; $html .= '</div>'; // Collection field $html .= '<div id="sell-media-search-collection" class="sell-media-search-field sell-media-search-collection">'; $html .= '<label for="collection">' . __('Collection', 'sell_media') . '</label>'; $html .= '<select name="collection">'; $html .= '<option value="">' . esc_attr(__('All', 'sell_media')) . '</option>'; $categories = get_categories('taxonomy=collection'); foreach ($categories as $category) { $html .= '<option value="' . $category->category_nicename . '">'; $html .= $category->cat_name; $html .= '</option>'; } $html .= '</select>'; $html .= '</div>'; // Hidden search options wrapper $html .= '</div>'; // Close button $html .= '<a href="javascript:void(0);" class="sell-media-search-close">×</a>'; $html .= '</div>'; $html .= '</form>'; $html .= '</div>'; echo apply_filters('sell_media_searchform_filter', $html); } }
/** * Filter the wp_title * * @param $title * @param $sep * @return title */ function sell_media_wp_title($title, $sep) { global $paged, $page; $settings = sell_media_get_plugin_options(); if (is_post_type_archive('sell_media_item')) { $name = get_bloginfo('name'); $obj = get_post_type_object('sell_media_item'); $slug = $settings->post_type_slug ? ucfirst(preg_replace('/[^a-zA-Z0-9]+/', ' ', $settings->post_type_slug)) : $obj->labels->name; $title = "{$slug} {$sep} {$name}"; } return $title; }
/** * Disable cache on Checkout and Thanks pages * * @since 2.0.2 * @return void */ function sell_media_nocache() { if (is_admin()) { return; } if (false === ($page_uris = get_transient('sell_media_cache_excluded_uris'))) { $settings = sell_media_get_plugin_options(); $checkout_page = $settings->checkout_page; $thanks_page = $settings->thanks_page; if (empty($checkout_page) || empty($thanks_page)) { return; } $page_uris = array(); // Exclude IPN listener $page_uris[] = '?sell_media-listener=IPN'; // Exclude default permalinks for pages $page_uris[] = '?page_id=' . $checkout_page; $page_uris[] = '?page_id=' . $thanks_page; // Exclude nice permalinks for pages $checkout_page = get_post($checkout_page); $thanks_page = get_post($thanks_page); if (!is_null($checkout_page)) { $page_uris[] = '/' . $checkout_page->post_name; } if (!is_null($thanks_page)) { $page_uris[] = '/' . $thanks_page->post_name; } set_transient('sell_media_cache_excluded_uris', $page_uris); } if (is_array($page_uris)) { foreach ($page_uris as $uri) { if (strstr($_SERVER['REQUEST_URI'], $uri)) { if (!defined('DONOTCACHEPAGE')) { define('DONOTCACHEPAGE', 'true'); } nocache_headers(); break; } } } delete_transient('sell_media_cache_excluded_uris'); }
/** * When a payment is made PayPal will send us a response and this function is * called. From here we will confirm arguments that we sent to PayPal which * the ones PayPal is sending back to us. * This is the Pink Lilly of the whole operation. */ function sell_media_process_paypal_ipn() { /** * Instantiate the IPNListener class */ include dirname(__FILE__) . '/php-paypal-ipn/IPNListener.php'; $listener = new IPNListener(); /** * Set to PayPal sandbox or live mode */ $settings = sell_media_get_plugin_options(); $listener->use_sandbox = $settings->test_mode ? true : false; /** * Check if IPN was successfully processed */ if ($verified = $listener->processIpn()) { /** * Log successful purchases */ $transactionData = $listener->getPostData(); // POST data array file_put_contents('ipn_success.log', print_r($transactionData, true) . PHP_EOL, LOCK_EX | FILE_APPEND); $message = null; /** * Verify seller PayPal email with PayPal email in settings * * Check if the seller email that was processed by the IPN matches what is saved as * the seller email in our DB */ $settings = sell_media_get_plugin_options(); if ($_POST['receiver_email'] != $settings->paypal_email) { $message .= "\nEmail seller email does not match email in settings\n"; } /** * Verify currency * * Check if the currency that was processed by the IPN matches what is saved as * the currency setting */ $settings = sell_media_get_plugin_options(); if ($_POST['mc_currency'] != $settings->currency) { $message .= "\nCurrency does not match those assigned in settings\n"; } /** * Check if this payment was already processed * * PayPal transaction id (txn_id) is stored in the database, we check * that against the txn_id returned. */ $txn_id = get_post_meta($_POST['custom'], 'txn_id', true); if (empty($txn_id)) { update_post_meta($_POST['custom'], 'txn_id', $_POST['txn_id']); } else { $message .= "\nThis payment was already processed\n"; return; } /** * Verify the payment is set to "Completed". * * Create a new payment, send customer an email and empty the cart */ if (!empty($_POST['payment_status']) && $_POST['payment_status'] == 'Completed') { // Return if this IPN doesn't contain a Sell Media item if (empty($_POST['option_selection1_1']) && ($_POST['option_selection1_1'] != 'print' || $_POST['option_selection1_1'] != 'download')) { return; } $data = array('post_title' => $_POST['payer_email'], 'post_status' => 'publish', 'post_type' => 'sell_media_payment'); $payment_id = wp_insert_post($data); $payments = Sell_Media()->payments; if ($payment_id) { update_post_meta($payment_id, '_paypal_args', $_POST); // record the PayPal payment details $payments->paypal_copy_args($payment_id); // create new user, auto log them in, email them registration Sell_Media()->customer->insert($_POST['payer_email'], $_POST['first_name'], $_POST['last_name']); $message .= "\nSuccess! Your purchase has been completed.\n"; $message .= "Your transaction number is: {$_POST['txn_id']}\n"; $message .= "To email: {$_POST['payer_email']}\n"; // Send email to buyer and admin $email_status = $payments->email_receipt($payment_id, $_POST['payer_email']); $admin_email_status = $payments->email_receipt($payment_id, $settings->from_email); $message .= "{$email_status}\n"; $message .= "{$admin_email_status}\n"; do_action('sell_media_after_successful_payment', $payment_id); } } else { $message .= "\nPayment status not set to Completed\n"; } /** * Check if this is the test mode * * If this is the test mode we email the IPN text report. * note about and box http://stackoverflow.com/questions/4298117/paypal-ipn-always-return-payment-status-pending-on-sandbox */ if ($settings->test_mode == true) { $message .= "\nTest Mode\n"; $email = array('to' => $settings->from_email, 'subject' => 'Verified IPN', 'message' => $message . "\n" . $listener->getTextReport()); wp_mail($email['to'], $email['subject'], $email['message']); } } else { /** * Log errors */ $errors = $listener->getErrors(); file_put_contents('ipn_errors.log', print_r($errors, true) . PHP_EOL, LOCK_EX | FILE_APPEND); /** * An Invalid IPN *may* be caused by a fraudulent transaction attempt. It's * a good idea to have a developer or sys admin manually investigate any * invalid IPN. */ wp_mail($settings->from_email, 'Invalid IPN', $listener->getTextReport()); } }