-
Notifications
You must be signed in to change notification settings - Fork 5
Post Factory Class
The post factory class Cf7_2_Post_Factory (file: includes/class-cf7-2-post-factory.php) is used both in the front-end and back-end processes to control the posts to which the forms are mapped to.
The factory class differentiates between system posts and custom posts.
these are existing posts created by the WordPress core or other plugins/themes. These are not managed by the factory and therefore does not allow any post configurations to be done by the user. However, new meta fields can be added to these posts.
these are posts that created and managed by the factory. Users can map a form to a new post, configure the label/name and other post attributes (that control the way the post is viewed/queried/access rights and so on), create meta fields as well as taxonomies.
Handled by function Cf7_2_Post_Factory::create_cf7_post_type()
Once a post is created its registration properties are stored as meta fields in the wpcf7_contact_form post form it is mapped to as meta-fields.
-
_cf7_2_post-prefixed, these store the post/taxonomy registration parameters. -
cf7_2_post_map-prefixed, these store the form fields mapped to the post fields (title/content/excerpt/author/slug) -
cf7_2_post_map_meta-prefixed, these store the form fields mapped to post meta-fields. -
cf7_2_post_map_taxonomy-prefixed, these store the form fields mapped to taxonomies.
All posts created by the factory need to be registered for each WordPress request as these are now an integral part of the setup.
The function Cf7_2_Post_Factory::register_cf7_post_maps is hooked on init.
It fetches all the created posts by calling Cf7_2_Post_Factory::get_mapped_post_types which returns a list of post IDs corresponding to wpcf7_contact_form post that are mapped to posts that have been created by the factory.
For each form IDs a factory object is initialised Cf7_2_Post_System::get_factory($post_id), which will fetch all the meta-fields associated with the mapping parameters Cf7_2_Post_Factory::load_post_mapping.
TODO/v5.0 - Cf7_2_Post_System class should be removed altogether, and its functionality integrated into the Cf7_2_Post_Factory
Handled by function Cf7_2_Post_Factory::save_form_2_post()
The mapping edit is currently done using a custom page,
wp-admin/admin.php?page=map_cf7_2_post&id=135&action=edit
The admin handling class method Cf7_2_Post_Admin::ajax_save_post_mapping() is called when an Ajax request is made to save form mapping properties, this in turns calls the system factory class method Cf7_2_Post_System::save($_POST) where $_POST is the edit mapping page submission. This in turns redirects to Cf7_2_Post_Factory::save_form_2_post() for handling custom posts created by the plugin.
TODO/v5.0 - move this to a tab/panel in the form editing page using the CF7 plugin wpcf7_editor_panels hook.
TODO/v5.0 - remove the assets/cf-admin-table/ in order to simplify the plugin.
TODO/v5.0 - remove admin/partials/cf72post-footer-script.php which hides the CF7 plugin menu.
Moving the map edit functionality to the form edit page will make the process more intuitive and accessible, furthermore, the additional files assets/cf-admin-table/ which re-draw the CF7 form table to use the WP core wp-admin/post.php file can be removed to ease the maintenance of the plugin.
Currently the custom posts created by the plugin are stored in the corresponding form meta-fields, however, it would be cleaner and more efficient to store this in a general plugin options array. This would ease the custom post registration on each init requests, rather than loading all the forms that are mapped. This will remove all the _cf7_2_post- meta-fields. It will require an update process to ensure forms are upgraded properly to the new meta-structure.
TODO/v5.0 - move the _cf7_2_post- meta-fields custom post form from mappings to the plugin options settings.
TODO/v5.0 - create an update process by storing the new version in a plugin options settings in order to determine if this update process has been completed in a previous update.
TODO/v5.0 - load and register custom-posts properties from the plugin options.
Handled by function Cf7_2_Post_Factory::save_form_2_post() saves the form submission to its mapped post type and fields, loading the form meta-fields to determine the saving process.