__( 'Permission denied.', 'quiztech' ) ], 403 ); } $job_id = isset( $_POST['job_id'] ) ? absint( $_POST['job_id'] ) : 0; $applicant_email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : ''; if ( ! $job_id || ! is_email( $applicant_email ) ) { wp_send_json_error( [ 'message' => __( 'Invalid Job ID or Email Address.', 'quiztech' ) ] ); } // Get linked assessment ID $assessment_id = get_post_meta( $job_id, '_quiztech_linked_assessment_id', true ); // Corrected meta key if ( empty( $assessment_id ) || 'assessment' !== get_post_type( $assessment_id ) ) { wp_send_json_error( [ 'message' => __( 'No valid assessment linked to this job.', 'quiztech' ) ] ); } $invitations = new Invitations(); $token_or_error = $invitations->create_invitation( $job_id, $assessment_id, $applicant_email ); if ( is_wp_error( $token_or_error ) ) { wp_send_json_error( [ 'message' => $token_or_error->get_error_message() ] ); } $token = $token_or_error; $email_sent = $invitations->send_invitation_email( $applicant_email, $token, [ 'job_title' => get_the_title( $job_id ) ] ); // Pass job title if ( $email_sent ) { wp_send_json_success( [ 'message' => __( 'Invitation sent successfully!', 'quiztech' ) ] ); } else { // Note: create_invitation succeeded, but email failed. Might want specific handling. wp_send_json_error( [ 'message' => __( 'Invitation created, but email failed to send. Check SMTP settings.', 'quiztech' ) ] ); } } /** * Enqueues admin scripts and styles for the Job edit screen. * * @param string $hook_suffix The current admin page hook. */ public function enqueue_admin_scripts( $hook_suffix ) { // Script enqueue logic will go here (Step 7) global $post_type; if ( 'job' === $post_type && ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) ) { $script_url = plugin_dir_url( QUIZTECH_PLUGIN_FILE ) . 'admin/js/job-metabox.js'; $script_local_path = plugin_dir_path( QUIZTECH_PLUGIN_FILE ) . 'admin/js/job-metabox.js'; // File system path $script_asset_path = plugin_dir_path( QUIZTECH_PLUGIN_FILE ) . 'admin/js/job-metabox.asset.php'; $script_asset = file_exists( $script_asset_path ) ? require( $script_asset_path ) : [ 'dependencies' => [], 'version' => file_exists( $script_local_path ) ? filemtime( $script_local_path ) : QUIZTECH_VERSION ]; // Use filemtime with local path wp_enqueue_script( 'quiztech-job-metabox-script', $script_url, // Use the URL here for enqueuing array_merge( $script_asset['dependencies'], [ 'jquery' ] ), // Add jquery dependency $script_asset['version'], true // Load in footer ); // Pass data to the script wp_localize_script( 'quiztech-job-metabox-script', 'quiztechJobMetabox', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'quiztech_send_invite_nonce_ajax' ), 'job_id' => get_the_ID(), // Get current post ID 'sending_text' => __( 'Sending...', 'quiztech' ), 'error_text' => __( 'Error:', 'quiztech' ), 'ajax_fail_text' => __( 'AJAX request failed.', 'quiztech' ), ]); } } }