Site icon Hip-Hop Website Design and Development

Customized plugin foreach wp_insert_post not working

I am sorry, I converse a bit of English.

Why not works?

My plugin: ~/wp-content/plugins/mypluggg/mypluggg.php

<?php
/**
 * Plugin Identify: mypluggg
 */
    operate movies() {
        // file_get_content()
        // $http_response_header
        $postarr = array();
        foreach( $movies as $key=> $video ) {
            $postarr [ $key ] = array( // and so forth.
            wp_insert_post( $postarr [ $key ], $wp_error );
        }
    }
    movies();
?>

Add 1 publish after which error display:

https://i.imgur.com/MlxcTsW.png

There was a crucial error on this web site.
Be taught extra about troubleshooting WordPress.

Why?

UPDATE(1):

foreach( $movies as $key=> $video ) {

    $postarr [ $key ] = array(

        'post_title'=> $movies [ 'title' ] [ $key ],
        'post_content'=> '<iframe src="https://*.com/' . $videos [ 'id' ] [ $key ] . '" frameborder=0 width=510 peak=400 scrolling=no allowfullscreen=allowfullscreen></iframe>',
        'post_status'=> 'publish',
        'post_author'=> 1,

        'meta_input'=> array(

            'web site'=> '*.com',
            'video_id'=> $movies [ 'id' ] [ $key ],
            'thumbnail'=> $thumbnail,
            'video_url'=> $video_url,
            'iframe_src_start'=> 'https://*.com/embedframe/',
            'iframe_src_end'=> '',
            'v_tag'=> $tag

        )

    );

}

UPDATE(2):

My ~/error_log file (I do not name is_user_logged_in operate):

[31-Aug-2021 15:16:22 UTC] PHP Deadly error:  Uncaught Error: Name to undefined operate is_user_logged_in() in /house/x/public_html2/y/public_html/wp-includes/publish.php:2793
Stack hint:
#0 /house/x/public_html2/y/public_html/wp-includes/publish.php(7359): _count_posts_cache_key('publish', 'readable')
#1 /house/x/public_html2/y/public_html/wp-includes/class-wp-hook.php(303): _transition_post_status('publish', 'new', Object(WP_Post))
#2 /house/x/public_html2/y/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
#3 /house/x/public_html2/y/public_html/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#4 /house/x/public_html2/y/public_html/wp-includes/publish.php(5098): do_action('transition_post...', 'publish', 'new', Object(WP_Post))
#5 /house/x/public_html2/y/public_html/wp-includes/publish.php(4368): wp_transition_post_status('publish', 'new', Object(WP_Post))
#6 /house/x/public_html2/y/public_html in /house/x/public_html2/y/public_html/wp-includes/publish.php on line 2793

UPDATE(3):

Just isn’t working, I see the error display (https://i.imgur.com/MlxcTsW.png):

$ID = wp_insert_post( $postarr [ $key ], $wp_error );
if( ! is_wp_error( $ID ) ) {} else {
    echo $ID-> get_error_message();
} else {}

UPDATE(4):

I strive create my new take a look at customized plugin, however the issue is similar. The total code:

~/wp-content/plugins/mypluk/mypluk.php

<?php

/**
 * Plugin Identify: mypluk
 */

    operate videoss() {

        $postarr = array();

        foreach( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27 ) as $key ) {

            $postarr [ $key ] = array(

                'post_title'=> 'title' . $key

            );

            $ID = wp_insert_post( $postarr [ $key ], $wp_error );

        }

    }

    videoss();

?>