[ 'post', 'page' ], 'schema_ld' => false, 'minify' => true, 'include_acf' => false, ]; } public function register_settings() { register_setting( self::OPTION_KEY, self::OPTION_KEY, [ 'type' => 'array', 'sanitize_callback' => function( $input ) { $defaults = self::get_defaults(); $out = is_array( $input ) ? $input : []; $allowed_types = [ 'post', 'page', 'attachment' ]; $selected_types = isset( $out['post_types'] ) ? (array) $out['post_types'] : []; $out['post_types'] = array_values( array_intersect( $selected_types, $allowed_types ) ); $out['schema_ld'] = ! empty( $out['schema_ld'] ); $out['minify'] = ! empty( $out['minify'] ); $out['include_acf'] = ! empty( $out['include_acf'] ); return wp_parse_args( $out, $defaults ); }, 'show_in_rest' => false, ] ); } /** * Register settings page under "Tools". */ public function add_settings_page() { add_management_page( esc_html__( 'AI JSON Extractor Lite', 'ai-json-extractor-auto-embed-lite' ), esc_html__( 'AI JSON Extractor Lite', 'ai-json-extractor-auto-embed-lite' ), 'manage_options', 'aijxal-settings', [ $this, 'render_settings_page' ] ); } public function render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $opts = wp_parse_args( (array) get_option( self::OPTION_KEY ), self::get_defaults() ); ?>

build_post_json( $post, ! empty( $opts['include_acf'] ) ); $flags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; $json = wp_json_encode( $data, $flags ); ?>

-Bereich ausgegeben werden.', 'ai-json-extractor-auto-embed-lite' ); ?>

post_type, (array) $opts['post_types'], true ) ) { return; } // Haupt-JSON-Daten aufbauen $data = $this->build_post_json( $post, ! empty( $opts['include_acf'] ) ); // Haupt-JSON: exakt im empfohlenen Stil echo "\n\n"; echo "\n"; // Optional: schema.org Article (application/ld+json) if ( ! empty( $opts['schema_ld'] ) ) { $schema = $this->build_basic_schema_article( $post ); if ( ! empty( $schema ) ) { echo "\n\n"; } } } private function build_post_json( WP_Post $post, $include_acf = false ) { $featured = get_post_thumbnail_id( $post ); $featured_url = $featured ? wp_get_attachment_image_url( $featured, 'full' ) : ''; $categories = array_map( function( $t ) { return [ 'id' => (int) $t->term_id, 'name' => $t->name, 'slug' => $t->slug, ]; }, get_the_terms( $post, 'category' ) ?: [] ); $tags = array_map( function( $t ) { return [ 'id' => (int) $t->term_id, 'name' => $t->name, 'slug' => $t->slug, ]; }, get_the_terms( $post, 'post_tag' ) ?: [] ); $data = [ 'id' => (int) $post->ID, 'type' => $post->post_type, 'title' => get_the_title( $post ), 'excerpt' => wp_strip_all_tags( get_the_excerpt( $post ), true ), 'permalink' => get_permalink( $post ), 'date' => get_the_date( DATE_W3C, $post ), 'modified' => get_the_modified_date( DATE_W3C, $post ), 'author' => get_the_author_meta( 'display_name', (int) $post->post_author ), 'featured' => $featured_url ? $featured_url : null, 'categories' => $categories, 'tags' => $tags, ]; if ( $include_acf && function_exists( 'get_fields' ) ) { $acf = get_fields( $post->ID ); if ( $acf && is_array( $acf ) ) { $data['acf'] = $acf; } } return $data; } private function build_basic_schema_article( WP_Post $post ) { if ( 'post' !== $post->post_type ) { return []; } $image_id = get_post_thumbnail_id( $post ); $image_url = $image_id ? wp_get_attachment_image_url( $image_id, 'full' ) : ''; $author_id = (int) $post->post_author; $author = get_the_author_meta( 'display_name', $author_id ); $schema = [ '@context' => 'https://schema.org', '@type' => 'Article', 'mainEntityOfPage' => [ '@type' => 'WebPage', '@id' => get_permalink( $post ), ], 'headline' => get_the_title( $post ), 'datePublished' => get_the_date( DATE_W3C, $post ), 'dateModified' => get_the_modified_date( DATE_W3C, $post ), 'author' => [ '@type' => 'Person', 'name' => $author, ], ]; if ( $image_url ) { $schema['image'] = [ $image_url ]; } return $schema; } } endif; // class exists // Bootstrap function aijxal_bootstrap_plugin() { static $instance = null; if ( null === $instance ) { $instance = new Aijxal_Auto_Embed_Lite(); } return $instance; } aijxal_bootstrap_plugin();