Content Seed - Source Excerpt 03
Summary
This source excerpt preserves a bounded section of 2IA.org/wp-content/themes/twoia-intelligence/inc/content-seed.php so readers can inspect the evidence without opening the full source file.
**Source path:** 2IA.org/wp-content/themes/twoia-intelligence/inc/content-seed.php
/**
* Seed missing draft pages and posts.
*
* @return int Number of created objects.
*/
function twoia_seed_draft_content() {
if ( ! current_user_can( 'manage_options' ) ) {
return 0;
}
$created = 0;
foreach ( twoia_seed_pages() as $title => $content ) {
$slug = sanitize_title( $title );
if ( get_page_by_path( $slug, OBJECT, 'page' ) ) {
continue;
}
$post_id = wp_insert_post(
array(
'post_title' => wp_strip_all_tags( $title ),
'post_name' => $slug,
'post_content' => wp_kses_post( $content ),
'post_status' => 'draft',
'post_type' => 'page',
)
);
if ( $post_id && ! is_wp_error( $post_id ) ) {
++$created;
}
}
foreach ( twoia_seed_posts() as $briefing ) {
$slug = sanitize_title( $briefing['title'] );
if ( get_page_by_path( $slug, OBJECT, 'post' ) ) {
continue;
}
$term = get_term_by( 'name', $briefing['category'], 'category' );
$post_id = wp_insert_post(
array(
'post_title' => wp_strip_all_tags( $briefing['title'] ),
'post_name' => $slug,
'post_content' => wp_kses_post( $briefing['content'] ),
'post_excerpt' => sanitize_text_field( $briefing['excerpt'] ),
'post_status' => 'draft',
'post_type' => 'post',
'post_category' => $term ? array( (int) $term->term_id ) : array(),
)
);
if ( $post_id && ! is_wp_error( $post_id ) ) {
++$created;
}
}
return $created;
}
/**
* Add admin page for optional seed content.
*/
function twoia_seed_admin_page() {
add_theme_page(
esc_html__( '2IA Seed Content', 'two-identities-anonymous' ),
esc_html__( '2IA Seed Content', 'two-identities-anonymous' ),
'manage_options',
'twoia-seed-content',
'twoia_render_seed_admin_page'
);
}
add_action( 'admin_menu', 'twoia_seed_admin_page' );
/**
* Render seed admin page.
*/
function twoia_render_seed_admin_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have permission to access this page.', 'two-identities-anonymous' ) );
}
$message = '';
if ( isset( $_POST['twoia_seed_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['twoia_seed_nonce'] ) ), 'twoia_seed_content' ) ) {
$created = twoia_seed_draft_content();
if ( $created > 0 ) {
$message = sprintf(
/* translators: %d: Number of created drafts. */
esc_html__( 'Created %d missing safe draft pages/posts. Review and publish manually when ready.', 'two-identities-anonymous' ),
$created
);
} else {
$message = esc_html__( 'No content was created. The starter pages/posts already exist.', 'two-identities-anonymous' );
}
}
?>
<div class="wrap">
<h1><?php esc_html_e( '2IA Seed Content', 'two-identities-anonymous' ); ?></h1>
<?php if ( $message ) : ?>
<div class="notice notice-info"><p><?php echo esc_html( $message ); ?></p></div>
<?php endif; ?>
<p><?php esc_html_e( 'This tool creates missing draft-only starter pages and posts for the 2IA research model. It does not publish content automatically and it does not add operational instructions.', 'two-identities-anonymous' ); ?></p>
<?php if ( twoia_count_pages_all_statuses() > 0 ) : ?>
<p><strong><?php esc_html_e( 'Existing pages detected.', 'two-identities-anonymous' ); ?></strong> <?php esc_html_e( 'The tool will only create missing starter drafts and will not duplicate existing pages.', 'two-identities-anonymous' ); ?></p>
<?php endif; ?>
<form method="post">
<?php wp_nonce_field( 'twoia_seed_content', 'twoia_seed_nonce' ); ?>
<?php submit_button( esc_html__( 'Create missing draft starter content', 'two-identities-anonymous' ) ); ?>
</form>
</div>
<?php
}
/**
* Admin notice to surface the seed page on empty sites.
*/
function twoia_seed_admin_notice() {
if ( ! current_user_can( 'manage_options' ) || ! get_theme_mod( 'twoia_show_seed_notice', true ) ) {
return;
}
if ( twoia_count_pages_all_statuses() > 0 ) {
return;
}
$screen = get_current_screen();
if ( $screen && 'appearance_page_twoia-seed-content' === $screen->id ) {
return;
}
?>
<div class="notice notice-info is-dismissible">
<p>
<?php esc_html_e( '2IA Intelligence can create safe draft starter pages and research posts for an empty site.', 'two-identities-anonymous' ); ?>
<a href="<?php echo esc_url( admin_url( 'themes.php?page=twoia-seed-content' ) ); ?>"><?php esc_html_e( 'Open seed content tool', 'two-identities-anonymous' ); ?></a>
</p>
</div>
<?php
}
add_action( 'admin_notices', 'twoia_seed_admin_notice' );