WordPress.org

Forums

How plugings are parsed? (5 posts)

  1. johannesfosseus
    Member
    Posted 4 years ago #

    Hi all

    Trying to understand the parsing processes of plugins, please help me?

    It seems to me that all "plugin code" is parsed at every page/post/backend request, is that correct?

    I noticed this when building an backed plugin that created warnings in the front-end, that confuses me. I want my back-end plug code to run, yes in the backend.

    Or if I want a plugin on the frontpage, does all the code get parsed on pages and other post_types?

    all the best // Johannes

  2. jkovis
    Member
    Posted 4 years ago #

    have you tried adding a conditionals like:

    if( is_admin() ) {
      // run some admin only plugin code here
    }

    or

    if( get_post_type() == 'book' ) {
      // run some 'book' post type code here
    }
  3. johannesfosseus
    Member
    Posted 4 years ago #

    Hi jkovis, and thank you for the reply!

    Yes, that is good thinking, but does that mean that the code wont get parsed? I guess no?

    That means that the methods/functions inside that block will not be executed? The php-file will still get loaded at every request, or do I miss something important?

    If (for example) my codebase get large I rather load only the files I need to execute the things I want.

    Please lead me to the correct way :-)

    regards // Johannes

  4. David Gwyer
    Member
    Posted 4 years ago #

    Yes, from my understanding the Plugin file will still get loaded but once it hits the conditional it will either run/not run depending on the condition (i.e. will be ignored).

    Say you only wanted a block of code to be parsed if it is in the admin section of WordPress then you could use something like:

    if( is_admin() ) {
      // run some admin only plugin code here
    }

    as jkovis pointed out.

  5. johannesfosseus
    Member
    Posted 4 years ago #

    ok, thank you both!

    regards // johannes

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags