Как создать собственную страницу исполнителя с помощью специального плагина в WordPress - PullRequest
0 голосов
/ 07 февраля 2020

Я исследую больше и использую код .. Я сделал этот код.

if (!defined('ABSPATH')) {
    die;
}
if(!class_exists('ArtistPublic')):
class ArtistPublic
{
    public static function createTemplate( ) {

        global $user_ID;
            $new_post = array(
                'post_title' => 'Artist',
                'post_content' => 'hello Artist',
                'post_status' => 'publish',
                'post_date' => date('Y-m-d H:i:s'),
                'post_author' => $user_ID,
                'post_type' => 'page',
            );
            $post_id = wp_insert_post($new_post);
            if( !$post_id )
                wp_die('Error creating template page');
            else
                update_post_meta( $post_id, '_wp_page_template', 'artist.php' );
        // Filter page template
//        add_filter('page_template', 'catch_plugin_template');


    }


    // Page template filter callback
    public static function catch_plugin_template($template) {
        if( is_page_template('artist.php') )
            $template = WP_PLUGIN_DIR . '/ItgArtist/public/templates/artist.php';
        return $template;
    }
    }
endif;

, но создать несколько страниц после refre sh. Есть ли хороший способ создать страницу, как это делает woocommerce ??

1 Ответ

0 голосов
/ 07 февраля 2020

Так что код будет похож на что-то

if (!defined('ABSPATH')) {
    die;
}

if(!class_exists('ArtistPublic')):
class ArtistPublic {
    public static function createTemplate( ) {    
        if( get_option('artist_page_id') ) :
            global $user_ID;
            $new_post = array(
                'post_title' => 'Artist',
                'post_content' => 'hello Artist',
                'post_status' => 'publish',
                'post_date' => date('Y-m-d H:i:s'),
                'post_author' => $user_ID,
                'post_type' => 'page',
            );
            $post_id = wp_insert_post($new_post);
            if( !$post_id ) :
                wp_die('Error creating template page');
            else :
                update_option('artist_page_id', $post_id);
                update_post_meta( $post_id, '_wp_page_template', 'artist.php' );
            endif;
        endif;
        // Filter page template
//        add_filter('page_template', 'catch_plugin_template');
    }
    // Page template filter callback
    public static function catch_plugin_template($template) {
        if( is_page_template('artist.php') )
            $template = WP_PLUGIN_DIR . '/ItgArtist/public/templates/artist.php';
        return $template;
    }
}
endif;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...