Make WordPress Core

Ticket #18438: taxes.combo.2.patch

File taxes.combo.2.patch, 13.0 KB (added by maxcutler, 12 years ago)

Refreshed patch after other recent changes.

  • wp-includes/class-wp-xmlrpc-server.php

     
    4141                        'wp.deletePost'                 => 'this:wp_deletePost',
    4242                        'wp.getPost'                    => 'this:wp_getPost',
    4343                        'wp.getPosts'                   => 'this:wp_getPosts',
     44                        'wp.newTerm'                    => 'this:wp_newTerm',
     45                        'wp.editTerm'                   => 'this:wp_editTerm',
     46                        'wp.deleteTerm'                 => 'this:wp_deleteTerm',
     47                        'wp.getTerm'                    => 'this:wp_getTerm',
     48                        'wp.getTerms'                   => 'this:wp_getTerms',
     49                        'wp.getTaxonomy'                => 'this:wp_getTaxonomy',
     50                        'wp.getTaxonomies'              => 'this:wp_getTaxonomies',
    4451                        'wp.getPage'                    => 'this:wp_getPage',
    4552                        'wp.getPages'                   => 'this:wp_getPages',
    4653                        'wp.newPage'                    => 'this:wp_newPage',
     
    452459        }
    453460
    454461        /**
     462         * Prepares taxonomy data for return in an XML-RPC object.
     463         *
     464         * @param array|object $taxonomy The unprepared taxonomy data
     465         * @return array The prepared taxonomy data
     466         */
     467        function prepare_taxonomy( $taxonomy ) {
     468                $_taxonomy = (array) $taxonomy;
     469
     470                unset( $_taxonomy['update_count_callback'] );
     471
     472                return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy );
     473        }
     474
     475        /**
     476         * Prepares term data for return in an XML-RPC object.
     477         *
     478         * @param array $term The unprepared term data
     479         * @return array The prepared term data
     480         */
     481        function prepare_term( $term ) {
     482                $_term = (array) $term;
     483
     484                return apply_filters( 'xmlrpc_prepare_term', $_term, $term );
     485        }
     486
     487        /**
    455488         * Prepares post data for return in an XML-RPC object.
    456489         *
    457490         * @access private
     
    508541                        $terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies );
    509542                        $_post['terms'] = array();
    510543                        foreach ( $terms as $term ) {
    511                                 $_post['terms'][] = (array) $term;
     544                                $_post['terms'][] = $this->prepare_term( $term );
    512545                        }
    513546                }
    514547
     
    10821115        }
    10831116
    10841117        /**
     1118         * Create a new term.
     1119         *
     1120         * @uses wp_insert_term()
     1121         * @param array $args Method parameters. Contains:
     1122         *  - int     $blog_id
     1123         *  - string  $username
     1124         *  - string  $password
     1125         *  - array   $content_struct
     1126         *      The $content_struct must contain:
     1127         *      - 'name'
     1128         *      - 'taxonomy'
     1129         *      Also, it can optionally contain:
     1130         *      - 'parent'
     1131         *      - 'description'
     1132         *      - 'slug'
     1133         * @return int term_id
     1134         */
     1135        function wp_newTerm( $args ) {
     1136                $this->escape( $args );
     1137
     1138                $blog_id            = (int) $args[0];
     1139                $username           = $args[1];
     1140                $password           = $args[2];
     1141                $content_struct     = $args[3];
     1142
     1143                if ( ! $user = $this->login( $username, $password ) )
     1144                        return $this->error;
     1145
     1146                do_action( 'xmlrpc_call', 'wp.newTerm' );
     1147
     1148                if ( ! taxonomy_exists( $content_struct['taxonomy'] ) )
     1149                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     1150
     1151                $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
     1152
     1153                if ( ! current_user_can( $taxonomy->cap->manage_terms ) )
     1154                        return new IXR_Error( 401, __( 'You are not allowed to create terms in this taxonomy.' ) );
     1155
     1156                $taxonomy = (array) $taxonomy;
     1157
     1158                // hold the data of the term
     1159                $term_data = array();
     1160
     1161                $term_data['name'] = trim( $content_struct['name'] );
     1162                if ( empty( $term_data['name'] ) )
     1163                        return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
     1164
     1165                if ( isset( $content_struct['parent'] ) ) {
     1166                        if ( ! $taxonomy['hierarchical'] )
     1167                                return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) );
     1168
     1169                        $parent_term_id = (int) $content_struct['parent'];
     1170                        $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
     1171
     1172                        if ( is_wp_error( $parent_term ) )
     1173                                return new IXR_Error( 500, $parent_term->get_error_message() );
     1174
     1175                        if ( ! $parent_term )
     1176                                return new IXR_Error( 500, __( 'Parent term does not exist.' ) );
     1177
     1178                        $term_data['parent'] = $content_struct['parent'];
     1179                }
     1180
     1181                if ( isset( $content_struct['description'] ) )
     1182                        $term_data['description'] = $content_struct['description'];
     1183
     1184                if ( isset( $content_struct['slug'] ) )
     1185                        $term_data['slug'] = $content_struct['slug'];
     1186
     1187                $term = wp_insert_term( $term_data['name'] , $taxonomy['name'] , $term_data );
     1188
     1189                if ( is_wp_error( $term ) )
     1190                        return new IXR_Error( 500, $term->get_error_message() );
     1191
     1192                if ( ! $term )
     1193                        return new IXR_Error( 500, __( 'Sorry, your term could not be created. Something wrong happened.' ) );
     1194
     1195                return $term['term_id'];
     1196        }
     1197
     1198        /**
     1199         * Edit a term.
     1200         *
     1201         * @uses wp_update_term()
     1202         * @param array $args Method parameters. Contains:
     1203         *  - int     $blog_id
     1204         *  - string  $username
     1205         *  - string  $password
     1206         *  - int     $term_id
     1207         *  - array   $content_struct
     1208         *      The $content_struct must contain:
     1209         *      - 'taxonomy'
     1210         *      Also, it can optionally contain:
     1211         *      - 'name'
     1212         *      - 'parent'
     1213         *      - 'description'
     1214         *      - 'slug'
     1215         * @return bool True, on success.
     1216         */
     1217        function wp_editTerm( $args ) {
     1218                $this->escape( $args );
     1219
     1220                $blog_id            = (int) $args[0];
     1221                $username           = $args[1];
     1222                $password           = $args[2];
     1223                $term_id            = (int) $args[3];
     1224                $content_struct     = $args[4];
     1225
     1226                if ( ! $user = $this->login( $username, $password ) )
     1227                        return $this->error;
     1228
     1229                do_action( 'xmlrpc_call', 'wp.editTerm' );
     1230
     1231                if ( ! taxonomy_exists( $content_struct['taxonomy'] ) )
     1232                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     1233
     1234                $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
     1235
     1236                if ( ! current_user_can( $taxonomy->cap->edit_terms ) )
     1237                        return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy.' ) );
     1238
     1239                $taxonomy = (array) $taxonomy;
     1240
     1241                // hold the data of the term
     1242                $term_data = array();
     1243
     1244                $term = get_term( $term_id , $content_struct['taxonomy'] );
     1245
     1246                if ( is_wp_error( $term ) )
     1247                        return new IXR_Error( 500, $term->get_error_message() );
     1248
     1249                if ( ! $term )
     1250                        return new IXR_Error( 404, __( 'Invalid term ID.' ) );
     1251
     1252                if ( isset( $content_struct['name'] ) ) {
     1253                        $term_data['name'] = trim( $content_struct['name'] );
     1254
     1255                        if ( empty( $term_data['name'] ) )
     1256                                return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
     1257                }
     1258
     1259                if ( isset( $content_struct['parent'] ) ) {
     1260                        if ( ! $taxonomy['hierarchical'] )
     1261                                return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) );
     1262
     1263                        $parent_term_id = (int) $content_struct['parent'];
     1264                        $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
     1265
     1266                        if ( is_wp_error( $parent_term ) )
     1267                                return new IXR_Error( 500, $term->get_error_message() );
     1268
     1269                        if ( ! $parent_term )
     1270                                return new IXR_Error( 403, __( 'Invalid parent term ID.' ) );
     1271
     1272                        $term_data['parent'] = $content_struct['parent'];
     1273                }
     1274
     1275                if ( isset( $content_struct['description'] ) )
     1276                        $term_data['description'] = $content_struct['description'];
     1277
     1278                if ( isset( $content_struct['slug'] ) )
     1279                        $term_data['slug'] = $content_struct['slug'];
     1280
     1281                $term = wp_update_term( $term_id , $taxonomy['name'] , $term_data );
     1282
     1283                if ( is_wp_error( $term ) )
     1284                        return new IXR_Error( 500, $term->get_error_message() );
     1285
     1286                if ( ! $term )
     1287                        return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) );
     1288
     1289                return true;
     1290        }
     1291
     1292        /**
     1293         * Delete a term.
     1294         *
     1295         * @uses wp_delete_term()
     1296         * @param array $args Method parameters. Contains:
     1297         *  - int     $blog_id
     1298         *  - string  $username
     1299         *  - string  $password
     1300         *  - string  $taxnomy_name
     1301         *  - int     $term_id
     1302         * @return boolean true
     1303         */
     1304        function wp_deleteTerm( $args ) {
     1305                $this->escape( $args );
     1306
     1307                $blog_id            = (int) $args[0];
     1308                $username           = $args[1];
     1309                $password           = $args[2];
     1310                $taxonomy_name      = $args[3];
     1311                $term_id            = (int) $args[4];
     1312
     1313                if ( ! $user = $this->login( $username, $password ) )
     1314                        return $this->error;
     1315
     1316                do_action( 'xmlrpc_call', 'wp.editTerm' );
     1317
     1318                if ( ! taxonomy_exists( $taxonomy_name ) )
     1319                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     1320
     1321                $taxonomy = get_taxonomy( $taxonomy_name );
     1322
     1323                if ( ! current_user_can( $taxonomy->cap->delete_terms ) )
     1324                        return new IXR_Error( 401, __( 'You are not allowed to delete terms in this taxonomy.' ) );
     1325
     1326                $term = get_term( $term_id, $taxonomy_name );
     1327
     1328                if ( is_wp_error( $term ) )
     1329                        return new IXR_Error( 500, $term->get_error_message() );
     1330
     1331                if ( ! $term )
     1332                        return new IXR_Error( 404, __( 'Invalid term ID.' ) );
     1333
     1334                $result = wp_delete_term( $term_id, $taxonomy_name );
     1335
     1336                if ( is_wp_error( $result ) )
     1337                        return new IXR_Error( 500, $term->get_error_message() );
     1338
     1339                if ( ! $result )
     1340                        return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) );
     1341
     1342                return $result;
     1343        }
     1344
     1345        /**
     1346         * Retrieve a term.
     1347         *
     1348         * @uses get_term()
     1349         * @param array $args Method parameters. Contains:
     1350         *  - int     $blog_id
     1351         *  - string  $username
     1352         *  - string  $password
     1353         *  - string  $taxonomy_name
     1354         *  - int     $term_id
     1355         * @return array contains:
     1356         *  - 'term_id'
     1357         *  - 'name'
     1358         *  - 'slug'
     1359         *  - 'term_group'
     1360         *  - 'term_taxonomy_id'
     1361         *  - 'taxonomy'
     1362         *  - 'description'
     1363         *  - 'parent'
     1364         *  - 'count'
     1365         */
     1366        function wp_getTerm( $args ) {
     1367                $this->escape( $args );
     1368
     1369                $blog_id            = (int) $args[0];
     1370                $username           = $args[1];
     1371                $password           = $args[2];
     1372                $taxonomy_name      = $args[3];
     1373                $term_id            = (int) $args[4];
     1374
     1375                if ( ! $user = $this->login( $username, $password ) )
     1376                        return $this->error;
     1377
     1378                do_action( 'xmlrpc_call', 'wp.getTerm' );
     1379
     1380                if ( ! taxonomy_exists( $taxonomy_name ) )
     1381                        return new IXR_Error( 403, __( 'Invalid taxonomy name.' ) );
     1382
     1383                $taxonomy = get_taxonomy( $taxonomy_name );
     1384
     1385                if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
     1386                        return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) );
     1387
     1388                $term = get_term( $term_id , $taxonomy_name );
     1389
     1390                if ( is_wp_error( $term ) )
     1391                        return new IXR_Error( 500, $term->get_error_message() );
     1392
     1393                if ( ! $term )
     1394                        return new IXR_Error( 404, __( 'Invalid term ID.' ) );
     1395
     1396                return $this->prepare_term( $term );
     1397        }
     1398
     1399        /**
     1400         * Retrieve all terms for a taxonomy.
     1401         *
     1402         * @uses get_terms()
     1403         * @param array $args Method parameters. Contains:
     1404         *  - int     $blog_id
     1405         *  - string  $username
     1406         *  - string  $password
     1407         *  - string   $taxonomy_name
     1408         * @return array terms
     1409         */
     1410        function wp_getTerms( $args ) {
     1411                $this->escape( $args );
     1412
     1413                $blog_id        = (int) $args[0];
     1414                $username       = $args[1];
     1415                $password       = $args[2];
     1416                $taxonomy_name  = $args[3];
     1417
     1418                if ( ! $user = $this->login( $username, $password ) )
     1419                        return $this->error;
     1420
     1421                do_action( 'xmlrpc_call', 'wp.getTerms' );
     1422
     1423                if ( ! taxonomy_exists( $taxonomy_name ) )
     1424                        return new IXR_Error( 403, __( 'Invalid taxonomy name.' ) );
     1425
     1426                $taxonomy = get_taxonomy( $taxonomy_name );
     1427
     1428                if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
     1429                        return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) );
     1430
     1431                $terms = get_terms( $taxonomy_name , array( 'get' => 'all' ) );
     1432
     1433                if ( is_wp_error( $terms ) )
     1434                        return new IXR_Error( 500, $terms->get_error_message() );
     1435
     1436                $struct = array();
     1437
     1438                foreach ( $terms as $term ) {
     1439                        $struct[] = $this->prepare_term( $term );
     1440                }
     1441
     1442                return $struct;
     1443        }
     1444
     1445        /**
     1446         * Retrieve a taxonomy.
     1447         *
     1448         * @uses get_taxonomy()
     1449         * @param array $args Method parameters. Contains:
     1450         *  - int     $blog_id
     1451         *  - string  $username
     1452         *  - string  $password
     1453         *  - string  $taxonomy_name
     1454         * @return array (@see get_taxonomy())
     1455         */
     1456        function wp_getTaxonomy( $args ) {
     1457                $this->escape( $args );
     1458
     1459                $blog_id        = (int) $args[0];
     1460                $username       = $args[1];
     1461                $password       = $args[2];
     1462                $taxonomy_name  = $args[3];
     1463
     1464                if ( ! $user = $this->login( $username, $password ) )
     1465                        return $this->error;
     1466
     1467                do_action( 'xmlrpc_call', 'wp.getTaxonomy' );
     1468
     1469                if ( ! taxonomy_exists( $taxonomy_name ) )
     1470                        return new IXR_Error( 403, __( 'The taxonomy type specified is not valid' ) );
     1471
     1472                $taxonomy = get_taxonomy( $taxonomy_name );
     1473
     1474                if ( ! current_user_can( $taxonomy->cap->edit_terms ) )
     1475                        return new IXR_Error( 401, __( 'Sorry, You are not allowed to edit this post type' ) );
     1476
     1477                return $this->prepare_taxonomy( $taxonomy );
     1478        }
     1479
     1480        /**
     1481         * Retrieve all taxonomies.
     1482         *
     1483         * @uses get_taxonomies()
     1484         * @param array $args Method parameters. Contains:
     1485         *  - int     $blog_id
     1486         *  - string  $username
     1487         *  - string  $password
     1488         * @return array taxonomies
     1489         */
     1490        function wp_getTaxonomies( $args ) {
     1491                $this->escape( $args );
     1492
     1493                $blog_id            = (int) $args[0];
     1494                $username           = $args[1];
     1495                $password           = $args[2];
     1496
     1497                if ( ! $user = $this->login( $username, $password ) )
     1498                        return $this->error;
     1499
     1500                do_action( 'xmlrpc_call', 'wp.getTaxonomies' );
     1501
     1502                $taxonomies = get_taxonomies( '', 'objects' );
     1503
     1504                // holds all the taxonomy data
     1505                $struct = array();
     1506
     1507                foreach ( $taxonomies as $taxonomy ) {
     1508                        // capability check for post_types
     1509                        if ( ! current_user_can( $taxonomy->cap->edit_terms ) )
     1510                                continue;
     1511
     1512                        $struct[] = $this->prepare_taxonomy( $taxonomy );
     1513                }
     1514
     1515                return $struct;
     1516        }
     1517
     1518        /**
    10851519         * Retrieve page.
    10861520         *
    10871521         * @since 2.2.0