to dirprocess: writing plugins                                         rev 5 nov 2021

Category: web:cms:cp/wp:plugins

 * include files with the usual include, require.

 *  defining paths:
      plugin_dir_path( __FILE__ )
        - returns the trailing slash in the filepath.
        - will output relative to the current file you call it from,
            so if your include statement is done from a subdirectory
            inside your plugin file structure you'll get the subdirectory
            back too.
         - gives relative path

      useful to define plugin directory at beginning:
        define( 'PLUGIN_DIR', dirname(__FILE__).'/' );

* Plugins are loaded before themes. 
    You can confirm that here: Plugin API/Action Reference « WordPress Codex 

    You can get around this by having your plugin register your
    custom post type(s) during the init action:

add_action( 'init', function() {
    $args = [
        'labels' => $labels,
        'public' => true,
        'supports' => apply_filters( "something/goes/here/supports/portfolio", [ 'title', 'editor', 'thumbnail' ],
    // call register_post_type() here
} );

Then, the load order will work like this: 

  - Plugin loads and adds code to init action
  - Theme loads and theme functions.php runs

  - init action runs, and your plugin code executes here

  - Then your theme can call 
      add_filter( 'something/goes/here/supports/portfolio', ... ) 
    in functions.php and it will work as expected.


begin 26 oct 2019
-- 0 --