_x( ‘Advertiser Ads’, ‘post type general name’, ‘advertiser-form’ ),
‘singular_name’ => _x( ‘Advertiser Ad’, ‘post type singular name’, ‘advertiser-form’ ),
‘menu_name’ => _x( ‘Advertiser Ads’, ‘admin menu’, ‘advertiser-form’ ),
‘name_admin_bar’ => _x( ‘Advertiser Ad’, ‘add new on admin bar’, ‘advertiser-form’ ),
‘add_new’ => _x( ‘Add New’, ‘advertiser ad’, ‘advertiser-form’ ),
‘add_new_item’ => __( ‘Add New Advertiser Ad’, ‘advertiser-form’ ),
‘new_item’ => __( ‘New Advertiser Ad’, ‘advertiser-form’ ),
‘edit_item’ => __( ‘Edit Advertiser Ad’, ‘advertiser-form’ ),
‘view_item’ => __( ‘View Advertiser Ad’, ‘advertiser-form’ ),
‘all_items’ => __( ‘All Advertiser Ads’, ‘advertiser-form’ ),
‘search_items’ => __( ‘Search Advertiser Ads’, ‘advertiser-form’ ),
‘parent_item_colon’ => __( ‘Parent Advertiser Ads:’, ‘advertiser-form’ ),
‘not_found’ => __( ‘No advertiser ads found.’, ‘advertiser-form’ ),
‘not_found_in_trash’ => __( ‘No advertiser ads found in Trash.’, ‘advertiser-form’ ),
);

$args = array(
‘labels’ => $labels,
‘public’ => false,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘capability_type’ => ‘post’,
‘has_archive’ => false,
‘hierarchical’ => false,
‘supports’ => array( ‘title’, ‘editor’ ),
‘menu_position’ => 21,
);
register_post_type( ‘advertiser_ad’, $args );
}
add_action( ‘init’, ‘advertiser_form_register_post_type’ );

/**
* Add meta boxes for the advertiser ad custom post type. This allows admins to
* view and edit the call‑to‑action text and URL associated with each ad.
*/
function advertiser_form_add_meta_boxes() {
add_meta_box(
‘advertiser_ad_meta’,
__( ‘Ad Details’, ‘advertiser-form’ ),
‘advertiser_form_meta_box_callback’,
‘advertiser_ad’,
‘normal’,
‘default’
);
}
add_action( ‘add_meta_boxes’, ‘advertiser_form_add_meta_boxes’ );

/**
* Render the meta box for ad details in the admin.
*
* @param WP_Post $post The post being edited.
*/
function advertiser_form_meta_box_callback( $post ) {
wp_nonce_field( ‘advertiser_form_meta_box’, ‘advertiser_form_meta_box_nonce’ );
$cta_text = get_post_meta( $post->ID, ‘_advertiser_cta_text’, true );
$cta_url = get_post_meta( $post->ID, ‘_advertiser_cta_url’, true );
?>



    ‘;
    foreach ( $errors as $error ) {
    echo ‘

  • ‘ . esc_html( $error ) . ‘
  • ‘;
    }
    echo ‘

‘;
}
?>








post_type ) {
return;
}
// Fetch custom meta
$cta_text = get_post_meta( $ad_post_id, ‘_advertiser_cta_text’, true );
$cta_url = get_post_meta( $ad_post_id, ‘_advertiser_cta_url’, true );
$image_id = get_post_meta( $ad_post_id, ‘_advertiser_image_id’, true );
$headline = $ad_post->post_title;
$content = apply_filters( ‘the_content’, $ad_post->post_content );
// Build the advertisement snippet
$snippet = ”;
$snippet .= ‘

‘;
// Include image if available
if ( $image_id ) {
$image_html = wp_get_attachment_image( $image_id, ‘medium’, false, array( ‘class’ => ‘advertiser-clip-image’, ‘style’ => ‘max-width:100%; height:auto; margin-bottom:10px;’ ) );
if ( $image_html ) {
$snippet .= ‘

‘ . $image_html . ‘

‘;
}
}
$snippet .= ‘

‘ . esc_html( $headline ) . ‘

‘;
// Use paragraph content as provided
$snippet .= ‘

‘ . $content . ‘

‘;
if ( ! empty( $cta_text ) && ! empty( $cta_url ) ) {
$snippet .= ‘

‘ . esc_html( $cta_text ) . ‘

‘;
}
$snippet .= ‘

‘;
$snippet .= “\n\n”;
// Locate or create the News Clips post (post type “post”)
// Try to locate an existing post titled “News Clips”
$news_clips_post = get_page_by_title( ‘News Clips’, OBJECT, ‘post’ );
if ( ! $news_clips_post ) {
// Create a new post titled News Clips if not found
$news_clips_post_id = wp_insert_post( array(
‘post_title’ => ‘News Clips’,
‘post_content’ => ”,
‘post_status’ => ‘publish’,
‘post_type’ => ‘post’,
‘post_author’ => get_current_user_id(),
) );
$news_clips_post = get_post( $news_clips_post_id );
}
// Prepend the new snippet to the existing content
if ( $news_clips_post ) {
$current_content = $news_clips_post->post_content;
// Prepend new snippet to existing content
$new_content = $snippet . $current_content;
wp_update_post( array(
‘ID’ => $news_clips_post->ID,
‘post_content’ => $new_content,
) );
}
}