feat: import post content records
This commit is contained in:
+13
-3
@@ -545,6 +545,10 @@ if ( ! function_exists( 'wp_insert_post' ) ) {
|
||||
* @return int|\WP_Error
|
||||
*/
|
||||
function wp_insert_post( array $postarr, $wp_error = false ) {
|
||||
if ( empty( $postarr['post_type'] ) ) {
|
||||
return $wp_error ? new WP_Error( 'invalid_post_type', 'Post type is required.' ) : 0;
|
||||
}
|
||||
|
||||
if ( isset( $postarr['ID'] ) && (int) $postarr['ID'] > 0 ) {
|
||||
$post_id = (int) $postarr['ID'];
|
||||
} else {
|
||||
@@ -629,7 +633,7 @@ if ( ! function_exists( 'get_posts' ) ) {
|
||||
* Minimal posts query for unit tests.
|
||||
*
|
||||
* @param array<string, mixed> $args Query args.
|
||||
* @return array<int, array<string, mixed>>
|
||||
* @return array<int, object>
|
||||
*/
|
||||
function get_posts( array $args = array() ) {
|
||||
$posts = array_values( $GLOBALS['wpcs_test_posts'] ?? array() );
|
||||
@@ -650,12 +654,18 @@ if ( ! function_exists( 'get_posts' ) ) {
|
||||
static function ( array $post ) use ( $args ): bool {
|
||||
$values = $GLOBALS['wpcs_test_post_meta'][ (int) $post['ID'] ][ (string) $args['meta_key'] ] ?? array();
|
||||
|
||||
return in_array( $args['meta_value'], $values, true );
|
||||
foreach ( $values as $value ) {
|
||||
if ( (string) $args['meta_value'] === (string) $value ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return array_values( $posts );
|
||||
return array_values( array_map( static fn( array $post ): object => (object) $post, $posts ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user