• When I develop a plugin, usually I need frontend page for him. I do the following:

    add_action ( 'the_content', 'myCatchFunction');
    
    function myCatchFunction($content) {
        $slug = 'myslug';
        if (get_post(get_the_ID())->post_name == $slug) {
            //do action
        }
    }

    and for the custom post types:

    add_filter( 'template_include', 'myCatchFunction', 1 );
    
    function myCatchFunction( $template_path ) {
        $slug = 'post_type_slug';
        if ( get_post_type() == $slug ) {
            //do action
        }
    }

    When I use first method, I need to create a page, and this is not good, because if I disactivate a module, I need to disactivate a page too.

    Is this is the one solution or there is another method without page creating?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There are various ways to insert content into various parts of a typical page. Sometimes it’s theme dependent, but nearly all themes tend to fire certain hooks like ‘wp_head’ and ‘wp_footer’. Sometimes creating a custom page is the best approach. It depends on the nature of your plugin. There isn’t ons single “best” approach.

    I don’t consider creating a page that serious an encroachment, though I agree it should be avoided if possible. You likely would not delete the page if your plugin is deactivated. Upon activation when you normally add the page, you can check if it already exists first. The time to remove the page is when your plugin is deleted. The deletion routine can fail to work if the user does not use the plugins screen to remove your plugin. Nothing to be done about that, but it’s only an extra row in the posts table, not the worst thing to have happen.

Viewing 1 replies (of 1 total)
  • The topic ‘What is action to show plugin page’ is closed to new replies.