templates, true ) ) { return; } $template_key = $template->get_id(); $this->templates[ $template_key ] = $template; } /** * Get list of template summaries for given email type * * @param string $email_type YayMail email/template name. Example: 'new_order'. * * @return array[] */ public function get_list( $email_type ) { $results = []; foreach ( $this->templates as $template ) { if ( $template->get_email_type() !== $email_type ) { continue; } $results[] = $template->get_template_data(); } usort( $results, function( $a, $b ) { $pos_a = isset( $a['position'] ) ? (int) $a['position'] : 10; $pos_b = isset( $b['position'] ) ? (int) $b['position'] : 10; if ( $pos_a === $pos_b ) { return strcmp( (string) ( $a['name'] ?? '' ), (string) ( $b['name'] ?? '' ) ); } return $pos_a - $pos_b; } ); return $results; } }