/** * Retrieve Bookmark data * * @since 2.1.0 * @uses $nxtdb Database Object * * @param mixed $bookmark * @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant * @param string $filter Optional, default is 'raw'. * @return array|object Type returned depends on $output value. */ function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') { global $nxtdb; if (empty($bookmark)) { if (isset($GLOBALS['link'])) { $_bookmark =& $GLOBALS['link']; } else { $_bookmark = null; } } elseif (is_object($bookmark)) { nxt_cache_add($bookmark->link_id, $bookmark, 'bookmark'); $_bookmark = $bookmark; } else { if (isset($GLOBALS['link']) && $GLOBALS['link']->link_id == $bookmark) { $_bookmark =& $GLOBALS['link']; } elseif (!($_bookmark = nxt_cache_get($bookmark, 'bookmark'))) { $_bookmark = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->links} WHERE link_id = %d LIMIT 1", $bookmark)); $_bookmark->link_category = array_unique(nxt_get_object_terms($_bookmark->link_id, 'link_category', array('fields' => 'ids'))); nxt_cache_add($_bookmark->link_id, $_bookmark, 'bookmark'); } } $_bookmark = sanitize_bookmark($_bookmark, $filter); if ($output == OBJECT) { return $_bookmark; } elseif ($output == ARRAY_A) { return get_object_vars($_bookmark); } elseif ($output == ARRAY_N) { return array_values(get_object_vars($_bookmark)); } else { return $_bookmark; } }
/** * Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts. * * @access private * @param string $new_status * @param string $old_status * @param object $post * @since 3.3.0 */ function _update_term_count_on_transition_post_status($new_status, $old_status, $post) { // Update counts for the post's terms. foreach ((array) get_object_taxonomies($post->post_type) as $taxonomy) { $tt_ids = nxt_get_object_terms($post->ID, $taxonomy, array('fields' => 'tt_ids')); nxt_update_term_count($tt_ids, $taxonomy); } }
/** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param unknown_type $post * @param unknown_type $errors * @return unknown */ function get_attachment_fields_to_edit($post, $errors = null) { if (is_int($post)) { $post =& get_post($post); } if (is_array($post)) { $post = (object) $post; } $image_url = nxt_get_attachment_url($post->ID); $edit_post = sanitize_post($post, 'edit'); $form_fields = array('post_title' => array('label' => __('Title'), 'value' => $edit_post->post_title), 'image_alt' => array(), 'post_excerpt' => array('label' => __('Caption'), 'value' => $edit_post->post_excerpt), 'post_content' => array('label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea'), 'url' => array('label' => __('Link URL'), 'input' => 'html', 'html' => image_link_input_fields($post, get_option('image_default_link_type')), 'helps' => __('Enter a link URL or click above for presets.')), 'menu_order' => array('label' => __('Order'), 'value' => $edit_post->menu_order), 'image_url' => array('label' => __('File URL'), 'input' => 'html', 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[{$post->ID}][url]' value='" . esc_attr($image_url) . "' /><br />", 'value' => nxt_get_attachment_url($post->ID), 'helps' => __('Location of the uploaded file.'))); foreach (get_attachment_taxonomies($post) as $taxonomy) { $t = (array) get_taxonomy($taxonomy); if (!$t['public']) { continue; } if (empty($t['label'])) { $t['label'] = $taxonomy; } if (empty($t['args'])) { $t['args'] = array(); } $terms = get_object_term_cache($post->ID, $taxonomy); if (empty($terms)) { $terms = nxt_get_object_terms($post->ID, $taxonomy, $t['args']); } $values = array(); foreach ($terms as $term) { $values[] = $term->name; } $t['value'] = join(', ', $values); $form_fields[$taxonomy] = $t; } // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) $form_fields = array_merge_recursive($form_fields, (array) $errors); $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post); return $form_fields; }
/** * is_assignment( $assignment_identifier ) * * Checks if a assignment with $assignment_identifier exists * * @param $assignment_identifier ID or Name of the assignment to be checked * @return Assignment object if assignment exists and null if not. */ function is_assignment($assignment_identifier = null) { global $bp, $post; $courseware_uri = bp_get_group_permalink($bp->groups->current_group) . 'courseware/'; if (is_object($assignment_identifier) && $assignment_identifier->post_type == "assignment") { if ($assignment_identifier->group[0]->name == $bp->groups->current_group->id) { return $assignment_identifier; } else { return null; } } if (!$assignment_identifier && get_class((object) $this->current_assignment) == __CLASS__) { return $this->current_assignment; } $assignment_query = array('post_type' => 'assignment', 'group_id' => $bp->groups->current_group->id); if ($assignment_identifier != null) { if (is_numeric($assignment_identifier)) { $assignment_query['p'] = $assignment_identifier; } else { $assignment_query['name'] = $assignment_identifier; } } $assignment = get_posts($assignment_query); if (!empty($assignment[0])) { $post = $assignment[0]; $assignment[0]->due_date = get_post_meta($assignment[0]->ID, 'due_date', true); $assignment[0]->group = nxt_get_object_terms($assignment[0]->ID, 'group_id'); $assignment_course = nxt_get_object_terms($assignment[0]->ID, 'course_id'); $assignment[0]->course = BPSP_Courses::is_course($assignment_course[0]->name); $assignment_lecture = get_post_meta($assignment[0]->ID, 'lecture_id', true); $assignment[0]->lecture = $assignment_lecture ? BPSP_Lectures::is_lecture($assignment_lecture) : null; $assignment[0]->forum_link = get_post_meta($assignment[0]->ID, 'topic_link', true); $assignment[0]->responded_author = get_post_meta($assignment[0]->ID, 'responded_author'); $assignment[0]->form_data = get_post_meta($assignment[0]->ID, 'form_data', true); $assignment[0]->permalink = $courseware_uri . 'assignment/' . $assignment[0]->post_name; // If Assignment has form, render it first if (!empty($assignment[0]->form_data)) { if (!isset($this) || !isset($this->frmb)) { $frmb = new FormBuilder(); } else { $frmb = $this->frmb; } $frmb->set_data($assignment[0]->form_data); $assignment[0]->form = $frmb->render(); } return $assignment[0]; } else { return null; } }
/** * edit_course_screen( $vars ) * * Hooks into courses_screen_handler * Edit course screen * * @param Array $vars a set of variables received for this screen template * @return Array $vars a set of variable passed to this screen template */ function edit_course_screen($vars) { global $bp; $nonce_name = 'edit_course'; $updated_course_id = false; $old_course = $this->is_course($this->current_course); $old_course->terms = nxt_get_object_terms($old_course->ID, 'group_id'); if (!$this->has_course_caps($bp->loggedin_user->id) || !is_super_admin() && $bp->groups->current_group->id != $old_course->terms[0]->name) { $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to update the course.', 'bpsp'); return $vars; } // Update course if (isset($_POST['course']) && $_POST['course']['object'] == 'group' && isset($_POST['_nxtnonce'])) { $updated_course = $_POST['course']; $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name); if (true != $is_nonce) { $vars['message'] = __('Nonce Error while editing a course.', 'bpsp'); } else { if (isset($updated_course['title']) && isset($updated_course['content']) && isset($updated_course['group_id'])) { $updated_course['title'] = strip_tags($updated_course['title']); $updated_course_id = nxt_update_post(array('ID' => $old_course->ID, 'post_title' => $updated_course['title'], 'post_content' => $updated_course['content'])); if ($updated_course_id) { $vars['message'] = __('New course was updated.', 'bpsp'); } else { $vars['error'] = __('New course could not be updated.', 'bpsp'); } } } } $vars['name'] = 'edit_course'; $vars['group_id'] = $bp->groups->current_group->id; $vars['user_id'] = $bp->loggedin_user->id; $vars['course'] = $this->is_course($updated_course_id); $vars['course_edit_uri'] = $vars['current_uri'] . '/course/edit/'; $vars['course_permalink'] = $vars['current_uri'] . '/course'; $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false); $vars['trail'] = array(__('Editing Course: ', 'bpsp') . $vars['course']->post_title => $vars['course']->permalink); return $vars; }
/** * Determine if the given object is associated with any of the given terms. * * The given terms are checked against the object's terms' term_ids, names and slugs. * Terms given as integers will only be checked against the object's terms' term_ids. * If no terms are given, determines if object is associated with any terms in the given taxonomy. * * @since 2.7.0 * @uses get_object_term_cache() * @uses nxt_get_object_terms() * * @param int $object_id ID of the object (post ID, link ID, ...) * @param string $taxonomy Single taxonomy name * @param int|string|array $terms Optional. Term term_id, name, slug or array of said * @return bool|nxt_Error. nxt_Error on input error. */ function is_object_in_term($object_id, $taxonomy, $terms = null) { if (!($object_id = (int) $object_id)) { return new nxt_Error('invalid_object', __('Invalid object ID')); } $object_terms = get_object_term_cache($object_id, $taxonomy); if (empty($object_terms)) { $object_terms = nxt_get_object_terms($object_id, $taxonomy); } if (is_nxt_error($object_terms)) { return $object_terms; } if (empty($object_terms)) { return false; } if (empty($terms)) { return !empty($object_terms); } $terms = (array) $terms; if ($ints = array_filter($terms, 'is_int')) { $strs = array_diff($terms, $ints); } else { $strs =& $terms; } foreach ($object_terms as $object_term) { if ($ints && in_array($object_term->term_id, $ints)) { return true; } // If int, check against term_id if ($strs) { if (in_array($object_term->term_id, $strs)) { return true; } if (in_array($object_term->name, $strs)) { return true; } if (in_array($object_term->slug, $strs)) { return true; } } } return false; }
nxt_update_post($menu_item_data); nxt_update_post($next_item_data); } // the item is last but still has a parent, so bubble up } elseif (!empty($menu_item_data['menu_item_parent']) && in_array($menu_item_data['menu_item_parent'], $orders_to_dbids)) { $menu_item_data['menu_item_parent'] = (int) get_post_meta($menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true); update_post_meta($menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent']); } } } break; case 'move-up-menu-item': check_admin_referer('move-menu_item'); $menu_item_id = isset($_REQUEST['menu-item']) ? (int) $_REQUEST['menu-item'] : 0; if (is_nav_menu_item($menu_item_id)) { $menus = isset($_REQUEST['menu']) ? array((int) $_REQUEST['menu']) : nxt_get_object_terms($menu_item_id, 'nav_menu', array('fields' => 'ids')); if (!is_nxt_error($menus) && !empty($menus[0])) { $menu_id = (int) $menus[0]; $ordered_menu_items = nxt_get_nav_menu_items($menu_id); $menu_item_data = (array) nxt_setup_nav_menu_item(get_post($menu_item_id)); // set up the data we need in one pass through the array of menu items $dbids_to_orders = array(); $orders_to_dbids = array(); foreach ((array) $ordered_menu_items as $ordered_menu_item_object) { if (isset($ordered_menu_item_object->ID)) { if (isset($ordered_menu_item_object->menu_order)) { $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order; $orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID; } } }
/** * Process the post data for the bulk editing of posts. * * Updates all bulk edited posts/pages, adding (but not removing) tags and * categories. Skips pages when they would be their own parent or child. * * @since 2.7.0 * * @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal. * @return array */ function bulk_edit_posts($post_data = null) { global $nxtdb; if (empty($post_data)) { $post_data =& $_POST; } if (isset($post_data['post_type'])) { $ptype = get_post_type_object($post_data['post_type']); } else { $ptype = get_post_type_object('post'); } if (!current_user_can($ptype->cap->edit_posts)) { if ('page' == $ptype->name) { nxt_die(__('You are not allowed to edit pages.')); } else { nxt_die(__('You are not allowed to edit posts.')); } } if (-1 == $post_data['_status']) { $post_data['post_status'] = null; unset($post_data['post_status']); } else { $post_data['post_status'] = $post_data['_status']; } unset($post_data['_status']); $post_IDs = array_map('intval', (array) $post_data['post']); $reset = array('post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky'); foreach ($reset as $field) { if (isset($post_data[$field]) && ('' == $post_data[$field] || -1 == $post_data[$field])) { unset($post_data[$field]); } } if (isset($post_data['post_category'])) { if (is_array($post_data['post_category']) && !empty($post_data['post_category'])) { $new_cats = array_map('absint', $post_data['post_category']); } else { unset($post_data['post_category']); } } $tax_input = array(); if (isset($post_data['tax_input'])) { foreach ($post_data['tax_input'] as $tax_name => $terms) { if (empty($terms)) { continue; } if (is_taxonomy_hierarchical($tax_name)) { $tax_input[$tax_name] = array_map('absint', $terms); } else { $tax_input[$tax_name] = preg_replace('/\\s*,\\s*/', ',', rtrim(trim($terms), ' ,')); $tax_input[$tax_name] = explode(',', $tax_input[$tax_name]); } } } if (isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent'])) { $pages = $nxtdb->get_results("SELECT ID, post_parent FROM {$nxtdb->posts} WHERE post_type = 'page'"); $children = array(); for ($i = 0; $i < 50 && $parent > 0; $i++) { $children[] = $parent; foreach ($pages as $page) { if ($page->ID == $parent) { $parent = $page->post_parent; break; } } } } if (isset($post_data['post_format'])) { if ('0' == $post_data['post_format']) { $post_data['post_format'] = false; } elseif (!current_theme_supports('post-formats', $post_data['post_format'])) { unset($post_data['post_format']); } } $updated = $skipped = $locked = array(); foreach ($post_IDs as $post_ID) { $post_type_object = get_post_type_object(get_post_type($post_ID)); if (!isset($post_type_object) || isset($children) && in_array($post_ID, $children) || !current_user_can($post_type_object->cap->edit_post, $post_ID)) { $skipped[] = $post_ID; continue; } if (nxt_check_post_lock($post_ID)) { $locked[] = $post_ID; continue; } $post = get_post($post_ID); $tax_names = get_object_taxonomies($post); foreach ($tax_names as $tax_name) { $taxonomy_obj = get_taxonomy($tax_name); if (isset($tax_input[$tax_name]) && current_user_can($taxonomy_obj->cap->assign_terms)) { $new_terms = $tax_input[$tax_name]; } else { $new_terms = array(); } if ($taxonomy_obj->hierarchical) { $current_terms = (array) nxt_get_object_terms($post_ID, $tax_name, array('fields' => 'ids')); } else { $current_terms = (array) nxt_get_object_terms($post_ID, $tax_name, array('fields' => 'names')); } $post_data['tax_input'][$tax_name] = array_merge($current_terms, $new_terms); } if (isset($new_cats) && in_array('category', $tax_names)) { $cats = (array) nxt_get_post_categories($post_ID); $post_data['post_category'] = array_unique(array_merge($cats, $new_cats)); unset($post_data['tax_input']['category']); } $post_data['post_mime_type'] = $post->post_mime_type; $post_data['guid'] = $post->guid; $post_data['ID'] = $post_ID; $updated[] = nxt_update_post($post_data); if (isset($post_data['sticky']) && current_user_can($ptype->cap->edit_others_posts)) { if ('sticky' == $post_data['sticky']) { stick_post($post_ID); } else { unstick_post($post_ID); } } if (isset($post_data['post_format'])) { set_post_format($post_ID, $post_data['post_format']); } } return array('updated' => $updated, 'skipped' => $skipped, 'locked' => $locked); }
/** * is_lecture( $lecture_identifier = null ) * * Checks if a lecture with $lecture_identifier exists * * @param $lecture_identifier ID or Name of the lecture to be checked * @return Lecture object if lecture exists and null if not. */ function is_lecture($lecture_identifier = null) { global $bp; $courseware_uri = bp_get_group_permalink($bp->groups->current_group) . 'courseware/'; if (is_object($lecture_identifier) && $lecture_identifier->post_type == "lecture") { if ($lecture_identifier->group[0]->name == $bp->groups->current_group->id) { return $lecture_identifier; } else { return null; } } if (!$lecture_identifier && get_class((object) $this->current_lecture) == __CLASS__) { return $this->current_lecture; } $lecture_query = array('post_type' => 'lecture', 'group_id' => $bp->groups->current_group->id); if ($lecture_identifier != null) { if (is_numeric($lecture_identifier)) { $lecture_query['p'] = $lecture_identifier; } else { $lecture_query['name'] = $lecture_identifier; } } $lecture = get_posts($lecture_query); if (reset($lecture)) { $lecture[0]->group = nxt_get_object_terms($lecture[0]->ID, 'group_id'); $lecture_course = nxt_get_object_terms($lecture[0]->ID, 'course_id'); $lecture[0]->course = !empty($lecture_course) ? BPSP_Courses::is_course(reset($lecture_course)->name) : null; $lecture[0]->permalink = $courseware_uri . 'lecture/' . $lecture[0]->post_name; return $lecture[0]; } else { return null; } }
/** * edit_schedule_screen( $vars ) * * Hooks into screen_handler * Edit schedule screen * * @param Array $vars a set of variables received for this screen template * @return Array $vars a set of variable passed to this screen template */ function edit_schedule_screen($vars) { global $bp; $nonce_name = 'edit_schedule'; $old_schedule = $this->is_schedule($this->current_schedule); $old_schedule->terms = nxt_get_object_terms($old_schedule->ID, 'group_id'); if (!$this->has_schedule_caps($bp->loggedin_user->id) || !is_super_admin() && $bp->groups->current_group->id != $old_schedule->terms[0]->name) { $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to update the schedule.', 'bpsp'); return $vars; } // Update schedule if (isset($_POST['schedule']) && $_POST['schedule']['object'] == 'group' && isset($_POST['_nxtnonce'])) { if (empty($_POST['schedule']['desc']) || empty($_POST['schedule']['start_date'])) { $vars['error'] = __('New schedule could not be added. Missing description and/or start date.', 'bpsp'); $_POST = null; return $this->edit_schedule_screen($vars); } $updated_schedule = $_POST['schedule']; if (isset($updated_schedule['end_date']) && !empty($updated_schedule['end_date'])) { $valid_dates = $this->datecheck($updated_schedule['start_date'], $updated_schedule['end_date']); } else { $valid_dates = true; } $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name); if (true != $is_nonce) { $vars['error'] = __('Nonce Error while editing a schedule.', 'bpsp'); } else { if (!empty($updated_schedule['group_id']) && $valid_dates) { $updated_schedule_id = nxt_update_post(array('ID' => $old_schedule->ID, 'post_title' => sanitize_text_field($updated_schedule['title']), 'post_content' => sanitize_text_field($updated_schedule['desc']))); if ($updated_schedule_id) { if (!empty($updated_schedule['course_id']) && BPSP_Courses::is_course($updated_schedule['course_id'])) { nxt_set_post_terms($updated_schedule_id, $updated_schedule['course_id'], 'course_id'); } elseif (empty($updated_schedule['course_id'])) { nxt_set_post_terms($updated_schedule_id, '', 'course_id'); } update_post_meta($updated_schedule_id, 'start_date', $updated_schedule['start_date'], $old_schedule->start_date); update_post_meta($updated_schedule_id, 'end_date', $updated_schedule['end_date'], $old_schedule->end_date); if (isset($updated_schedule['lecture_id'])) { update_post_meta($updated_schedule_id, 'lecture_id', $updated_schedule['lecture_id']); } if (!empty($updated_schedule['location'])) { if ($old_schedule->location) { update_post_meta($updated_schedule_id, 'location', $updated_schedule['location'], $old_schedule->location); } else { add_post_meta($updated_schedule_id, 'location', $updated_schedule['location']); } } $vars['message'] = __('Schedule was updated.', 'bpsp'); } else { $vars['error'] = __('Schedule could not be updated.', 'bpsp'); } } } } $vars['name'] = 'edit_schedule'; $vars['group_id'] = $bp->groups->current_group->id; $vars['course_id'] = $this->current_course->ID; $vars['lecture_id'] = get_post_meta($old_schedule->ID, 'lecture_id', true); $vars['user_id'] = $bp->loggedin_user->id; $vars['lectures'] = BPSP_Lectures::has_lectures($bp->groups->current_group->id); $vars['schedule'] = $this->is_schedule($old_schedule->ID); $vars['schedule_edit_uri'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule . '/edit'; $vars['schedule_delete_uri'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule . '/delete'; $vars['schedule_delete_title'] = __('Delete Course', 'bpsp'); $vars['schedule_permalink'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule; $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false); $vars['delete_nonce'] = add_query_arg('_nxtnonce', nxt_create_nonce('delete_schedule'), $vars['schedule_delete_uri']); $vars['trail'] = array($vars['schedule']->lecture->post_title => $vars['schedule']->lecture->permalink, __('Editing Schedule: ', 'bpsp') . $vars['schedule']->post_title => $vars['schedule']->permalink); return $vars; }
/** * Output list of taxonomy terms, in XML tag format, associated with a post * * @since 2.3.0 */ function wxr_post_taxonomy() { global $post; $taxonomies = get_object_taxonomies($post->post_type); if (empty($taxonomies)) { return; } $terms = nxt_get_object_terms($post->ID, $taxonomies); foreach ((array) $terms as $term) { echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata($term->name) . "</category>\n"; } }
/** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $post */ function get_inline_data($post) { $post_type_object = get_post_type_object($post->post_type); if (!current_user_can($post_type_object->cap->edit_post, $post->ID)) { return; } $title = esc_textarea(trim($post->post_title)); echo ' <div class="hidden" id="inline_' . $post->ID . '"> <div class="post_title">' . $title . '</div> <div class="post_name">' . apply_filters('editable_slug', $post->post_name) . '</div> <div class="post_author">' . $post->post_author . '</div> <div class="comment_status">' . esc_html($post->comment_status) . '</div> <div class="ping_status">' . esc_html($post->ping_status) . '</div> <div class="_status">' . esc_html($post->post_status) . '</div> <div class="jj">' . mysql2date('d', $post->post_date, false) . '</div> <div class="mm">' . mysql2date('m', $post->post_date, false) . '</div> <div class="aa">' . mysql2date('Y', $post->post_date, false) . '</div> <div class="hh">' . mysql2date('H', $post->post_date, false) . '</div> <div class="mn">' . mysql2date('i', $post->post_date, false) . '</div> <div class="ss">' . mysql2date('s', $post->post_date, false) . '</div> <div class="post_password">' . esc_html($post->post_password) . '</div>'; if ($post_type_object->hierarchical) { echo '<div class="post_parent">' . $post->post_parent . '</div>'; } if ($post->post_type == 'page') { echo '<div class="page_template">' . esc_html(get_post_meta($post->ID, '_nxt_page_template', true)) . '</div>'; } if ($post_type_object->hierarchical) { echo '<div class="menu_order">' . $post->menu_order . '</div>'; } $taxonomy_names = get_object_taxonomies($post->post_type); foreach ($taxonomy_names as $taxonomy_name) { $taxonomy = get_taxonomy($taxonomy_name); if ($taxonomy->hierarchical && $taxonomy->show_ui) { echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode(',', nxt_get_object_terms($post->ID, $taxonomy_name, array('fields' => 'ids'))) . '</div>'; } elseif ($taxonomy->show_ui) { echo '<div class="tags_input" id="' . $taxonomy_name . '_' . $post->ID . '">' . esc_html(str_replace(',', ', ', get_terms_to_edit($post->ID, $taxonomy_name))) . '</div>'; } } if (!$post_type_object->hierarchical) { echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; } if (post_type_supports($post->post_type, 'post-formats')) { echo '<div class="post_format">' . esc_html(get_post_format($post->ID)) . '</div>'; } echo '</div>'; }
/** * Retrieve boundary post. * * Boundary being either the first or last post by publish date within the constraints specified * by $in_same_cat or $excluded_categories. * * @since 2.8.0 * * @param bool $in_same_cat Optional. Whether returned post should be in a same category. * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. * @param bool $start Optional. Whether to retrieve first or last post. * @return object */ function get_boundary_post($in_same_cat = false, $excluded_categories = '', $start = true) { global $post; if (empty($post) || !is_single() || is_attachment()) { return null; } $cat_array = array(); if (!is_array($excluded_categories)) { $excluded_categories = explode(',', $excluded_categories); } if ($in_same_cat || !empty($excluded_categories)) { if ($in_same_cat) { $cat_array = nxt_get_object_terms($post->ID, 'category', array('fields' => 'ids')); } if (!empty($excluded_categories)) { $excluded_categories = array_map('intval', $excluded_categories); $excluded_categories = array_diff($excluded_categories, $cat_array); $inverse_cats = array(); foreach ($excluded_categories as $excluded_category) { $inverse_cats[] = $excluded_category * -1; } $excluded_categories = $inverse_cats; } } $categories = implode(',', array_merge($cat_array, $excluded_categories)); $order = $start ? 'ASC' : 'DESC'; return get_posts(array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false)); }
/** * Redirects incoming links to the proper URL based on the site url. * * Search engines consider www.somedomain.com and somedomain.com to be two * different URLs when they both go to the same location. This SEO enhancement * prevents penalty for duplicate content by redirecting all incoming links to * one or the other. * * Prevents redirection for feeds, trackbacks, searches, comment popup, and * admin URLs. Does not redirect on IIS, page/post previews, and on form data. * * Will also attempt to find the correct link when a user enters a URL that does * not exist based on exact NXTClass query. Will instead try to parse the URL * or query in an attempt to figure the correct page to go to. * * @since 2.3.0 * @uses $nxt_rewrite * @uses $is_IIS * * @param string $requested_url Optional. The URL that was requested, used to * figure if redirect is needed. * @param bool $do_redirect Optional. Redirect to the new URL. * @return null|false|string Null, if redirect not needed. False, if redirect * not needed or the string of the URL */ function redirect_canonical($requested_url = null, $do_redirect = true) { global $nxt_rewrite, $is_IIS, $nxt_query, $nxtdb; if (is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || $is_IIS) { return; } if (!$requested_url) { // build the URL in the address bar $requested_url = is_ssl() ? 'https://' : 'http://'; $requested_url .= $_SERVER['HTTP_HOST']; $requested_url .= $_SERVER['REQUEST_URI']; } $original = @parse_url($requested_url); if (false === $original) { return; } // Some PHP setups turn requests for / into /index.php in REQUEST_URI // See: http://trac.nxtclass.org/ticket/5017 // See: http://trac.nxtclass.org/ticket/7173 // Disabled, for now: // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']); $redirect = $original; $redirect_url = false; // Notice fixing if (!isset($redirect['path'])) { $redirect['path'] = ''; } if (!isset($redirect['query'])) { $redirect['query'] = ''; } if (is_singular() && 1 > $nxt_query->post_count && ($id = get_query_var('p'))) { $vars = $nxtdb->get_results($nxtdb->prepare("SELECT post_type, post_parent FROM {$nxtdb->posts} WHERE ID = %d", $id)); if (isset($vars[0]) && ($vars = $vars[0])) { if ('revision' == $vars->post_type && $vars->post_parent > 0) { $id = $vars->post_parent; } if ($redirect_url = get_permalink($id)) { $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']); } } } // These tests give us a nxt-generated permalink if (is_404()) { // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id')); if ($id && ($redirect_post = get_post($id))) { $post_type_obj = get_post_type_object($redirect_post->post_type); if ($post_type_obj->public) { $redirect_url = get_permalink($redirect_post); $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']); } } if (!$redirect_url) { $redirect_url = redirect_guess_404_permalink(); } } elseif (is_object($nxt_rewrite) && $nxt_rewrite->using_permalinks()) { // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 if (is_attachment() && !empty($_GET['attachment_id']) && !$redirect_url) { if ($redirect_url = get_attachment_link(get_query_var('attachment_id'))) { $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); } } elseif (is_single() && !empty($_GET['p']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('p'))) { $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); } } elseif (is_single() && !empty($_GET['name']) && !$redirect_url) { if ($redirect_url = get_permalink($nxt_query->get_queried_object_id())) { $redirect['query'] = remove_query_arg('name', $redirect['query']); } } elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) { if ($redirect_url = get_permalink(get_query_var('page_id'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (is_page() && !is_feed() && isset($nxt_query->queried_object) && 'page' == get_option('show_on_front') && $nxt_query->queried_object->ID == get_option('page_on_front') && !$redirect_url) { $redirect_url = home_url('/'); } elseif (is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && !$redirect_url) { if ($redirect_url = get_permalink(get_option('page_for_posts'))) { $redirect['query'] = remove_query_arg('page_id', $redirect['query']); } } elseif (!empty($_GET['m']) && (is_year() || is_month() || is_day())) { $m = get_query_var('m'); switch (strlen($m)) { case 4: // Yearly $redirect_url = get_year_link($m); break; case 6: // Monthly $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2)); break; case 8: // Daily $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); break; } if ($redirect_url) { $redirect['query'] = remove_query_arg('m', $redirect['query']); } // now moving on to non ?m=X year/month/day links } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day'])) { if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); } } elseif (is_month() && get_query_var('year') && !empty($_GET['monthnum'])) { if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) { $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); } } elseif (is_year() && !empty($_GET['year'])) { if ($redirect_url = get_year_link(get_query_var('year'))) { $redirect['query'] = remove_query_arg('year', $redirect['query']); } } elseif (is_author() && !empty($_GET['author']) && preg_match('|^[0-9]+$|', $_GET['author'])) { $author = get_userdata(get_query_var('author')); if (false !== $author && $nxtdb->get_var($nxtdb->prepare("SELECT ID FROM {$nxtdb->posts} WHERE {$nxtdb->posts}.post_author = %d AND {$nxtdb->posts}.post_status = 'publish' LIMIT 1", $author->ID))) { if ($redirect_url = get_author_posts_url($author->ID, $author->user_nicename)) { $redirect['query'] = remove_query_arg('author', $redirect['query']); } } } elseif (is_category() || is_tag() || is_tax()) { // Terms (Tags/categories) $term_count = 0; foreach ($nxt_query->tax_query->queries as $tax_query) { $term_count += count($tax_query['terms']); } $obj = $nxt_query->get_queried_object(); if ($term_count <= 1 && !empty($obj->term_id) && ($tax_url = get_term_link((int) $obj->term_id, $obj->taxonomy)) && !is_nxt_error($tax_url)) { if (!empty($redirect['query'])) { // Strip taxonomy query vars off the url. $qv_remove = array('term', 'taxonomy'); if (is_category()) { $qv_remove[] = 'category_name'; $qv_remove[] = 'cat'; } elseif (is_tag()) { $qv_remove[] = 'tag'; $qv_remove[] = 'tag_id'; } else { // Custom taxonomies will have a custom query var, remove those too: $tax_obj = get_taxonomy($obj->taxonomy); if (false !== $tax_obj->query_var) { $qv_remove[] = $tax_obj->query_var; } } $rewrite_vars = array_diff(array_keys($nxt_query->query), array_keys($_GET)); if (!array_diff($rewrite_vars, array_keys($_GET))) { // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']); //Remove all of the per-tax qv's // Create the destination url for this taxonomy $tax_url = parse_url($tax_url); if (!empty($tax_url['query'])) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. parse_str($tax_url['query'], $query_vars); $redirect['query'] = add_query_arg($query_vars, $redirect['query']); } else { // Taxonomy is accessible via a "pretty-URL" $redirect['path'] = $tax_url['path']; } } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite foreach ($qv_remove as $_qv) { if (isset($rewrite_vars[$_qv])) { $redirect['query'] = remove_query_arg($_qv, $redirect['query']); } } } } } } elseif (is_single() && strpos($nxt_rewrite->permalink_structure, '%category%') !== false) { $category = get_category_by_path(get_query_var('category_name')); $post_terms = nxt_get_object_terms($nxt_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); if (!$category || is_nxt_error($category) || !is_nxt_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms)) { $redirect_url = get_permalink($nxt_query->get_queried_object_id()); } } // Post Paging if (is_singular() && get_query_var('page') && $redirect_url) { $redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged'); $redirect['query'] = remove_query_arg('page', $redirect['query']); } // paging and feeds if (get_query_var('paged') || is_feed() || get_query_var('cpage')) { while (preg_match("#/{$nxt_rewrite->pagination_base}/?[0-9]+?(/+)?\$#", $redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path']) || preg_match('#/comment-page-[0-9]+(/+)?$#', $redirect['path'])) { // Strip off paging and feed $redirect['path'] = preg_replace("#/{$nxt_rewrite->pagination_base}/?[0-9]+?(/+)?\$#", '/', $redirect['path']); // strip off any existing paging $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings $redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging } $addl_path = ''; if (is_feed() && in_array(get_query_var('feed'), $nxt_rewrite->feeds)) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; if (get_query_var('withcomments')) { $addl_path .= 'comments/'; } if ('rss' == get_default_feed() && 'feed' == get_query_var('feed') || 'rss' == get_query_var('feed')) { $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == 'rss2' ? '' : 'rss2'), 'feed'); } else { $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ? '' : get_query_var('feed')), 'feed'); } $redirect['query'] = remove_query_arg('feed', $redirect['query']); } elseif (is_feed() && 'old' == get_query_var('feed')) { $old_feed_files = array('nxt-atom.php' => 'atom', 'nxt-commentsrss2.php' => 'comments_rss2', 'nxt-feed.php' => get_default_feed(), 'nxt-rdf.php' => 'rdf', 'nxt-rss.php' => 'rss2', 'nxt-rss2.php' => 'rss2'); if (isset($old_feed_files[basename($redirect['path'])])) { $redirect_url = get_feed_link($old_feed_files[basename($redirect['path'])]); nxt_redirect($redirect_url, 301); die; } } if (get_query_var('paged') > 0) { $paged = get_query_var('paged'); $redirect['query'] = remove_query_arg('paged', $redirect['query']); if (!is_feed()) { if ($paged > 1 && !is_single()) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit("{$nxt_rewrite->pagination_base}/{$paged}", 'paged'); } elseif (!is_single()) { $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : ''; } } elseif ($paged > 1) { $redirect['query'] = add_query_arg('paged', $paged, $redirect['query']); } } if (get_option('page_comments') && ('newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 || 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1)) { $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit('comment-page-' . get_query_var('cpage'), 'commentpaged'); $redirect['query'] = remove_query_arg('cpage', $redirect['query']); } $redirect['path'] = user_trailingslashit(preg_replace('|/index.php/?$|', '/', $redirect['path'])); // strip off trailing /index.php/ if (!empty($addl_path) && $nxt_rewrite->using_index_permalinks() && strpos($redirect['path'], '/index.php/') === false) { $redirect['path'] = trailingslashit($redirect['path']) . 'index.php/'; } if (!empty($addl_path)) { $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; } $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; } } // tack on any additional query vars $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); if ($redirect_url && !empty($redirect['query'])) { parse_str($redirect['query'], $_parsed_query); $redirect = @parse_url($redirect_url); if (!empty($_parsed_query['name']) && !empty($redirect['query'])) { parse_str($redirect['query'], $_parsed_redirect_query); if (empty($_parsed_redirect_query['name'])) { unset($_parsed_query['name']); } } $_parsed_query = array_map('rawurlencode', $_parsed_query); $redirect_url = add_query_arg($_parsed_query, $redirect_url); } if ($redirect_url) { $redirect = @parse_url($redirect_url); } // www.example.com vs example.com $user_home = @parse_url(home_url()); if (!empty($user_home['host'])) { $redirect['host'] = $user_home['host']; } if (empty($user_home['path'])) { $user_home['path'] = '/'; } // Handle ports if (!empty($user_home['port'])) { $redirect['port'] = $user_home['port']; } else { unset($redirect['port']); } // trailing /index.php $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']); // Remove trailing spaces from the path $redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']); if (!empty($redirect['query'])) { // Remove trailing spaces from certain terminating query string args $redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']); // Clean up empty query strings $redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); // Redirect obsolete feeds $redirect['query'] = preg_replace('#(^|&)feed=rss(&|$)#', '$1feed=rss2$3', $redirect['query']); // Remove redundant leading ampersands $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']); } // strip /index.php/ when we're not using PATHINFO permalinks if (!$nxt_rewrite->using_index_permalinks()) { $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); } // trailing slashes if (is_object($nxt_rewrite) && $nxt_rewrite->using_permalinks() && !is_404() && (!is_front_page() || is_front_page() && get_query_var('paged') > 1)) { $user_ts_type = ''; if (get_query_var('paged') > 0) { $user_ts_type = 'paged'; } else { foreach (array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type) { $func = 'is_' . $type; if (call_user_func($func)) { $user_ts_type = $type; break; } } } $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); } elseif (is_front_page()) { $redirect['path'] = trailingslashit($redirect['path']); } // Strip multiple slashes out of the URL if (strpos($redirect['path'], '//') > -1) { $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); } // Always trailing slash the Front Page URL if (trailingslashit($redirect['path']) == trailingslashit($user_home['path'])) { $redirect['path'] = trailingslashit($redirect['path']); } // Ignore differences in host capitalization, as this can lead to infinite redirects // Only redirect no-www <=> yes-www if (strtolower($original['host']) == strtolower($redirect['host']) || strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host'])) { $redirect['host'] = $original['host']; } $compare_original = array($original['host'], $original['path']); if (!empty($original['port'])) { $compare_original[] = $original['port']; } if (!empty($original['query'])) { $compare_original[] = $original['query']; } $compare_redirect = array($redirect['host'], $redirect['path']); if (!empty($redirect['port'])) { $compare_redirect[] = $redirect['port']; } if (!empty($redirect['query'])) { $compare_redirect[] = $redirect['query']; } if ($compare_original !== $compare_redirect) { $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; if (!empty($redirect['port'])) { $redirect_url .= ':' . $redirect['port']; } $redirect_url .= $redirect['path']; if (!empty($redirect['query'])) { $redirect_url .= '?' . $redirect['query']; } } if (!$redirect_url || $redirect_url == $requested_url) { return false; } // Hex encoded octets are case-insensitive. if (false !== strpos($requested_url, '%')) { if (!function_exists('lowercase_octets')) { function lowercase_octets($matches) { return strtolower($matches[0]); } } $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); } // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); if (!$redirect_url || $redirect_url == $requested_url) { // yes, again -- in case the filter aborted the request return false; } if ($do_redirect) { // protect against chained redirects if (!redirect_canonical($redirect_url, false)) { nxt_redirect($redirect_url, 301); exit; } else { // Debug // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) ); return false; } } else { return $redirect_url; } }
/** * Retrieves the link categories associated with the link specified. * * @since 2.1.0 * * @param int $link_id Link ID to look up * @return array The requested link's categories */ function nxt_get_link_cats($link_id = 0) { $cats = nxt_get_object_terms($link_id, 'link_category', array('fields' => 'ids')); return array_unique($cats); }
/** * Add the class property classes for the current context, if applicable. * * @access private * @since 3.0 * * @param array $menu_items The current menu item objects to which to add the class property information. */ function _nxt_menu_item_classes_by_context(&$menu_items) { global $nxt_query; $queried_object = $nxt_query->get_queried_object(); $queried_object_id = (int) $nxt_query->queried_object_id; $active_object = ''; $active_ancestor_item_ids = array(); $active_parent_item_ids = array(); $active_parent_object_ids = array(); $possible_taxonomy_ancestors = array(); $possible_object_parents = array(); $home_page_id = (int) get_option('page_for_posts'); if ($nxt_query->is_singular && !empty($queried_object->post_type) && !is_post_type_hierarchical($queried_object->post_type)) { foreach ((array) get_object_taxonomies($queried_object->post_type) as $taxonomy) { if (is_taxonomy_hierarchical($taxonomy)) { $term_hierarchy = _get_term_hierarchy($taxonomy); $terms = nxt_get_object_terms($queried_object_id, $taxonomy, array('fields' => 'ids')); if (is_array($terms)) { $possible_object_parents = array_merge($possible_object_parents, $terms); $term_to_ancestor = array(); foreach ((array) $term_hierarchy as $anc => $descs) { foreach ((array) $descs as $desc) { $term_to_ancestor[$desc] = $anc; } } foreach ($terms as $desc) { do { $possible_taxonomy_ancestors[$taxonomy][] = $desc; if (isset($term_to_ancestor[$desc])) { $_desc = $term_to_ancestor[$desc]; unset($term_to_ancestor[$desc]); $desc = $_desc; } else { $desc = 0; } } while (!empty($desc)); } } } } } elseif (!empty($queried_object->post_type) && is_post_type_hierarchical($queried_object->post_type)) { _get_post_ancestors($queried_object); } elseif (!empty($queried_object->taxonomy) && is_taxonomy_hierarchical($queried_object->taxonomy)) { $term_hierarchy = _get_term_hierarchy($queried_object->taxonomy); $term_to_ancestor = array(); foreach ((array) $term_hierarchy as $anc => $descs) { foreach ((array) $descs as $desc) { $term_to_ancestor[$desc] = $anc; } } $desc = $queried_object->term_id; do { $possible_taxonomy_ancestors[$queried_object->taxonomy][] = $desc; if (isset($term_to_ancestor[$desc])) { $_desc = $term_to_ancestor[$desc]; unset($term_to_ancestor[$desc]); $desc = $_desc; } else { $desc = 0; } } while (!empty($desc)); } $possible_object_parents = array_filter($possible_object_parents); $front_page_url = home_url(); foreach ((array) $menu_items as $key => $menu_item) { $menu_items[$key]->current = false; $classes = (array) $menu_item->classes; $classes[] = 'menu-item'; $classes[] = 'menu-item-type-' . $menu_item->type; $classes[] = 'menu-item-object-' . $menu_item->object; // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object if ($nxt_query->is_singular && 'taxonomy' == $menu_item->type && in_array($menu_item->object_id, $possible_object_parents)) { $active_parent_object_ids[] = (int) $menu_item->object_id; $active_parent_item_ids[] = (int) $menu_item->db_id; $active_object = $queried_object->post_type; // if the menu item corresponds to the currently-queried post or taxonomy object } elseif ($menu_item->object_id == $queried_object_id && (!empty($home_page_id) && 'post_type' == $menu_item->type && $nxt_query->is_home && $home_page_id == $menu_item->object_id || 'post_type' == $menu_item->type && $nxt_query->is_singular || 'taxonomy' == $menu_item->type && ($nxt_query->is_category || $nxt_query->is_tag || $nxt_query->is_tax))) { $classes[] = 'current-menu-item'; $menu_items[$key]->current = true; $_anc_id = (int) $menu_item->db_id; while (($_anc_id = get_post_meta($_anc_id, '_menu_item_menu_item_parent', true)) && !in_array($_anc_id, $active_ancestor_item_ids)) { $active_ancestor_item_ids[] = $_anc_id; } if ('post_type' == $menu_item->type && 'page' == $menu_item->object) { // Back compat classes for pages to match nxt_page_menu() $classes[] = 'page_item'; $classes[] = 'page-item-' . $menu_item->object_id; $classes[] = 'current_page_item'; } $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; // if the menu item corresponds to the currently-requested URL } elseif ('custom' == $menu_item->object) { $_root_relative_current = untrailingslashit($_SERVER['REQUEST_URI']); $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_root_relative_current; $raw_item_url = strpos($menu_item->url, '#') ? substr($menu_item->url, 0, strpos($menu_item->url, '#')) : $menu_item->url; $item_url = untrailingslashit($raw_item_url); $_indexless_current = untrailingslashit(preg_replace('/index.php$/', '', $current_url)); if ($raw_item_url && in_array($item_url, array($current_url, $_indexless_current, $_root_relative_current))) { $classes[] = 'current-menu-item'; $menu_items[$key]->current = true; $_anc_id = (int) $menu_item->db_id; while (($_anc_id = get_post_meta($_anc_id, '_menu_item_menu_item_parent', true)) && !in_array($_anc_id, $active_ancestor_item_ids)) { $active_ancestor_item_ids[] = $_anc_id; } if (in_array(home_url(), array(untrailingslashit($current_url), untrailingslashit($_indexless_current)))) { // Back compat for home link to match nxt_page_menu() $classes[] = 'current_page_item'; } $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; // give front page item current-menu-item class when extra query arguments involved } elseif ($item_url == $front_page_url && is_front_page()) { $classes[] = 'current-menu-item'; } if (untrailingslashit($item_url) == home_url()) { $classes[] = 'menu-item-home'; } } // back-compat with nxt_page_menu: add "current_page_parent" to static home page link for any non-page query if (!empty($home_page_id) && 'post_type' == $menu_item->type && empty($nxt_query->is_page) && $home_page_id == $menu_item->object_id) { $classes[] = 'current_page_parent'; } $menu_items[$key]->classes = array_unique($classes); } $active_ancestor_item_ids = array_filter(array_unique($active_ancestor_item_ids)); $active_parent_item_ids = array_filter(array_unique($active_parent_item_ids)); $active_parent_object_ids = array_filter(array_unique($active_parent_object_ids)); // set parent's class foreach ((array) $menu_items as $key => $parent_item) { $classes = (array) $parent_item->classes; $menu_items[$key]->current_item_ancestor = false; $menu_items[$key]->current_item_parent = false; if (isset($parent_item->type) && ('post_type' == $parent_item->type && !empty($queried_object->post_type) && is_post_type_hierarchical($queried_object->post_type) && in_array($parent_item->object_id, $queried_object->ancestors) && $parent_item->object != $queried_object->ID || 'taxonomy' == $parent_item->type && isset($possible_taxonomy_ancestors[$parent_item->object]) && in_array($parent_item->object_id, $possible_taxonomy_ancestors[$parent_item->object]) && (!isset($queried_object->term_id) || $parent_item->object_id != $queried_object->term_id))) { $classes[] = empty($queried_object->taxonomy) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor'; } if (in_array(intval($parent_item->db_id), $active_ancestor_item_ids)) { $classes[] = 'current-menu-ancestor'; $menu_items[$key]->current_item_ancestor = true; } if (in_array($parent_item->db_id, $active_parent_item_ids)) { $classes[] = 'current-menu-parent'; $menu_items[$key]->current_item_parent = true; } if (in_array($parent_item->object_id, $active_parent_object_ids)) { $classes[] = 'current-' . $active_object . '-parent'; } if ('post_type' == $parent_item->type && 'page' == $parent_item->object) { // Back compat classes for pages to match nxt_page_menu() if (in_array('current-menu-parent', $classes)) { $classes[] = 'current_page_parent'; } if (in_array('current-menu-ancestor', $classes)) { $classes[] = 'current_page_ancestor'; } } $menu_items[$key]->classes = array_unique($classes); } }
/** * Retrieve the terms of the taxonomy that are attached to the post. * * @since 2.5.0 * * @param int $id Post ID. Is not optional. * @param string $taxonomy Taxonomy name. * @return array|bool False on failure. Array of term objects on success. */ function get_the_terms($id = 0, $taxonomy) { global $post; $id = (int) $id; if (!$id) { if (!$post->ID) { return false; } else { $id = (int) $post->ID; } } $terms = get_object_term_cache($id, $taxonomy); if (false === $terms) { $terms = nxt_get_object_terms($id, $taxonomy); nxt_cache_add($id, $terms, $taxonomy . '_relationships'); } $terms = apply_filters('get_the_terms', $terms, $id, $taxonomy); if (empty($terms)) { return false; } return $terms; }