WP Meta Description Updater

I recent made a plugin and it has been working till today: The meta descriptions seem not be updating here is my code snippet // Handle File Upload and Processing add_action( 'admin_init', 'md_updater_handle_file_upload' ) function md_updater_handle_file_upload() { if ( isset( $_POST['md_updater_nonce_field'] ) && wp_verify_nonce( $_POST['md_updater_nonce_field'], 'md_updater_nonce' ) && isset( $_FILES['md_csv_file'] ) && current_user_can( 'manage_options' ) ) { $csv_file = $_FILES['md_csv_file']; // Check for upload errors if ( $csv_file['error'] !== UPLOAD_ERR_OK ) { add_action( 'admin_notices', 'md_updater_upload_error_notice' ); return; } // Validate file type $file_type = wp_check_filetype( $csv_file['name'] ); if ( $file_type['ext'] !== 'csv' ) { add_action( 'admin_notices', 'md_updater_invalid_file_notice' ); return; } // Process the CSV file $file_tmp_path = $csv_file['tmp_name']; $csv_data = array_map( 'str_getcsv', file( $file_tmp_path ) ); // Remove header row if present $header = $csv_data[0]; if ( $header[0] === 'Type' ) { array_shift( $csv_data ); } foreach ( $csv_data as $row ) { // Assuming columns: Type, ID, Title/Name, URL, Meta Description $type = sanitize_text_field( $row[0] ); $id = intval( $row[1] ); // $title_or_name = sanitize_text_field( $row[2] ); // Not used in import // $url = esc_url_raw( $row[3] ); // Not used in import $meta_description = sanitize_text_field( $row[4] ); if ( ( $meta_description ) ) { if ( in_array( $type, array( 'post', 'page' ), true ) && $id > 0 ) { // Update post meta update_post_meta( $id, '_yoast_wpseo_metadesc', $meta_description ); } elseif ( taxonomy_exists( $type ) && $id > 0 ) { // Update term meta update_term_meta( $id, '_yoast_wpseo_metadesc', $meta_description ); } } } add_action( 'admin_notices', 'md_updater_success_notice' ); } } I need fresh eyes to spot any potential errors that could be affecting meta description update. Any input will do right now, super appreciated!

Comment (0)

You’ll be in good company