'; abstract public static function get_data( $attributes = [] ); /** * Render list elements * * @param $element Element data * @param $args includes * $render_data * $template * $is_nested */ public static function get_layout( $element_data, $args ) { $file_name = str_replace( '_', '-', static::$type ); $path = 'templates/elements/' . $file_name . '.php'; return apply_filters( 'yaymail_' . static::$type . '_layout', yaymail_get_content( $path, array_merge( [ 'element' => $element_data ], $args ) ), $element_data, $args ); } /** * Check available in email. * * @param string|array $email_ids The email ID(s) to be set as available. Special placeholders such as * `NON_ORDER_EMAILS`, `WITH_ORDER_EMAILS`, and `GLOBAL_HEADER_FOOTER_ID` can be used to include predefined sets * of email IDs or the global header/footer ID. * If provided as a string, it represents a single email ID. * If provided as an array, it represents multiple email IDs. * @return void */ public function is_available_in_email( $email ) { if ( ! ( $email instanceof BaseEmail ) && ! is_string( $email ) ) { return false; } if ( is_string( $email ) ) { $email = yaymail_get_email( $email ); if ( empty( $email ) || ! $email instanceof BaseEmail ) { return false; } } $available_email_ids = (array) $this->available_email_ids; $available_email_ids = apply_filters( 'yaymail_element_available_email_ids', $available_email_ids, $this ); return ( in_array( YAYMAIL_ALL_EMAILS, $available_email_ids, true ) ) || ( in_array( YAYMAIL_NON_ORDER_EMAILS, $available_email_ids, true ) && in_array( YAYMAIL_NON_ORDER_EMAILS, $email->email_types, true ) ) || ( in_array( YAYMAIL_WITH_ORDER_EMAILS, $available_email_ids, true ) && in_array( YAYMAIL_WITH_ORDER_EMAILS, $email->email_types, true ) ) || ( in_array( YAYMAIL_GLOBAL_HEADER_FOOTER_ID, $available_email_ids, true ) && in_array( YAYMAIL_GLOBAL_HEADER_FOOTER_ID, $email->email_types, true ) ) || in_array( $email->get_id(), $available_email_ids, true ); } public static function get_type() { return static::$type; } /** * Converts an element's data to use default values. * * This function iterates through the 'data' array of an element, replacing each value with its 'default_value'. * It then updates the element's 'data' with the formatted data and returns the modified element. * * @param array $element The element to be modified. * @return array The modified element with default values applied. */ public static function reduce_new_element( $element ) { $data = $element['data']; $formatted_data = []; foreach ( $data as $key => $value ) { $fallback_value = $value; if ( isset( $value['value_path'] ) ) { $fallback_value = ''; } $formatted_data[ $key ] = $value['default_value'] ?? $fallback_value; } $element['data'] = $formatted_data; return $element; } public static function merge_common_data( $element, $attributes = [] ) { if ( empty( $attributes['custom_css_classes'] ) ) { return $element; } $element['data']['custom_css_classes'] = $attributes['custom_css_classes']; return $element; } public static function get_object_data( ...$args ) { return self::reduce_new_element( static::get_data( ...$args ) ); } }