Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@

/**
* Include the TGM_Plugin_Activation class.
*
* Depending on your implementation, you may want to change the include call:
*
* Parent Theme:
* require_once get_template_directory() . '/path/to/class-tgm-plugin-activation.php';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this - parent themes can call get_stylesheet_directory() too, since template dir = stylesheet dir in parent themes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, however, not applicable in this case.

If no child theme is being loaded, the get_stylesheet_directory() would be fine as WP will detect that there is no child theme and return the parent theme directory.

If a parent theme uses TGMPA and a child theme of that parent is the loaded theme, things would go very wrong with the include call. This is not a url/path which is being passed to a get_template_part() call, after all, but a hard file include.

To demonstrate, take this example set up:

/wp-content/themes/
    - /parent-theme
        - /vendor/tgmpa/tgm-plugin-activation.php
    - /child-theme
        - does not include tgmpa

The get_template_directory() function would return /path/to/wp-content/themes/parent-theme.
The get_stylesheet_directory() function would return /path/to/wp-content/themes/child-theme.

If the parent theme would include the file using get_stylesheet_directory(), this would result in a fatal file not found error.

*
* Child Theme:
* require_once get_stylesheet_directory() . '/path/to/class-tgm-plugin-activation.php';
*
* Plugin:
* require_once dirname( __FILE__ ) . '/path/to/class-tgm-plugin-activation.php';
*/
require_once dirname( __FILE__ ) . '/class-tgm-plugin-activation.php';

add_action( 'tgmpa_register', 'my_theme_register_required_plugins' );

/**
* Register the required plugins for this theme.
*
Expand Down