/** * Print scripts * * @since 1.0 */ function edd_wl_print_scripts() { global $edd_options; // Use minified libraries if SCRIPT_DEBUG is turned off $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; // register scripts wp_register_script('edd-wl', EDD_WL_PLUGIN_URL . 'includes/js/edd-wl' . $suffix . '.js', array('jquery'), EDD_WL_VERSION, true); wp_register_script('edd-wl-validate', EDD_WL_PLUGIN_URL . 'includes/js/jquery.validate' . $suffix . '.js', array('jquery'), EDD_WL_VERSION, true); wp_register_script('edd-wl-modal', EDD_WL_PLUGIN_URL . 'includes/js/modal' . $suffix . '.js', array('jquery'), EDD_WL_VERSION, true); // load scripts on single post type pages $post_types = edd_wl_allowed_post_types(); foreach ($post_types as $post_type) { if (is_singular($post_type)) { wp_enqueue_script('edd-wl'); wp_enqueue_script('edd-wl-modal'); } } // load validation if email sharing is present if (edd_wl_is_page('view') && edd_wl_sharing_is_enabled('email')) { wp_enqueue_script('edd-wl-validate'); } wp_localize_script('edd-wl', 'edd_wl_scripts', array('wish_list_page' => edd_wl_get_wish_list_uri(), 'wish_list_add' => edd_wl_get_wish_list_create_uri(), 'ajax_nonce' => wp_create_nonce('edd_wl_ajax_nonce'))); // CSS $file = 'edd-wl' . $suffix . '.css'; $templates_dir = edd_get_theme_template_dir_name(); $child_theme_style_sheet = trailingslashit(get_stylesheet_directory()) . $templates_dir . $file; $child_theme_style_sheet_2 = trailingslashit(get_stylesheet_directory()) . $templates_dir . 'edd-wl.css'; $parent_theme_style_sheet = trailingslashit(get_template_directory()) . $templates_dir . $file; $parent_theme_style_sheet_2 = trailingslashit(get_template_directory()) . $templates_dir . 'edd-wl.css'; $edd_plugin_style_sheet = trailingslashit(edd_wl_get_templates_dir()) . $file; // Look in the child theme directory first, followed by the parent theme, followed by the EDD core templates directory // Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled. // This allows users to copy just edd-wl.css to their theme if (file_exists($child_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2))) { if (!empty($nonmin)) { $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . 'edd-wl.css'; } else { $url = trailingslashit(get_stylesheet_directory_uri()) . $templates_dir . $file; } } elseif (file_exists($parent_theme_style_sheet) || !empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2))) { if (!empty($nonmin)) { $url = trailingslashit(get_template_directory_uri()) . $templates_dir . 'edd-wl.css'; } else { $url = trailingslashit(get_template_directory_uri()) . $templates_dir . $file; } } elseif (file_exists($edd_plugin_style_sheet) || file_exists($edd_plugin_style_sheet)) { $url = trailingslashit(edd_wl_get_templates_url()) . $file; } wp_enqueue_style('edd-wl-styles', $url, array(), EDD_WL_VERSION, 'screen'); }
/** * Performs redirect actions * * @since 1.0 * @uses edd_wl_is_private_list() * @uses edd_wl_get_wish_list_uri() * @return void */ function edd_wl_redirects() { // Prevent private lists from being viewed. Also only allows users to access edit slugs with own list ID if (edd_wl_is_private_list() || !edd_wl_is_users_list(get_query_var('edit')) && get_query_var('edit')) { // Don't redirect if we're on single download page. // Extra check to fix compatibility with crowdfunding extension or any other extension that uses an edit query var on the single download page if (!is_singular('download')) { $redirect = apply_filters('edd_wl_private_redirect', edd_wl_get_wish_list_uri()); wp_redirect($redirect); edd_die(); } } // redirect if edit or view page is accessed but edit/view query_var does not exist if (edd_wl_is_page('view') && !get_query_var('view') || edd_wl_is_page('edit') && !get_query_var('edit')) { wp_redirect(edd_wl_get_wish_list_uri()); edd_die(); } }
/** * Set various messages * * @since 1.0 * @todo provide better filtering of messages */ function edd_wl_set_messages() { // get array of messages $messages = edd_wl_messages(); /** * wish-lists.php */ // no lists if no posts if (!edd_wl_get_query() && edd_wl_is_page('wish-lists')) { edd_wl_set_message('no_lists', $messages['no_lists']); } /** * wish-list-create.php */ // must login if (edd_wl_is_page('create') && !edd_wl_allow_guest_creation()) { edd_wl_set_message('must_login', $messages['must_login']); } /** * wish-list-view.php */ if (edd_wl_is_page('view')) { $downloads = edd_wl_get_list_id() ? edd_wl_get_wish_list(edd_wl_get_list_id()) : array(); // list updated if (isset($_GET['list']) && $_GET['list'] == 'updated') { edd_wl_set_message('list_updated', $messages['list_updated']); } // list created if (isset($_GET['list']) && $_GET['list'] == 'created') { if (is_user_logged_in()) { edd_wl_set_message('list_created', $messages['list_created']); } else { edd_wl_set_message('list_created', $messages['list_created_guest']); } } // no downloads if (empty($downloads)) { edd_wl_set_message('no_downloads', $messages['no_downloads']); } } }
/** * List is private * * This is used to redirect, or prevent viewing or editing of private lists * @return [type] */ function edd_wl_is_private_list() { if (get_query_var('wl_view')) { $list_id = get_query_var('wl_view'); } elseif (get_query_var('wl_edit')) { $list_id = get_query_var('wl_edit'); } else { $list_id = ''; } if (!$list_id) { return; } $list_status = get_post_status($list_id); if ('private' == $list_status && !edd_wl_is_users_list($list_id) && (edd_wl_is_page('view') || edd_wl_is_page('edit'))) { return true; } }