echo link_cat_row($updated['term_id']);
             } else {
                 die(__('Category not updated.'));
             }
             break;
         case 'tag':
             $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag';
             $tag = get_term($id, $taxonomy);
             $_POST['description'] = $tag->description;
             $updated = wp_update_term($id, $taxonomy, $_POST);
             if ($updated && !is_wp_error($updated)) {
                 $tag = get_term($updated['term_id'], $taxonomy);
                 if (!$tag || is_wp_error($tag)) {
                     die(__('Tag not updated.'));
                 }
                 echo _tag_row($tag, '', $taxonomy);
             } else {
                 die(__('Tag not updated.'));
             }
             break;
     }
     exit;
     break;
 case 'find_posts':
     check_ajax_referer('find-posts');
     if (empty($_POST['ps'])) {
         exit;
     }
     $what = isset($_POST['pages']) ? 'page' : 'post';
     $s = stripslashes($_POST['ps']);
     preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $page
 * @param unknown_type $pagesize
 * @param unknown_type $searchterms
 * @return unknown
 */
function tag_rows( $page = 1, $pagesize = 20, $searchterms = '' ) {

	// Get a page worth of tags
	$start = ($page - 1) * $pagesize;

	$args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);

	if ( !empty( $searchterms ) ) {
		$args['search'] = $searchterms;
	}

	$tags = get_terms( 'post_tag', $args );

	// convert it to table rows
	$out = '';
	$count = 0;
	foreach( $tags as $tag )
		$out .= _tag_row( $tag, ++$count % 2 ? ' class="iedit alternate"' : ' class="iedit"' );

	// filter and send to screen
	echo $out;
	return $count;
}
Exemple #3
0
         case 'link-cat':
             $updated = wp_update_term($id, 'link_category', $_POST);
             if ($updated && !is_wp_error($updated)) {
                 echo link_cat_row($updated['term_id']);
             } else {
                 die(__('Category not updated.'));
             }
             break;
         case 'tag':
             $updated = wp_update_term($id, 'post_tag', $_POST);
             if ($updated && !is_wp_error($updated)) {
                 $tag = get_term($updated['term_id'], 'post_tag');
                 if (!$tag || is_wp_error($tag)) {
                     die(__('Tag not updated.'));
                 }
                 echo _tag_row($tag);
             } else {
                 die(__('Tag not updated.'));
             }
             break;
     }
     exit;
     break;
 case 'meta-box-order':
     check_ajax_referer('meta-box-order');
     update_user_option($GLOBALS['current_user']->ID, "meta-box-order_{$_POST['page']}", $_POST['order']);
     die('1');
     break;
 case 'find_posts':
     check_ajax_referer('find-posts');
     if (empty($_POST['ps'])) {
Exemple #4
0
			$tag = get_term( $id, $taxonomy );
			$_POST['description'] = $tag->description;

			$updated = wp_update_term($id, $taxonomy, $_POST);
			if ( $updated && !is_wp_error($updated) ) {
				$tag = get_term( $updated['term_id'], $taxonomy );
				if ( !$tag || is_wp_error( $tag ) ) {
					if ( is_wp_error($tag) && $tag->get_error_message() )
						die( $tag->get_error_message() );
					die( __('Item not updated.') );
				}

				set_current_screen( 'edit-' . $taxonomy );

				echo _tag_row($tag, 0, $taxonomy);
			} else {
				if ( is_wp_error($updated) && $updated->get_error_message() )
					die( $updated->get_error_message() );
				die( __('Item not updated.') );
			}

			break;
	}

	exit;
	break;
