$action, 'placement' => $placement, 'size' => $size, 'generation_size' => $size, 'display_size' => sanitize_key($raw['display_size'] ?? 'large'), 'custom_width' => absint($raw['custom_width'] ?? 800), 'custom_height' => absint($raw['custom_height'] ?? 0), 'alignment' => sanitize_key($raw['alignment'] ?? 'none'), 'mobile_behavior' => sanitize_key($raw['mobile_behavior'] ?? 'full_width'), 'replace_existing' => !empty($raw['replace_existing']) ? 'yes' : 'no', 'attachment_id' => absint($raw['attachment_id'] ?? 0), 'prompt' => sanitize_textarea_field($raw['prompt'] ?? ''), ]; } function aiwest_content_post_action_links($post_id) { $post_id = absint($post_id); if (!$post_id) return ''; $edit_link = get_edit_post_link($post_id); $preview_link = get_preview_post_link($post_id); $permalink = get_permalink($post_id); $post_status = get_post_status($post_id); $links = []; if ($edit_link) { $links[] = '' . esc_html(__('Edit post', 'ai-webmaster-studio')) . ''; } if ($post_status === 'publish' && $permalink) { $links[] = '' . esc_html(__('View post', 'ai-webmaster-studio')) . ''; } elseif ($preview_link) { $links[] = '' . esc_html(__('Preview post', 'ai-webmaster-studio')) . ''; } if (!$links) return ''; return '
' . implode(' ', $links) . '
'; } function aiwest_content_media_label($type, $value) { $value = sanitize_key($value); $labels = [ 'source' => [ 'library' => __('Media Library', 'ai-webmaster-studio'), 'ai' => __('AI', 'ai-webmaster-studio'), 'generated' => __('AI', 'ai-webmaster-studio'), 'none' => __('None', 'ai-webmaster-studio'), ], 'placement' => [ 'featured' => __('Featured image / SEO', 'ai-webmaster-studio'), 'content_top' => __('Top of content', 'ai-webmaster-studio'), 'featured_and_content_top' => __('Featured image + top of content', 'ai-webmaster-studio'), 'after_first_paragraph' => __('After first paragraph', 'ai-webmaster-studio'), 'content_end' => __('End of content', 'ai-webmaster-studio'), ], 'display_size' => [ 'thumbnail' => __('Thumbnail', 'ai-webmaster-studio'), 'medium' => __('Medium', 'ai-webmaster-studio'), 'large' => __('Large', 'ai-webmaster-studio'), 'full' => __('Full', 'ai-webmaster-studio'), 'custom' => __('Custom width', 'ai-webmaster-studio'), ], ]; return $labels[$type][$value] ?? $value; } function aiwest_content_media_success_notice($post_id, $result) { $post_id = absint($post_id); $result = is_array($result) ? $result : []; $attachment_id = absint($result['attachment_id'] ?? 0); $source = sanitize_key($result['source'] ?? (($result['status'] ?? '') === 'generated' ? 'ai' : 'library')); $placement = sanitize_key($result['placement'] ?? ''); $display_size = sanitize_key($result['display_size'] ?? ''); $message = $result['message'] ?? __('Image has been updated.', 'ai-webmaster-studio'); $notice = '' . esc_html(__('Image has been applied.', 'ai-webmaster-studio')) . ' ' . esc_html($message) . '
'; $details = []; if ($source) { $details[] = '' . esc_html(__('Source:', 'ai-webmaster-studio')) . ' ' . esc_html(aiwest_content_media_label('source', $source)); } if ($placement) { $details[] = '' . esc_html(__('Placement:', 'ai-webmaster-studio')) . ' ' . esc_html(aiwest_content_media_label('placement', $placement)); } if ($display_size) { $details[] = '' . esc_html(__('Display size:', 'ai-webmaster-studio')) . ' ' . esc_html(aiwest_content_media_label('display_size', $display_size)); } if ($attachment_id) { $details[] = '' . esc_html(__('Image ID:', 'ai-webmaster-studio')) . ' ' . intval($attachment_id); } if ($details) { $notice .= '' . implode(' | ', $details) . '
'; } if ($attachment_id) { $image = wp_get_attachment_image($attachment_id, [120, 120], false, ['class' => 'aiwest-notice-media-image', 'loading' => 'lazy']); if ($image) { $notice .= '' . esc_html(__('Content history item has been deleted. The WordPress post was not deleted.', 'ai-webmaster-studio')) . '
'; } if ($action === 'apply_media') { $post_id = AIWEST_Security::post_int('post_id'); $media_options = aiwest_content_sanitize_media_options(AIWEST_Security::post_array('aiwest_media')); if ($post_id && class_exists('AIWEST_Content_Engine') && method_exists('AIWEST_Content_Engine', 'handle_media_for_existing_post')) { $result = AIWEST_Content_Engine::handle_media_for_existing_post($post_id, $media_options); if (is_wp_error($result)) { $notice = '' . esc_html(__('Could not update image:', 'ai-webmaster-studio')) . ' ' . esc_html($result->get_error_message()) . '
' . esc_html($result['message'] ?? __('Could not update image.', 'ai-webmaster-studio')) . '
' . esc_html(__('Missing post or graphics module.', 'ai-webmaster-studio')) . '
' . esc_html(__('Content could not be generated:', 'ai-webmaster-studio')) . ' ' . esc_html($post_id->get_error_message()) . '
' . esc_html(__('Content has been created.', 'ai-webmaster-studio')) . ' ' . esc_html(__('Post ID:', 'ai-webmaster-studio')) . ' ' . intval($post_id) . ', ' . esc_html(__('status:', 'ai-webmaster-studio')) . ' ' . esc_html($post_status) . '.
'; if ($generated_attachment_id) { $media_details = []; if (!empty($media_result['source'])) $media_details[] = '' . esc_html(__('Image source:', 'ai-webmaster-studio')) . ' ' . esc_html(aiwest_content_media_label('source', $media_result['source'])); if (!empty($media_result['placement'])) $media_details[] = '' . esc_html(__('Image placement:', 'ai-webmaster-studio')) . ' ' . esc_html(aiwest_content_media_label('placement', $media_result['placement'])); if ($media_details) $notice .= '' . implode(' | ', $media_details) . '
'; $image = wp_get_attachment_image($generated_attachment_id, [120, 120], false, ['class' => 'aiwest-notice-media-image', 'loading' => 'lazy']); if ($image) $notice .= '