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.
      plugin_dir_path(__DIR__)
         - gives relative path
    http://codex.wordpress.org/Function_Reference/plugin_dir_path
    http://codex.wordpress.org/Determining_Plugin_and_Content_Directories

      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.

  -- https://forums.classicpress.net/t/custom-post-types-supports-while-using-apply-filters-and-add-filter/3729


_______________________________________________________
begin 26 oct 2019
-- 0 --