/** * Update the terms/taxonomy for this product. */ function dfrpswc_update_terms($post, $product, $set, $action) { // Get the IDs of the categories this product is associated with. $terms = array(); $terms = dfrps_get_cpt_terms($set['ID']); // Create an array with key of taxonomy and values of terms $taxonomies = array(DFRPSWC_TAXONOMY => $terms, 'product_tag' => '', 'product_type' => 'external'); // Then apply filters so users can override $taxonomies = apply_filters('dfrpswc_filter_taxonomy_array', $taxonomies, $post, $product, $set, $action); // Remove 'product_tag' from array if value is empty. if (empty($taxonomies['product_tag'])) { unset($taxonomies['product_tag']); } // Then iterate over the array using wp_set_post_terms() foreach ($taxonomies as $taxonomy => $terms) { $append = $taxonomy == DFRPSWC_TAXONOMY ? TRUE : FALSE; $result = wp_set_post_terms($post['ID'], $terms, $taxonomy, $append); } }
function dfrps_ajax_dashboard() { check_ajax_referer('dfrps_ajax_nonce', 'dfrps_security'); // Set $postid variable. $postid = isset($_REQUEST['postid']) && $_REQUEST['postid'] > 0 ? $_REQUEST['postid'] : false; // If $postid doesn't validate, show error. if (!$postid) { _e('No post ID provided. A post ID is required.', DFRPS_DOMAIN); die; } $html = ''; $post_title = get_the_title($postid); $post_status = get_post_status($postid); $meta = get_post_custom($postid); $type = get_post_meta($postid, '_dfrps_cpt_type', TRUE); $update_phase = isset($meta['_dfrps_cpt_update_phase'][0]) ? intval($meta['_dfrps_cpt_update_phase'][0]) : 0; $next_update_time = isset($meta['_dfrps_cpt_next_update_time'][0]) ? $meta['_dfrps_cpt_next_update_time'][0] : false; $last_update_time = $meta['_dfrps_cpt_last_update_time_completed'][0]; $temp_query = isset($meta['_dfrps_cpt_temp_query'][0]) ? $meta['_dfrps_cpt_temp_query'][0] : false; $saved_query = isset($meta['_dfrps_cpt_query'][0]) ? $meta['_dfrps_cpt_query'][0] : false; $term_ids = dfrps_get_cpt_terms($postid, FALSE); $links = array(); $cats_query = false; if ($term_ids && !empty($type)) { $registered_cpts = get_option('dfrps_registered_cpts', array()); $tax = $registered_cpts[$type]['taxonomy']; $cats_query = true; foreach ($term_ids as $id) { $term = get_term($id, $tax); if (is_object($term) && isset($term->count) && $term->count > 0) { $links[] = array('name' => $term->name, 'url' => esc_url(get_term_link($term, $tax))); } } } // Product Set 'type' is inactive. Just show message and don't show next update time or [Bump] button. if (!dfrps_set_is_active($type)) { $html .= '<div state="inactive_type"></div>'; $html .= '<p><span class="dashicons dashicons-flag"></span> ' . __('This Product Set is inactive. To re-activate this Product Set, install and activate the importer plugin responsible for importing products into the "' . $type . '" custom post type.', DFRPS_DOMAIN) . '</p>'; } else { // Status: auto-draft if ($post_status != 'publish' && $post_status != 'future') { $title_class = $post_title != '' && $post_title != __('Auto Draft') ? ' dfrps_dashboard_step_completed' : ''; $temp_class = $temp_query != '' ? ' dfrps_dashboard_step_completed' : ''; $saved_class = $saved_query != '' ? ' dfrps_dashboard_step_completed' : ''; $cats_class = $cats_query ? ' dfrps_dashboard_step_completed' : ''; $html .= '<div state="00"></div>'; $html .= '<p><span class="dashicons dashicons-smiley"></span> ' . __('Let\'s get started on a new Product Set!', DFRPS_DOMAIN) . '</p>'; $html .= '<ol>'; $html .= '<li id="dfrps_step_title" class="' . $title_class . '">' . __('Title your Product Set.', DFRPS_DOMAIN) . '</li>'; $html .= '<li id="dfrps_step_search" class="' . $temp_class . '">' . __('Search for products.', DFRPS_DOMAIN) . '</li>'; $html .= '<li id="dfrps_step_save" class="' . $saved_class . '">' . __(' Click <strong>[Add as Saved Search]</strong> when you\'re happy with search results.', DFRPS_DOMAIN) . '</li>'; $html .= '<li id="dfrps_step_category" class="' . $cats_class . '">' . __('Select a category to import into.', DFRPS_DOMAIN) . '</li>'; $html .= '<li id="dfrps_step_publish">' . __('Click the <strong>[Publish]</strong> button to import these products into your site.', DFRPS_DOMAIN) . '</li>'; $html .= '</ol>'; } // Status: publish if ($post_status == 'publish' || $post_status == 'future') { if ($update_phase > 0) { $percent = dfrps_percent_complete($postid); if ($last_update_time == 0) { $html .= '<div state="updating_' . $percent . '"></div>'; $html .= '<p><span class="dashicons dashicons-upload"></span>' . __('The products in this Product Set are currently being imported into your site.', DFRPS_DOMAIN) . '</p>'; } else { $html .= '<div state="updating_' . $percent . '"></div>'; $html .= '<p><span class="dashicons dashicons-upload"></span>' . __('The products in this Product Set are currently being updated.', DFRPS_DOMAIN) . '</p>'; } if ($percent) { $html .= dfrps_progress_bar($percent); } } elseif ($last_update_time == 0) { if ($post_status == 'future') { $html .= '<div state="future"></div>'; $html .= '<p><span class="dashicons dashicons-clock"></span> ' . __('This Product Set is scheduled to be published at a future date. The products in this Set will be imported when the Set becomes published.', DFRPS_DOMAIN) . '</p>'; } else { $html .= '<div state="queued"></div>'; $html .= '<p><span class="dashicons dashicons-calendar"></span> ' . __('The products in this Product Set are queued to update on ', DFRPS_DOMAIN) . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $next_update_time) . '.</p>'; $html .= '<p><span class="dashicons dashicons-info"></span><em>' . __('Actual update time is determined by its place in the queue as well as the next scheduled cron.', DFRPS_DOMAIN) . '</em></p>'; } } elseif ($last_update_time + 60 > date_i18n('U')) { $html .= '<div state="recently_completed"></div>'; $html .= '<p><span class="dashicons dashicons-yes"></span> ' . __('This Product Set completed a full product update less than 1 minute ago.', DFRPS_DOMAIN) . '</p>'; $num_links = count($links); if ($num_links > 0) { $html .= '<p><span class="dashicons dashicons-welcome-view-site"></span> ' . __('View category: ', DFRPS_DOMAIN); $i = 1; foreach ($links as $link) { $html .= '<a href="' . $link['url'] . '" target="_blank">' . $link['name'] . '</a>'; $i++; if ($i <= $num_links) { $html .= ', '; } } $html . '</p>'; } } elseif (date_i18n('U') > $next_update_time) { $html .= '<div state="queued"></div>'; $html .= '<p><span class="dashicons dashicons-calendar"></span> ' . __('The products in this Product Set are queued to update on ', DFRPS_DOMAIN) . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $next_update_time) . '.</p>'; $html .= '<p><span class="dashicons dashicons-info"></span><em>' . __('Actual update time is determined by its place in the queue as well as the next scheduled cron.', DFRPS_DOMAIN) . '</em></p>'; } else { $html .= '<div state="scheduled"></div>'; $html .= '<p><span class="dashicons dashicons-calendar"></span> ' . __('The products in this Product Set are scheduled to update on ', DFRPS_DOMAIN) . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $next_update_time) . '.</p>'; $html .= '<p> <a href="#" class="button" id="dfrps_set_next_update_time_to_now">' . __('Bump', DFRPS_DOMAIN) . '</a><br /> <small><em>' . __('Bump Product Set to front of update queue.', DFRPS_DOMAIN) . '</em></small> </p>'; } } } echo $html; die; }
function category_metabox($post, $box) { $cpt_name = $box['args']['cpt']['name']; $cpt_type = $box['args']['cpt']['post_type']; $taxonomy = $box['args']['cpt']['taxonomy']; $tax_name = $box['args']['cpt']['tax_name']; $tax_instructions = $box['args']['cpt']['tax_instructions']; $tax = get_taxonomy($taxonomy); $name = $taxonomy == 'category' ? 'post_category' : 'tax_input[' . $taxonomy . ']'; $selected_cats = dfrps_get_cpt_terms($post->ID); // Ticket: 9167 ?> <div id="taxonomy-<?php echo $taxonomy; ?> " class="categorydiv"> <div class="dfrps_tax_instructions"><?php echo $tax_instructions; ?> </div> <div id="<?php echo $taxonomy; ?> -all" class="tabs-panel dfrps_category_selection_panel"> <div class="dfrps_saving_taxonomy"><?php _e('Saving…', DFRPS_DOMAIN); ?> </div> <?php echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. ?> <ul id="<?php echo $taxonomy; ?> checklist" data-wp-lists="list:<?php echo $taxonomy; ?> " class="categorychecklist form-no-clear" cpt="<?php echo $cpt_type; ?> "> <?php wp_terms_checklist(false, array('selected_cats' => $selected_cats, 'taxonomy' => $taxonomy)); ?> </ul> </div> <?php if (current_user_can($tax->cap->edit_terms)) { ?> <div id="<?php echo $taxonomy; ?> -adder" class="wp-hidden-children"> <h4><a id="<?php echo $taxonomy; ?> -add-toggle" href="#<?php echo $taxonomy; ?> -add" class="hide-if-no-js"> <?php printf(__('+ %s'), $tax->labels->add_new_item); ?> </a></h4> <p id="<?php echo $taxonomy; ?> -add" class="category-add wp-hidden-child"> <label class="screen-reader-text" for="new<?php echo $taxonomy; ?> "><?php echo $tax->labels->add_new_item; ?> </label> <input type="text" name="new<?php echo $taxonomy; ?> " id="new<?php echo $taxonomy; ?> " class="form-required form-input-tip" value="<?php echo esc_attr($tax->labels->new_item_name); ?> " aria-required="true"/> <label class="screen-reader-text" for="new<?php echo $taxonomy; ?> _parent"><?php echo $tax->labels->parent_item_colon; ?> </label> <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new' . $taxonomy . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $tax->labels->parent_item . ' —')); ?> <input type="button" id="<?php echo $taxonomy; ?> -add-submit" data-wp-lists="add:<?php echo $taxonomy; ?> checklist:<?php echo $taxonomy; ?> -add" class="button category-add-submit" value="<?php echo esc_attr($tax->labels->add_new_item); ?> " /> <?php wp_nonce_field('add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy, false); ?> <span id="<?php echo $taxonomy; ?> -ajax-response"></span> </p> </div> <?php } ?> </div> <?php }
/** * This adds the term IDs to the post (ie. product, coupon, etc) except for * the post that we are currently updating. If the post is not getting deleted, * then its term IDs will be added by the integration plugin. */ function dfrps_add_term_ids_to_post($post_id, $set, $cpt, $taxonomy) { // Get all Product Set IDs which added this product. This returns and array of ids. $set_ids = get_post_meta($post_id, '_dfrps_product_set_id', FALSE); // Loop through all set_ids and remove this set's ID from the $set_ids array. $this_set_id = intval($set['ID']); if (isset($set_ids) && !empty($set_ids)) { $set_ids = array_map('intval', $set_ids); foreach ($set_ids as $set_id) { if (($key = array_search($this_set_id, $set_ids)) !== false) { unset($set_ids[$key]); } } } // Loop through remaining sets (all set IDs expect this set id) and // get the term ids for the other sets. $terms = array(); if (isset($set_ids) && !empty($set_ids)) { foreach ($set_ids as $id) { $terms = array_merge($terms, dfrps_get_cpt_terms($id)); } } $terms = array_map('intval', $terms); // Make sure these $terms are integers $terms = array_unique($terms); // Add term ids to this product. wp_set_object_terms($post_id, $terms, $taxonomy, FALSE); }