case 'find_posts':
	check_ajax_referer( 'find-posts' );

	if ( empty($_POST['ps']) )
     }
     if ('' === trim($_POST['name'])) {
         $x = new WP_Ajax_Response(array('what' => 'tag', 'id' => new WP_Error('name', __('You did not enter a tag name.'))));
         $x->send();
     }
     $tag = wp_insert_term($_POST['name'], 'post_tag', $_POST);
     if (is_wp_error($tag)) {
         $x = new WP_Ajax_Response(array('what' => 'tag', 'id' => $tag));
         $x->send();
     }
     if (!$tag || !($tag = get_term($tag['term_id'], 'post_tag'))) {
         die('0');
     }
     $tag_full_name = $tag->name;
     $tag_full_name = attribute_escape($tag_full_name);
     $x = new WP_Ajax_Response(array('what' => 'tag', 'id' => $tag->term_id, 'data' => _tag_row($tag), 'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__('Tag <a href="#%s">%s</a> added'), "tag-{$tag->term_id}", $tag_full_name))));
     $x->send();
     break;
 case 'add-comment':
     check_ajax_referer($action);
     if (!current_user_can('edit_post', $id)) {
         die('-1');
     }
     $search = isset($_POST['s']) ? $_POST['s'] : false;
     $start = isset($_POST['page']) ? intval($_POST['page']) * 25 - 1 : 24;
     $status = isset($_POST['comment_status']) ? $_POST['comment_status'] : false;
     $mode = isset($_POST['mode']) ? $_POST['mode'] : 'detail';
     list($comments, $total) = _wp_get_comment_list($status, $search, $start, 1);
     if (!$comments) {
         die('1');
     }
			'what' => 'tag',
			'id' => $tag
		) );
		$x->send();
	}

	if ( !$tag || (!$tag = get_term( $tag['term_id'], 'post_tag' )) )
		die('0');

	$tag_full_name = $tag->name;
	$tag_full_name = attribute_escape($tag_full_name);

	$x = new WP_Ajax_Response( array(
		'what' => 'tag',
		'id' => $tag->term_id,
		'data' => _tag_row( $tag ),
		'supplemental' => array('name' => $tag_full_name, 'show-link' => sprintf(__( 'Tag <a href="#%s">%s</a> added' ), "tag-$tag->term_id", $tag_full_name))
	) );
	$x->send();
	break;
case 'add-comment' :
	check_ajax_referer( $action );
	if ( !current_user_can( 'edit_post', $id ) )
		die('-1');
	$search = isset($_POST['s']) ? $_POST['s'] : false;
	$start = isset($_POST['page']) ? intval($_POST['page']) * 25 - 1: 24;
	$status = isset($_POST['comment_status']) ? $_POST['comment_status'] : false;
	$mode = isset($_POST['mode']) ? $_POST['mode'] : 'detail';

	list($comments, $total) = _wp_get_comment_list( $status, $search, $start, 1 );
Exemple #7
0
function _term_rows($taxonomy, $terms, &$children, $page = 1, $per_page = 20, &$count, $parent = 0, $level = 0)
{
    $start = ($page - 1) * $per_page;
    $end = $start + $per_page;
    $output = '';
    foreach ($terms as $key => $term) {
        if ($count >= $end) {
            break;
        }
        if ($term->parent != $parent && empty($_GET['s'])) {
            continue;
        }
        // If the page starts in a subtree, print the parents.
        if ($count == $start && $term->parent > 0 && empty($_GET['s'])) {
            $my_parents = $parent_ids = array();
            $p = $term->parent;
            while ($p) {
                $my_parent = get_term($p, $taxonomy);
                $my_parents[] = $my_parent;
                $p = $my_parent->parent;
                if (in_array($p, $parent_ids)) {
                    // Prevent parent loops.
                    break;
                }
                $parent_ids[] = $p;
            }
            unset($parent_ids);
            $num_parents = count($my_parents);
            while ($my_parent = array_pop($my_parents)) {
                $output .= "\t" . _tag_row($my_parent, $level - $num_parents, $taxonomy);
                $num_parents--;
            }
        }
        if ($count >= $start) {
            $output .= "\t" . _tag_row($term, $level, $taxonomy);
        }
        ++$count;
        unset($terms[$key]);
        if (isset($children[$term->term_id]) && empty($_GET['s'])) {
            $output .= _term_rows($taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1);
        }
    }
    return $output;
}