bbp_exclude_forum_ids( $type = 'string' )
Returns a meta_query that either includes or excludes hidden forum IDs from a query.
Description
Parameters
-
(Optional) The type of value to return. (string|array|meta_query)
Source
File: bp-forums/forums/functions.php
1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 | function bbp_exclude_forum_ids( $type = 'string' ) { // Setup arrays $private = $hidden = $meta_query = $forum_ids = array (); // Default return value switch ( $type ) { case 'string' : $retval = '' ; break ; case 'array' : $retval = array (); break ; case 'meta_query' : $retval = array ( array () ) ; break ; } // Exclude for everyone but keymasters if ( ! bbp_is_user_keymaster() ) { // Private forums if ( !current_user_can( 'read_private_forums' ) ) $private = bbp_get_private_forum_ids(); // Hidden forums if ( !current_user_can( 'read_hidden_forums' ) ) $hidden = bbp_get_hidden_forum_ids(); // Merge private and hidden forums together $forum_ids = ( array ) array_filter ( wp_parse_id_list( array_merge ( $private , $hidden ) ) ); // There are forums that need to be excluded if ( ! empty ( $forum_ids ) ) { switch ( $type ) { // Separate forum ID's into a comma separated string case 'string' : $retval = implode( ',' , $forum_ids ); break ; // Use forum_ids array case 'array' : $retval = $forum_ids ; break ; // Build a meta_query case 'meta_query' : $retval = array ( 'key' => '_bbp_forum_id' , 'value' => implode( ',' , $forum_ids ), 'type' => 'numeric' , 'compare' => ( 1 < count ( $forum_ids ) ) ? 'NOT IN' : '!=' ); break ; } } } // Filter and return the results return apply_filters( 'bbp_exclude_forum_ids' , $retval , $forum_ids , $type ); } |
Changelog
Version | Description |
---|---|
bbPress (r3291) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.