| | 1685 | |
| | 1686 | /** |
| | 1687 | * Add metadata field to a network. |
| | 1688 | * |
| | 1689 | * @since 4.5.0 |
| | 1690 | * |
| | 1691 | * @param int $network_id Network ID. |
| | 1692 | * @param string $meta_key Metadata name. |
| | 1693 | * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
| | 1694 | * @param bool $unique Optional. Whether the same key should not be added. |
| | 1695 | * Default false. |
| | 1696 | * @return int|false Meta ID on success, false on failure. |
| | 1697 | */ |
| | 1698 | function add_network_meta( $network_id, $meta_key, $meta_value, $unique = false ) { |
| | 1699 | return add_metadata( 'site', $network_id, $meta_key, $meta_value, $unique ); |
| | 1700 | } |
| | 1701 | |
| | 1702 | /** |
| | 1703 | * Remove metadata matching criteria from a network. |
| | 1704 | * |
| | 1705 | * You can match based on the key, or key and value. Removing based on key and |
| | 1706 | * value, will keep from removing duplicate metadata with the same key. It also |
| | 1707 | * allows removing all metadata matching key, if needed. |
| | 1708 | * |
| | 1709 | * @since 4.5.0 |
| | 1710 | * |
| | 1711 | * @param int $network_id Network ID. |
| | 1712 | * @param string $meta_key Metadata name. |
| | 1713 | * @param mixed $meta_value Optional. Metadata value. Must be serializable if |
| | 1714 | * non-scalar. Default empty. |
| | 1715 | * @return bool True on success, false on failure. |
| | 1716 | */ |
| | 1717 | function delete_network_meta( $network_id, $meta_key, $meta_value = '' ) { |
| | 1718 | return delete_metadata( 'site', $network_id, $meta_key, $meta_value ); |
| | 1719 | } |
| | 1720 | |
| | 1721 | /** |
| | 1722 | * Retrieve network meta field for a network. |
| | 1723 | * |
| | 1724 | * @since 4.5.0 |
| | 1725 | * |
| | 1726 | * @param int $network_id Network ID. |
| | 1727 | * @param string $key Optional. The meta key to retrieve. By default, returns |
| | 1728 | * data for all keys. Default empty. |
| | 1729 | * @param bool $single Optional. Whether to return a single value. Default false. |
| | 1730 | * @return mixed Will be an array if $single is false. Will be value of meta data |
| | 1731 | * field if $single is true. |
| | 1732 | */ |
| | 1733 | function get_network_meta( $network_id, $key = '', $single = false ) { |
| | 1734 | return get_metadata( 'site', $network_id, $key, $single ); |
| | 1735 | } |
| | 1736 | |
| | 1737 | /** |
| | 1738 | * Update network meta field based on network ID. |
| | 1739 | * |
| | 1740 | * Use the $prev_value parameter to differentiate between meta fields with the |
| | 1741 | * same key and network ID. |
| | 1742 | * |
| | 1743 | * If the meta field for the network does not exist, it will be added. |
| | 1744 | * |
| | 1745 | * @since 4.5.0 |
| | 1746 | * |
| | 1747 | * @param int $network_id Network ID. |
| | 1748 | * @param string $meta_key Metadata key. |
| | 1749 | * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. |
| | 1750 | * @param mixed $prev_value Optional. Previous value to check before removing. |
| | 1751 | * Default empty. |
| | 1752 | * @return int|bool Meta ID if the key didn't exist, true on successful update, |
| | 1753 | * false on failure. |
| | 1754 | */ |
| | 1755 | function update_network_meta( $network_id, $meta_key, $meta_value, $prev_value = '' ) { |
| | 1756 | return update_metadata( 'site', $network_id, $meta_key, $meta_value, $prev_value ); |
| | 1757 | } |
| | 1758 | |
| | 1759 | /** |
| | 1760 | * Delete everything from network meta matching meta key. |
| | 1761 | * |
| | 1762 | * @since 4.5.0 |
| | 1763 | * |
| | 1764 | * @param string $network_meta_key Key to search for when deleting. |
| | 1765 | * @return bool Whether the network meta key was deleted from the database. |
| | 1766 | */ |
| | 1767 | function delete_network_meta_by_key( $network_meta_key ) { |
| | 1768 | return delete_metadata( 'site', null, $network_meta_key, '', true ); |
| | 1769 | } |