| 1138 | * Create a new term. |
| 1139 | * |
| 1140 | * @uses wp_insert_term() |
| 1141 | * @param array $args Method parameters. Contains: |
| 1142 | * - int $blog_id |
| 1143 | * - string $username |
| 1144 | * - string $password |
| 1145 | * - array $content_struct |
| 1146 | * The $content_struct must contain: |
| 1147 | * - 'name' |
| 1148 | * - 'taxonomy' |
| 1149 | * Also, it can optionally contain: |
| 1150 | * - 'parent' |
| 1151 | * - 'description' |
| 1152 | * - 'slug' |
| 1153 | * @return int term_id |
| 1154 | */ |
| 1155 | function wp_newTerm( $args ) { |
| 1156 | $this->escape( $args ); |
| 1157 | |
| 1158 | $blog_id = (int) $args[0]; |
| 1159 | $username = $args[1]; |
| 1160 | $password = $args[2]; |
| 1161 | $content_struct = $args[3]; |
| 1162 | |
| 1163 | if ( ! $user = $this->login( $username, $password ) ) |
| 1164 | return $this->error; |
| 1165 | |
| 1166 | do_action( 'xmlrpc_call', 'wp.newTerm' ); |
| 1167 | |
| 1168 | if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
| 1169 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1170 | |
| 1171 | $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
| 1172 | |
| 1173 | if ( ! current_user_can( $taxonomy->cap->manage_terms ) ) |
| 1174 | return new IXR_Error( 401, __( 'You are not allowed to create terms in this taxonomy.' ) ); |
| 1175 | |
| 1176 | $taxonomy = (array) $taxonomy; |
| 1177 | |
| 1178 | // hold the data of the term |
| 1179 | $term_data = array(); |
| 1180 | |
| 1181 | $term_data['name'] = trim( $content_struct['name'] ); |
| 1182 | if ( empty( $term_data['name'] ) ) |
| 1183 | return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
| 1184 | |
| 1185 | if ( isset( $content_struct['parent'] ) ) { |
| 1186 | if ( ! $taxonomy['hierarchical'] ) |
| 1187 | return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
| 1188 | |
| 1189 | $parent_term_id = (int) $content_struct['parent']; |
| 1190 | $parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
| 1191 | |
| 1192 | if ( is_wp_error( $parent_term ) ) |
| 1193 | return new IXR_Error( 500, $parent_term->get_error_message() ); |
| 1194 | |
| 1195 | if ( ! $parent_term ) |
| 1196 | return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
| 1197 | |
| 1198 | $term_data['parent'] = $content_struct['parent']; |
| 1199 | } |
| 1200 | |
| 1201 | if ( isset( $content_struct['description'] ) ) |
| 1202 | $term_data['description'] = $content_struct['description']; |
| 1203 | |
| 1204 | if ( isset( $content_struct['slug'] ) ) |
| 1205 | $term_data['slug'] = $content_struct['slug']; |
| 1206 | |
| 1207 | $term = wp_insert_term( $term_data['name'] , $taxonomy['name'] , $term_data ); |
| 1208 | |
| 1209 | if ( is_wp_error( $term ) ) |
| 1210 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1211 | |
| 1212 | if ( ! $term ) |
| 1213 | return new IXR_Error( 500, __( 'Sorry, your term could not be created. Something wrong happened.' ) ); |
| 1214 | |
| 1215 | return strval( $term['term_id'] ); |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Edit a term. |
| 1220 | * |
| 1221 | * @uses wp_update_term() |
| 1222 | * @param array $args Method parameters. Contains: |
| 1223 | * - int $blog_id |
| 1224 | * - string $username |
| 1225 | * - string $password |
| 1226 | * - int $term_id |
| 1227 | * - array $content_struct |
| 1228 | * The $content_struct must contain: |
| 1229 | * - 'taxonomy' |
| 1230 | * Also, it can optionally contain: |
| 1231 | * - 'name' |
| 1232 | * - 'parent' |
| 1233 | * - 'description' |
| 1234 | * - 'slug' |
| 1235 | * @return bool True, on success. |
| 1236 | */ |
| 1237 | function wp_editTerm( $args ) { |
| 1238 | $this->escape( $args ); |
| 1239 | |
| 1240 | $blog_id = (int) $args[0]; |
| 1241 | $username = $args[1]; |
| 1242 | $password = $args[2]; |
| 1243 | $term_id = (int) $args[3]; |
| 1244 | $content_struct = $args[4]; |
| 1245 | |
| 1246 | if ( ! $user = $this->login( $username, $password ) ) |
| 1247 | return $this->error; |
| 1248 | |
| 1249 | do_action( 'xmlrpc_call', 'wp.editTerm' ); |
| 1250 | |
| 1251 | if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
| 1252 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1253 | |
| 1254 | $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
| 1255 | |
| 1256 | if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) |
| 1257 | return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy.' ) ); |
| 1258 | |
| 1259 | $taxonomy = (array) $taxonomy; |
| 1260 | |
| 1261 | // hold the data of the term |
| 1262 | $term_data = array(); |
| 1263 | |
| 1264 | $term = get_term( $term_id , $content_struct['taxonomy'] ); |
| 1265 | |
| 1266 | if ( is_wp_error( $term ) ) |
| 1267 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1268 | |
| 1269 | if ( ! $term ) |
| 1270 | return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
| 1271 | |
| 1272 | if ( isset( $content_struct['name'] ) ) { |
| 1273 | $term_data['name'] = trim( $content_struct['name'] ); |
| 1274 | |
| 1275 | if ( empty( $term_data['name'] ) ) |
| 1276 | return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
| 1277 | } |
| 1278 | |
| 1279 | if ( isset( $content_struct['parent'] ) ) { |
| 1280 | if ( ! $taxonomy['hierarchical'] ) |
| 1281 | return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
| 1282 | |
| 1283 | $parent_term_id = (int) $content_struct['parent']; |
| 1284 | $parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
| 1285 | |
| 1286 | if ( is_wp_error( $parent_term ) ) |
| 1287 | return new IXR_Error( 500, $parent_term->get_error_message() ); |
| 1288 | |
| 1289 | if ( ! $parent_term ) |
| 1290 | return new IXR_Error( 403, __( 'Parent term does not exist.' ) ); |
| 1291 | |
| 1292 | $term_data['parent'] = $content_struct['parent']; |
| 1293 | } |
| 1294 | |
| 1295 | if ( isset( $content_struct['description'] ) ) |
| 1296 | $term_data['description'] = $content_struct['description']; |
| 1297 | |
| 1298 | if ( isset( $content_struct['slug'] ) ) |
| 1299 | $term_data['slug'] = $content_struct['slug']; |
| 1300 | |
| 1301 | $term = wp_update_term( $term_id , $taxonomy['name'] , $term_data ); |
| 1302 | |
| 1303 | if ( is_wp_error( $term ) ) |
| 1304 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1305 | |
| 1306 | if ( ! $term ) |
| 1307 | return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
| 1308 | |
| 1309 | return true; |
| 1310 | } |
| 1311 | |
| 1312 | /** |
| 1313 | * Delete a term. |
| 1314 | * |
| 1315 | * @uses wp_delete_term() |
| 1316 | * @param array $args Method parameters. Contains: |
| 1317 | * - int $blog_id |
| 1318 | * - string $username |
| 1319 | * - string $password |
| 1320 | * - string $taxnomy_name |
| 1321 | * - int $term_id |
| 1322 | * @return boolean true |
| 1323 | */ |
| 1324 | function wp_deleteTerm( $args ) { |
| 1325 | $this->escape( $args ); |
| 1326 | |
| 1327 | $blog_id = (int) $args[0]; |
| 1328 | $username = $args[1]; |
| 1329 | $password = $args[2]; |
| 1330 | $taxonomy_name = $args[3]; |
| 1331 | $term_id = (int) $args[4]; |
| 1332 | |
| 1333 | if ( ! $user = $this->login( $username, $password ) ) |
| 1334 | return $this->error; |
| 1335 | |
| 1336 | do_action( 'xmlrpc_call', 'wp.editTerm' ); |
| 1337 | |
| 1338 | if ( ! taxonomy_exists( $taxonomy_name ) ) |
| 1339 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1340 | |
| 1341 | $taxonomy = get_taxonomy( $taxonomy_name ); |
| 1342 | |
| 1343 | if ( ! current_user_can( $taxonomy->cap->delete_terms ) ) |
| 1344 | return new IXR_Error( 401, __( 'You are not allowed to delete terms in this taxonomy.' ) ); |
| 1345 | |
| 1346 | $term = get_term( $term_id, $taxonomy_name ); |
| 1347 | |
| 1348 | if ( is_wp_error( $term ) ) |
| 1349 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1350 | |
| 1351 | if ( ! $term ) |
| 1352 | return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
| 1353 | |
| 1354 | $result = wp_delete_term( $term_id, $taxonomy_name ); |
| 1355 | |
| 1356 | if ( is_wp_error( $result ) ) |
| 1357 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1358 | |
| 1359 | if ( ! $result ) |
| 1360 | return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) ); |
| 1361 | |
| 1362 | return $result; |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * Retrieve a term. |
| 1367 | * |
| 1368 | * @uses get_term() |
| 1369 | * @param array $args Method parameters. Contains: |
| 1370 | * - int $blog_id |
| 1371 | * - string $username |
| 1372 | * - string $password |
| 1373 | * - string $taxonomy_name |
| 1374 | * - int $term_id |
| 1375 | * @return array contains: |
| 1376 | * - 'term_id' |
| 1377 | * - 'name' |
| 1378 | * - 'slug' |
| 1379 | * - 'term_group' |
| 1380 | * - 'term_taxonomy_id' |
| 1381 | * - 'taxonomy' |
| 1382 | * - 'description' |
| 1383 | * - 'parent' |
| 1384 | * - 'count' |
| 1385 | */ |
| 1386 | function wp_getTerm( $args ) { |
| 1387 | $this->escape( $args ); |
| 1388 | |
| 1389 | $blog_id = (int) $args[0]; |
| 1390 | $username = $args[1]; |
| 1391 | $password = $args[2]; |
| 1392 | $taxonomy_name = $args[3]; |
| 1393 | $term_id = (int) $args[4]; |
| 1394 | |
| 1395 | if ( ! $user = $this->login( $username, $password ) ) |
| 1396 | return $this->error; |
| 1397 | |
| 1398 | do_action( 'xmlrpc_call', 'wp.getTerm' ); |
| 1399 | |
| 1400 | if ( ! taxonomy_exists( $taxonomy_name ) ) |
| 1401 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1402 | |
| 1403 | $taxonomy = get_taxonomy( $taxonomy_name ); |
| 1404 | |
| 1405 | if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
| 1406 | return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); |
| 1407 | |
| 1408 | $term = get_term( $term_id , $taxonomy_name ); |
| 1409 | |
| 1410 | if ( is_wp_error( $term ) ) |
| 1411 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1412 | |
| 1413 | if ( ! $term ) |
| 1414 | return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
| 1415 | |
| 1416 | return $this->prepare_term( $term ); |
| 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * Retrieve all terms for a taxonomy. |
| 1421 | * |
| 1422 | * @uses get_terms() |
| 1423 | * @param array $args Method parameters. Contains: |
| 1424 | * - int $blog_id |
| 1425 | * - string $username |
| 1426 | * - string $password |
| 1427 | * - string $taxonomy_name |
| 1428 | * @return array terms |
| 1429 | */ |
| 1430 | function wp_getTerms( $args ) { |
| 1431 | $this->escape( $args ); |
| 1432 | |
| 1433 | $blog_id = (int) $args[0]; |
| 1434 | $username = $args[1]; |
| 1435 | $password = $args[2]; |
| 1436 | $taxonomy_name = $args[3]; |
| 1437 | |
| 1438 | if ( ! $user = $this->login( $username, $password ) ) |
| 1439 | return $this->error; |
| 1440 | |
| 1441 | do_action( 'xmlrpc_call', 'wp.getTerms' ); |
| 1442 | |
| 1443 | if ( ! taxonomy_exists( $taxonomy_name ) ) |
| 1444 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1445 | |
| 1446 | $taxonomy = get_taxonomy( $taxonomy_name ); |
| 1447 | |
| 1448 | if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
| 1449 | return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); |
| 1450 | |
| 1451 | $terms = get_terms( $taxonomy_name , array( 'get' => 'all' ) ); |
| 1452 | |
| 1453 | if ( is_wp_error( $terms ) ) |
| 1454 | return new IXR_Error( 500, $terms->get_error_message() ); |
| 1455 | |
| 1456 | $struct = array(); |
| 1457 | |
| 1458 | foreach ( $terms as $term ) { |
| 1459 | $struct[] = $this->prepare_term( $term ); |
| 1460 | } |
| 1461 | |
| 1462 | return $struct; |
| 1463 | } |
| 1464 | |
| 1465 | /** |
| 1466 | * Retrieve a taxonomy. |
| 1467 | * |
| 1468 | * @uses get_taxonomy() |
| 1469 | * @param array $args Method parameters. Contains: |
| 1470 | * - int $blog_id |
| 1471 | * - string $username |
| 1472 | * - string $password |
| 1473 | * - string $taxonomy_name |
| 1474 | * @return array (@see get_taxonomy()) |
| 1475 | */ |
| 1476 | function wp_getTaxonomy( $args ) { |
| 1477 | $this->escape( $args ); |
| 1478 | |
| 1479 | $blog_id = (int) $args[0]; |
| 1480 | $username = $args[1]; |
| 1481 | $password = $args[2]; |
| 1482 | $taxonomy_name = $args[3]; |
| 1483 | |
| 1484 | if ( ! $user = $this->login( $username, $password ) ) |
| 1485 | return $this->error; |
| 1486 | |
| 1487 | do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
| 1488 | |
| 1489 | if ( ! taxonomy_exists( $taxonomy_name ) ) |
| 1490 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1491 | |
| 1492 | $taxonomy = get_taxonomy( $taxonomy_name ); |
| 1493 | |
| 1494 | if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) |
| 1495 | return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); |
| 1496 | |
| 1497 | return $this->prepare_taxonomy( $taxonomy ); |
| 1498 | } |
| 1499 | |
| 1500 | /** |
| 1501 | * Retrieve all taxonomies. |
| 1502 | * |
| 1503 | * @uses get_taxonomies() |
| 1504 | * @param array $args Method parameters. Contains: |
| 1505 | * - int $blog_id |
| 1506 | * - string $username |
| 1507 | * - string $password |
| 1508 | * @return array taxonomies |
| 1509 | */ |
| 1510 | function wp_getTaxonomies( $args ) { |
| 1511 | $this->escape( $args ); |
| 1512 | |
| 1513 | $blog_id = (int) $args[0]; |
| 1514 | $username = $args[1]; |
| 1515 | $password = $args[2]; |
| 1516 | |
| 1517 | if ( ! $user = $this->login( $username, $password ) ) |
| 1518 | return $this->error; |
| 1519 | |
| 1520 | do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
| 1521 | |
| 1522 | $taxonomies = get_taxonomies( '', 'objects' ); |
| 1523 | |
| 1524 | // holds all the taxonomy data |
| 1525 | $struct = array(); |
| 1526 | |
| 1527 | foreach ( $taxonomies as $taxonomy ) { |
| 1528 | // capability check for post_types |
| 1529 | if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) |
| 1530 | continue; |
| 1531 | |
| 1532 | $struct[] = $this->prepare_taxonomy( $taxonomy ); |
| 1533 | } |
| 1534 | |
| 1535 | return $struct; |
| 1536 | } |
| 1537 | |
| 1538 | /** |