Changeset 63603
- Timestamp:
- 09/11/2026 04:50:51 PM (14 hours ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/meta.php (modified) (2 diffs)
-
src/wp-includes/ms-site.php (modified) (1 diff)
-
tests/phpunit/tests/meta/registerMeta.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/meta.php
r63497 r63603 1790 1790 * 1791 1791 * @since 4.9.8 1792 * @since 7.2.0 Added support for 'blog' object type in multisite. 1792 1793 * 1793 1794 * @param string $object_type Type of object metadata is for. Accepts 'blog', 'post', 'comment', 'term', … … 1835 1836 $object_subtype = 'user'; 1836 1837 break; 1838 1839 case 'blog': 1840 if ( ! is_multisite() || $object_id <= 0 ) { 1841 break; 1842 } 1843 1844 $site = get_site( $object_id ); 1845 if ( ! $site ) { 1846 break; 1847 } 1848 1849 $object_subtype = 'blog'; 1850 break; 1837 1851 } 1838 1852 -
trunk/src/wp-includes/ms-site.php
r61615 r63603 1131 1131 1132 1132 /** 1133 * Registers a meta key for sites. 1134 * 1135 * @since 7.2.0 1136 * 1137 * @param string $meta_key The meta key to register. 1138 * @param array $args Data used to describe the meta key when registered. See 1139 * {@see register_meta()} for a list of supported arguments. 1140 * @return bool True if the meta key was successfully registered, false if not. 1141 */ 1142 function register_site_meta( $meta_key, array $args ) { 1143 return register_meta( 'blog', $meta_key, $args ); 1144 } 1145 1146 /** 1147 * Unregisters a meta key for sites. 1148 * 1149 * @since 7.2.0 1150 * 1151 * @param string $meta_key The meta key to unregister. 1152 * @return bool True on success, false if the meta key was not previously registered. 1153 */ 1154 function unregister_site_meta( $meta_key ) { 1155 return unregister_meta_key( 'blog', $meta_key ); 1156 } 1157 1158 /** 1133 1159 * Updates the count of sites for a network based on a changed site. 1134 1160 * -
trunk/tests/phpunit/tests/meta/registerMeta.php
r59023 r63603 9 9 protected static $comment_id; 10 10 protected static $user_id; 11 protected static $blog_id; 11 12 12 13 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { … … 15 16 self::$comment_id = $factory->comment->create(); 16 17 self::$user_id = $factory->user->create(); 18 19 if ( is_multisite() ) { 20 self::$blog_id = $factory->blog->create(); 21 } 17 22 } 18 23 … … 22 27 wp_delete_comment( self::$comment_id, true ); 23 28 self::delete_user( self::$user_id ); 29 30 if ( is_multisite() ) { 31 wp_delete_site( self::$blog_id ); 32 wp_update_network_site_counts(); 33 } 24 34 } 25 35 … … 1107 1117 1108 1118 /** 1119 * @ticket 44387 1120 * @group ms-required 1121 */ 1122 public function test_get_object_subtype_for_blog_returns_blog_when_site_exists() { 1123 $this->assertSame( 'blog', get_object_subtype( 'blog', self::$blog_id ) ); 1124 } 1125 1126 /** 1127 * @ticket 44387 1128 * @group ms-required 1129 */ 1130 public function test_get_object_subtype_for_blog_returns_empty_string_for_invalid_site() { 1131 $this->assertSame( '', get_object_subtype( 'blog', 0 ) ); 1132 $this->assertSame( '', get_object_subtype( 'blog', 999999 ) ); 1133 } 1134 1135 /** 1136 * @ticket 44387 1137 * @group ms-excluded 1138 */ 1139 public function test_get_object_subtype_for_blog_returns_empty_string_no_multisite() { 1140 $this->assertSame( '', get_object_subtype( 'blog', 0 ) ); 1141 } 1142 1143 /** 1144 * @ticket 44387 1145 * @group ms-required 1146 */ 1147 public function test_get_object_subtype_for_blog_with_registered_meta() { 1148 if ( ! is_site_meta_supported() ) { 1149 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); 1150 } 1151 1152 $this->assertSame( 'blog', get_object_subtype( 'blog', self::$blog_id ) ); 1153 1154 register_meta( 1155 'blog', 1156 'site_rating', 1157 array( 1158 'single' => true, 1159 'object_subtype' => 'blog', 1160 ) 1161 ); 1162 add_site_meta( self::$blog_id, 'site_rating', '5' ); 1163 1164 $meta = get_registered_metadata( 'blog', self::$blog_id, 'site_rating' ); 1165 1166 unregister_meta_key( 'blog', 'site_rating', 'blog' ); 1167 delete_site_meta( self::$blog_id, 'site_rating' ); 1168 1169 $this->assertSame( '5', $meta ); 1170 } 1171 1172 /** 1109 1173 * Test that attempting to register meta with revisions_enabled set to true on a 1110 1174 * post type that does not have revisions enabled fails and throws a `doing_it_wrong` notice. … … 1136 1200 $this->assertFalse( $register ); 1137 1201 } 1202 1203 /** 1204 * @ticket 44387 1205 * @group ms-required 1206 */ 1207 public function test_register_site_meta_returns_true_on_success() { 1208 if ( ! is_site_meta_supported() ) { 1209 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); 1210 } 1211 1212 $result = register_site_meta( 'test_site_meta_key', array( 'single' => true ) ); 1213 unregister_site_meta( 'test_site_meta_key' ); 1214 1215 $this->assertTrue( $result ); 1216 } 1217 1218 /** 1219 * @ticket 44387 1220 * @group ms-required 1221 */ 1222 public function test_unregister_site_meta_returns_true_on_success() { 1223 if ( ! is_site_meta_supported() ) { 1224 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); 1225 } 1226 1227 register_site_meta( 'test_site_meta_key', array( 'single' => true ) ); 1228 $result = unregister_site_meta( 'test_site_meta_key' ); 1229 1230 $this->assertTrue( $result ); 1231 } 1138 1232 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)