Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function __add_global_categories( $term_id )
- {
- if ( get_current_blog_id() !== BLOG_ID_CURRENT_SITE || ( !$term = get_term( $term_id, 'category' ) ) )
- return $term_id; // bail
- if ( !$term->parent || ( !$parent = get_term( $term->parent, 'category' ) ) )
- $parent = null;
- global $wpdb;
- $blogs = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}'" );
- foreach ( $blogs as $blog ) {
- $wpdb->set_blog_id( $blog );
- if ( $parent && ( $_parent = get_term_by( 'slug', $parent->slug, 'category' ) ) )
- $_parent_ID = $_parent->term_id;
- else
- $_parent_ID = 0;
- wp_insert_term( $term->name, 'category', array(
- 'slug' => $term->slug,
- 'parent' => $_parent_ID,
- 'description' => $term->description
- ));
- }
- $wpdb->set_blog_id( BLOG_ID_CURRENT_SITE );
- }
- add_action( 'created_category', '__add_global_categories' );
- <?php function mau_add_network_terms($terms_to_add, $siteids, $testrun = false) {
- // check if this is multisite install
- if ( !is_multisite() )
- return 'This is not a multisite WordPress installation.';
- // very basic input check
- if ( empty($terms_to_add) || empty($siteids) || !is_array($terms_to_add) || !is_array($siteids) )
- return 'Nah, I eat only arrays!';
- if ($testrun) $log = '<p><em>No need to get excited. This is just a test run.</em></p>';
- else $log = '';
- // loop thru blogs
- foreach ($siteids as $blog_id) :
- switch_to_blog( absint($blog_id) );
- $log .= '<h4>'.get_blog_details( $blog_id )->blogname.':</h4>';
- $log .= '<ul id="ntlog">';
- // loop thru taxonomies
- foreach ( $terms_to_add as $taxonomy => $terms ) {
- // check if taxonomy exists
- if ( taxonomy_exists($taxonomy) ) {
- // get taxonomy name
- $tax_name = get_taxonomy($taxonomy);
- $tax_name = $tax_name->labels->name;
- //loop thru terms
- foreach ( $terms as $term ) {
- // check if term exists
- if ( term_exists($term, $taxonomy) ) {
- $log .= "<li class='notice' ><em>$term already exists in the $tax_name taxonomy - not added!</em></li>";
- } else {
- // if it doesn't exist insert the $term to $taxonomy
- $term = strip_tags($term);
- $taxonomy = strip_tags($taxonomy);
- if (!$testrun)
- wp_insert_term( $term, $taxonomy );
- $log .= "<li><b>$term</b> successfully added to the <b>$tax_name</b> taxonomy</li>";
- }
- }
- } else {
- // tell our log that taxonomy doesn't exists
- $log .= "<li class='notice'><em>The $tax_name taxonomy doesn't exist! Skipping...</em></li>";
- }
- }
- $log .= '</ul>';
- // we're done here
- restore_current_blog();
- endforeach;
- if ($testrun) $log .= '<p><em>No need to get excited. This was just the test run.</em></p>';
- return $log;
- } ?>
- add_action('init', 'central_taxonomies');
- function central_taxonomies () {
- global $wpdb;
- $wpdb->terms = "wp_terms";
- $wpdb->term_taxonomy = "wp_term_taxonomy";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement