WordPress.org

Make WordPress Core

Ticket #29684: 29684.19.diff

File 29684.19.diff, 1.9 KB (added by flixos90, 3 years ago)
  • src/wp-includes/class-wp-network.php

     
    219219                 *
    220220                 * @since 4.9.0
    221221                 *
    222                  * @param int|null $main_site_id If a positive integer is returned, it is interpreted as the main site ID.
    223                  * @param int $network_id The ID of the network for which the main site was detected.
     222                 * @param int|null   $main_site_id If a positive integer is returned, it is interpreted as the main site ID.
     223                 * @param WP_Network $network      The network object for which the main site was detected.
    224224                 */
    225                 $main_site_id = (int) apply_filters( 'pre_get_main_site_id', null, $this->id );
     225                $main_site_id = (int) apply_filters( 'pre_get_main_site_id', null, $this );
    226226                if ( 0 < $main_site_id ) {
    227227                        return $main_site_id;
    228228                }
  • tests/phpunit/tests/multisite/getMainSiteId.php

     
    107107        }
    108108
    109109        /**
     110         * @ticket 29684
     111         */
     112        public function test_get_main_site_id_filtered_depending_on_network() {
     113                add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id_depending_on_network' ), 10, 2 );
     114                $result = get_main_site_id( self::$network_ids['wordpress.org/'] );
     115
     116                $this->assertSame( 333, $result );
     117        }
     118
     119        public function filter_get_main_site_id_depending_on_network( $main_site_id, $network ) {
     120                // Override main site ID for a specific network for the test.
     121                if ( $network->id === (int) self::$network_ids['wordpress.org/'] ) {
     122                        return 333;
     123                }
     124
     125                return $main_site_id;
     126        }
     127
     128        /**
    110129         * @ticket 41936
    111130         */
    112131        public function test_get_main_site_id_with_property_value() {