Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改函数并创建表单以在Wordpress上触发它_Php_Wordpress_Forms_Hook - Fatal编程技术网

Php 更改函数并创建表单以在Wordpress上触发它

Php 更改函数并创建表单以在Wordpress上触发它,php,wordpress,forms,hook,Php,Wordpress,Forms,Hook,你好,我想改变一个由Automattic开发的wordpress插件的功能。称为合著者加。他们已经为它创建了一个WP-CLI命令列表,还有一些。函数在这里 /** *为所有没有作者术语的帖子创建作者术语 * *@子命令为帖子创建术语 */ 公共功能为职位创建职位术语(){ 全局$coauthors\u plus,$wp\u post\u类型 // Cache these to prevent repeated lookups $authors = array(); $au

你好,我想改变一个由Automattic开发的wordpress插件的功能。称为合著者加。他们已经为它创建了一个WP-CLI命令列表,还有一些。函数在这里

/** *为所有没有作者术语的帖子创建作者术语 * *@子命令为帖子创建术语 */ 公共功能为职位创建职位术语(){ 全局$coauthors\u plus,$wp\u post\u类型

    // Cache these to prevent repeated lookups
    $authors = array();
    $author_terms = array();

    $args = array(
            'order'            => 'ASC',
            'orderby'          => 'ID',
            'post_type'         => $coauthors_plus->supported_post_types,
            'posts_per_page'    => 100,
            'paged'             => 1,
            'update_meta_cache' => false,
        );

    $posts = new WP_Query( $args );
    $affected = 0;
    $count = 0;
    $total_posts = $posts->found_posts;
    WP_CLI::line( "Now inspecting or updating {$posts->found_posts} total posts." );
    while ( $posts->post_count ) {

        foreach ( $posts->posts as $single_post ) {

            $count++;

            $terms = wp_get_post_terms( $single_post->ID, $coauthors_plus->coauthor_taxonomy );
            if ( is_wp_error( $terms ) ) {
                WP_CLI::error( $terms->get_error_message() );
            }

            if ( ! empty( $terms ) ) {
                WP_CLI::line( "{$count}/{$posts->found_posts}) Skipping - Post #{$single_post->ID} '{$single_post->post_title}' already has these terms: " . implode( ', ', wp_list_pluck( $terms, 'name' ) ) );
                continue;
            }

            $author = ( ! empty( $authors[ $single_post->post_author ] ) ) ? $authors[ $single_post->post_author ] : get_user_by( 'id', $single_post->post_author );
            $authors[ $single_post->post_author ] = $author;

            $author_term = ( ! empty( $author_terms[ $single_post->post_author ] ) ) ? $author_terms[ $single_post->post_author ] : $coauthors_plus->update_author_term( $author );
            $author_terms[ $single_post->post_author ] = $author_term;

            wp_set_post_terms( $single_post->ID, array( $author_term->slug ), $coauthors_plus->coauthor_taxonomy );
            WP_CLI::line( "{$count}/{$total_posts}) Added - Post #{$single_post->ID} '{$single_post->post_title}' now has an author term for: " . $author->user_nicename );
            $affected++;
        }

        if ( $count && 0 === $count % 500 ) {
            $this->stop_the_insanity();
            sleep( 1 );
        }

        $args['paged']++;
        $posts = new WP_Query( $args );
    }
    WP_CLI::line( 'Updating author terms with new counts' );
    foreach ( $authors as $author ) {
        $coauthors_plus->update_author_term( $author );
    }

    WP_CLI::success( "Done! Of {$total_posts} posts, {$affected} now have author terms." );

}
`

我想删除一项要求,即帖子不需要有一个术语,这样最终的结果是新的合著者被附加到现有的作者身上

第二个变化是创建一个表单(可能在前端显示一个短代码),其中当前用户自动添加到字段中,并在表单提交时作为合著者提交

任何有关这方面的帮助都将不胜感激。谢谢