1 ) { /* translators: %1$s: a group of conditions. */ $text = sprintf( __( '(%1$s)', 'gateforge' ), $text ); } return $text; } if ( 'ref' === $op ) { /* translators: %1$s: the id of a reusable group of conditions. */ return sprintf( __( 'the group %1$s', 'gateforge' ), isset( $node['id'] ) && is_scalar( $node['id'] ) ? (string) $node['id'] : '' ); } return __( 'an unsupported part', 'gateforge' ); } /** * Describe a cond node. * * @param array $node Node. * @param Registry $registry Registry. * @return string */ private static function cond( array $node, Registry $registry ) { $def = $registry->get( $node['cond'] ); $label = $def ? $def['label'] : (string) $node['cond']; $args = isset( $node['args'] ) && is_array( $node['args'] ) ? $node['args'] : array(); if ( empty( $args ) ) { return $label; } $entity = $def ? $def['entity'] : ''; $parts = array(); foreach ( $args as $a ) { $parts[] = self::arg( $a, $entity ); $entity = ''; } /* translators: 1: condition label, 2: its arguments. */ return sprintf( __( '%1$s %2$s', 'gateforge' ), $label, implode( '; ', $parts ) ); } /** * Describe an argument, with entity names where known. * * @param mixed $a Value. * @param string $entity Entity type. * @return string */ private static function arg( $a, $entity ) { if ( is_array( $a ) ) { $out = array(); foreach ( $a as $x ) { $out[] = self::arg( $x, $entity ); } return implode( ', ', $out ); } if ( is_int( $a ) && '' !== $entity && function_exists( 'get_post' ) ) { return self::entity_name( $a, $entity ); } return Printer::value( $a ); } /** * Resolve an entity name. * * @param int $id ID. * @param string $entity Entity type. * @return string */ private static function entity_name( $id, $entity ) { if ( 0 === strpos( $entity, 'term:' ) ) { $term = get_term( $id, substr( $entity, 5 ) ); if ( $term && ! is_wp_error( $term ) ) { /* translators: 1: term name, 2: term ID. */ return sprintf( _x( '%1$s (ID %2$d)', 'term name and ID', 'gateforge' ), $term->name, $id ); } /* translators: %1$d: term ID. */ return sprintf( __( 'Term ID %1$d (deleted)', 'gateforge' ), $id ); } if ( 'user' === $entity ) { // 10.5 (F10): display names only for callers who may list users. $user = ( function_exists( 'current_user_can' ) && current_user_can( 'list_users' ) ) ? get_userdata( $id ) : false; if ( $user ) { /* translators: 1: user display name, 2: user ID. */ return sprintf( __( '%1$s (user ID %2$d)', 'gateforge' ), $user->display_name, $id ); } /* translators: %1$d: user ID. */ return sprintf( __( 'User ID %1$d', 'gateforge' ), $id ); } $post = get_post( $id ); if ( $post && ( ! function_exists( 'current_user_can' ) || current_user_can( 'read_post', $id ) ) ) { /* translators: 1: post title, 2: post ID. */ return sprintf( _x( '%1$s (ID %2$d)', 'post title and ID', 'gateforge' ), get_the_title( $post ), $id ); } if ( $post ) { /* translators: %1$d: post or page ID the current user may not read. */ return sprintf( __( 'Item ID %1$d', 'gateforge' ), $id ); } /* translators: %1$d: post or page ID. */ return sprintf( __( 'Item ID %1$d (deleted)', 'gateforge' ), $id ); } }