public function cloneTerm( $term_id ) {
		// Retrieve term
		foreach ( $this->sourceBookTerms as $k => $v ) {
			if ( $v['id'] === absint( $term_id ) ) {
				$term = $this->sourceBookTerms[ $k ];
				break;
			}
		};

		if ( empty( $term['slug'] ) || empty( $term['taxonomy'] ) ) {
			// Doing it wrong...
			return false;
		}

		// Check for matching term
		foreach ( $this->targetBookTerms as $k => $v ) {
			if ( $v['slug'] === $term['slug'] && $v['taxonomy'] === $term['taxonomy'] ) {
				return $v['id'];
			}
		};

		// Set endpoint
		$endpoint = $term['taxonomy'];

		// _links key needs to be removed, pop it out into an ignored variable
		$_links = array_pop( $term );

		// Remove source-specific properties
		$bad_keys = [ 'id', 'count', 'link', 'parent', 'taxonomy' ];
		foreach ( $bad_keys as $bad_key ) {
			unset( $term[ $bad_key ] );
		}

		// POST internal request
		$request = new \WP_REST_Request( 'POST', "/pressbooks/v2/$endpoint" );
		$request->set_body_params( $term );
		$request->set_param( '_fields', 'id' );
		$response = rest_do_request( $request )->get_data();

		// Inform user of failure, bail
		if ( is_wp_error( $response ) || @$response['data']['status'] >= 400 ) { // @codingStandardsIgnoreLine
			return false;
		} else {
			return $response['id'];
		}
	}
public function cloneTerm( $term_id ) {
		// Retrieve term
		foreach ( $this->sourceBookTerms as $k => $v ) {
			if ( $v['id'] === absint( $term_id ) ) {
				$term = $this->sourceBookTerms[ $k ];
				break;
			}
		};

		if ( empty( $term['slug'] ) || empty( $term['taxonomy'] ) ) {
			// Doing it wrong...
			return false;
		}

		// Check for matching term
		foreach ( $this->targetBookTerms as $k => $v ) {
			if ( $v['slug'] === $term['slug'] && $v['taxonomy'] === $term['taxonomy'] ) {
				return $v['id'];
			}
		};

		// Set endpoint
		$endpoint = $term['taxonomy'];

		// _links key needs to be removed, pop it out into an ignored variable
		$_links = array_pop( $term );

		// Remove source-specific properties
		$bad_keys = [ 'id', 'count', 'link', 'parent', 'taxonomy' ];
		foreach ( $bad_keys as $bad_key ) {
			unset( $term[ $bad_key ] );
		}

		// POST internal request
		$request = new \WP_REST_Request( 'POST', "/pressbooks/v2/$endpoint" );
		$request->set_body_params( $term );
		$request->set_param( '_fields', 'id' );
		$response = rest_do_request( $request )->get_data();

		// Inform user of failure, bail
		if ( is_wp_error( $response ) || @$response['data']['status'] >= 400 ) { // @codingStandardsIgnoreLine
			return false;
		} else {
			return $response['id'];
		}
	}
public function cloneTerm ( $ term_id ) { // Retrieve term foreach ( $ this -> sourceBookTerms as $ k => $ v ) { if ( $ v [ 'id' ] === absint ( $ term_id ) ) { $ term = $ this -> sourceBookTerms [ $ k ] ; break ; } } ; if ( empty ( $ term [ 'slug' ] ) || empty ( $ term [ 'taxonomy' ] ) ) { // Doing it wrong... return false ; } // Check for matching term foreach ( $ this -> targetBookTerms as $ k => $ v ) { if ( $ v [ 'slug' ] === $ term [ 'slug' ] && $ v [ 'taxonomy' ] === $ term [ 'taxonomy' ] ) { return $ v [ 'id' ] ; } } ; // Set endpoint $ endpoint = $ term [ 'taxonomy' ] ; // _links key needs to be removed, pop it out into an ignored variable $ _links = array_pop ( $ term ) ; // Remove source-specific properties $ bad_keys = [ 'id' , 'count' , 'link' , 'parent' , 'taxonomy' ] ; foreach ( $ bad_keys as $ bad_key ) { unset ( $ term [ $ bad_key ] ) ; } // POST internal request $ request = new \ WP_REST_Request ( 'POST' , "/pressbooks/v2/$endpoint" ) ; $ request -> set_body_params ( $ term ) ; $ request -> set_param ( '_fields' , 'id' ) ; $ response = rest_do_request ( $ request ) -> get_data ( ) ; // Inform user of failure, bail if ( is_wp_error ( $ response ) || @ $ response [ 'data' ] [ 'status' ] >= 400 ) { // @codingStandardsIgnoreLine return false ; } else { return $ response [ 'id' ] ; } }
Clone term from a source book to a target book.

@since 4.1.0

@param int $term_id The ID of the term within the source book.

@return bool | int False if creating a new term failed; the ID of the new term if it the clone succeeded or the ID of a matching term if it exists.
Clone term from a source book to a target book .