From 0bef634eb8bfba22fd1c134e1a2022507db00223 Mon Sep 17 00:00:00 2001 From: Viktor Miller Date: Tue, 3 Feb 2026 17:29:23 +0900 Subject: [PATCH] fix: correct Formidable API usage and move activation hooks to top level - Replace non-existent FrmFormActionsController::create_action() with proper API - Use get_form_actions('wppost')->prepare_new() pattern - Affects job submission, edit, and deactivation forms - Move register_activation_hook() to main plugin file top level - WordPress requires activation hooks at bootstrap, not in plugins_loaded - Fixes missing page creation on plugin activation Co-Authored-By: Claude Sonnet 4.5 --- ddhh-job-manager.php | 4 + includes/class-ddhh-job-manager.php | 4 - includes/class-formidable.php | 144 +++++++--------------------- 3 files changed, 40 insertions(+), 112 deletions(-) diff --git a/ddhh-job-manager.php b/ddhh-job-manager.php index 857bb49..7e73a63 100644 --- a/ddhh-job-manager.php +++ b/ddhh-job-manager.php @@ -47,6 +47,10 @@ require_once DDHH_JM_PLUGIN_DIR . 'includes/class-user-preferences.php'; require_once DDHH_JM_PLUGIN_DIR . 'includes/class-scheduler.php'; require_once DDHH_JM_PLUGIN_DIR . 'includes/class-ddhh-job-manager.php'; +// Register activation and deactivation hooks (must be at top level). +register_activation_hook( __FILE__, array( 'DDHH_JM_Activator', 'activate' ) ); +register_deactivation_hook( __FILE__, array( 'DDHH_JM_Deactivator', 'deactivate' ) ); + /** * Initialize the plugin. */ diff --git a/includes/class-ddhh-job-manager.php b/includes/class-ddhh-job-manager.php index 0035d27..b9cec0a 100644 --- a/includes/class-ddhh-job-manager.php +++ b/includes/class-ddhh-job-manager.php @@ -43,10 +43,6 @@ class DDHH_JM_Job_Manager { * Initialize hooks */ private function init_hooks() { - // Register activation and deactivation hooks - register_activation_hook( DDHH_JM_PLUGIN_FILE, array( 'DDHH_JM_Activator', 'activate' ) ); - register_deactivation_hook( DDHH_JM_PLUGIN_FILE, array( 'DDHH_JM_Deactivator', 'deactivate' ) ); - // Initialize post types add_action( 'init', array( 'DDHH_JM_Post_Types', 'register' ) ); diff --git a/includes/class-formidable.php b/includes/class-formidable.php index c829d1b..634d67d 100644 --- a/includes/class-formidable.php +++ b/includes/class-formidable.php @@ -867,49 +867,21 @@ class DDHH_JM_Formidable { // Create the Create Post action if ( ! empty( $field_ids ) ) { - $action_values = array( - 'menu_order' => 1, - 'post_status' => 'published', - 'post_content' => array( - 'post_type' => 'job_offer', - 'post_status' => 'pending', - 'post_title' => $field_ids['job_title'], - 'post_content' => $field_ids['job_description'], - 'post_author' => 'current_user', - 'post_custom_fields' => array( - array( - 'meta_name' => 'job_location', - 'field_id' => $field_ids['job_location'], - ), - array( - 'meta_name' => 'job_type', - 'field_id' => $field_ids['job_type'], - ), - array( - 'meta_name' => 'job_deadline', - 'field_id' => $field_ids['job_deadline'], - ), - array( - 'meta_name' => 'job_contact_email', - 'field_id' => $field_ids['job_contact_email'], - ), - array( - 'meta_name' => 'job_logo', - 'field_id' => $field_ids['job_logo'], - ), - ), - ), - ); - - // Create the form action using the proper API - FrmFormActionsController::create_action( - $form_id, - array( - 'post_excerpt' => 'wppost', - 'post_content' => $action_values, - 'menu_order' => 1, - ) + $action_control = FrmFormActionsController::get_form_actions( 'wppost' ); + $new_action = $action_control->prepare_new( $form_id ); + $new_action->post_content['post_type'] = 'job_offer'; + $new_action->post_content['post_status'] = 'pending'; + $new_action->post_content['post_title'] = $field_ids['job_title']; + $new_action->post_content['post_content'] = $field_ids['job_description']; + $new_action->post_content['post_author'] = 'current_user'; + $new_action->post_content['post_custom_fields'] = array( + array( 'meta_name' => 'job_location', 'field_id' => $field_ids['job_location'] ), + array( 'meta_name' => 'job_type', 'field_id' => $field_ids['job_type'] ), + array( 'meta_name' => 'job_deadline', 'field_id' => $field_ids['job_deadline'] ), + array( 'meta_name' => 'job_contact_email', 'field_id' => $field_ids['job_contact_email'] ), + array( 'meta_name' => 'job_logo', 'field_id' => $field_ids['job_logo'] ), ); + $action_control->save_settings( $new_action ); } } @@ -1037,49 +1009,21 @@ class DDHH_JM_Formidable { // Create the Update Post action if ( ! empty( $field_ids ) ) { - $action_values = array( - 'menu_order' => 1, - 'post_status' => 'published', - 'post_content' => array( - 'post_type' => 'job_offer', - 'post_status' => 'pending', - 'post_title' => $field_ids['job_title'], - 'post_content' => $field_ids['job_description'], - 'post_id' => 'id_param', - 'post_custom_fields' => array( - array( - 'meta_name' => 'job_location', - 'field_id' => $field_ids['job_location'], - ), - array( - 'meta_name' => 'job_type', - 'field_id' => $field_ids['job_type'], - ), - array( - 'meta_name' => 'job_deadline', - 'field_id' => $field_ids['job_deadline'], - ), - array( - 'meta_name' => 'job_contact_email', - 'field_id' => $field_ids['job_contact_email'], - ), - array( - 'meta_name' => 'job_logo', - 'field_id' => $field_ids['job_logo'], - ), - ), - ), - ); - - // Create the form action using the proper API - FrmFormActionsController::create_action( - $form_id, - array( - 'post_excerpt' => 'wppost', - 'post_content' => $action_values, - 'menu_order' => 1, - ) + $action_control = FrmFormActionsController::get_form_actions( 'wppost' ); + $new_action = $action_control->prepare_new( $form_id ); + $new_action->post_content['post_type'] = 'job_offer'; + $new_action->post_content['post_status'] = 'pending'; + $new_action->post_content['post_title'] = $field_ids['job_title']; + $new_action->post_content['post_content'] = $field_ids['job_description']; + $new_action->post_content['post_id'] = 'id_param'; + $new_action->post_content['post_custom_fields'] = array( + array( 'meta_name' => 'job_location', 'field_id' => $field_ids['job_location'] ), + array( 'meta_name' => 'job_type', 'field_id' => $field_ids['job_type'] ), + array( 'meta_name' => 'job_deadline', 'field_id' => $field_ids['job_deadline'] ), + array( 'meta_name' => 'job_contact_email', 'field_id' => $field_ids['job_contact_email'] ), + array( 'meta_name' => 'job_logo', 'field_id' => $field_ids['job_logo'] ), ); + $action_control->save_settings( $new_action ); } } @@ -1251,31 +1195,15 @@ class DDHH_JM_Formidable { // Create the Update Post action if ( ! empty( $field_ids ) ) { - $action_values = array( - 'menu_order' => 1, - 'post_status' => 'published', - 'post_content' => array( - 'post_type' => 'job_offer', - 'post_status' => 'draft', - 'post_id' => 'id_param', - 'post_custom_fields' => array( - array( - 'meta_name' => 'job_deactivation_reason', - 'field_id' => $field_ids['deactivation_reason'], - ), - ), - ), - ); - - // Create the form action using the proper API - FrmFormActionsController::create_action( - $form_id, - array( - 'post_excerpt' => 'wppost', - 'post_content' => $action_values, - 'menu_order' => 1, - ) + $action_control = FrmFormActionsController::get_form_actions( 'wppost' ); + $new_action = $action_control->prepare_new( $form_id ); + $new_action->post_content['post_type'] = 'job_offer'; + $new_action->post_content['post_status'] = 'draft'; + $new_action->post_content['post_id'] = 'id_param'; + $new_action->post_content['post_custom_fields'] = array( + array( 'meta_name' => 'job_deactivation_reason', 'field_id' => $field_ids['deactivation_reason'] ), ); + $action_control->save_settings( $new_action ); } }