Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Tobias O. http://www.seo-blackhat.com

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

quick fix for the broken wp_newCategory function in the wordpress xmlrpc.php

// just replace the original one and call each arg as a var from the xml client
// if you dont need desc and parent_id (pid) you also dont need to send the slug
// because its slugged by wp_insert_category anyway... ;)
// it also returns the category id if it already exists without adding a new one

function wp_newCategory($args) {
global $wpdb;
$this->escape($args);

$blog_id = (int) $args[0];
$username = $args[1];
$password = $args[2];
$category_name = $args[3];
$category_slug = $args[4];
$category_pid = $args[5];
$category_desc = $args[6];

if(!$this->login_pass_ok($username, $password)) {
return($this->error);
}

// Set the user context and make sure they are
// allowed to add a category.
set_current_user(0, $username);
if(!current_user_can("manage_categories", $page_id)) {
return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
}

// We need this to make use of the wp_insert_category()
// funciton.
require_once(ABSPATH . "wp-admin/admin-db.php");

$cats = $wpdb->get_results("SELECT cat_ID,cat_name,category_parent FROM $wpdb->categories WHERE cat_name = '".mysql_escape_string( $category_name )."' LIMIT 1", ARRAY_A);
if( count( $cats ) == 1 ) return( $cats[0]['cat_ID'] );

// If no slug was provided make it empty so that
// WordPress will generate one.
if(empty($category_slug)) {
$category_slug = "";
}

// If no parent_id was provided make it empty
// so that it will be a top level page (no parent).
if ( !isset($category_pid) )
$category_pid = "";

// If no description was provided make it empty.
if(empty($category_desc)) {
$category_desc = "";
}

$new_category = array(
"cat_name" => $category_name,
"category_nicename" => $category_slug,
"category_parent" => $category_pid,
"category_description" => $category_desc
);

$cat_id = wp_insert_category($new_category);
if(!$cat_id) {
return(new IXR_Error(500, __("Sorry, the new category failed.")));
}

return($cat_id);
}
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed