Y
Y
Yuri Yanin2016-11-23 06:10:49
CMS
Yuri Yanin, 2016-11-23 06:10:49

How are additional pages created in Wordpress plugins?

I came to the conclusion that it is better to implement most things right away through the creation of plugins. I started to research the issue and got stuck on this topic:
I created the main page of the plugin through add_menu_page and also created the submenu add_submenu_page. Both functions are displayed in the admin, but I need to create a page like custom post types, where I could create new elements and on which they would be displayed and worked with in the future. From what I could understand myself, this kind of page works via GET if I'm not mistaken (I looked at the example of creating tags in a post and changing the url line), that is, as I understand it, it just
outputs what is asked for and no standard function WP doesn't have such pages to sculpt and everything is done through php processing?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Yanchevsky, 2016-11-23
@deniscopro

If I understand correctly, you need custom post types and custom taxonomies .
Comment code:

add_action('init', 'register_posttype');
function register_posttype() {
        $labels = array(
            'name' => __('Shortcodes', 'dco-sm'),
            'singular_name' => __('Shortcode', 'dco-sm'),
            'menu_name' => __('Shortcodes', 'dco-sm'),
            'all_items' => __('DCO Shortcodes Menu', 'dco-sm'),
            'add_new' => __('Add New', 'dco-sm'),
            'add_new_item' => __('Add New Shortcode', 'dco-sm'),
            'edit' => __('Edit'),
            'edit_item' => __('Edit Shortcode', 'dco-sm'),
            'new_item' => __('New Shortcode', 'dco-sm'),
            'view' => __('View', 'dco-sm'),
            'view_item' => __('View Shortcode', 'dco-sm'),
            'search_items' => __('Search Shortcode', 'dco-sm'),
            'not_found' => __('No Shortcodes found', 'dco-sm'),
            'not_found_in_trash' => __('No Shortcodes found in Trash', 'dco-sm'),
        );

        $args = array(
            'labels' => $labels,
            'description' => __('Custom post type for DCO Shortcodes Menu', 'dco-sm'),
            'public' => false,
            'show_ui' => true,
            'show_in_rest' => false,
            'has_archive' => false,
            'show_in_menu' => 'myplugin-admin.php',
            'show_in_admin_bar' => false,
            'exclude_from_search' => false,
            'capability_type' => 'post',
            'map_meta_cap' => true,
            'hierarchical' => false,
            'rewrite' => false,
            'query_var' => false,
            'supports' => array('title'),
        );
        register_post_type('dco_shortcode', $args);
    }

function wpdocs_register_my_custom_menu_page() {
    add_menu_page(
        __( 'Custom Menu Title', 'textdomain' ),
        'custom menu',
        'manage_options',
        'myplugin-admin.php',
        '',
        plugins_url( 'myplugin/images/icon.png' ),
        6
    );
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );

Screenshot of the admin .

I
Igor Vorotnev, 2016-11-23
@HeadOnFire

Well, you either work through Custom Post Type / Custom Taxonomy, with their native pages and UI, or make your own pages and build your tables using the WP_List_Table class class . Why bother with a hybrid of a rhinoceros and a hippopotamus? Or explain the specific use case of your plugin, because it seems to me that you are still doing something wrong due to a lack of understanding of the core of WP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question