Displaying Custom Data

This is my mind dump on how to use the boiler plate for a custom plugin type. This is based on the worked example Now Hiring by Chris Wilcoxson.

Adding data

  • includes\class_pgn.php::define_admin_hooks() creates the class pgn_admin which has the functions to create the custom type & taxomony and add the admin menu. register the class functions on hooks
  • admin/class_pgn_admin.php mostly the 2 functions to setup the custom post type and the taxonomy

Displaying data

steps involved in the process of showing entries of the CPT

  1. (includes\class_)pgn::define_template_hooks — add an action to load a template that does the work, see next item
  2. (public\nh-template-functions::template_loader — include the appropriate template using includes\now-hiring-global-functions::now_hiring_get_template(template-name)
  3. (includes\class_)pgn::define_public_hooks() : add a init hook to call the function register_shortcodes
  4. (public\class_)pgn_public::register_shortcodes add the shortcode to call a function in this class
  5. (public\class_)pgn_public::sc_action do the display work:
    • public\nh_public::list_openings
      • ob_start()
      • setup SC attributes including template name
      • includes\Now_Hiring_Shared::get_openings to get items
      • include public\templates\nh-loop
        • invoke action handlers registered in 1 passing thru the item and the meta
        • display the items requires the following templates
          • now-hiring-before-loop
          • now-hiring-before-loop-content
          • now-hiring-loop-content
          • now-hiring-after-loop-content
          • now-hiring-after-loop
      • get the output
      • clean up
      • return output

How it works

  • (includes\class_)pgn::define_public_hooks() call from constructor and create class pgn_public and does the following
    • sets up the single using add_filter -> ‘single_template’ with call back in public\pgn-public::single_cpt_template
    • registers shortcodes, see below
  • (includes\class_) pgn:: define_template_hooks() call from constructor and add_action all different parts of the template, call back functions defined in pgn_Template_Functions
  • (public\class_) pgn_Template_Functions is a series of functions that include pgn_get_template(template name)
  • (includes\pgn_global_functions) locates the requested template file, looks in the theme first then in the plugin

Displaying – registering a short code

  • Includes\class_pgn.php Pgn::constructor calls Pgn:: define_public_hooks()
  • Pgn:: define_public_hooks()
    • $this->loader->add_action( ‘init’, $plugin_public, ‘register_shortcodes’ ) — registers the short codes
    • $this->loader->add_action( ‘nowhiring’, $plugin_public, ‘do_something’ ) — registers callback function

Leave a Reply

Your email address will not be published. Required fields are marked *