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 <noreply@anthropic.com>
This commit is contained in:
@@ -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' ) );
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user