Disable gps during flying and in the specific conditions

hi I want to stopping using gps during flying in some conditions : “if sat count under the 10 , if the control mode is auto or rtl , if the plane is arming and if the gps hdop error is too high”. I am doing it inside Arduplane.cpp file with force_disable function and its stop using gps and make its status to no_fix but after that it doens`t getting using gps even in the all condiotions.How can i do stop using gps just in the conditions of above?

You could try using a Lua script to change the AHRS_GPS_USE parameter.